|
Lines 28-33
a/Source/WebCore/platform/image-decoders/ImageDecoder.h_sec1
|
| 28 |
|
28 |
|
| 29 |
#pragma once |
29 |
#pragma once |
| 30 |
|
30 |
|
|
|
31 |
#include "BitmapPixels.h" |
| 31 |
#include "IntRect.h" |
32 |
#include "IntRect.h" |
| 32 |
#include "ImageSource.h" |
33 |
#include "ImageSource.h" |
| 33 |
#include "PlatformScreen.h" |
34 |
#include "PlatformScreen.h" |
|
Lines 57-63
using ColorProfile = Vector<char>;
a/Source/WebCore/platform/image-decoders/ImageDecoder.h_sec2
|
| 57 |
DisposeOverwritePrevious // Clear frame to previous framebuffer |
58 |
DisposeOverwritePrevious // Clear frame to previous framebuffer |
| 58 |
// contents |
59 |
// contents |
| 59 |
}; |
60 |
}; |
| 60 |
typedef unsigned PixelData; |
|
|
| 61 |
|
61 |
|
| 62 |
ImageFrame(); |
62 |
ImageFrame(); |
| 63 |
|
63 |
|
|
Lines 80-109
using ColorProfile = Vector<char>;
a/Source/WebCore/platform/image-decoders/ImageDecoder.h_sec3
|
| 80 |
// Copies the pixel data at [(startX, startY), (endX, startY)) to the |
80 |
// Copies the pixel data at [(startX, startY), (endX, startY)) to the |
| 81 |
// same X-coordinates on each subsequent row up to but not including |
81 |
// same X-coordinates on each subsequent row up to but not including |
| 82 |
// endY. |
82 |
// endY. |
| 83 |
void copyRowNTimes(int startX, int endX, int startY, int endY) |
83 |
void copyRowNTimes(int startX, int endX, int startY, int endY); |
| 84 |
{ |
|
|
| 85 |
ASSERT(startX < width()); |
| 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 |
} |
| 94 |
|
84 |
|
| 95 |
// Allocates space for the pixel data. Must be called before any pixels |
85 |
// Allocates space for the pixel data. Must be called before any pixels |
| 96 |
// are written. Must only be called once. Returns whether allocation |
86 |
// are written. Must only be called once. Returns whether allocation |
| 97 |
// succeeded. |
87 |
// succeeded. |
| 98 |
bool setSize(int newWidth, int newHeight); |
88 |
bool setSize(int newWidth, int newHeight); |
|
|
89 |
|
| 90 |
IntSize size() const { return m_pixels->size(); } |
| 99 |
|
91 |
|
| 100 |
// Returns a caller-owned pointer to the underlying native image data. |
92 |
// Returns a caller-owned pointer to the underlying native image data. |
| 101 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
93 |
// (Actual use: This pointer will be owned by BitmapImage and freed in |
| 102 |
// FrameData::clear()). |
94 |
// FrameData::clear()). |
| 103 |
NativeImagePtr asNewNativeImage() const; |
95 |
NativeImagePtr asNewNativeImage() const { return m_pixels->image(); } |
|
|
96 |
|
| 97 |
inline BitmapPixels* pixels() const { return m_pixels ? m_pixels.get() : nullptr; } |
| 98 |
inline bool hasPixels() const { return pixels(); } |
| 104 |
|
99 |
|
| 105 |
bool hasAlpha() const; |
100 |
bool hasAlpha() const; |
| 106 |
const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
|
|
| 107 |
FrameStatus status() const { return m_status; } |
101 |
FrameStatus status() const { return m_status; } |
| 108 |
unsigned duration() const { return m_duration; } |
102 |
unsigned duration() const { return m_duration; } |
| 109 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
103 |
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
|
Lines 111-117
using ColorProfile = Vector<char>;
a/Source/WebCore/platform/image-decoders/ImageDecoder.h_sec4
|
| 111 |
|
105 |
|
| 112 |
void setHasAlpha(bool alpha); |
106 |
void setHasAlpha(bool alpha); |
| 113 |
void setColorProfile(const ColorProfile&); |
107 |
void setColorProfile(const ColorProfile&); |
| 114 |
void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
|
|
| 115 |
void setStatus(FrameStatus status); |
108 |
void setStatus(FrameStatus status); |
| 116 |
void setDuration(unsigned duration) { m_duration = duration; } |
109 |
void setDuration(unsigned duration) { m_duration = duration; } |
| 117 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
110 |
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
|
Lines 119-226
using ColorProfile = Vector<char>;
a/Source/WebCore/platform/image-decoders/ImageDecoder.h_sec5
|
| 119 |
|
112 |
|
| 120 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
113 |
inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a) |
| 121 |
{ |
114 |
{ |
| 122 |
setRGBA(getAddr(x, y), r, g, b, a); |
115 |
m_pixels->setRGBA(x, y, r, g, b, a); |
| 123 |
} |
116 |
} |
| 124 |
|
117 |
|
| 125 |
inline PixelData* getAddr(int x, int y) |
118 |
inline RGBA32* getAddr(int x, int y) |
| 126 |
{ |
119 |
{ |
| 127 |
return m_bytes + (y * width()) + x; |
120 |
return m_pixels->at(x, y); |
| 128 |
} |
121 |
} |
| 129 |
|
122 |
|
| 130 |
inline bool hasPixelData() const |
123 |
inline void setRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 131 |
{ |
124 |
{ |
| 132 |
return m_bytes; |
125 |
m_pixels->setRGBA(dest, r, g, b, a); |
| 133 |
} |
|
|
| 134 |
|
| 135 |
// Use fix point multiplier instead of integer division or floating point math. |
| 136 |
// This multipler produces exactly the same result for all values in range 0 - 255. |
| 137 |
static const unsigned fixPointShift = 24; |
| 138 |
static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 * (1 << fixPointShift)) + 1; |
| 139 |
// Multiplies unsigned value by fixpoint value and converts back to unsigned. |
| 140 |
static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v) |
| 141 |
{ |
| 142 |
return (fixed * v) >> fixPointShift; |
| 143 |
} |
| 144 |
|
| 145 |
inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 146 |
{ |
| 147 |
if (m_premultiplyAlpha && a < 255) { |
| 148 |
if (!a) { |
| 149 |
*dest = 0; |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
unsigned alphaMult = a * fixPointMult; |
| 154 |
r = fixPointUnsignedMultiply(r, alphaMult); |
| 155 |
g = fixPointUnsignedMultiply(g, alphaMult); |
| 156 |
b = fixPointUnsignedMultiply(b, alphaMult); |
| 157 |
} |
| 158 |
*dest = (a << 24 | r << 16 | g << 8 | b); |
| 159 |
} |
126 |
} |
| 160 |
|
127 |
|
| 161 |
#if ENABLE(APNG) |
128 |
#if ENABLE(APNG) |
| 162 |
static inline unsigned divide255(unsigned a) |
129 |
inline void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 163 |
{ |
130 |
{ |
| 164 |
return (a + (a >> 8) + 1) >> 8; |
131 |
m_pixels->overRGBA(dest, r, g, b, a); |
| 165 |
} |
|
|
| 166 |
|
| 167 |
inline void overRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a) |
| 168 |
{ |
| 169 |
if (!a) |
| 170 |
return; |
| 171 |
|
| 172 |
if (a < 255) { |
| 173 |
unsigned aDest = ((*dest) >> 24) & 255; |
| 174 |
if (aDest) { |
| 175 |
unsigned rDest = ((*dest) >> 16) & 255; |
| 176 |
unsigned gDest = ((*dest) >> 8) & 255; |
| 177 |
unsigned bDest = (*dest) & 255; |
| 178 |
unsigned aAux = 255 - a; |
| 179 |
if (!m_premultiplyAlpha) { |
| 180 |
rDest = divide255(rDest * aDest); |
| 181 |
gDest = divide255(gDest * aDest); |
| 182 |
bDest = divide255(bDest * aDest); |
| 183 |
} |
| 184 |
r = divide255(r * a + rDest * aAux); |
| 185 |
g = divide255(g * a + gDest * aAux); |
| 186 |
b = divide255(b * a + bDest * aAux); |
| 187 |
a += divide255(aDest * aAux); |
| 188 |
if (!m_premultiplyAlpha) { |
| 189 |
r = (r * 255 + a - 1) / a; |
| 190 |
g = (g * 255 + a - 1) / a; |
| 191 |
b = (b * 255 + a - 1) / a; |
| 192 |
} |
| 193 |
} else if (m_premultiplyAlpha) { |
| 194 |
r = divide255(r * a); |
| 195 |
g = divide255(g * a); |
| 196 |
b = divide255(b * a); |
| 197 |
} |
| 198 |
} |
| 199 |
*dest = (a << 24 | r << 16 | g << 8 | b); |
| 200 |
} |
132 |
} |
| 201 |
#endif |
133 |
#endif |
| 202 |
|
134 |
|
| 203 |
private: |
135 |
private: |
| 204 |
int width() const |
136 |
std::unique_ptr<BitmapPixels> m_pixels; |
| 205 |
{ |
|
|
| 206 |
return m_size.width(); |
| 207 |
} |
| 208 |
|
137 |
|
| 209 |
int height() const |
|
|
| 210 |
{ |
| 211 |
return m_size.height(); |
| 212 |
} |
| 213 |
|
| 214 |
Vector<PixelData> m_backingStore; |
| 215 |
PixelData* m_bytes; // The memory is backed by m_backingStore. |
| 216 |
IntSize m_size; |
| 217 |
// FIXME: Do we need m_colorProfile anymore? |
138 |
// FIXME: Do we need m_colorProfile anymore? |
| 218 |
ColorProfile m_colorProfile; |
139 |
ColorProfile m_colorProfile; |
| 219 |
bool m_hasAlpha; |
140 |
bool m_hasAlpha; |
| 220 |
IntRect m_originalFrameRect; // This will always just be the entire |
|
|
| 221 |
// buffer except for GIF frames whose |
| 222 |
// original rect was smaller than the |
| 223 |
// overall image size. |
| 224 |
FrameStatus m_status; |
141 |
FrameStatus m_status; |
| 225 |
unsigned m_duration; |
142 |
unsigned m_duration; |
| 226 |
FrameDisposalMethod m_disposalMethod; |
143 |
FrameDisposalMethod m_disposalMethod; |