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

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

Issue 1460523002: GIF decoding to Index8, unit tests and misusing unit test as benchmark (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup. tableChanged was wrong - do proper check. Created 5 years, 1 month 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 12 matching lines...) Expand all
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/Assertions.h" 34 #include "wtf/Assertions.h"
34 #include "wtf/PassRefPtr.h" 35 #include "wtf/PassRefPtr.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 // ImageFrame represents the decoded image data. This buffer is what all 39 // ImageFrame represents the decoded image data. This buffer is what all
39 // decoders write a single frame into. 40 // decoders write a single frame into.
40 class PLATFORM_EXPORT ImageFrame { 41 class PLATFORM_EXPORT ImageFrame {
41 public: 42 public:
42 enum Status { FrameEmpty, FramePartial, FrameComplete }; 43 enum Status { FrameEmpty, FramePartial, FrameComplete };
(...skipping 16 matching lines...) Expand all
59 enum AlphaBlendSource { 60 enum AlphaBlendSource {
60 // Blend non-opaque pixels atop the corresponding pixels in the 61 // Blend non-opaque pixels atop the corresponding pixels in the
61 // initial buffer state (i.e. any previous frame buffer after having 62 // initial buffer state (i.e. any previous frame buffer after having
62 // been properly disposed). 63 // been properly disposed).
63 BlendAtopPreviousFrame, 64 BlendAtopPreviousFrame,
64 65
65 // Blend non-opaque pixels against fully transparent (i.e. simply 66 // Blend non-opaque pixels against fully transparent (i.e. simply
66 // overwrite the corresponding pixels). 67 // overwrite the corresponding pixels).
67 BlendAtopBgcolor, 68 BlendAtopBgcolor,
68 }; 69 };
70 enum ColorType {
71 N32 = kN32_SkColorType,
72 Index8 = kIndex_8_SkColorType
73 };
69 typedef uint32_t PixelData; 74 typedef uint32_t PixelData;
75 typedef uint8_t PixelData8;
70 76
71 ImageFrame(); 77 ImageFrame();
72 78
73 // The assignment operator reads m_hasAlpha (inside setStatus()) before it 79 // The assignment operator reads m_hasAlpha (inside setStatus()) before it
74 // sets it (in setHasAlpha()). This doesn't cause any problems, since the 80 // 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 81 // 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 82 // need to initialize m_hasAlpha to some value before calling the operator
77 // lest any tools complain about using an uninitialized value. 83 // lest any tools complain about using an uninitialized value.
78 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other); } 84 ImageFrame(const ImageFrame& other) : m_hasAlpha(false) { operator=(other); }
79 85
80 // For backends which refcount their data, this operator doesn't need to 86 // For backends which refcount their data, this operator doesn't need to
81 // create a new copy of the image data, only increase the ref count. 87 // create a new copy of the image data, only increase the ref count.
82 ImageFrame& operator=(const ImageFrame& other); 88 ImageFrame& operator=(const ImageFrame& other);
83 89
84 // These do not touch other metadata, only the raw pixel data. 90 // These do not touch other metadata, only the raw pixel data.
85 void clearPixelData(); 91 void clearPixelData();
86 void zeroFillPixelData(); 92 void zeroFillPixelData();
87 void zeroFillFrameRect(const IntRect&); 93 void zeroFillFrameRect(const IntRect&);
88 94
89 // Makes this frame have an independent copy of the provided image's 95 // Makes this frame have an independent copy of the provided image's
90 // pixel data, so that modifications in one frame are not reflected in 96 // pixel data, so that modifications in one frame are not reflected in
91 // the other. Returns whether the copy succeeded. 97 // the other. Returns whether the copy succeeded.
92 bool copyBitmapData(const ImageFrame&); 98 bool copyBitmapData(const ImageFrame&);
99 bool copyBitmapData(const ImageFrame&, ImageFrame::ColorType);
93 100
94 // Copies the pixel data at [(startX, startY), (endX, startY)) to the 101 // Copies the pixel data at [(startX, startY), (endX, startY)) to the
95 // same X-coordinates on each subsequent row up to but not including 102 // same X-coordinates on each subsequent row up to but not including
96 // endY. 103 // endY.
97 void copyRowNTimes(int startX, int endX, int startY, int endY) 104 void copyRowNTimes(int startX, int endX, int startY, int endY)
98 { 105 {
99 ASSERT(startX < width()); 106 ASSERT(startX < width());
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. Must only be called once. Returns whether allocation
111 // succeeded. 118 // succeeded.
112 bool setSize(int newWidth, int newHeight); 119 bool setSize(int newWidth, int newHeight);
120 bool setSizeIndex8(int newWidth, int newHeight, const Vector<blink::ImageFra me::PixelData>& colorMap, size_t indexOfTransparent = kNotFound);
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 inline PixelData8* getAddr8(int x, int y)
158 {
159 return m_bitmap.getAddr8(x, y);
160 }
161
149 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a) 162 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsign ed a)
150 { 163 {
151 setRGBA(getAddr(x, y), r, g, b, a); 164 setRGBA(getAddr(x, y), r, g, b, a);
152 } 165 }
153 166
154 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a) 167 inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, uns igned a)
155 { 168 {
156 if (m_premultiplyAlpha) 169 if (m_premultiplyAlpha)
157 setRGBAPremultiply(dest, r, g, b, a); 170 setRGBAPremultiply(dest, r, g, b, a);
158 else 171 else
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // The frame that must be decoded before this frame can be decoded. 227 // The frame that must be decoded before this frame can be decoded.
215 // WTF::kNotFound if this frame doesn't require any previous frame. 228 // WTF::kNotFound if this frame doesn't require any previous frame.
216 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never 229 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never
217 // be read for image formats that do not have multiple frames. 230 // be read for image formats that do not have multiple frames.
218 size_t m_requiredPreviousFrameIndex; 231 size_t m_requiredPreviousFrameIndex;
219 }; 232 };
220 233
221 } // namespace blink 234 } // namespace blink
222 235
223 #endif 236 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698