• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "ImageDecoder.h"
28 
29 #include <cairo.h>
30 
31 namespace WebCore {
32 
RGBA32Buffer()33 RGBA32Buffer::RGBA32Buffer()
34     : m_hasAlpha(false)
35     , m_status(FrameEmpty)
36     , m_duration(0)
37     , m_disposalMethod(DisposeNotSpecified)
38 {
39 }
40 
clear()41 void RGBA32Buffer::clear()
42 {
43     m_bytes.clear();
44     m_status = FrameEmpty;
45     // NOTE: Do not reset other members here; clearFrameBufferCache()
46     // calls this to free the bitmap data, but other functions like
47     // initFrameBuffer() and frameComplete() may still need to read
48     // other metadata out of this frame later.
49 }
50 
zeroFill()51 void RGBA32Buffer::zeroFill()
52 {
53     m_bytes.fill(0);
54     m_hasAlpha = true;
55 }
56 
copyBitmapData(const RGBA32Buffer & other)57 void RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other)
58 {
59     if (this == &other)
60         return;
61 
62     m_bytes = other.m_bytes;
63     m_size = other.m_size;
64     setHasAlpha(other.m_hasAlpha);
65 }
66 
setSize(int newWidth,int newHeight)67 bool RGBA32Buffer::setSize(int newWidth, int newHeight)
68 {
69     // NOTE: This has no way to check for allocation failure if the
70     // requested size was too big...
71     m_bytes.resize(newWidth * newHeight);
72     m_size = IntSize(newWidth, newHeight);
73 
74     // Zero the image.
75     zeroFill();
76 
77     return true;
78 }
79 
asNewNativeImage() const80 NativeImagePtr RGBA32Buffer::asNewNativeImage() const
81 {
82     return cairo_image_surface_create_for_data(
83         reinterpret_cast<unsigned char*>(const_cast<PixelData*>(
84             m_bytes.data())), CAIRO_FORMAT_ARGB32, width(), height(),
85         width() * sizeof(PixelData));
86 }
87 
hasAlpha() const88 bool RGBA32Buffer::hasAlpha() const
89 {
90     return m_hasAlpha;
91 }
92 
setHasAlpha(bool alpha)93 void RGBA32Buffer::setHasAlpha(bool alpha)
94 {
95     m_hasAlpha = alpha;
96 }
97 
setStatus(FrameStatus status)98 void RGBA32Buffer::setStatus(FrameStatus status)
99 {
100     m_status = status;
101 }
102 
operator =(const RGBA32Buffer & other)103 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
104 {
105     if (this == &other)
106         return *this;
107 
108     copyBitmapData(other);
109     setRect(other.rect());
110     setStatus(other.status());
111     setDuration(other.duration());
112     setDisposalMethod(other.disposalMethod());
113     return *this;
114 }
115 
width() const116 int RGBA32Buffer::width() const {
117     return m_size.width();
118 }
119 
height() const120 int RGBA32Buffer::height() const {
121     return m_size.height();
122 }
123 
124 } // namespace WebCore
125