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" | |
scroggo_chromium
2016/04/29 19:48:14
Why is this needed? I don't think you're using any
| |
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; | |
scroggo_chromium
2016/04/29 19:48:14
nit: 8 just tells me that this is 8 bit, but not t
| |
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&); |
96 void zeroFillFrameRectIndex8(const IntRect&, unsigned char transparentIndex) ; | |
scroggo_chromium
2016/04/29 19:48:14
I'm not a big fan of this name. Although the inten
| |
90 | 97 |
91 // Makes this frame have an independent copy of the provided image's | 98 // 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 | 99 // pixel data, so that modifications in one frame are not reflected in |
93 // the other. Returns whether the copy succeeded. | 100 // the other. Returns whether the copy succeeded. |
94 bool copyBitmapData(const ImageFrame&); | 101 bool copyBitmapData(const ImageFrame&); |
95 | 102 bool copyBitmapData(const ImageFrame&, ImageFrame::ColorType); |
96 // Copies the pixel data at [(startX, startY), (endX, startY)) to the | |
97 // same X-coordinates on each subsequent row up to but not including | |
98 // endY. | |
99 void copyRowNTimes(int startX, int endX, int startY, int endY) | |
100 { | |
101 ASSERT(startX < width()); | |
102 ASSERT(endX <= width()); | |
103 ASSERT(startY < height()); | |
104 ASSERT(endY <= height()); | |
105 const int rowBytes = (endX - startX) * sizeof(PixelData); | |
106 const PixelData* const startAddr = getAddr(startX, startY); | |
107 for (int destY = startY + 1; destY < endY; ++destY) | |
108 memcpy(getAddr(startX, destY), startAddr, rowBytes); | |
109 } | |
110 | 103 |
111 // Allocates space for the pixel data. Must be called before any pixels | 104 // Allocates space for the pixel data. Must be called before any pixels |
112 // are written. Must only be called once. Returns whether allocation | 105 // are written. Must only be called once. Returns whether allocation |
113 // succeeded. | 106 // succeeded. |
114 bool setSize(int newWidth, int newHeight); | 107 bool setSize(int newWidth, int newHeight, SkColor background = 0); |
scroggo_chromium
2016/04/29 19:48:14
I think it would be clearer to use SK_ColorTRANSPA
| |
108 bool setSizeIndex8(int newWidth, int newHeight, const Vector<blink::ImageFra me::PixelData>& colorMap, unsigned backgroundIndex, bool backgroundIsTransparent = true); | |
115 | 109 |
116 // Returns a caller-owned pointer to the underlying native image data. | 110 // Returns a caller-owned pointer to the underlying native image data. |
117 // (Actual use: This pointer will be owned by BitmapImage and freed in | 111 // (Actual use: This pointer will be owned by BitmapImage and freed in |
118 // FrameData::clear()). | 112 // FrameData::clear()). |
119 const SkBitmap& bitmap() const; | 113 const SkBitmap& bitmap() const; |
120 | 114 |
121 bool hasAlpha() const; | 115 bool hasAlpha() const; |
122 const IntRect& originalFrameRect() const { return m_originalFrameRect; } | 116 const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
123 Status status() const { return m_status; } | 117 Status status() const { return m_status; } |
124 unsigned duration() const { return m_duration; } | 118 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 | 135 // 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. | 136 // (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; } | 137 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged; } |
144 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr eviousFrameIndex = previousFrameIndex; } | 138 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr eviousFrameIndex = previousFrameIndex; } |
145 | 139 |
146 inline PixelData* getAddr(int x, int y) | 140 inline PixelData* getAddr(int x, int y) |
147 { | 141 { |
148 return m_bitmap.getAddr32(x, y); | 142 return m_bitmap.getAddr32(x, y); |
149 } | 143 } |
150 | 144 |
145 inline PixelData8* getAddr8(int x, int y) | |
146 { | |
147 return m_bitmap.getAddr8(x, y); | |
148 } | |
149 | |
151 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a) | 150 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a) |
152 { | 151 { |
153 setRGBA(getAddr(x, y), r, g, b, a); | 152 setRGBA(getAddr(x, y), r, g, b, a); |
154 } | 153 } |
155 | 154 |
156 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a) | 155 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a) |
157 { | 156 { |
158 if (m_premultiplyAlpha) | 157 if (m_premultiplyAlpha) |
159 setRGBAPremultiply(dest, r, g, b, a); | 158 setRGBAPremultiply(dest, r, g, b, a); |
160 else | 159 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. | 215 // The frame that must be decoded before this frame can be decoded. |
217 // WTF::kNotFound if this frame doesn't require any previous frame. | 216 // WTF::kNotFound if this frame doesn't require any previous frame. |
218 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never | 217 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never |
219 // be read for image formats that do not have multiple frames. | 218 // be read for image formats that do not have multiple frames. |
220 size_t m_requiredPreviousFrameIndex; | 219 size_t m_requiredPreviousFrameIndex; |
221 }; | 220 }; |
222 | 221 |
223 } // namespace blink | 222 } // namespace blink |
224 | 223 |
225 #endif | 224 #endif |
OLD | NEW |