|
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 82-223
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec3
|
| 82 |
// endY. |
83 |
// endY. |
| 83 |
void copyRowNTimes(int startX, int endX, int startY, int endY) |
84 |
void copyRowNTimes(int startX, int endX, int startY, int endY) |
| 84 |
{ |
85 |
{ |
| 85 |
ASSERT(startX < width()); |
86 |
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 |
} |
87 |
} |
| 94 |
|
88 |
|
| 95 |
// Allocates space for the pixel data. Must be called before any pixels |
89 |
// Allocates space for the pixel data. Must be called before any pixels |
| 96 |
// are written. Must only be called once. Returns whether allocation |
90 |
// are written. Must only be called once. Returns whether allocation |
| 97 |
// succeeded. |
91 |
// succeeded. |
| 98 |
bool setSize(int newWidth, int newHeight); |
92 |
bool setSize(const IntSize&); |
|
|
93 |
IntSize size() const { return m_backingStore->size(); } |
| 99 |
|
94 |
|
| 100 |
// Returns a caller-owned pointer to the underlying native image data. |
95 |
// Returns a caller-owned pointer to the underlying native image data. |
| 101 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
96 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
| 102 |
// FrameData::clear()). |
97 |
// FrameData::clear()). |
| 103 |
NativeImagePtr asNewNativeImage() const; |
98 |
NativeImagePtr asNewNativeImage() const { return m_backingStore->image(); } |
| 104 |
|
99 |
|
|
|
100 |
inline ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; } |
| 101 |
inline bool hasBackingStore() const { return backingStore(); } |
| 102 |
|
| 105 |
bool hasAlpha() const; |
103 |
bool hasAlpha() const; |
| 106 |
const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
104 |
IntRect originalFrameRect() const { return m_backingStore ? m_backingStore->frameRect() : IntRect(); } |
| 107 |
FrameStatus status() const { return m_status; } |
105 |
FrameStatus status() const { return m_status; } |
| 108 |
unsigned duration() const { return m_duration; } |
106 |
unsigned duration() const { return m_duration; } |
| 109 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
107 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
| 110 |
bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
108 |
bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
| 111 |
|
109 |
|
|
|
110 |
void setBackingStore(const ImageBackingStore*); |
| 111 |
|
| 112 |
void setHasAlpha(bool alpha); |
112 |
void setHasAlpha(bool alpha); |
| 113 |
void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
113 |
void setOriginalFrameRect(const IntRect&); |
| 114 |
void setStatus(FrameStatus status); |
114 |
void setStatus(FrameStatus status); |
| 115 |
void setDuration(unsigned duration) { m_duration = duration; } |
115 |
void setDuration(unsigned duration) { m_duration = duration; } |
| 116 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
116 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
| 117 |
void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = premultiplyAlpha; } |
117 |
void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = premultiplyAlpha; } |
| 118 |
|
118 |
|
| 119 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
119 |
inline RGBA32* getAddr(int x, int y) |
| 120 |
{ |
|
|
| 121 |
setRGBA(getAddr(x, y), r, g, b, a); |
| 122 |
} |
| 123 |
|
| 124 |
inline PixelData* getAddr(int x, int y) |
| 125 |
{ |
| 126 |
return m_bytes + (y * width()) + x; |
| 127 |
} |
| 128 |
|
| 129 |
inline bool hasPixelData() const |
| 130 |
{ |
120 |
{ |
| 131 |
return m_bytes; |
121 |
return m_backingStore->at(x, y); |
| 132 |
} |
122 |
} |
| 133 |
|
123 |
|
| 134 |
// Use fix point multiplier instead of integer division or floating point math. |
124 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
| 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 |
{ |
125 |
{ |
| 141 |
return (fixed * v) >> fixPointShift; |
126 |
m_backingStore->setRGBA(x, y, r, g, b, a); |
| 142 |
} |
127 |
} |
| 143 |
|
128 |
|
| 144 |
inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
129 |
inline void setRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 145 |
{ |
130 |
{ |
| 146 |
if (m_premultiplyAlpha && a < 255) { |
131 |
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 |
} |
132 |
} |
| 159 |
|
133 |
|
| 160 |
#if ENABLE(APNG) |
134 |
#if ENABLE(APNG) |
| 161 |
static inline unsigned divide255(unsigned a) |
135 |
inline void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 162 |
{ |
136 |
{ |
| 163 |
return (a + (a >> 8) + 1) >> 8; |
137 |
m_backingStore->overRGBA(dest, r, g, b, a); |
| 164 |
} |
|
|
| 165 |
|
| 166 |
inline void overRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 167 |
{ |
| 168 |
if (!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 |
} |
138 |
} |
| 200 |
#endif |
139 |
#endif |
| 201 |
|
140 |
|
| 202 |
private: |
141 |
private: |
| 203 |
int width() const |
142 |
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; |
143 |
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; |
144 |
FrameStatus m_status; |
| 222 |
unsigned m_duration; |
145 |
unsigned m_duration; |
| 223 |
FrameDisposalMethod m_disposalMethod; |
146 |
FrameDisposalMethod m_disposalMethod; |
|
Lines 287-297
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec4
|
| 287 |
|
210 |
|
| 288 |
// Returns whether the size is legal (i.e. not going to result in |
211 |
// Returns whether the size is legal (i.e. not going to result in |
| 289 |
// overflow elsewhere). If not, marks decoding as failed. |
212 |
// overflow elsewhere). If not, marks decoding as failed. |
| 290 |
virtual bool setSize(unsigned width, unsigned height) |
213 |
virtual bool setSize(const IntSize& size) |
| 291 |
{ |
214 |
{ |
| 292 |
if (isOverSize(width, height)) |
215 |
if (ImageBackingStore::isOverSize(size)) |
| 293 |
return setFailed(); |
216 |
return setFailed(); |
| 294 |
m_size = IntSize(width, height); |
217 |
m_size = size; |
| 295 |
m_sizeAvailable = true; |
218 |
m_sizeAvailable = true; |
| 296 |
return true; |
219 |
return true; |
| 297 |
} |
220 |
} |
|
Lines 386-400
using ColorProfile = Vector<char>;
Source/WebCore/platform/image-decoders/ImageDecoder.h_sec5
|
| 386 |
ImageOrientation m_orientation; |
309 |
ImageOrientation m_orientation; |
| 387 |
|
310 |
|
| 388 |
private: |
311 |
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; |
312 |
IntSize m_size; |
| 399 |
bool m_sizeAvailable { false }; |
313 |
bool m_sizeAvailable { false }; |
| 400 |
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |
314 |
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |