Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageFrame.h

Issue 1403393004: JPEGImageDecoder RGB565 and downsample support and related Skia imagegenerator changes Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 = kRGBA_8888_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 22 matching lines...) Expand all
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. Must only be called once. Returns whether allocation
111 // succeeded. 118 // succeeded.
112 bool setSize(int newWidth, int newHeight); 119 // called from decoder before start writing pixel data
scroggo_chromium 2015/10/19 20:41:36 I don't see how this says anything different from
aleksandar.stojiljkovic 2015/10/20 09:51:12 Updating it, "Must only be called once" is not nee
120 bool setSize(int newWidth, int newHeight, ColorType bitmapType = RGBA8888);
113 121
114 // Returns a caller-owned pointer to the underlying native image data. 122 // Returns a caller-owned pointer to the underlying native image data.
115 // (Actual use: This pointer will be owned by BitmapImage and freed in 123 // (Actual use: This pointer will be owned by BitmapImage and freed in
116 // FrameData::clear()). 124 // FrameData::clear()).
117 const SkBitmap& bitmap() const; 125 const SkBitmap& bitmap() const;
118 126
119 bool hasAlpha() const; 127 bool hasAlpha() const;
120 const IntRect& originalFrameRect() const { return m_originalFrameRect; } 128 const IntRect& originalFrameRect() const { return m_originalFrameRect; }
121 Status status() const { return m_status; } 129 Status status() const { return m_status; }
122 unsigned duration() const { return m_duration; } 130 unsigned duration() const { return m_duration; }
(...skipping 16 matching lines...) Expand all
139 // The pixelsChanged flag needs to be set when the raw pixel data was direct ly modified 147 // 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. 148 // (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; } 149 void setPixelsChanged(bool pixelsChanged) { m_pixelsChanged = pixelsChanged; }
142 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr eviousFrameIndex = previousFrameIndex; } 150 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requiredPr eviousFrameIndex = previousFrameIndex; }
143 151
144 inline PixelData* getAddr(int x, int y) 152 inline PixelData* getAddr(int x, int y)
145 { 153 {
146 return m_bitmap.getAddr32(x, y); 154 return m_bitmap.getAddr32(x, y);
147 } 155 }
148 156
157 template<class T>
158 inline T* getAddrT(int x, int y)
159 {
160 ASSERT_NOT_REACHED();
161 }
162
149 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a) 163 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a)
150 { 164 {
151 setRGBA(getAddr(x, y), r, g, b, a); 165 setRGBA(getAddr(x, y), r, g, b, a);
152 } 166 }
153 167
154 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a) 168 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a)
155 { 169 {
156 if (m_premultiplyAlpha) 170 if (m_premultiplyAlpha)
157 setRGBAPremultiply(dest, r, g, b, a); 171 setRGBAPremultiply(dest, r, g, b, a);
158 else 172 else
(...skipping 12 matching lines...) Expand all
171 } 185 }
172 186
173 *dest = SkPackARGB32NoCheck(a, r, g, b); 187 *dest = SkPackARGB32NoCheck(a, r, g, b);
174 } 188 }
175 189
176 static inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsig ned b, unsigned a) 190 static inline void setRGBARaw(PixelData* dest, unsigned r, unsigned g, unsig ned b, unsigned a)
177 { 191 {
178 *dest = SkPackARGB32NoCheck(a, r, g, b); 192 *dest = SkPackARGB32NoCheck(a, r, g, b);
179 } 193 }
180 194
195 static inline void setRGB565(PixelData16* dest, unsigned r, unsigned g, unsi gned b)
196 {
197 *dest = SkDitherPack888ToRGB16(r, g, b);
aleksandar.stojiljkovic 2015/10/19 18:17:09 Dither: Don't know if it makes sense to use ordere
198 }
199
181 // Notifies the SkBitmap if any pixels changed and resets the flag. 200 // Notifies the SkBitmap if any pixels changed and resets the flag.
182 inline void notifyBitmapIfPixelsChanged() 201 inline void notifyBitmapIfPixelsChanged()
183 { 202 {
184 if (m_pixelsChanged) 203 if (m_pixelsChanged)
185 m_bitmap.notifyPixelsChanged(); 204 m_bitmap.notifyPixelsChanged();
186 m_pixelsChanged = false; 205 m_pixelsChanged = false;
187 } 206 }
188 207
189 private: 208 private:
190 int width() const 209 int width() const
(...skipping 20 matching lines...) Expand all
211 // True if the pixels changed, but the bitmap has not yet been notified. 230 // True if the pixels changed, but the bitmap has not yet been notified.
212 bool m_pixelsChanged; 231 bool m_pixelsChanged;
213 232
214 // The frame that must be decoded before this frame can be decoded. 233 // The frame that must be decoded before this frame can be decoded.
215 // WTF::kNotFound if this frame doesn't require any previous frame. 234 // WTF::kNotFound if this frame doesn't require any previous frame.
216 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never 235 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never
217 // be read for image formats that do not have multiple frames. 236 // be read for image formats that do not have multiple frames.
218 size_t m_requiredPreviousFrameIndex; 237 size_t m_requiredPreviousFrameIndex;
219 }; 238 };
220 239
240 template<>
241 inline ImageFrame::PixelData* ImageFrame::getAddrT<ImageFrame::PixelData>(int x, int y)
242 {
243 return m_bitmap.getAddr32(x, y);
244 }
245
246 template<>
247 inline ImageFrame::PixelData16* ImageFrame::getAddrT<ImageFrame::PixelData16>(in t x, int y)
248 {
249 return m_bitmap.getAddr16(x, y);
250 }
251
221 } // namespace blink 252 } // namespace blink
222 253
223 #endif 254 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698