98
99
return m_image.get();
101
PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const
102
void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable)
104
bool isPainting = m_data.m_painter->isActive();
106
m_data.m_painter->end();
108
QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
109
ASSERT(!image.isNull());
111
for (int y = 0; y < m_size.height(); ++y) {
112
for (int x = 0; x < m_size.width(); x++) {
113
QRgb value = image.pixel(x, y);
114
value = qRgba(lookUpTable[qRed(value)],
115
lookUpTable[qGreen(value)],
116
lookUpTable[qBlue(value)],
117
lookUpTable[qAlpha(value)]);
118
image.setPixel(x, y, value);
122
m_data.m_pixmap = QPixmap::fromImage(image);
125
m_data.m_painter->begin(&m_data.m_pixmap);
128
template <Multiply multiplied>
129
PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size)
103
131
PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height());
104
unsigned char* data = result->data()->data();
132
unsigned char* data = result->data()->data()->data();
106
if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > m_size.width() || (rect.y() + rect.height()) > m_size.height())
134
if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > size.width() || (rect.y() + rect.height()) > size.height())
107
135
memset(data, 0, result->data()->length());
109
137
int originx = rect.x();
126
154
int endy = rect.y() + rect.height();
127
if (endy > m_size.height())
128
endy = m_size.height();
155
if (endy > size.height())
156
endy = size.height();
129
157
int numRows = endy - originy;
131
QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
159
QImage image = imageData.m_pixmap.toImage();
160
if (multiplied == Unmultiplied)
161
image = image.convertToFormat(QImage::Format_ARGB32);
163
image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
132
165
ASSERT(!image.isNull());
134
167
unsigned destBytesPerRow = 4 * rect.width();
152
void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint)
185
PassRefPtr<ImageData> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const
187
return getImageData<Unmultiplied>(rect, m_data, m_size);
190
PassRefPtr<ImageData> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const
192
return getImageData<Premultiplied>(rect, m_data, m_size);
195
template <Multiply multiplied>
196
void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& data, const IntSize& size)
154
198
ASSERT(sourceRect.width() > 0);
155
199
ASSERT(sourceRect.height() > 0);
157
201
int originx = sourceRect.x();
158
202
int destx = destPoint.x() + sourceRect.x();
159
203
ASSERT(destx >= 0);
160
ASSERT(destx < m_size.width());
204
ASSERT(destx < size.width());
161
205
ASSERT(originx >= 0);
162
206
ASSERT(originx <= sourceRect.right());
164
208
int endx = destPoint.x() + sourceRect.right();
165
ASSERT(endx <= m_size.width());
209
ASSERT(endx <= size.width());
167
211
int numColumns = endx - destx;
169
213
int originy = sourceRect.y();
170
214
int desty = destPoint.y() + sourceRect.y();
171
215
ASSERT(desty >= 0);
172
ASSERT(desty < m_size.height());
216
ASSERT(desty < size.height());
173
217
ASSERT(originy >= 0);
174
218
ASSERT(originy <= sourceRect.bottom());
176
220
int endy = destPoint.y() + sourceRect.bottom();
177
ASSERT(endy <= m_size.height());
221
ASSERT(endy <= size.height());
178
222
int numRows = endy - desty;
180
224
unsigned srcBytesPerRow = 4 * source->width();
182
bool isPainting = m_data.m_painter->isActive();
226
bool isPainting = data.m_painter->isActive();
184
m_data.m_painter->end();
186
QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
187
ASSERT(!image.isNull());
189
unsigned char* srcRows = source->data()->data() + originy * srcBytesPerRow + originx * 4;
228
data.m_painter->end();
230
QImage image = data.m_pixmap.toImage();
231
if (multiplied == Unmultiplied)
232
image = image.convertToFormat(QImage::Format_ARGB32);
234
image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
236
unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4;
190
237
for (int y = 0; y < numRows; ++y) {
191
238
quint32* scanLine = reinterpret_cast<quint32*>(image.scanLine(y + desty));
192
239
for (int x = 0; x < numColumns; x++) {
194
scanLine[x + destx] = reinterpret_cast<quint32*>(srcRows + basex)[0];
240
// ImageData stores the pixels in RGBA while QImage is ARGB
241
quint32 pixel = reinterpret_cast<quint32*>(srcRows + 4 * x)[0];
242
pixel = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00);
243
scanLine[x + destx] = pixel;
197
246
srcRows += srcBytesPerRow;
200
m_data.m_pixmap = QPixmap::fromImage(image);
249
data.m_pixmap = QPixmap::fromImage(image);
203
m_data.m_painter->begin(&m_data.m_pixmap);
252
data.m_painter->begin(&data.m_pixmap);
255
void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint)
257
putImageData<Unmultiplied>(source, sourceRect, destPoint, m_data, m_size);
260
void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint)
262
putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size);
206
265
// We get a mimeType here but QImageWriter does not support mimetypes but