OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #ifndef ImageFrame_h | 27 #ifndef ImageFrame_h |
28 #define ImageFrame_h | 28 #define ImageFrame_h |
29 | 29 |
30 #include "platform/PlatformExport.h" | 30 #include "platform/PlatformExport.h" |
31 #include "platform/geometry/IntRect.h" | 31 #include "platform/geometry/IntRect.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "third_party/skia/include/core/SkColorPriv.h" |
33 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
34 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
35 #include "wtf/PassRefPtr.h" | 36 #include "wtf/PassRefPtr.h" |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 // ImageFrame represents the decoded image data. This buffer is what all | 40 // ImageFrame represents the decoded image data. This buffer is what all |
40 // decoders write a single frame into. | 41 // decoders write a single frame into. |
41 class PLATFORM_EXPORT ImageFrame final { | 42 class PLATFORM_EXPORT ImageFrame final { |
42 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 43 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
(...skipping 18 matching lines...) Expand all Loading... |
61 enum AlphaBlendSource { | 62 enum AlphaBlendSource { |
62 // Blend non-opaque pixels atop the corresponding pixels in the | 63 // Blend non-opaque pixels atop the corresponding pixels in the |
63 // initial buffer state (i.e. any previous frame buffer after having | 64 // initial buffer state (i.e. any previous frame buffer after having |
64 // been properly disposed). | 65 // been properly disposed). |
65 BlendAtopPreviousFrame, | 66 BlendAtopPreviousFrame, |
66 | 67 |
67 // Blend non-opaque pixels against fully transparent (i.e. simply | 68 // Blend non-opaque pixels against fully transparent (i.e. simply |
68 // overwrite the corresponding pixels). | 69 // overwrite the corresponding pixels). |
69 BlendAtopBgcolor, | 70 BlendAtopBgcolor, |
70 }; | 71 }; |
| 72 enum ColorType { |
| 73 N32 = kN32_SkColorType, |
| 74 Index8 = kIndex_8_SkColorType |
| 75 }; |
71 typedef uint32_t PixelData; | 76 typedef uint32_t PixelData; |
| 77 typedef uint8_t PixelData8; |
72 | 78 |
73 ImageFrame(); | 79 ImageFrame(); |
74 | 80 |
75 // The assignment operator reads m_hasAlpha (inside setStatus()) before it | 81 // The assignment operator reads m_hasAlpha (inside setStatus()) before it |
76 // sets it (in setHasAlpha()). This doesn't cause any problems, since the | 82 // sets it (in setHasAlpha()). This doesn't cause any problems, since the |
77 // setHasAlpha() call ensures all state is set correctly, but it means we | 83 // setHasAlpha() call ensures all state is set correctly, but it means we |
78 // need to initialize m_hasAlpha to some value before calling the operator | 84 // need to initialize m_hasAlpha to some value before calling the operator |
79 // lest any tools complain about using an uninitialized value. | 85 // lest any tools complain about using an uninitialized value. |
80 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other);
} | 86 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other);
} |
81 | 87 |
82 // For backends which refcount their data, this operator doesn't need to | 88 // For backends which refcount their data, this operator doesn't need to |
83 // create a new copy of the image data, only increase the ref count. | 89 // create a new copy of the image data, only increase the ref count. |
84 ImageFrame& operator=(const ImageFrame& other); | 90 ImageFrame& operator=(const ImageFrame& other); |
85 | 91 |
86 // These do not touch other metadata, only the raw pixel data. | 92 // These do not touch other metadata, only the raw pixel data. |
87 void clearPixelData(); | 93 void clearPixelData(); |
88 void zeroFillPixelData(); | 94 void zeroFillPixelData(); |
89 void zeroFillFrameRect(const IntRect&); | 95 void zeroFillFrameRect(const IntRect&); |
90 | 96 |
91 // Makes this frame have an independent copy of the provided image's | 97 // Makes this frame have an independent copy of the provided image's |
92 // pixel data, so that modifications in one frame are not reflected in | 98 // pixel data, so that modifications in one frame are not reflected in |
93 // the other. Returns whether the copy succeeded. | 99 // the other. Returns whether the copy succeeded. |
94 bool copyBitmapData(const ImageFrame&); | 100 bool copyBitmapData(const ImageFrame&); |
| 101 bool copyBitmapData(const ImageFrame&, ImageFrame::ColorType); |
95 | 102 |
96 // Copies the pixel data at [(startX, startY), (endX, startY)) to the | 103 // Copies the pixel data at [(startX, startY), (endX, startY)) to the |
97 // same X-coordinates on each subsequent row up to but not including | 104 // same X-coordinates on each subsequent row up to but not including |
98 // endY. | 105 // endY. |
99 void copyRowNTimes(int startX, int endX, int startY, int endY) | 106 void copyRowNTimes(int startX, int endX, int startY, int endY) |
100 { | 107 { |
101 ASSERT(startX < width()); | 108 ASSERT(startX < width()); |
102 ASSERT(endX <= width()); | 109 ASSERT(endX <= width()); |
103 ASSERT(startY < height()); | 110 ASSERT(startY < height()); |
104 ASSERT(endY <= height()); | 111 ASSERT(endY <= height()); |
105 const int rowBytes = (endX - startX) * sizeof(PixelData); | 112 const int rowBytes = (endX - startX) * sizeof(PixelData); |
106 const PixelData* const startAddr = getAddr(startX, startY); | 113 const PixelData* const startAddr = getAddr(startX, startY); |
107 for (int destY = startY + 1; destY < endY; ++destY) | 114 for (int destY = startY + 1; destY < endY; ++destY) |
108 memcpy(getAddr(startX, destY), startAddr, rowBytes); | 115 memcpy(getAddr(startX, destY), startAddr, rowBytes); |
109 } | 116 } |
110 | 117 |
111 // Allocates space for the pixel data. Must be called before any pixels | 118 // Allocates space for the pixel data. Must be called before any pixels |
112 // are written. Must only be called once. Returns whether allocation | 119 // are written. Must only be called once. Returns whether allocation |
113 // succeeded. | 120 // succeeded. |
114 bool setSize(int newWidth, int newHeight); | 121 bool setSize(int newWidth, int newHeight, SkColor background = 0); |
| 122 bool setSizeIndex8(int newWidth, int newHeight, const Vector<blink::ImageFra
me::PixelData>& colorMap, unsigned char backgroundIndex, bool backgroundIsTransp
arent = true); |
115 | 123 |
116 // Returns a caller-owned pointer to the underlying native image data. | 124 // Returns a caller-owned pointer to the underlying native image data. |
117 // (Actual use: This pointer will be owned by BitmapImage and freed in | 125 // (Actual use: This pointer will be owned by BitmapImage and freed in |
118 // FrameData::clear()). | 126 // FrameData::clear()). |
119 const SkBitmap& bitmap() const; | 127 const SkBitmap& bitmap() const; |
120 | 128 |
121 bool hasAlpha() const; | 129 bool hasAlpha() const; |
122 const IntRect& originalFrameRect() const { return m_originalFrameRect; } | 130 const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
123 Status status() const { return m_status; } | 131 Status status() const { return m_status; } |
124 unsigned duration() const { return m_duration; } | 132 unsigned duration() const { return m_duration; } |
(...skipping 16 matching lines...) Expand all Loading... |
141 // The pixelsChanged flag needs to be set when the raw pixel data was direct
ly modified | 149 // The pixelsChanged flag needs to be set when the raw pixel data was direct
ly modified |
142 // (e.g. through a pointer or setRGBA). The flag is usually set after a batc
h of changes was made. | 150 // (e.g. through a pointer or setRGBA). The flag is usually set after a batc
h of changes was made. |
143 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged;
} | 151 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged;
} |
144 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr
eviousFrameIndex = previousFrameIndex; } | 152 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr
eviousFrameIndex = previousFrameIndex; } |
145 | 153 |
146 inline PixelData* getAddr(int x, int y) | 154 inline PixelData* getAddr(int x, int y) |
147 { | 155 { |
148 return m_bitmap.getAddr32(x, y); | 156 return m_bitmap.getAddr32(x, y); |
149 } | 157 } |
150 | 158 |
| 159 inline PixelData8* getAddr8(int x, int y) |
| 160 { |
| 161 return m_bitmap.getAddr8(x, y); |
| 162 } |
| 163 |
151 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign
ed a) | 164 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign
ed a) |
152 { | 165 { |
153 setRGBA(getAddr(x, y), r, g, b, a); | 166 setRGBA(getAddr(x, y), r, g, b, a); |
154 } | 167 } |
155 | 168 |
156 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns
igned a) | 169 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns
igned a) |
157 { | 170 { |
158 if (m_premultiplyAlpha) | 171 if (m_premultiplyAlpha) |
159 setRGBAPremultiply(dest, r, g, b, a); | 172 setRGBAPremultiply(dest, r, g, b, a); |
160 else | 173 else |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // The frame that must be decoded before this frame can be decoded. | 229 // The frame that must be decoded before this frame can be decoded. |
217 // WTF::kNotFound if this frame doesn't require any previous frame. | 230 // WTF::kNotFound if this frame doesn't require any previous frame. |
218 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never | 231 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never |
219 // be read for image formats that do not have multiple frames. | 232 // be read for image formats that do not have multiple frames. |
220 size_t m_requiredPreviousFrameIndex; | 233 size_t m_requiredPreviousFrameIndex; |
221 }; | 234 }; |
222 | 235 |
223 } // namespace blink | 236 } // namespace blink |
224 | 237 |
225 #endif | 238 #endif |
OLD | NEW |