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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 enum AlphaBlendSource { | 59 enum AlphaBlendSource { |
60 // Blend non-opaque pixels atop the corresponding pixels in the | 60 // Blend non-opaque pixels atop the corresponding pixels in the |
61 // initial buffer state (i.e. any previous frame buffer after having | 61 // initial buffer state (i.e. any previous frame buffer after having |
62 // been properly disposed). | 62 // been properly disposed). |
63 BlendAtopPreviousFrame, | 63 BlendAtopPreviousFrame, |
64 | 64 |
65 // Blend non-opaque pixels against fully transparent (i.e. simply | 65 // Blend non-opaque pixels against fully transparent (i.e. simply |
66 // overwrite the corresponding pixels). | 66 // overwrite the corresponding pixels). |
67 BlendAtopBgcolor, | 67 BlendAtopBgcolor, |
68 }; | 68 }; |
| 69 |
| 70 enum ColorType { |
| 71 RGBA8888 = kN32_SkColorType, |
| 72 RGB565 = kRGB_565_SkColorType |
| 73 }; |
| 74 |
69 typedef uint32_t PixelData; | 75 typedef uint32_t PixelData; |
| 76 typedef uint16_t PixelData16; |
70 | 77 |
71 ImageFrame(); | 78 ImageFrame(); |
72 | 79 |
73 // The assignment operator reads m_hasAlpha (inside setStatus()) before it | 80 // The assignment operator reads m_hasAlpha (inside setStatus()) before it |
74 // sets it (in setHasAlpha()). This doesn't cause any problems, since the | 81 // sets it (in setHasAlpha()). This doesn't cause any problems, since the |
75 // setHasAlpha() call ensures all state is set correctly, but it means we | 82 // setHasAlpha() call ensures all state is set correctly, but it means we |
76 // need to initialize m_hasAlpha to some value before calling the operator | 83 // need to initialize m_hasAlpha to some value before calling the operator |
77 // lest any tools complain about using an uninitialized value. | 84 // lest any tools complain about using an uninitialized value. |
78 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other);
} | 85 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other);
} |
79 | 86 |
(...skipping 20 matching lines...) Expand all Loading... |
100 ASSERT(endX <= width()); | 107 ASSERT(endX <= width()); |
101 ASSERT(startY < height()); | 108 ASSERT(startY < height()); |
102 ASSERT(endY <= height()); | 109 ASSERT(endY <= height()); |
103 const int rowBytes = (endX - startX) * sizeof(PixelData); | 110 const int rowBytes = (endX - startX) * sizeof(PixelData); |
104 const PixelData* const startAddr = getAddr(startX, startY); | 111 const PixelData* const startAddr = getAddr(startX, startY); |
105 for (int destY = startY + 1; destY < endY; ++destY) | 112 for (int destY = startY + 1; destY < endY; ++destY) |
106 memcpy(getAddr(startX, destY), startAddr, rowBytes); | 113 memcpy(getAddr(startX, destY), startAddr, rowBytes); |
107 } | 114 } |
108 | 115 |
109 // Allocates space for the pixel data. Must be called before any pixels | 116 // Allocates space for the pixel data. Must be called before any pixels |
110 // are written. Must only be called once. Returns whether allocation | 117 // are written. Returns whether allocation succeeded. |
111 // succeeded. | 118 bool setSize(int newWidth, int newHeight, ColorType bitmapType = RGBA8888); |
112 bool setSize(int newWidth, int newHeight); | 119 inline bool hasSize(const IntSize& size, ColorType bitmapType) const |
| 120 { |
| 121 // skip checking height, no stretching involved |
| 122 return (m_bitmap.width() == size.width()) && (bitmapType == static_cast<
ColorType>(m_bitmap.colorType())); |
| 123 } |
113 | 124 |
114 // Returns a caller-owned pointer to the underlying native image data. | 125 // Returns a caller-owned pointer to the underlying native image data. |
115 // (Actual use: This pointer will be owned by BitmapImage and freed in | 126 // (Actual use: This pointer will be owned by BitmapImage and freed in |
116 // FrameData::clear()). | 127 // FrameData::clear()). |
117 const SkBitmap& bitmap() const; | 128 const SkBitmap& bitmap() const; |
118 | 129 |
119 bool hasAlpha() const; | 130 bool hasAlpha() const; |
120 const IntRect& originalFrameRect() const { return m_originalFrameRect; } | 131 const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
121 Status status() const { return m_status; } | 132 Status status() const { return m_status; } |
122 unsigned duration() const { return m_duration; } | 133 unsigned duration() const { return m_duration; } |
(...skipping 16 matching lines...) Expand all Loading... |
139 // The pixelsChanged flag needs to be set when the raw pixel data was direct
ly modified | 150 // The pixelsChanged flag needs to be set when the raw pixel data was direct
ly modified |
140 // (e.g. through a pointer or setRGBA). The flag is usually set after a batc
h of changes was made. | 151 // (e.g. through a pointer or setRGBA). The flag is usually set after a batc
h of changes was made. |
141 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged;
} | 152 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged;
} |
142 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr
eviousFrameIndex = previousFrameIndex; } | 153 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr
eviousFrameIndex = previousFrameIndex; } |
143 | 154 |
144 inline PixelData* getAddr(int x, int y) | 155 inline PixelData* getAddr(int x, int y) |
145 { | 156 { |
146 return m_bitmap.getAddr32(x, y); | 157 return m_bitmap.getAddr32(x, y); |
147 } | 158 } |
148 | 159 |
| 160 template<class T> |
| 161 inline T* getAddrT(int x, int y) |
| 162 { |
| 163 ASSERT_NOT_REACHED(); |
| 164 } |
| 165 |
149 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign
ed a) | 166 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign
ed a) |
150 { | 167 { |
151 setRGBA(getAddr(x, y), r, g, b, a); | 168 setRGBA(getAddr(x, y), r, g, b, a); |
152 } | 169 } |
153 | 170 |
154 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns
igned a) | 171 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns
igned a) |
155 { | 172 { |
156 if (m_premultiplyAlpha) | 173 if (m_premultiplyAlpha) |
157 setRGBAPremultiply(dest, r, g, b, a); | 174 setRGBAPremultiply(dest, r, g, b, a); |
158 else | 175 else |
(...skipping 12 matching lines...) Expand all Loading... |
171 } | 188 } |
172 | 189 |
173 *dest = SkPackARGB32NoCheck(a, r, g, b); | 190 *dest = SkPackARGB32NoCheck(a, r, g, b); |
174 } | 191 } |
175 | 192 |
176 static inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsig
ned b, unsigned a) | 193 static inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsig
ned b, unsigned a) |
177 { | 194 { |
178 *dest = SkPackARGB32NoCheck(a, r, g, b); | 195 *dest = SkPackARGB32NoCheck(a, r, g, b); |
179 } | 196 } |
180 | 197 |
| 198 static inline void setRGB565(PixelData16* dest, unsigned r, unsigned g, unsi
gned b) |
| 199 { |
| 200 *dest = SkDitherPack888ToRGB16(r, g, b); |
| 201 } |
| 202 |
181 // Notifies the SkBitmap if any pixels changed and resets the flag. | 203 // Notifies the SkBitmap if any pixels changed and resets the flag. |
182 inline void notifyBitmapIfPixelsChanged() | 204 inline void notifyBitmapIfPixelsChanged() |
183 { | 205 { |
184 if (m_pixelsChanged) | 206 if (m_pixelsChanged) |
185 m_bitmap.notifyPixelsChanged(); | 207 m_bitmap.notifyPixelsChanged(); |
186 m_pixelsChanged = false; | 208 m_pixelsChanged = false; |
187 } | 209 } |
188 | 210 |
189 private: | 211 private: |
190 int width() const | 212 int width() const |
(...skipping 20 matching lines...) Expand all Loading... |
211 // True if the pixels changed, but the bitmap has not yet been notified. | 233 // True if the pixels changed, but the bitmap has not yet been notified. |
212 bool m_pixelsChanged; | 234 bool m_pixelsChanged; |
213 | 235 |
214 // The frame that must be decoded before this frame can be decoded. | 236 // The frame that must be decoded before this frame can be decoded. |
215 // WTF::kNotFound if this frame doesn't require any previous frame. | 237 // WTF::kNotFound if this frame doesn't require any previous frame. |
216 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never | 238 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never |
217 // be read for image formats that do not have multiple frames. | 239 // be read for image formats that do not have multiple frames. |
218 size_t m_requiredPreviousFrameIndex; | 240 size_t m_requiredPreviousFrameIndex; |
219 }; | 241 }; |
220 | 242 |
| 243 template<> |
| 244 inline ImageFrame::PixelData* ImageFrame::getAddrT<ImageFrame::PixelData>(int x,
int y) |
| 245 { |
| 246 return m_bitmap.getAddr32(x, y); |
| 247 } |
| 248 |
| 249 template<> |
| 250 inline ImageFrame::PixelData16* ImageFrame::getAddrT<ImageFrame::PixelData16>(in
t x, int y) |
| 251 { |
| 252 return m_bitmap.getAddr16(x, y); |
| 253 } |
| 254 |
221 } // namespace blink | 255 } // namespace blink |
222 | 256 |
223 #endif | 257 #endif |
OLD | NEW |