|
Lines 28-35
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec1
|
| 28 |
|
28 |
|
| 29 |
#pragma once |
29 |
#pragma once |
| 30 |
|
30 |
|
| 31 |
#include "IntRect.h" |
31 |
#include "ImageBackingStore.h" |
| 32 |
#include "ImageSource.h" |
32 |
#include "ImageSource.h" |
|
|
33 |
#include "IntRect.h" |
| 34 |
#include "IntSize.h" |
| 33 |
#include "PlatformScreen.h" |
35 |
#include "PlatformScreen.h" |
| 34 |
#include "SharedBuffer.h" |
36 |
#include "SharedBuffer.h" |
| 35 |
#include <wtf/Assertions.h> |
37 |
#include <wtf/Assertions.h> |
|
Lines 57-63
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec2
|
| 57 |
DisposeOverwritePrevious // Clear frame to previous framebuffer |
59 |
DisposeOverwritePrevious // Clear frame to previous framebuffer |
| 58 |
// contents |
60 |
// contents |
| 59 |
}; |
61 |
}; |
| 60 |
typedef unsigned PixelData; |
|
|
| 61 |
|
62 |
|
| 62 |
ImageFrame(); |
63 |
ImageFrame(); |
| 63 |
|
64 |
|
|
Lines 72-223
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec3
|
| 72 |
void zeroFillPixelData(); |
73 |
void zeroFillPixelData(); |
| 73 |
void zeroFillFrameRect(const IntRect&); |
74 |
void zeroFillFrameRect(const IntRect&); |
| 74 |
|
75 |
|
| 75 |
// Makes this frame have an independent copy of the provided image's |
|
|
| 76 |
// pixel data, so that modifications in one frame are not reflected in |
| 77 |
// the other. Returns whether the copy succeeded. |
| 78 |
bool copyBitmapData(const ImageFrame&); |
| 79 |
|
| 80 |
// Copies the pixel data at [(startX, startY), (endX, startY)) to the |
76 |
// Copies the pixel data at [(startX, startY), (endX, startY)) to the |
| 81 |
// same X-coordinates on each subsequent row up to but not including |
77 |
// same X-coordinates on each subsequent row up to but not including |
| 82 |
// endY. |
78 |
// endY. |
| 83 |
void copyRowNTimes(int startX, int endX, int startY, int endY) |
79 |
void copyRowNTimes(int startX, int endX, int startY, int endY) |
| 84 |
{ |
80 |
{ |
| 85 |
ASSERT(startX < width()); |
81 |
m_backingStore->repeatFirstRow(IntRect(startX, startY, endX -startX , endY - startY)); |
| 86 |
ASSERT(endX <= width()); |
|
|
| 87 |
ASSERT(startY < height()); |
| 88 |
ASSERT(endY <= height()); |
| 89 |
const int rowBytes = (endX - startX) * sizeof(PixelData); |
| 90 |
const PixelData* const startAddr = getAddr(startX, startY); |
| 91 |
for (int destY = startY + 1; destY < endY; ++destY) |
| 92 |
memcpy(getAddr(startX, destY), startAddr, rowBytes); |
| 93 |
} |
82 |
} |
| 94 |
|
83 |
|
| 95 |
// Allocates space for the pixel data. Must be called before any pixels |
84 |
// Allocates space for the pixel data. Must be called before any pixels |
| 96 |
// are written. Must only be called once. Returns whether allocation |
85 |
// are written. Must only be called once. Returns whether allocation |
| 97 |
// succeeded. |
86 |
// succeeded. |
| 98 |
bool setSize(int newWidth, int newHeight); |
87 |
bool setSize(const IntSize&, bool premultiplyAlpha); |
|
|
88 |
IntSize size() const { return m_backingStore->size(); } |
| 99 |
|
89 |
|
| 100 |
// Returns a caller-owned pointer to the underlying native image data. |
90 |
// Returns a caller-owned pointer to the underlying native image data. |
| 101 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
91 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
| 102 |
// FrameData::clear()). |
92 |
// FrameData::clear()). |
| 103 |
NativeImagePtr asNewNativeImage() const; |
93 |
NativeImagePtr asNewNativeImage() const { return m_backingStore->image(); } |
| 104 |
|
94 |
|
|
|
95 |
inline ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; } |
| 96 |
inline bool hasBackingStore() const { return backingStore(); } |
| 97 |
|
| 105 |
bool hasAlpha() const; |
98 |
bool hasAlpha() const; |
| 106 |
const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
99 |
const IntRect& originalFrameRect() const { return m_backingStore ? m_backingStore->frameRect() : IntRect(); } |
| 107 |
FrameStatus status() const { return m_status; } |
100 |
FrameStatus status() const { return m_status; } |
| 108 |
unsigned duration() const { return m_duration; } |
101 |
unsigned duration() const { return m_duration; } |
| 109 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
102 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
| 110 |
bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
103 |
bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
| 111 |
|
104 |
|
|
|
105 |
void setBackingStore(const ImageBackingStore*); |
| 106 |
|
| 112 |
void setHasAlpha(bool alpha); |
107 |
void setHasAlpha(bool alpha); |
| 113 |
void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
108 |
void setOriginalFrameRect(const IntRect&); |
| 114 |
void setStatus(FrameStatus status); |
109 |
void setStatus(FrameStatus status); |
| 115 |
void setDuration(unsigned duration) { m_duration = duration; } |
110 |
void setDuration(unsigned duration) { m_duration = duration; } |
| 116 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
111 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
| 117 |
void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = premultiplyAlpha; } |
112 |
void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = premultiplyAlpha; } |
| 118 |
|
113 |
|
| 119 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
114 |
inline RGBA32* getAddr(int x, int y) |
| 120 |
{ |
115 |
{ |
| 121 |
setRGBA(getAddr(x, y), r, g, b, a); |
116 |
return m_backingStore->at(x, y); |
| 122 |
} |
117 |
} |
| 123 |
|
118 |
|
| 124 |
inline PixelData* getAddr(int x, int y) |
119 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
| 125 |
{ |
|
|
| 126 |
return m_bytes + (y * width()) + x; |
| 127 |
} |
| 128 |
|
| 129 |
inline bool hasPixelData() const |
| 130 |
{ |
| 131 |
return m_bytes; |
| 132 |
} |
| 133 |
|
| 134 |
// Use fix point multiplier instead of integer division or floating point math. |
| 135 |
// This multipler produces exactly the same result for all values in range 0 - 255. |
| 136 |
static const unsigned fixPointShift = 24; |
| 137 |
static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 * (1 << fixPointShift)) + 1; |
| 138 |
// Multiplies unsigned value by fixpoint value and converts back to unsigned. |
| 139 |
static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v) |
| 140 |
{ |
120 |
{ |
| 141 |
return (fixed * v) >> fixPointShift; |
121 |
m_backingStore->setRGBA(x, y, r, g, b, a); |
| 142 |
} |
122 |
} |
| 143 |
|
123 |
|
| 144 |
inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
124 |
inline void setRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 145 |
{ |
125 |
{ |
| 146 |
if (m_premultiplyAlpha && a < 255) { |
126 |
m_backingStore->setRGBA(dest, r, g, b, a); |
| 147 |
if (!a) { |
|
|
| 148 |
*dest = 0; |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
unsigned alphaMult = a * fixPointMult; |
| 153 |
r = fixPointUnsignedMultiply(r, alphaMult); |
| 154 |
g = fixPointUnsignedMultiply(g, alphaMult); |
| 155 |
b = fixPointUnsignedMultiply(b, alphaMult); |
| 156 |
} |
| 157 |
*dest = (a << 24 | r << 16 | g << 8 | b); |
| 158 |
} |
127 |
} |
| 159 |
|
128 |
|
| 160 |
#if ENABLE(APNG) |
129 |
#if ENABLE(APNG) |
| 161 |
static inline unsigned divide255(unsigned a) |
130 |
inline void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 162 |
{ |
|
|
| 163 |
return (a + (a >> 8) + 1) >> 8; |
| 164 |
} |
| 165 |
|
| 166 |
inline void overRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 167 |
{ |
131 |
{ |
| 168 |
if (!a) |
132 |
m_backingStore->overRGBA(dest, r, g, b, a); |
| 169 |
return; |
|
|
| 170 |
|
| 171 |
if (a < 255) { |
| 172 |
unsigned aDest = ((*dest) >> 24) & 255; |
| 173 |
if (aDest) { |
| 174 |
unsigned rDest = ((*dest) >> 16) & 255; |
| 175 |
unsigned gDest = ((*dest) >> 8) & 255; |
| 176 |
unsigned bDest = (*dest) & 255; |
| 177 |
unsigned aAux = 255 - a; |
| 178 |
if (!m_premultiplyAlpha) { |
| 179 |
rDest = divide255(rDest * aDest); |
| 180 |
gDest = divide255(gDest * aDest); |
| 181 |
bDest = divide255(bDest * aDest); |
| 182 |
} |
| 183 |
r = divide255(r * a + rDest * aAux); |
| 184 |
g = divide255(g * a + gDest * aAux); |
| 185 |
b = divide255(b * a + bDest * aAux); |
| 186 |
a += divide255(aDest * aAux); |
| 187 |
if (!m_premultiplyAlpha) { |
| 188 |
r = (r * 255 + a - 1) / a; |
| 189 |
g = (g * 255 + a - 1) / a; |
| 190 |
b = (b * 255 + a - 1) / a; |
| 191 |
} |
| 192 |
} else if (m_premultiplyAlpha) { |
| 193 |
r = divide255(r * a); |
| 194 |
g = divide255(g * a); |
| 195 |
b = divide255(b * a); |
| 196 |
} |
| 197 |
} |
| 198 |
*dest = (a << 24 | r << 16 | g << 8 | b); |
| 199 |
} |
133 |
} |
| 200 |
#endif |
134 |
#endif |
| 201 |
|
135 |
|
| 202 |
private: |
136 |
private: |
| 203 |
int width() const |
137 |
std::unique_ptr<ImageBackingStore> m_backingStore; |
| 204 |
{ |
|
|
| 205 |
return m_size.width(); |
| 206 |
} |
| 207 |
|
| 208 |
int height() const |
| 209 |
{ |
| 210 |
return m_size.height(); |
| 211 |
} |
| 212 |
|
| 213 |
Vector<PixelData> m_backingStore; |
| 214 |
PixelData* m_bytes; // The memory is backed by m_backingStore. |
| 215 |
IntSize m_size; |
| 216 |
bool m_hasAlpha; |
138 |
bool m_hasAlpha; |
| 217 |
IntRect m_originalFrameRect; // This will always just be the entire |
|
|
| 218 |
// buffer except for GIF frames whose |
| 219 |
// original rect was smaller than the |
| 220 |
// overall image size. |
| 221 |
FrameStatus m_status; |
139 |
FrameStatus m_status; |
| 222 |
unsigned m_duration; |
140 |
unsigned m_duration; |
| 223 |
FrameDisposalMethod m_disposalMethod; |
141 |
FrameDisposalMethod m_disposalMethod; |
|
Lines 287-297
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec4
|
| 287 |
|
205 |
|
| 288 |
// Returns whether the size is legal (i.e. not going to result in |
206 |
// Returns whether the size is legal (i.e. not going to result in |
| 289 |
// overflow elsewhere). If not, marks decoding as failed. |
207 |
// overflow elsewhere). If not, marks decoding as failed. |
| 290 |
virtual bool setSize(unsigned width, unsigned height) |
208 |
virtual bool setSize(const IntSize& size) |
| 291 |
{ |
209 |
{ |
| 292 |
if (isOverSize(width, height)) |
210 |
if (ImageBackingStore::isOverSize(size)) |
| 293 |
return setFailed(); |
211 |
return setFailed(); |
| 294 |
m_size = IntSize(width, height); |
212 |
m_size = size; |
| 295 |
m_sizeAvailable = true; |
213 |
m_sizeAvailable = true; |
| 296 |
return true; |
214 |
return true; |
| 297 |
} |
215 |
} |
|
Lines 386-400
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec5
|
| 386 |
ImageOrientation m_orientation; |
304 |
ImageOrientation m_orientation; |
| 387 |
|
305 |
|
| 388 |
private: |
306 |
private: |
| 389 |
// Some code paths compute the size of the image as "width * height * 4" |
|
|
| 390 |
// and return it as a (signed) int. Avoid overflow. |
| 391 |
static bool isOverSize(unsigned width, unsigned height) |
| 392 |
{ |
| 393 |
unsigned long long total_size = static_cast<unsigned long long>(width) |
| 394 |
* static_cast<unsigned long long>(height); |
| 395 |
return total_size > ((1 << 29) - 1); |
| 396 |
} |
| 397 |
|
| 398 |
IntSize m_size; |
307 |
IntSize m_size; |
| 399 |
bool m_sizeAvailable { false }; |
308 |
bool m_sizeAvailable { false }; |
| 400 |
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |
309 |
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |