Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | static inline bool isLocked(QImageData *data) | - |
10 | { | - |
11 | return data != 0 && data->is_locked; | - |
12 | } | - |
13 | static QImage rotated90(const QImage &src); | - |
14 | static QImage rotated180(const QImage &src); | - |
15 | static QImage rotated270(const QImage &src); | - |
16 | | - |
17 | QBasicAtomicInt qimage_serial_number = { (1) }; | - |
18 | | - |
19 | QImageData::QImageData() | - |
20 | : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(0), | - |
21 | format(QImage::Format_ARGB32), bytes_per_line(0), | - |
22 | ser_no(qimage_serial_number.fetchAndAddRelaxed(1)), | - |
23 | detach_no(0), | - |
24 | ldpmx(qt_defaultDpiX() * 100 / qreal(2.54)), | - |
| ldpmy(qt_defaultDpiY() * 100 / qreal(2.54)),dpmx(qt_defaultDpiX() * 100 / qreal(2.54)), | |
25 | dpmy(qt_defaultDpiY() * 100 / qreal(2.54)), | - |
26 | offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false), | - |
27 | is_cached(false), is_locked(false), cleanupFunction(0), cleanupInfo(0), | - |
28 | paintEngine(0) | - |
29 | { | - |
30 | } executed: } Execution Count:182740 | 182740 |
31 | QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) | - |
32 | { | - |
33 | if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid) | - |
34 | return 0; | - |
35 | | - |
36 | uint width = size.width(); | - |
37 | uint height = size.height(); | - |
38 | uint depth = qt_depthForFormat(format); | - |
39 | | - |
40 | switch (format) { | - |
41 | case QImage::Format_Mono: | - |
42 | case QImage::Format_MonoLSB: | - |
43 | numColors = 2; | - |
44 | break; | - |
45 | case QImage::Format_Indexed8: | - |
46 | numColors = qBound(0, numColors, 256); | - |
47 | break; | - |
48 | default: | - |
49 | numColors = 0; | - |
50 | break; | - |
51 | } | - |
52 | | - |
53 | const int bytes_per_line = ((width * depth + 31) >> 5) << 2; | - |
54 | | - |
55 | | - |
56 | if (2147483647/depth < width | - |
57 | || bytes_per_line <= 0 | - |
58 | || height <= 0 | - |
59 | || 2147483647/uint(bytes_per_line) < height | - |
60 | || 2147483647/sizeof(uchar *) < uint(height)) | - |
61 | return 0; | - |
62 | | - |
63 | QScopedPointer<QImageData> d(new QImageData); | - |
64 | d->colortable.resize(numColors); | - |
65 | if (depth == 1) { | - |
66 | d->colortable[0] = QColor(Qt::black).rgba(); | - |
67 | d->colortable[1] = QColor(Qt::white).rgba(); | - |
68 | } else { | - |
69 | for (int i = 0; i < numColors; ++i) | - |
70 | d->colortable[i] = 0; | - |
71 | } | - |
72 | | - |
73 | d->width = width; | - |
74 | d->height = height; | - |
75 | d->depth = depth; | - |
76 | d->format = format; | - |
77 | d->has_alpha_clut = false; | - |
78 | d->is_cached = false; | - |
79 | | - |
80 | d->bytes_per_line = bytes_per_line; | - |
81 | | - |
82 | d->nbytes = d->bytes_per_line*height; | - |
83 | d->data = (uchar *)malloc(d->nbytes); | - |
84 | | - |
85 | if (!d->data) { | - |
86 | return 0; | - |
87 | } | - |
88 | | - |
89 | d->ref.ref(); | - |
90 | return d.take(); | - |
91 | | - |
92 | } | - |
93 | | - |
94 | QImageData::~QImageData() | - |
95 | { | - |
96 | if (cleanupFunction) | - |
97 | cleanupFunction(cleanupInfo); | - |
98 | if (is_cached) | - |
99 | QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no)); | - |
100 | delete paintEngine; | - |
101 | if (data && own_data) | - |
102 | free(data); | - |
103 | data = 0; | - |
104 | } | - |
105 | | - |
106 | | - |
107 | bool QImageData::checkForAlphaPixels() const | - |
108 | { | - |
109 | bool has_alpha_pixels = false; | - |
110 | | - |
111 | switch (format) { | - |
112 | | - |
113 | case QImage::Format_Mono: | - |
114 | case QImage::Format_MonoLSB: | - |
115 | case QImage::Format_Indexed8: | - |
116 | has_alpha_pixels = has_alpha_clut; | - |
117 | break; | - |
118 | | - |
119 | case QImage::Format_ARGB32: | - |
120 | case QImage::Format_ARGB32_Premultiplied: { | - |
121 | uchar *bits = data; | - |
122 | for (int y=0; y<height && !has_alpha_pixels; ++y) { | - |
123 | for (int x=0; x<width; ++x) | - |
124 | has_alpha_pixels |= (((uint *)bits)[x] & 0xff000000) != 0xff000000; | - |
125 | bits += bytes_per_line; | - |
126 | } | - |
127 | } break; | - |
128 | | - |
129 | case QImage::Format_ARGB8555_Premultiplied: | - |
130 | case QImage::Format_ARGB8565_Premultiplied: { | - |
131 | uchar *bits = data; | - |
132 | uchar *end_bits = data + bytes_per_line; | - |
133 | | - |
134 | for (int y=0; y<height && !has_alpha_pixels; ++y) { | - |
135 | while (bits < end_bits) { | - |
136 | has_alpha_pixels |= bits[0] != 0; | - |
137 | bits += 3; | - |
138 | } | - |
139 | bits = end_bits; | - |
140 | end_bits += bytes_per_line; | - |
141 | } | - |
142 | } break; | - |
143 | | - |
144 | case QImage::Format_ARGB6666_Premultiplied: { | - |
145 | uchar *bits = data; | - |
146 | uchar *end_bits = data + bytes_per_line; | - |
147 | | - |
148 | for (int y=0; y<height && !has_alpha_pixels; ++y) { | - |
149 | while (bits < end_bits) { | - |
150 | has_alpha_pixels |= (bits[0] & 0xfc) != 0; | - |
151 | bits += 3; | - |
152 | } | - |
153 | bits = end_bits; | - |
154 | end_bits += bytes_per_line; | - |
155 | } | - |
156 | } break; | - |
157 | | - |
158 | case QImage::Format_ARGB4444_Premultiplied: { | - |
159 | uchar *bits = data; | - |
160 | uchar *end_bits = data + bytes_per_line; | - |
161 | | - |
162 | for (int y=0; y<height && !has_alpha_pixels; ++y) { | - |
163 | while (bits < end_bits) { | - |
164 | has_alpha_pixels |= (bits[0] & 0xf0) != 0; | - |
165 | bits += 2; | - |
166 | } | - |
167 | bits = end_bits; | - |
168 | end_bits += bytes_per_line; | - |
169 | } | - |
170 | } break; | - |
171 | | - |
172 | default: | - |
173 | break; | - |
174 | } | - |
175 | | - |
176 | return has_alpha_pixels; | - |
177 | } | - |
178 | static const uchar bitflip[256] = { | - |
179 | 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, | - |
180 | 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, | - |
181 | 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, | - |
182 | 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, | - |
183 | 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, | - |
184 | 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, | - |
185 | 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, | - |
186 | 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, | - |
187 | 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, | - |
188 | 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, | - |
189 | 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, | - |
190 | 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, | - |
191 | 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, | - |
192 | 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, | - |
193 | 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, | - |
194 | 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 | - |
195 | }; | - |
196 | | - |
197 | const uchar *qt_get_bitflip_array() | - |
198 | { | - |
199 | return bitflip; | - |
200 | } | - |
201 | QImage::QImage() | - |
202 | : QPaintDevice() | - |
203 | { | - |
204 | d = 0; | - |
205 | } | - |
206 | QImage::QImage(int width, int height, Format format) | - |
207 | : QPaintDevice() | - |
208 | { | - |
209 | d = QImageData::create(QSize(width, height), format, 0); | - |
210 | } | - |
211 | QImage::QImage(const QSize &size, Format format) | - |
212 | : QPaintDevice() | - |
213 | { | - |
214 | d = QImageData::create(size, format, 0); | - |
215 | } | - |
216 | | - |
217 | | - |
218 | | - |
219 | QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QImage::Format format, bool readOnly, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - |
220 | { | - |
221 | QImageData *d = 0; | - |
222 | | - |
223 | if (format == QImage::Format_Invalid) | - |
224 | return d; | - |
225 | | - |
226 | const int depth = qt_depthForFormat(format); | - |
227 | const int calc_bytes_per_line = ((width * depth + 31)/32) * 4; | - |
228 | const int min_bytes_per_line = (width * depth + 7)/8; | - |
229 | | - |
230 | if (bpl <= 0) | - |
231 | bpl = calc_bytes_per_line; | - |
232 | | - |
233 | if (width <= 0 || height <= 0 || !data | - |
234 | || 2147483647/sizeof(uchar *) < uint(height) | - |
235 | || 2147483647/uint(depth) < uint(width) | - |
236 | || bpl <= 0 | - |
237 | || height <= 0 | - |
238 | || bpl < min_bytes_per_line | - |
239 | || 2147483647/uint(bpl) < uint(height)) | - |
240 | return d; | - |
241 | | - |
242 | d = new QImageData; | - |
243 | d->ref.ref(); | - |
244 | | - |
245 | d->own_data = false; | - |
246 | d->ro_data = readOnly; | - |
247 | d->data = data; | - |
248 | d->width = width; | - |
249 | d->height = height; | - |
250 | d->depth = depth; | - |
251 | d->format = format; | - |
252 | | - |
253 | d->bytes_per_line = bpl; | - |
254 | d->nbytes = d->bytes_per_line * height; | - |
255 | | - |
256 | d->cleanupFunction = cleanupFunction; | - |
257 | d->cleanupInfo = cleanupInfo; | - |
258 | | - |
259 | return d; | - |
260 | } | - |
261 | QImage::QImage(uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - |
262 | : QPaintDevice() | - |
263 | { | - |
264 | d = QImageData::create(data, width, height, 0, format, false, cleanupFunction, cleanupInfo); | - |
265 | } | - |
266 | QImage::QImage(const uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - |
267 | : QPaintDevice() | - |
268 | { | - |
269 | d = QImageData::create(const_cast<uchar*>(data), width, height, 0, format, true, cleanupFunction, cleanupInfo); | - |
270 | } | - |
271 | QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - |
272 | :QPaintDevice() | - |
273 | { | - |
274 | d = QImageData::create(data, width, height, bytesPerLine, format, false, cleanupFunction, cleanupInfo); | - |
275 | } | - |
276 | QImage::QImage(const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - |
277 | :QPaintDevice() | - |
278 | { | - |
279 | d = QImageData::create(const_cast<uchar*>(data), width, height, bytesPerLine, format, true, cleanupFunction, cleanupInfo); | - |
280 | } | - |
281 | QImage::QImage(const QString &fileName, const char *format) | - |
282 | : QPaintDevice() | - |
283 | { | - |
284 | d = 0; | - |
285 | load(fileName, format); | - |
286 | } | - |
287 | | - |
288 | | - |
289 | extern bool qt_read_xpm_image_or_array(QIODevice *device, const char * const *source, QImage &image); | - |
290 | QImage::QImage(const char * const xpm[]) | - |
291 | : QPaintDevice() | - |
292 | { | - |
293 | d = 0; | - |
294 | if (!xpm) | - |
295 | return; | - |
296 | if (!qt_read_xpm_image_or_array(0, xpm, *this)) | - |
297 | | - |
298 | QMessageLogger("image/qimage.cpp", 970968, __PRETTY_FUNCTION__).warning("QImage::QImage(), XPM is not supported"); | - |
299 | } | - |
300 | QImage::QImage(const QImage &image) | - |
301 | : QPaintDevice() | - |
302 | { | - |
303 | if (image.paintingActive() || isLocked(image.d)) { | - |
304 | d = 0; | - |
305 | image.copy().swap(*this); | - |
306 | } else { | - |
307 | d = image.d; | - |
308 | if (d) | - |
309 | d->ref.ref(); | - |
310 | } | - |
311 | } | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | QImage::~QImage() | - |
318 | { | - |
319 | if (d && !d->ref.deref()) | - |
320 | delete d; | - |
321 | } | - |
322 | QImage &QImage::operator=(const QImage &image) | - |
323 | { | - |
324 | if (image.paintingActive() || isLocked(image.d)) { | - |
325 | operator=(image.copy()); | - |
326 | } else { | - |
327 | if (image.d) | - |
328 | image.d->ref.ref(); | - |
329 | if (d && !d->ref.deref()) | - |
330 | delete d; | - |
331 | d = image.d; | - |
332 | } | - |
333 | return *this; | - |
334 | } | - |
335 | int QImage::devType() const | - |
336 | { | - |
337 | return QInternal::Image; | - |
338 | } | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
343 | QImage::operator QVariant() const | - |
344 | { | - |
345 | return QVariant(QVariant::Image, this); | - |
346 | } | - |
347 | void QImage::detach() | - |
348 | { | - |
349 | if (d) { | - |
350 | if (d->is_cached && d->ref.load() == 1) | - |
351 | QImagePixmapCleanupHooks::executeImageHooks(cacheKey()); | - |
352 | | - |
353 | if (d->ref.load() != 1 || d->ro_data) | - |
354 | *this = copy(); | - |
355 | | - |
356 | if (d) | - |
357 | ++d->detach_no; | - |
358 | } | - |
359 | } | - |
360 | QImage QImage::copy(const QRect& r) const | - |
361 | { | - |
362 | if (!d) | - |
363 | return QImage(); | - |
364 | | - |
365 | if (r.isNull()) { | - |
366 | QImage image(d->width, d->height, d->format); | - |
367 | if (image.isNull()) | - |
368 | return image; | - |
369 | | - |
370 | | - |
371 | | - |
372 | if (image.d->nbytes != d->nbytes) { | - |
373 | int bpl = qMin(bytesPerLine(), image.bytesPerLine()); | - |
374 | for (int i = 0; i < height(); i++) | - |
375 | memcpy(image.scanLine(i), scanLine(i), bpl); | - |
376 | } else | - |
377 | memcpy(image.bits(), bits(), d->nbytes); | - |
378 | image.d->colortable = d->colortable; | - |
379 | image.d->dpmx = d->dpmx; | - |
380 | image.d->dpmy = d->dpmy; | - |
381 | image.d->offset = d->offset; | - |
382 | image.d->has_alpha_clut = d->has_alpha_clut; | - |
383 | image.d->text = d->text; | - |
384 | return image; | - |
385 | } | - |
386 | | - |
387 | int x = r.x(); | - |
388 | int y = r.y(); | - |
389 | int w = r.width(); | - |
390 | int h = r.height(); | - |
391 | | - |
392 | int dx = 0; | - |
393 | int dy = 0; | - |
394 | if (w <= 0 || h <= 0) | - |
395 | return QImage(); | - |
396 | | - |
397 | QImage image(w, h, d->format); | - |
398 | if (image.isNull()) | - |
399 | return image; | - |
400 | | - |
401 | if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) { | - |
402 | | - |
403 | image.fill(0); | - |
404 | if (x < 0) { | - |
405 | dx = -x; | - |
406 | x = 0; | - |
407 | } | - |
408 | if (y < 0) { | - |
409 | dy = -y; | - |
410 | y = 0; | - |
411 | } | - |
412 | } | - |
413 | | - |
414 | image.d->colortable = d->colortable; | - |
415 | | - |
416 | int pixels_to_copy = qMax(w - dx, 0); | - |
417 | if (x > d->width) | - |
418 | pixels_to_copy = 0; | - |
419 | else if (pixels_to_copy > d->width - x) | - |
420 | pixels_to_copy = d->width - x; | - |
421 | int lines_to_copy = qMax(h - dy, 0); | - |
422 | if (y > d->height) | - |
423 | lines_to_copy = 0; | - |
424 | else if (lines_to_copy > d->height - y) | - |
425 | lines_to_copy = d->height - y; | - |
426 | | - |
427 | bool byteAligned = true; | - |
428 | if (d->format == Format_Mono || d->format == Format_MonoLSB) | - |
429 | byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7); | - |
430 | | - |
431 | if (byteAligned) { | - |
432 | const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line; | - |
433 | uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line; | - |
434 | const int bytes_to_copy = (pixels_to_copy * d->depth) >> 3; | - |
435 | for (int i = 0; i < lines_to_copy; ++i) { | - |
436 | memcpy(dest, src, bytes_to_copy); | - |
437 | src += d->bytes_per_line; | - |
438 | dest += image.d->bytes_per_line; | - |
439 | } | - |
440 | } else if (d->format == Format_Mono) { | - |
441 | const uchar *src = d->data + y * d->bytes_per_line; | - |
442 | uchar *dest = image.d->data + dy * image.d->bytes_per_line; | - |
443 | for (int i = 0; i < lines_to_copy; ++i) { | - |
444 | for (int j = 0; j < pixels_to_copy; ++j) { | - |
445 | if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7))) | - |
446 | dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7)); | - |
447 | else | - |
448 | dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7)); | - |
449 | } | - |
450 | src += d->bytes_per_line; | - |
451 | dest += image.d->bytes_per_line; | - |
452 | } | - |
453 | } else { | - |
454 | qt_noop(); | - |
455 | const uchar *src = d->data + y * d->bytes_per_line; | - |
456 | uchar *dest = image.d->data + dy * image.d->bytes_per_line; | - |
457 | for (int i = 0; i < lines_to_copy; ++i) { | - |
458 | for (int j = 0; j < pixels_to_copy; ++j) { | - |
459 | if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7))) | - |
460 | dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7)); | - |
461 | else | - |
462 | dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7)); | - |
463 | } | - |
464 | src += d->bytes_per_line; | - |
465 | dest += image.d->bytes_per_line; | - |
466 | } | - |
467 | } | - |
468 | | - |
469 | image.d->dpmx = dotsPerMeterX(); | - |
470 | image.d->dpmy = dotsPerMeterY(); | - |
471 | image.d->devicePixelRatio = devicePixelRatio(); | - |
472 | image.d->offset = offset(); | - |
473 | image.d->has_alpha_clut = d->has_alpha_clut; | - |
474 | image.d->text = d->text; | - |
475 | return image; | - |
476 | } | - |
477 | bool QImage::isNull() const | - |
478 | { | - |
479 | return !d; | - |
480 | } | - |
481 | int QImage::width() const | - |
482 | { | - |
483 | return d ? d->width : 0; | - |
484 | } | - |
485 | int QImage::height() const | - |
486 | { | - |
487 | return d ? d->height : 0; | - |
488 | } | - |
489 | QSize QImage::size() const | - |
490 | { | - |
491 | return d ? QSize(d->width, d->height) : QSize(0, 0); | - |
492 | } | - |
493 | QRect QImage::rect() const | - |
494 | { | - |
495 | return d ? QRect(0, 0, d->width, d->height) : QRect(); | - |
496 | } | - |
497 | int QImage::depth() const | - |
498 | { | - |
499 | return d ? d->depth : 0; | - |
500 | } | - |
501 | int QImage::colorCount() const | - |
502 | { | - |
503 | return d ? d->colortable.size() : 0; | - |
504 | } | - |
505 | void QImage::setColorTable(const QVector<QRgb> colors) | - |
506 | { | - |
507 | if (!d) | - |
508 | return; | - |
509 | detach(); | - |
510 | | - |
511 | | - |
512 | if (!d) | - |
513 | return; | - |
514 | | - |
515 | d->colortable = colors; | - |
516 | d->has_alpha_clut = false; | - |
517 | for (int i = 0; i < d->colortable.size(); ++i) { | - |
518 | if (qAlpha(d->colortable.at(i)) != 255) { | - |
519 | d->has_alpha_clut = true; | - |
520 | break; | - |
521 | } | - |
522 | } | - |
523 | } | - |
524 | | - |
525 | | - |
526 | | - |
527 | | - |
528 | | - |
529 | | - |
530 | | - |
531 | QVector<QRgb> QImage::colorTable() const | - |
532 | { | - |
533 | return d ? d->colortable : QVector<QRgb>(); | - |
534 | } | - |
535 | qreal QImage::devicePixelRatio() const | - |
536 | { | - |
537 | if (!d) | - |
538 | return 1.0; | - |
539 | return d->devicePixelRatio; | - |
540 | } | - |
541 | void QImage::setDevicePixelRatio(qreal scaleFactor) | - |
542 | { | - |
543 | if (!d) | - |
544 | return; | - |
545 | detach(); | - |
546 | d->devicePixelRatio = scaleFactor; | - |
547 | } | - |
548 | int QImage::byteCount() const | - |
549 | { | - |
550 | return d ? d->nbytes : 0; | - |
551 | } | - |
552 | int QImage::bytesPerLine() const | - |
553 | { | - |
554 | return (d && d->height) ? d->nbytes / d->height : 0; | - |
555 | } | - |
556 | QRgb QImage::color(int i) const | - |
557 | { | - |
558 | qt_noop(); | - |
559 | return d ? d->colortable.at(i) : QRgb(uint(-1)); | - |
560 | } | - |
561 | void QImage::setColor(int i, QRgb c) | - |
562 | { | - |
563 | if (!d) | - |
564 | return; | - |
565 | if (i < 0 || d->depth > 8 || i >= 1<<d->depth) { | - |
566 | QMessageLogger("image/qimage.cpp", 14801478, __PRETTY_FUNCTION__).warning("QImage::setColor: Index out of bound %d", i); | - |
567 | return; | - |
568 | } | - |
569 | detach(); | - |
570 | | - |
571 | | - |
572 | if (!d) | - |
573 | return; | - |
574 | | - |
575 | if (i >= d->colortable.size()) | - |
576 | setColorCount(i+1); | - |
577 | d->colortable[i] = c; | - |
578 | d->has_alpha_clut |= (qAlpha(c) != 255); | - |
579 | } | - |
580 | uchar *QImage::scanLine(int i) | - |
581 | { | - |
582 | if (!d) | - |
583 | return 0; | - |
584 | | - |
585 | detach(); | - |
586 | | - |
587 | | - |
588 | if (!d) | - |
589 | return 0; | - |
590 | | - |
591 | return d->data + i * d->bytes_per_line; | - |
592 | } | - |
593 | | - |
594 | | - |
595 | | - |
596 | | - |
597 | const uchar *QImage::scanLine(int i) const | - |
598 | { | - |
599 | if (!d) | - |
600 | return 0; | - |
601 | | - |
602 | qt_noop(); | - |
603 | return d->data + i * d->bytes_per_line; | - |
604 | } | - |
605 | const uchar *QImage::constScanLine(int i) const | - |
606 | { | - |
607 | if (!d) | - |
608 | return 0; | - |
609 | | - |
610 | qt_noop(); | - |
611 | return d->data + i * d->bytes_per_line; | - |
612 | } | - |
613 | uchar *QImage::bits() | - |
614 | { | - |
615 | if (!d) | - |
616 | return 0; | - |
617 | detach(); | - |
618 | | - |
619 | | - |
620 | if (!d) | - |
621 | return 0; | - |
622 | | - |
623 | return d->data; | - |
624 | } | - |
625 | const uchar *QImage::bits() const | - |
626 | { | - |
627 | return d ? d->data : 0; | - |
628 | } | - |
629 | const uchar *QImage::constBits() const | - |
630 | { | - |
631 | return d ? d->data : 0; | - |
632 | } | - |
633 | void QImage::fill(uint pixel) | - |
634 | { | - |
635 | if (!d) | - |
636 | return; | - |
637 | | - |
638 | detach(); | - |
639 | | - |
640 | | - |
641 | if (!d) | - |
642 | return; | - |
643 | | - |
644 | if (d->depth == 1 || d->depth == 8) { | - |
645 | int w = d->width; | - |
646 | if (d->depth == 1) { | - |
647 | if (pixel & 1) | - |
648 | pixel = 0xffffffff; | - |
649 | else | - |
650 | pixel = 0; | - |
651 | w = (w + 7) / 8; | - |
652 | } else { | - |
653 | pixel &= 0xff; | - |
654 | } | - |
655 | qt_rectfill<quint8>(d->data, pixel, 0, 0, | - |
656 | w, d->height, d->bytes_per_line); | - |
657 | return; | - |
658 | } else if (d->depth == 16) { | - |
659 | qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel, | - |
660 | 0, 0, d->width, d->height, d->bytes_per_line); | - |
661 | return; | - |
662 | } else if (d->depth == 24) { | - |
663 | qt_rectfill<quint24>(reinterpret_cast<quint24*>(d->data), pixel, | - |
664 | 0, 0, d->width, d->height, d->bytes_per_line); | - |
665 | return; | - |
666 | } | - |
667 | | - |
668 | if (d->format == Format_RGB32) | - |
669 | pixel |= 0xff000000; | - |
670 | | - |
671 | qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel, | - |
672 | 0, 0, d->width, d->height, d->bytes_per_line); | - |
673 | } | - |
674 | void QImage::fill(Qt::GlobalColor color) | - |
675 | { | - |
676 | fill(QColor(color)); | - |
677 | } | - |
678 | void QImage::fill(const QColor &color) | - |
679 | { | - |
680 | if (!d) | - |
681 | return; | - |
682 | detach(); | - |
683 | | - |
684 | | - |
685 | if (!d) | - |
686 | return; | - |
687 | | - |
688 | if (d->depth == 32) { | - |
689 | uint pixel = color.rgba(); | - |
690 | if (d->format == QImage::Format_ARGB32_Premultiplied) | - |
691 | pixel = PREMUL(pixel); | - |
692 | fill((uint) pixel); | - |
693 | | - |
694 | } else if (d->format == QImage::Format_RGB16) { | - |
695 | fill((uint) qConvertRgb32To16(color.rgba())); | - |
696 | | - |
697 | } else if (d->depth == 1) { | - |
698 | if (color == Qt::color1) | - |
699 | fill((uint) 1); | - |
700 | else | - |
701 | fill((uint) 0); | - |
702 | | - |
703 | } else if (d->depth == 8) { | - |
704 | uint pixel = 0; | - |
705 | for (int i=0; i<d->colortable.size(); ++i) { | - |
706 | if (color.rgba() == d->colortable.at(i)) { | - |
707 | pixel = i; | - |
708 | break; | - |
709 | } | - |
710 | } | - |
711 | fill(pixel); | - |
712 | | - |
713 | } else { | - |
714 | QPainter p(this); | - |
715 | p.setCompositionMode(QPainter::CompositionMode_Source); | - |
716 | p.fillRect(rect(), color); | - |
717 | } | - |
718 | | - |
719 | } | - |
720 | void QImage::invertPixels(InvertMode mode) | - |
721 | { | - |
722 | if (!d) | - |
723 | return; | - |
724 | | - |
725 | detach(); | - |
726 | | - |
727 | | - |
728 | if (!d) | - |
729 | return; | - |
730 | | - |
731 | if (depth() != 32) { | - |
732 | | - |
733 | int bpl = (d->width * d->depth + 7) / 8; | - |
734 | int pad = d->bytes_per_line - bpl; | - |
735 | uchar *sl = d->data; | - |
736 | for (int y=0; y<d->height; ++y) { | - |
737 | for (int x=0; x<bpl; ++x) | - |
738 | *sl++ ^= 0xff; | - |
739 | sl += pad; | - |
740 | } | - |
741 | } else { | - |
742 | quint32 *p = (quint32*)d->data; | - |
743 | quint32 *end = (quint32*)(d->data + d->nbytes); | - |
744 | uint xorbits = (mode == InvertRgba) ? 0xffffffff : 0x00ffffff; | - |
745 | while (p < end) | - |
746 | *p++ ^= xorbits; | - |
747 | } | - |
748 | } | - |
749 | void QImage::setColorCount(int colorCount) | - |
750 | { | - |
751 | if (!d) { | - |
752 | QMessageLogger("image/qimage.cpp", 18311829, __PRETTY_FUNCTION__).warning("QImage::setColorCount: null image"); | - |
753 | return; | - |
754 | } | - |
755 | | - |
756 | detach(); | - |
757 | | - |
758 | | - |
759 | if (!d) | - |
760 | return; | - |
761 | | - |
762 | if (colorCount == d->colortable.size()) | - |
763 | return; | - |
764 | if (colorCount <= 0) { | - |
765 | d->colortable = QVector<QRgb>(); | - |
766 | return; | - |
767 | } | - |
768 | int nc = d->colortable.size(); | - |
769 | d->colortable.resize(colorCount); | - |
770 | for (int i = nc; i < colorCount; ++i) | - |
771 | d->colortable[i] = 0; | - |
772 | } | - |
773 | | - |
774 | | - |
775 | | - |
776 | | - |
777 | | - |
778 | | - |
779 | QImage::Format QImage::format() const | - |
780 | { | - |
781 | return d ? d->format : Format_Invalid; | - |
782 | } | - |
783 | | - |
784 | | - |
785 | | - |
786 | | - |
787 | | - |
788 | | - |
789 | | - |
790 | typedef void (*Image_Converter)(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
791 | | - |
792 | typedef bool (*InPlace_Image_Converter)(QImageData *data, Qt::ImageConversionFlags); | - |
793 | | - |
794 | static void convert_ARGB_to_ARGB_PM(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
795 | { | - |
796 | qt_noop(); | - |
797 | qt_noop(); | - |
798 | qt_noop(); | - |
799 | qt_noop(); | - |
800 | | - |
801 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
802 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
803 | const QRgb *src_data = (QRgb *) src->data; | - |
804 | QRgb *dest_data = (QRgb *) dest->data; | - |
805 | | - |
806 | for (int i = 0; i < src->height; ++i) { | - |
807 | const QRgb *end = src_data + src->width; | - |
808 | while (src_data < end) { | - |
809 | *dest_data = PREMUL(*src_data); | - |
810 | ++src_data; | - |
811 | ++dest_data; | - |
812 | } | - |
813 | src_data += src_pad; | - |
814 | dest_data += dest_pad; | - |
815 | } | - |
816 | } | - |
817 | | - |
818 | static bool convert_ARGB_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
819 | { | - |
820 | qt_noop(); | - |
821 | | - |
822 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
823 | QRgb *rgb_data = (QRgb *) data->data; | - |
824 | | - |
825 | for (int i = 0; i < data->height; ++i) { | - |
826 | const QRgb *end = rgb_data + data->width; | - |
827 | while (rgb_data < end) { | - |
828 | *rgb_data = PREMUL(*rgb_data); | - |
829 | ++rgb_data; | - |
830 | } | - |
831 | rgb_data += pad; | - |
832 | } | - |
833 | data->format = QImage::Format_ARGB32_Premultiplied; | - |
834 | return true; | - |
835 | } | - |
836 | | - |
837 | static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
838 | { | - |
839 | qt_noop(); | - |
840 | const int depth = 32; | - |
841 | | - |
842 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
843 | const int nbytes = dst_bytes_per_line * data->height; | - |
844 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
845 | if (!newData) | - |
846 | return false; | - |
847 | | - |
848 | data->data = newData; | - |
849 | | - |
850 | | - |
851 | uchar *src_data = newData + data->nbytes; | - |
852 | quint32 *dest_data = (quint32 *) (newData + nbytes); | - |
853 | const int width = data->width; | - |
854 | const int src_pad = data->bytes_per_line - width; | - |
855 | const int dest_pad = (dst_bytes_per_line >> 2) - width; | - |
856 | if (data->colortable.size() == 0) { | - |
857 | data->colortable.resize(256); | - |
858 | for (int i = 0; i < 256; ++i) | - |
859 | data->colortable[i] = qRgb(i, i, i); | - |
860 | } else { | - |
861 | for (int i = 0; i < data->colortable.size(); ++i) | - |
862 | data->colortable[i] = PREMUL(data->colortable.at(i)); | - |
863 | | - |
864 | | - |
865 | const int oldSize = data->colortable.size(); | - |
866 | const QRgb lastColor = data->colortable.at(oldSize - 1); | - |
867 | data->colortable.insert(oldSize, 256 - oldSize, lastColor); | - |
868 | } | - |
869 | | - |
870 | for (int i = 0; i < data->height; ++i) { | - |
871 | src_data -= src_pad; | - |
872 | dest_data -= dest_pad; | - |
873 | for (int pixI = 0; pixI < width; ++pixI) { | - |
874 | --src_data; | - |
875 | --dest_data; | - |
876 | *dest_data = data->colortable.at(*src_data); | - |
877 | } | - |
878 | } | - |
879 | | - |
880 | data->colortable = QVector<QRgb>(); | - |
881 | data->format = QImage::Format_ARGB32_Premultiplied; | - |
882 | data->bytes_per_line = dst_bytes_per_line; | - |
883 | data->depth = depth; | - |
884 | data->nbytes = nbytes; | - |
885 | | - |
886 | return true; | - |
887 | } | - |
888 | | - |
889 | static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
890 | { | - |
891 | qt_noop(); | - |
892 | const int depth = 32; | - |
893 | | - |
894 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
895 | const int nbytes = dst_bytes_per_line * data->height; | - |
896 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
897 | if (!newData) | - |
898 | return false; | - |
899 | | - |
900 | data->data = newData; | - |
901 | | - |
902 | | - |
903 | uchar *src_data = newData + data->nbytes; | - |
904 | quint32 *dest_data = (quint32 *) (newData + nbytes); | - |
905 | const int width = data->width; | - |
906 | const int src_pad = data->bytes_per_line - width; | - |
907 | const int dest_pad = (dst_bytes_per_line >> 2) - width; | - |
908 | if (data->colortable.size() == 0) { | - |
909 | data->colortable.resize(256); | - |
910 | for (int i = 0; i < 256; ++i) | - |
911 | data->colortable[i] = qRgb(i, i, i); | - |
912 | } else { | - |
913 | | - |
914 | const int oldSize = data->colortable.size(); | - |
915 | const QRgb lastColor = data->colortable.at(oldSize - 1); | - |
916 | data->colortable.insert(oldSize, 256 - oldSize, lastColor); | - |
917 | } | - |
918 | | - |
919 | for (int i = 0; i < data->height; ++i) { | - |
920 | src_data -= src_pad; | - |
921 | dest_data -= dest_pad; | - |
922 | for (int pixI = 0; pixI < width; ++pixI) { | - |
923 | --src_data; | - |
924 | --dest_data; | - |
925 | *dest_data = (quint32) data->colortable.at(*src_data); | - |
926 | } | - |
927 | } | - |
928 | | - |
929 | data->colortable = QVector<QRgb>(); | - |
930 | data->format = QImage::Format_RGB32; | - |
931 | data->bytes_per_line = dst_bytes_per_line; | - |
932 | data->depth = depth; | - |
933 | data->nbytes = nbytes; | - |
934 | | - |
935 | return true; | - |
936 | } | - |
937 | | - |
938 | static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
939 | { | - |
940 | qt_noop(); | - |
941 | const int depth = 16; | - |
942 | | - |
943 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
944 | const int nbytes = dst_bytes_per_line * data->height; | - |
945 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
946 | if (!newData) | - |
947 | return false; | - |
948 | | - |
949 | data->data = newData; | - |
950 | | - |
951 | | - |
952 | uchar *src_data = newData + data->nbytes; | - |
953 | quint16 *dest_data = (quint16 *) (newData + nbytes); | - |
954 | const int width = data->width; | - |
955 | const int src_pad = data->bytes_per_line - width; | - |
956 | const int dest_pad = (dst_bytes_per_line >> 1) - width; | - |
957 | | - |
958 | quint16 colorTableRGB16[256]; | - |
959 | if (data->colortable.isEmpty()) { | - |
960 | for (int i = 0; i < 256; ++i) | - |
961 | colorTableRGB16[i] = qConvertRgb32To16(qRgb(i, i, i)); | - |
962 | } else { | - |
963 | | - |
964 | const int tableSize = data->colortable.size(); | - |
965 | for (int i = 0; i < tableSize; ++i) | - |
966 | colorTableRGB16[i] = qConvertRgb32To16(data->colortable.at(i)); | - |
967 | data->colortable = QVector<QRgb>(); | - |
968 | | - |
969 | | - |
970 | const quint16 lastColor = colorTableRGB16[tableSize - 1]; | - |
971 | for (int i = tableSize; i < 256; ++i) | - |
972 | colorTableRGB16[i] = lastColor; | - |
973 | } | - |
974 | | - |
975 | for (int i = 0; i < data->height; ++i) { | - |
976 | src_data -= src_pad; | - |
977 | dest_data -= dest_pad; | - |
978 | for (int pixI = 0; pixI < width; ++pixI) { | - |
979 | --src_data; | - |
980 | --dest_data; | - |
981 | *dest_data = colorTableRGB16[*src_data]; | - |
982 | } | - |
983 | } | - |
984 | | - |
985 | data->format = QImage::Format_RGB16; | - |
986 | data->bytes_per_line = dst_bytes_per_line; | - |
987 | data->depth = depth; | - |
988 | data->nbytes = nbytes; | - |
989 | | - |
990 | return true; | - |
991 | } | - |
992 | | - |
993 | static bool convert_RGB_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
994 | { | - |
995 | qt_noop(); | - |
996 | const int depth = 16; | - |
997 | | - |
998 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
999 | const int src_bytes_per_line = data->bytes_per_line; | - |
1000 | quint32 *src_data = (quint32 *) data->data; | - |
1001 | quint16 *dst_data = (quint16 *) data->data; | - |
1002 | | - |
1003 | for (int i = 0; i < data->height; ++i) { | - |
1004 | for (int j = 0; j < data->width; ++j) | - |
1005 | dst_data[j] = qConvertRgb32To16(src_data[j]); | - |
1006 | src_data = (quint32 *) (((char*)src_data) + src_bytes_per_line); | - |
1007 | dst_data = (quint16 *) (((char*)dst_data) + dst_bytes_per_line); | - |
1008 | } | - |
1009 | data->format = QImage::Format_RGB16; | - |
1010 | data->bytes_per_line = dst_bytes_per_line; | - |
1011 | data->depth = depth; | - |
1012 | data->nbytes = dst_bytes_per_line * data->height; | - |
1013 | uchar *const newData = (uchar *)realloc(data->data, data->nbytes); | - |
1014 | if (newData) { | - |
1015 | data->data = newData; | - |
1016 | return true; | - |
1017 | } else { | - |
1018 | return false; | - |
1019 | } | - |
1020 | } | - |
1021 | | - |
1022 | static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1023 | { | - |
1024 | qt_noop(); | - |
1025 | qt_noop(); | - |
1026 | qt_noop(); | - |
1027 | qt_noop(); | - |
1028 | | - |
1029 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
1030 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
1031 | const QRgb *src_data = (QRgb *) src->data; | - |
1032 | QRgb *dest_data = (QRgb *) dest->data; | - |
1033 | | - |
1034 | for (int i = 0; i < src->height; ++i) { | - |
1035 | const QRgb *end = src_data + src->width; | - |
1036 | while (src_data < end) { | - |
1037 | *dest_data = (qAlpha(*src_data) == 0 ? 0 : ((qAlpha(*src_data) << 24) | (((255*qRed(*src_data))/ qAlpha(*src_data)) << 16) | (((255*qGreen(*src_data)) / qAlpha(*src_data)) << 8) | ((255*qBlue(*src_data)) / qAlpha(*src_data)))); | - |
1038 | ++src_data; | - |
1039 | ++dest_data; | - |
1040 | } | - |
1041 | src_data += src_pad; | - |
1042 | dest_data += dest_pad; | - |
1043 | } | - |
1044 | } | - |
1045 | | - |
1046 | static void convert_ARGB_PM_to_RGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1047 | { | - |
1048 | qt_noop(); | - |
1049 | qt_noop(); | - |
1050 | qt_noop(); | - |
1051 | qt_noop(); | - |
1052 | | - |
1053 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
1054 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
1055 | const QRgb *src_data = (QRgb *) src->data; | - |
1056 | QRgb *dest_data = (QRgb *) dest->data; | - |
1057 | | - |
1058 | for (int i = 0; i < src->height; ++i) { | - |
1059 | const QRgb *end = src_data + src->width; | - |
1060 | while (src_data < end) { | - |
1061 | *dest_data = 0xff000000 | (qAlpha(*src_data) == 0 ? 0 : ((qAlpha(*src_data) << 24) | (((255*qRed(*src_data))/ qAlpha(*src_data)) << 16) | (((255*qGreen(*src_data)) / qAlpha(*src_data)) << 8) | ((255*qBlue(*src_data)) / qAlpha(*src_data)))); | - |
1062 | ++src_data; | - |
1063 | ++dest_data; | - |
1064 | } | - |
1065 | src_data += src_pad; | - |
1066 | dest_data += dest_pad; | - |
1067 | } | - |
1068 | } | - |
1069 | | - |
1070 | static void swap_bit_order(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1071 | { | - |
1072 | qt_noop(); | - |
1073 | qt_noop(); | - |
1074 | qt_noop(); | - |
1075 | qt_noop(); | - |
1076 | qt_noop(); | - |
1077 | qt_noop(); | - |
1078 | | - |
1079 | dest->colortable = src->colortable; | - |
1080 | | - |
1081 | const uchar *src_data = src->data; | - |
1082 | const uchar *end = src->data + src->nbytes; | - |
1083 | uchar *dest_data = dest->data; | - |
1084 | while (src_data < end) { | - |
1085 | *dest_data = bitflip[*src_data]; | - |
1086 | ++src_data; | - |
1087 | ++dest_data; | - |
1088 | } | - |
1089 | } | - |
1090 | | - |
1091 | static void mask_alpha_converter(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1092 | { | - |
1093 | qt_noop(); | - |
1094 | qt_noop(); | - |
1095 | | - |
1096 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
1097 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
1098 | const uint *src_data = (const uint *)src->data; | - |
1099 | uint *dest_data = (uint *)dest->data; | - |
1100 | | - |
1101 | for (int i = 0; i < src->height; ++i) { | - |
1102 | const uint *end = src_data + src->width; | - |
1103 | while (src_data < end) { | - |
1104 | *dest_data = *src_data | 0xff000000; | - |
1105 | ++src_data; | - |
1106 | ++dest_data; | - |
1107 | } | - |
1108 | src_data += src_pad; | - |
1109 | dest_data += dest_pad; | - |
1110 | } | - |
1111 | } | - |
1112 | | - |
1113 | static QVector<QRgb> fix_color_table(const QVector<QRgb> &ctbl, QImage::Format format) | - |
1114 | { | - |
1115 | QVector<QRgb> colorTable = ctbl; | - |
1116 | if (format == QImage::Format_RGB32) { | - |
1117 | | - |
1118 | for (int i = 0; i < colorTable.size(); ++i) | - |
1119 | if (qAlpha(colorTable.at(i) != 0xff)) | - |
1120 | colorTable[i] = colorTable.at(i) | 0xff000000; | - |
1121 | } else if (format == QImage::Format_ARGB32_Premultiplied) { | - |
1122 | | - |
1123 | for (int i = 0; i < colorTable.size(); ++i) | - |
1124 | colorTable[i] = PREMUL(colorTable.at(i)); | - |
1125 | } | - |
1126 | return colorTable; | - |
1127 | } | - |
1128 | | - |
1129 | | - |
1130 | | - |
1131 | | - |
1132 | | - |
1133 | static void dither_to_Mono(QImageData *dst, const QImageData *src, | - |
1134 | Qt::ImageConversionFlags flags, bool fromalpha) | - |
1135 | { | - |
1136 | qt_noop(); | - |
1137 | qt_noop(); | - |
1138 | qt_noop(); | - |
1139 | | - |
1140 | dst->colortable.clear(); | - |
1141 | dst->colortable.append(0xffffffff); | - |
1142 | dst->colortable.append(0xff000000); | - |
1143 | | - |
1144 | enum { Threshold, Ordered, Diffuse } dithermode; | - |
1145 | | - |
1146 | if (fromalpha) { | - |
1147 | if ((flags & Qt::AlphaDither_Mask) == Qt::DiffuseAlphaDither) | - |
1148 | dithermode = Diffuse; | - |
1149 | else if ((flags & Qt::AlphaDither_Mask) == Qt::OrderedAlphaDither) | - |
1150 | dithermode = Ordered; | - |
1151 | else | - |
1152 | dithermode = Threshold; | - |
1153 | } else { | - |
1154 | if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) | - |
1155 | dithermode = Threshold; | - |
1156 | else if ((flags & Qt::Dither_Mask) == Qt::OrderedDither) | - |
1157 | dithermode = Ordered; | - |
1158 | else | - |
1159 | dithermode = Diffuse; | - |
1160 | } | - |
1161 | | - |
1162 | int w = src->width; | - |
1163 | int h = src->height; | - |
1164 | int d = src->depth; | - |
1165 | uchar gray[256]; | - |
1166 | bool use_gray = (d == 8); | - |
1167 | if (use_gray) { | - |
1168 | if (fromalpha) { | - |
1169 | | - |
1170 | | - |
1171 | for (int i = 0; i < src->colortable.size(); i++) | - |
1172 | gray[i] = (255 - (src->colortable.at(i) >> 24)); | - |
1173 | } else { | - |
1174 | | - |
1175 | | - |
1176 | for (int i = 0; i < src->colortable.size(); i++) | - |
1177 | gray[i] = qGray(src->colortable.at(i)); | - |
1178 | } | - |
1179 | } | - |
1180 | | - |
1181 | uchar *dst_data = dst->data; | - |
1182 | int dst_bpl = dst->bytes_per_line; | - |
1183 | const uchar *src_data = src->data; | - |
1184 | int src_bpl = src->bytes_per_line; | - |
1185 | | - |
1186 | switch (dithermode) { | - |
1187 | case Diffuse: { | - |
1188 | QScopedArrayPointer<int> lineBuffer(new int[w * 2]); | - |
1189 | int *line1 = lineBuffer.data(); | - |
1190 | int *line2 = lineBuffer.data() + w; | - |
1191 | int bmwidth = (w+7)/8; | - |
1192 | | - |
1193 | int *b1, *b2; | - |
1194 | int wbytes = w * (d/8); | - |
1195 | register const uchar *p = src->data; | - |
1196 | const uchar *end = p + wbytes; | - |
1197 | b2 = line2; | - |
1198 | if (use_gray) { | - |
1199 | while (p < end) | - |
1200 | *b2++ = gray[*p++]; | - |
1201 | } else { | - |
1202 | if (fromalpha) { | - |
1203 | while (p < end) { | - |
1204 | *b2++ = 255 - (*(uint*)p >> 24); | - |
1205 | p += 4; | - |
1206 | } | - |
1207 | } else { | - |
1208 | while (p < end) { | - |
1209 | *b2++ = qGray(*(uint*)p); | - |
1210 | p += 4; | - |
1211 | } | - |
1212 | } | - |
1213 | } | - |
1214 | for (int y=0; y<h; y++) { | - |
1215 | int *tmp = line1; line1 = line2; line2 = tmp; | - |
1216 | bool not_last_line = y < h - 1; | - |
1217 | if (not_last_line) { | - |
1218 | p = src->data + (y+1)*src->bytes_per_line; | - |
1219 | end = p + wbytes; | - |
1220 | b2 = line2; | - |
1221 | if (use_gray) { | - |
1222 | while (p < end) | - |
1223 | *b2++ = gray[*p++]; | - |
1224 | } else { | - |
1225 | if (fromalpha) { | - |
1226 | while (p < end) { | - |
1227 | *b2++ = 255 - (*(uint*)p >> 24); | - |
1228 | p += 4; | - |
1229 | } | - |
1230 | } else { | - |
1231 | while (p < end) { | - |
1232 | *b2++ = qGray(*(uint*)p); | - |
1233 | p += 4; | - |
1234 | } | - |
1235 | } | - |
1236 | } | - |
1237 | } | - |
1238 | | - |
1239 | int err; | - |
1240 | uchar *p = dst->data + y*dst->bytes_per_line; | - |
1241 | memset(p, 0, bmwidth); | - |
1242 | b1 = line1; | - |
1243 | b2 = line2; | - |
1244 | int bit = 7; | - |
1245 | for (int x=1; x<=w; x++) { | - |
1246 | if (*b1 < 128) { | - |
1247 | err = *b1++; | - |
1248 | *p |= 1 << bit; | - |
1249 | } else { | - |
1250 | err = *b1++ - 255; | - |
1251 | } | - |
1252 | if (bit == 0) { | - |
1253 | p++; | - |
1254 | bit = 7; | - |
1255 | } else { | - |
1256 | bit--; | - |
1257 | } | - |
1258 | if (x < w) | - |
1259 | *b1 += (err*7)>>4; | - |
1260 | if (not_last_line) { | - |
1261 | b2[0] += (err*5)>>4; | - |
1262 | if (x > 1) | - |
1263 | b2[-1] += (err*3)>>4; | - |
1264 | if (x < w) | - |
1265 | b2[1] += err>>4; | - |
1266 | } | - |
1267 | b2++; | - |
1268 | } | - |
1269 | } | - |
1270 | } break; | - |
1271 | case Ordered: { | - |
1272 | | - |
1273 | memset(dst->data, 0, dst->nbytes); | - |
1274 | if (d == 32) { | - |
1275 | for (int i=0; i<h; i++) { | - |
1276 | const uint *p = (const uint *)src_data; | - |
1277 | const uint *end = p + w; | - |
1278 | uchar *m = dst_data; | - |
1279 | int bit = 7; | - |
1280 | int j = 0; | - |
1281 | if (fromalpha) { | - |
1282 | while (p < end) { | - |
1283 | if ((*p++ >> 24) >= qt_bayer_matrix[j++&15][i&15]) | - |
1284 | *m |= 1 << bit; | - |
1285 | if (bit == 0) { | - |
1286 | m++; | - |
1287 | bit = 7; | - |
1288 | } else { | - |
1289 | bit--; | - |
1290 | } | - |
1291 | } | - |
1292 | } else { | - |
1293 | while (p < end) { | - |
1294 | if ((uint)qGray(*p++) < qt_bayer_matrix[j++&15][i&15]) | - |
1295 | *m |= 1 << bit; | - |
1296 | if (bit == 0) { | - |
1297 | m++; | - |
1298 | bit = 7; | - |
1299 | } else { | - |
1300 | bit--; | - |
1301 | } | - |
1302 | } | - |
1303 | } | - |
1304 | dst_data += dst_bpl; | - |
1305 | src_data += src_bpl; | - |
1306 | } | - |
1307 | } else | - |
1308 | { | - |
1309 | for (int i=0; i<h; i++) { | - |
1310 | const uchar *p = src_data; | - |
1311 | const uchar *end = p + w; | - |
1312 | uchar *m = dst_data; | - |
1313 | int bit = 7; | - |
1314 | int j = 0; | - |
1315 | while (p < end) { | - |
1316 | if ((uint)gray[*p++] < qt_bayer_matrix[j++&15][i&15]) | - |
1317 | *m |= 1 << bit; | - |
1318 | if (bit == 0) { | - |
1319 | m++; | - |
1320 | bit = 7; | - |
1321 | } else { | - |
1322 | bit--; | - |
1323 | } | - |
1324 | } | - |
1325 | dst_data += dst_bpl; | - |
1326 | src_data += src_bpl; | - |
1327 | } | - |
1328 | } | - |
1329 | } break; | - |
1330 | default: { | - |
1331 | memset(dst->data, 0, dst->nbytes); | - |
1332 | if (d == 32) { | - |
1333 | for (int i=0; i<h; i++) { | - |
1334 | const uint *p = (const uint *)src_data; | - |
1335 | const uint *end = p + w; | - |
1336 | uchar *m = dst_data; | - |
1337 | int bit = 7; | - |
1338 | if (fromalpha) { | - |
1339 | while (p < end) { | - |
1340 | if ((*p++ >> 24) >= 128) | - |
1341 | *m |= 1 << bit; | - |
1342 | if (bit == 0) { | - |
1343 | m++; | - |
1344 | bit = 7; | - |
1345 | } else { | - |
1346 | bit--; | - |
1347 | } | - |
1348 | } | - |
1349 | } else { | - |
1350 | while (p < end) { | - |
1351 | if (qGray(*p++) < 128) | - |
1352 | *m |= 1 << bit; | - |
1353 | if (bit == 0) { | - |
1354 | m++; | - |
1355 | bit = 7; | - |
1356 | } else { | - |
1357 | bit--; | - |
1358 | } | - |
1359 | } | - |
1360 | } | - |
1361 | dst_data += dst_bpl; | - |
1362 | src_data += src_bpl; | - |
1363 | } | - |
1364 | } else | - |
1365 | if (d == 8) { | - |
1366 | for (int i=0; i<h; i++) { | - |
1367 | const uchar *p = src_data; | - |
1368 | const uchar *end = p + w; | - |
1369 | uchar *m = dst_data; | - |
1370 | int bit = 7; | - |
1371 | while (p < end) { | - |
1372 | if (gray[*p++] < 128) | - |
1373 | *m |= 1 << bit; | - |
1374 | if (bit == 0) { | - |
1375 | m++; | - |
1376 | bit = 7; | - |
1377 | } else { | - |
1378 | bit--; | - |
1379 | } | - |
1380 | } | - |
1381 | dst_data += dst_bpl; | - |
1382 | src_data += src_bpl; | - |
1383 | } | - |
1384 | } | - |
1385 | } | - |
1386 | } | - |
1387 | | - |
1388 | if (dst->format == QImage::Format_MonoLSB) { | - |
1389 | | - |
1390 | uchar *sl = dst->data; | - |
1391 | int bpl = (dst->width + 7) * dst->depth / 8; | - |
1392 | int pad = dst->bytes_per_line - bpl; | - |
1393 | for (int y=0; y<dst->height; ++y) { | - |
1394 | for (int x=0; x<bpl; ++x) { | - |
1395 | *sl = bitflip[*sl]; | - |
1396 | ++sl; | - |
1397 | } | - |
1398 | sl += pad; | - |
1399 | } | - |
1400 | } | - |
1401 | } | - |
1402 | | - |
1403 | static void convert_X_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1404 | { | - |
1405 | dither_to_Mono(dst, src, flags, false); | - |
1406 | } | - |
1407 | | - |
1408 | static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1409 | { | - |
1410 | QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32)); | - |
1411 | convert_ARGB_PM_to_ARGB(tmp.data(), src, flags); | - |
1412 | dither_to_Mono(dst, tmp.data(), flags, false); | - |
1413 | } | - |
1414 | struct QRgbMap { | - |
1415 | inline QRgbMap() : used(0) { } | - |
1416 | uchar pix; | - |
1417 | uchar used; | - |
1418 | QRgb rgb; | - |
1419 | }; | - |
1420 | | - |
1421 | static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1422 | { | - |
1423 | qt_noop(); | - |
1424 | qt_noop(); | - |
1425 | qt_noop(); | - |
1426 | qt_noop(); | - |
1427 | | - |
1428 | bool do_quant = (flags & Qt::DitherMode_Mask) == Qt::PreferDither | - |
1429 | || src->format == QImage::Format_ARGB32; | - |
1430 | uint alpha_mask = src->format == QImage::Format_RGB32 ? 0xff000000 : 0; | - |
1431 | | - |
1432 | const int tablesize = 997; | - |
1433 | QRgbMap table[tablesize]; | - |
1434 | int pix=0; | - |
1435 | | - |
1436 | if (!dst->colortable.isEmpty()) { | - |
1437 | QVector<QRgb> ctbl = dst->colortable; | - |
1438 | dst->colortable.resize(256); | - |
1439 | | - |
1440 | | - |
1441 | for (int i = 0; i < dst->colortable.size(); ++i) { | - |
1442 | | - |
1443 | QRgb p = ctbl.at(i) | alpha_mask; | - |
1444 | int hash = p % tablesize; | - |
1445 | for (;;) { | - |
1446 | if (table[hash].used) { | - |
1447 | if (table[hash].rgb == p) { | - |
1448 | | - |
1449 | break; | - |
1450 | } else { | - |
1451 | | - |
1452 | if (++hash == tablesize) hash = 0; | - |
1453 | } | - |
1454 | } else { | - |
1455 | | - |
1456 | qt_noop(); | - |
1457 | | - |
1458 | dst->colortable[pix] = p; | - |
1459 | table[hash].pix = pix++; | - |
1460 | table[hash].rgb = p; | - |
1461 | table[hash].used = 1; | - |
1462 | break; | - |
1463 | } | - |
1464 | } | - |
1465 | } | - |
1466 | } | - |
1467 | | - |
1468 | if ((flags & Qt::DitherMode_Mask) != Qt::PreferDither) { | - |
1469 | dst->colortable.resize(256); | - |
1470 | const uchar *src_data = src->data; | - |
1471 | uchar *dest_data = dst->data; | - |
1472 | for (int y = 0; y < src->height; y++) { | - |
1473 | const QRgb *s = (const QRgb *)src_data; | - |
1474 | uchar *b = dest_data; | - |
1475 | for (int x = 0; x < src->width; ++x) { | - |
1476 | QRgb p = s[x] | alpha_mask; | - |
1477 | int hash = p % tablesize; | - |
1478 | for (;;) { | - |
1479 | if (table[hash].used) { | - |
1480 | if (table[hash].rgb == (p)) { | - |
1481 | | - |
1482 | break; | - |
1483 | } else { | - |
1484 | | - |
1485 | if (++hash == tablesize) hash = 0; | - |
1486 | } | - |
1487 | } else { | - |
1488 | | - |
1489 | if (pix == 256) { | - |
1490 | do_quant = true; | - |
1491 | | - |
1492 | x = src->width; | - |
1493 | y = src->height; | - |
1494 | } else { | - |
1495 | | - |
1496 | dst->colortable[pix] = p; | - |
1497 | table[hash].pix = pix++; | - |
1498 | table[hash].rgb = p; | - |
1499 | table[hash].used = 1; | - |
1500 | } | - |
1501 | break; | - |
1502 | } | - |
1503 | } | - |
1504 | *b++ = table[hash].pix; | - |
1505 | } | - |
1506 | src_data += src->bytes_per_line; | - |
1507 | dest_data += dst->bytes_per_line; | - |
1508 | } | - |
1509 | } | - |
1510 | int numColors = do_quant ? 256 : pix; | - |
1511 | | - |
1512 | dst->colortable.resize(numColors); | - |
1513 | | - |
1514 | if (do_quant) { | - |
1515 | | - |
1516 | | - |
1517 | | - |
1518 | | - |
1519 | | - |
1520 | | - |
1521 | for (int rc=0; rc<=5; rc++) | - |
1522 | for (int gc=0; gc<=5; gc++) | - |
1523 | for (int bc=0; bc<=5; bc++) | - |
1524 | dst->colortable[(((rc)*(5 +1)+(gc))*(5 +1)+(bc))] = 0xff000000 | qRgb(rc*255/5, gc*255/5, bc*255/5); | - |
1525 | | - |
1526 | const uchar *src_data = src->data; | - |
1527 | uchar *dest_data = dst->data; | - |
1528 | if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) { | - |
1529 | for (int y = 0; y < src->height; y++) { | - |
1530 | const QRgb *p = (const QRgb *)src_data; | - |
1531 | const QRgb *end = p + src->width; | - |
1532 | uchar *b = dest_data; | - |
1533 | | - |
1534 | while (p < end) { | - |
1535 | | - |
1536 | *b++ = | - |
1537 | (((((uchar) ((qRed(*p) * (5) + 127) / 255)))*(5 +1)+(((uchar) ((qGreen(*p) * (5) + 127) / 255))))*(5 +1)+(((uchar) ((qBlue(*p) * (5) + 127) / 255)))); | - |
1538 | | - |
1539 | | - |
1540 | | - |
1541 | | - |
1542 | | - |
1543 | p++; | - |
1544 | } | - |
1545 | src_data += src->bytes_per_line; | - |
1546 | dest_data += dst->bytes_per_line; | - |
1547 | } | - |
1548 | } else if ((flags & Qt::Dither_Mask) == Qt::DiffuseDither) { | - |
1549 | int* line1[3]; | - |
1550 | int* line2[3]; | - |
1551 | int* pv[3]; | - |
1552 | QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]); | - |
1553 | line1[0] = lineBuffer.data(); | - |
1554 | line2[0] = lineBuffer.data() + src->width; | - |
1555 | line1[1] = lineBuffer.data() + src->width * 2; | - |
1556 | line2[1] = lineBuffer.data() + src->width * 3; | - |
1557 | line1[2] = lineBuffer.data() + src->width * 4; | - |
1558 | line2[2] = lineBuffer.data() + src->width * 5; | - |
1559 | pv[0] = lineBuffer.data() + src->width * 6; | - |
1560 | pv[1] = lineBuffer.data() + src->width * 7; | - |
1561 | pv[2] = lineBuffer.data() + src->width * 8; | - |
1562 | | - |
1563 | int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian); | - |
1564 | for (int y = 0; y < src->height; y++) { | - |
1565 | const uchar* q = src_data; | - |
1566 | const uchar* q2 = y < src->height - 1 ? q + src->bytes_per_line : src->data; | - |
1567 | uchar *b = dest_data; | - |
1568 | for (int chan = 0; chan < 3; chan++) { | - |
1569 | int *l1 = (y&1) ? line2[chan] : line1[chan]; | - |
1570 | int *l2 = (y&1) ? line1[chan] : line2[chan]; | - |
1571 | if (y == 0) { | - |
1572 | for (int i = 0; i < src->width; i++) | - |
1573 | l1[i] = q[i*4+chan+endian]; | - |
1574 | } | - |
1575 | if (y+1 < src->height) { | - |
1576 | for (int i = 0; i < src->width; i++) | - |
1577 | l2[i] = q2[i*4+chan+endian]; | - |
1578 | } | - |
1579 | | - |
1580 | if (y&1) { | - |
1581 | for (int x = 0; x < src->width; x++) { | - |
1582 | int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); | - |
1583 | int err = l1[x] - pix * 255 / 5; | - |
1584 | pv[chan][x] = pix; | - |
1585 | | - |
1586 | | - |
1587 | if (x + 1< src->width) { | - |
1588 | l1[x+1] += (err*7)>>4; | - |
1589 | l2[x+1] += err>>4; | - |
1590 | } | - |
1591 | l2[x]+=(err*5)>>4; | - |
1592 | if (x>1) | - |
1593 | l2[x-1]+=(err*3)>>4; | - |
1594 | } | - |
1595 | } else { | - |
1596 | for (int x = src->width; x-- > 0;) { | - |
1597 | int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); | - |
1598 | int err = l1[x] - pix * 255 / 5; | - |
1599 | pv[chan][x] = pix; | - |
1600 | | - |
1601 | | - |
1602 | if (x > 0) { | - |
1603 | l1[x-1] += (err*7)>>4; | - |
1604 | l2[x-1] += err>>4; | - |
1605 | } | - |
1606 | l2[x]+=(err*5)>>4; | - |
1607 | if (x + 1 < src->width) | - |
1608 | l2[x+1]+=(err*3)>>4; | - |
1609 | } | - |
1610 | } | - |
1611 | } | - |
1612 | if (endian) { | - |
1613 | for (int x = 0; x < src->width; x++) { | - |
1614 | *b++ = (((pv[0][x])*(5 +1)+(pv[1][x]))*(5 +1)+(pv[2][x])); | - |
1615 | } | - |
1616 | } else { | - |
1617 | for (int x = 0; x < src->width; x++) { | - |
1618 | *b++ = (((pv[2][x])*(5 +1)+(pv[1][x]))*(5 +1)+(pv[0][x])); | - |
1619 | } | - |
1620 | } | - |
1621 | src_data += src->bytes_per_line; | - |
1622 | dest_data += dst->bytes_per_line; | - |
1623 | } | - |
1624 | } else { | - |
1625 | for (int y = 0; y < src->height; y++) { | - |
1626 | const QRgb *p = (const QRgb *)src_data; | - |
1627 | const QRgb *end = p + src->width; | - |
1628 | uchar *b = dest_data; | - |
1629 | | - |
1630 | int x = 0; | - |
1631 | while (p < end) { | - |
1632 | uint d = qt_bayer_matrix[y & 15][x & 15] << 8; | - |
1633 | | - |
1634 | | - |
1635 | *b++ = | - |
1636 | (((((uchar) ((((256 * (5) + (5) + 1)) * (qRed(*p)) + (d)) >> 16)))*(5 +1)+(((uchar) ((((256 * (5) + (5) + 1)) * (qGreen(*p)) + (d)) >> 16))))*(5 +1)+(((uchar) ((((256 * (5) + (5) + 1)) * (qBlue(*p)) + (d)) >> 16)))); | - |
1637 | | - |
1638 | | - |
1639 | | - |
1640 | | - |
1641 | | - |
1642 | | - |
1643 | p++; | - |
1644 | x++; | - |
1645 | } | - |
1646 | src_data += src->bytes_per_line; | - |
1647 | dest_data += dst->bytes_per_line; | - |
1648 | } | - |
1649 | } | - |
1650 | | - |
1651 | if (src->format != QImage::Format_RGB32 | - |
1652 | && src->format != QImage::Format_RGB16) { | - |
1653 | const int trans = 216; | - |
1654 | qt_noop(); | - |
1655 | dst->colortable[trans] = 0; | - |
1656 | QScopedPointer<QImageData> mask(QImageData::create(QSize(src->width, src->height), QImage::Format_Mono)); | - |
1657 | dither_to_Mono(mask.data(), src, flags, true); | - |
1658 | uchar *dst_data = dst->data; | - |
1659 | const uchar *mask_data = mask->data; | - |
1660 | for (int y = 0; y < src->height; y++) { | - |
1661 | for (int x = 0; x < src->width ; x++) { | - |
1662 | if (!(mask_data[x>>3] & (0x80 >> (x & 7)))) | - |
1663 | dst_data[x] = trans; | - |
1664 | } | - |
1665 | mask_data += mask->bytes_per_line; | - |
1666 | dst_data += dst->bytes_per_line; | - |
1667 | } | - |
1668 | dst->has_alpha_clut = true; | - |
1669 | } | - |
1670 | | - |
1671 | | - |
1672 | | - |
1673 | | - |
1674 | | - |
1675 | | - |
1676 | } | - |
1677 | } | - |
1678 | | - |
1679 | static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1680 | { | - |
1681 | QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32)); | - |
1682 | convert_ARGB_PM_to_ARGB(tmp.data(), src, flags); | - |
1683 | convert_RGB_to_Indexed8(dst, tmp.data(), flags); | - |
1684 | } | - |
1685 | | - |
1686 | static void convert_ARGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1687 | { | - |
1688 | convert_RGB_to_Indexed8(dst, src, flags); | - |
1689 | } | - |
1690 | | - |
1691 | static void convert_Indexed8_to_X32(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1692 | { | - |
1693 | qt_noop(); | - |
1694 | qt_noop(); | - |
1695 | | - |
1696 | | - |
1697 | qt_noop(); | - |
1698 | qt_noop(); | - |
1699 | | - |
1700 | QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); | - |
1701 | if (colorTable.size() == 0) { | - |
1702 | colorTable.resize(256); | - |
1703 | for (int i=0; i<256; ++i) | - |
1704 | colorTable[i] = qRgb(i, i, i); | - |
1705 | } | - |
1706 | | - |
1707 | int w = src->width; | - |
1708 | const uchar *src_data = src->data; | - |
1709 | uchar *dest_data = dest->data; | - |
1710 | int tableSize = colorTable.size() - 1; | - |
1711 | for (int y = 0; y < src->height; y++) { | - |
1712 | uint *p = (uint *)dest_data; | - |
1713 | const uchar *b = src_data; | - |
1714 | uint *end = p + w; | - |
1715 | | - |
1716 | while (p < end) | - |
1717 | *p++ = colorTable.at(qMin<int>(tableSize, *b++)); | - |
1718 | | - |
1719 | src_data += src->bytes_per_line; | - |
1720 | dest_data += dest->bytes_per_line; | - |
1721 | } | - |
1722 | } | - |
1723 | | - |
1724 | static void convert_Mono_to_X32(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1725 | { | - |
1726 | qt_noop(); | - |
1727 | qt_noop(); | - |
1728 | | - |
1729 | | - |
1730 | qt_noop(); | - |
1731 | qt_noop(); | - |
1732 | | - |
1733 | QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); | - |
1734 | | - |
1735 | | - |
1736 | if (colorTable.size() < 2) { | - |
1737 | if (colorTable.size() == 0) | - |
1738 | colorTable << 0xff000000; | - |
1739 | colorTable << 0xffffffff; | - |
1740 | } | - |
1741 | | - |
1742 | const uchar *src_data = src->data; | - |
1743 | uchar *dest_data = dest->data; | - |
1744 | if (src->format == QImage::Format_Mono) { | - |
1745 | for (int y = 0; y < dest->height; y++) { | - |
1746 | register uint *p = (uint *)dest_data; | - |
1747 | for (int x = 0; x < dest->width; x++) | - |
1748 | *p++ = colorTable.at((src_data[x>>3] >> (7 - (x & 7))) & 1); | - |
1749 | | - |
1750 | src_data += src->bytes_per_line; | - |
1751 | dest_data += dest->bytes_per_line; | - |
1752 | } | - |
1753 | } else { | - |
1754 | for (int y = 0; y < dest->height; y++) { | - |
1755 | register uint *p = (uint *)dest_data; | - |
1756 | for (int x = 0; x < dest->width; x++) | - |
1757 | *p++ = colorTable.at((src_data[x>>3] >> (x & 7)) & 1); | - |
1758 | | - |
1759 | src_data += src->bytes_per_line; | - |
1760 | dest_data += dest->bytes_per_line; | - |
1761 | } | - |
1762 | } | - |
1763 | } | - |
1764 | | - |
1765 | | - |
1766 | static void convert_Mono_to_Indexed8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1767 | { | - |
1768 | qt_noop(); | - |
1769 | qt_noop(); | - |
1770 | qt_noop(); | - |
1771 | qt_noop(); | - |
1772 | | - |
1773 | QVector<QRgb> ctbl = src->colortable; | - |
1774 | if (ctbl.size() > 2) { | - |
1775 | ctbl.resize(2); | - |
1776 | } else if (ctbl.size() < 2) { | - |
1777 | if (ctbl.size() == 0) | - |
1778 | ctbl << 0xff000000; | - |
1779 | ctbl << 0xffffffff; | - |
1780 | } | - |
1781 | dest->colortable = ctbl; | - |
1782 | dest->has_alpha_clut = src->has_alpha_clut; | - |
1783 | | - |
1784 | | - |
1785 | const uchar *src_data = src->data; | - |
1786 | uchar *dest_data = dest->data; | - |
1787 | if (src->format == QImage::Format_Mono) { | - |
1788 | for (int y = 0; y < dest->height; y++) { | - |
1789 | register uchar *p = dest_data; | - |
1790 | for (int x = 0; x < dest->width; x++) | - |
1791 | *p++ = (src_data[x>>3] >> (7 - (x & 7))) & 1; | - |
1792 | src_data += src->bytes_per_line; | - |
1793 | dest_data += dest->bytes_per_line; | - |
1794 | } | - |
1795 | } else { | - |
1796 | for (int y = 0; y < dest->height; y++) { | - |
1797 | register uchar *p = dest_data; | - |
1798 | for (int x = 0; x < dest->width; x++) | - |
1799 | *p++ = (src_data[x>>3] >> (x & 7)) & 1; | - |
1800 | src_data += src->bytes_per_line; | - |
1801 | dest_data += dest->bytes_per_line; | - |
1802 | } | - |
1803 | } | - |
1804 | } | - |
1805 | | - |
1806 | | - |
1807 | static void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1808 | { | - |
1809 | const int buffer_size = 2048; | - |
1810 | uint buffer[buffer_size]; | - |
1811 | const QPixelLayout *srcLayout = &qPixelLayouts[src->format]; | - |
1812 | const QPixelLayout *destLayout = &qPixelLayouts[dest->format]; | - |
1813 | const uchar *srcData = src->data; | - |
1814 | uchar *destData = dest->data; | - |
1815 | | - |
1816 | FetchPixelsFunc fetch = qFetchPixels[srcLayout->bpp]; | - |
1817 | StorePixelsFunc store = qStorePixels[destLayout->bpp]; | - |
1818 | | - |
1819 | for (int y = 0; y < src->height; ++y) { | - |
1820 | int x = 0; | - |
1821 | while (x < src->width) { | - |
1822 | int l = qMin(src->width - x, buffer_size); | - |
1823 | const uint *ptr = fetch(buffer, srcData, x, l); | - |
1824 | ptr = srcLayout->convertToARGB32PM(buffer, ptr, l, srcLayout, 0); | - |
1825 | ptr = destLayout->convertFromARGB32PM(buffer, ptr, l, destLayout, 0); | - |
1826 | store(destData, ptr, x, l); | - |
1827 | x += l; | - |
1828 | } | - |
1829 | srcData += src->bytes_per_line; | - |
1830 | destData += dest->bytes_per_line; | - |
1831 | } | - |
1832 | } | - |
1833 | | - |
1834 | | - |
1835 | | - |
1836 | static Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats] = | - |
1837 | { | - |
1838 | { | - |
1839 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
1840 | }, | - |
1841 | { | - |
1842 | 0, | - |
1843 | 0, | - |
1844 | swap_bit_order, | - |
1845 | convert_Mono_to_Indexed8, | - |
1846 | convert_Mono_to_X32, | - |
1847 | convert_Mono_to_X32, | - |
1848 | convert_Mono_to_X32, | - |
1849 | 0, | - |
1850 | 0, | - |
1851 | 0, | - |
1852 | 0, | - |
1853 | 0, | - |
1854 | 0, | - |
1855 | 0, | - |
1856 | 0, | - |
1857 | 0 | - |
1858 | }, | - |
1859 | | - |
1860 | { | - |
1861 | 0, | - |
1862 | swap_bit_order, | - |
1863 | 0, | - |
1864 | convert_Mono_to_Indexed8, | - |
1865 | convert_Mono_to_X32, | - |
1866 | convert_Mono_to_X32, | - |
1867 | convert_Mono_to_X32, | - |
1868 | 0, | - |
1869 | 0, | - |
1870 | 0, | - |
1871 | 0, | - |
1872 | 0, | - |
1873 | 0, | - |
1874 | 0, | - |
1875 | 0, | - |
1876 | 0 | - |
1877 | }, | - |
1878 | | - |
1879 | { | - |
1880 | 0, | - |
1881 | convert_X_to_Mono, | - |
1882 | convert_X_to_Mono, | - |
1883 | 0, | - |
1884 | convert_Indexed8_to_X32, | - |
1885 | convert_Indexed8_to_X32, | - |
1886 | convert_Indexed8_to_X32, | - |
1887 | 0, | - |
1888 | 0, | - |
1889 | 0, | - |
1890 | 0, | - |
1891 | 0, | - |
1892 | 0, | - |
1893 | 0, | - |
1894 | 0, | - |
1895 | 0 | - |
1896 | }, | - |
1897 | | - |
1898 | { | - |
1899 | 0, | - |
1900 | convert_X_to_Mono, | - |
1901 | convert_X_to_Mono, | - |
1902 | convert_RGB_to_Indexed8, | - |
1903 | 0, | - |
1904 | mask_alpha_converter, | - |
1905 | mask_alpha_converter, | - |
1906 | convert_generic, | - |
1907 | convert_generic, | - |
1908 | convert_generic, | - |
1909 | convert_generic, | - |
1910 | convert_generic, | - |
1911 | convert_generic, | - |
1912 | convert_generic, | - |
1913 | convert_generic, | - |
1914 | convert_generic | - |
1915 | }, | - |
1916 | | - |
1917 | { | - |
1918 | 0, | - |
1919 | convert_X_to_Mono, | - |
1920 | convert_X_to_Mono, | - |
1921 | convert_ARGB_to_Indexed8, | - |
1922 | mask_alpha_converter, | - |
1923 | 0, | - |
1924 | convert_ARGB_to_ARGB_PM, | - |
1925 | convert_generic, | - |
1926 | convert_generic, | - |
1927 | convert_generic, | - |
1928 | convert_generic, | - |
1929 | convert_generic, | - |
1930 | convert_generic, | - |
1931 | convert_generic, | - |
1932 | convert_generic, | - |
1933 | convert_generic | - |
1934 | }, | - |
1935 | | - |
1936 | { | - |
1937 | 0, | - |
1938 | convert_ARGB_PM_to_Mono, | - |
1939 | convert_ARGB_PM_to_Mono, | - |
1940 | convert_ARGB_PM_to_Indexed8, | - |
1941 | convert_ARGB_PM_to_RGB, | - |
1942 | convert_ARGB_PM_to_ARGB, | - |
1943 | 0, | - |
1944 | 0, | - |
1945 | 0, | - |
1946 | 0, | - |
1947 | 0, | - |
1948 | 0, | - |
1949 | 0, | - |
1950 | 0, | - |
1951 | 0, | - |
1952 | 0 | - |
1953 | }, | - |
1954 | | - |
1955 | { | - |
1956 | 0, | - |
1957 | 0, | - |
1958 | 0, | - |
1959 | 0, | - |
1960 | convert_generic, | - |
1961 | convert_generic, | - |
1962 | convert_generic, | - |
1963 | 0, | - |
1964 | 0, | - |
1965 | 0, | - |
1966 | 0, | - |
1967 | | - |
1968 | | - |
1969 | | - |
1970 | 0, | - |
1971 | | - |
1972 | 0, | - |
1973 | 0, | - |
1974 | 0, | - |
1975 | 0 | - |
1976 | }, | - |
1977 | | - |
1978 | { | - |
1979 | 0, | - |
1980 | 0, | - |
1981 | 0, | - |
1982 | 0, | - |
1983 | convert_generic, | - |
1984 | convert_generic, | - |
1985 | convert_generic, | - |
1986 | 0, | - |
1987 | 0, | - |
1988 | 0, | - |
1989 | 0, | - |
1990 | 0, | - |
1991 | 0, | - |
1992 | 0, | - |
1993 | 0, | - |
1994 | 0 | - |
1995 | }, | - |
1996 | | - |
1997 | { | - |
1998 | 0, | - |
1999 | 0, | - |
2000 | 0, | - |
2001 | 0, | - |
2002 | convert_generic, | - |
2003 | convert_generic, | - |
2004 | convert_generic, | - |
2005 | 0, | - |
2006 | 0, | - |
2007 | 0, | - |
2008 | 0, | - |
2009 | 0, | - |
2010 | 0, | - |
2011 | 0, | - |
2012 | 0, | - |
2013 | 0 | - |
2014 | }, | - |
2015 | | - |
2016 | { | - |
2017 | 0, | - |
2018 | 0, | - |
2019 | 0, | - |
2020 | 0, | - |
2021 | convert_generic, | - |
2022 | convert_generic, | - |
2023 | convert_generic, | - |
2024 | 0, | - |
2025 | 0, | - |
2026 | 0, | - |
2027 | 0, | - |
2028 | 0, | - |
2029 | 0, | - |
2030 | 0, | - |
2031 | 0, | - |
2032 | 0 | - |
2033 | }, | - |
2034 | | - |
2035 | { | - |
2036 | 0, | - |
2037 | 0, | - |
2038 | 0, | - |
2039 | 0, | - |
2040 | convert_generic, | - |
2041 | convert_generic, | - |
2042 | convert_generic, | - |
2043 | | - |
2044 | | - |
2045 | | - |
2046 | 0, | - |
2047 | | - |
2048 | 0, | - |
2049 | 0, | - |
2050 | 0, | - |
2051 | 0, | - |
2052 | 0, | - |
2053 | 0, | - |
2054 | 0, | - |
2055 | 0 | - |
2056 | }, | - |
2057 | | - |
2058 | { | - |
2059 | 0, | - |
2060 | 0, | - |
2061 | 0, | - |
2062 | 0, | - |
2063 | convert_generic, | - |
2064 | convert_generic, | - |
2065 | convert_generic, | - |
2066 | 0, | - |
2067 | 0, | - |
2068 | 0, | - |
2069 | 0, | - |
2070 | 0, | - |
2071 | 0, | - |
2072 | 0, | - |
2073 | 0, | - |
2074 | 0 | - |
2075 | }, | - |
2076 | | - |
2077 | { | - |
2078 | 0, | - |
2079 | 0, | - |
2080 | 0, | - |
2081 | 0, | - |
2082 | convert_generic, | - |
2083 | convert_generic, | - |
2084 | convert_generic, | - |
2085 | 0, | - |
2086 | 0, | - |
2087 | 0, | - |
2088 | 0, | - |
2089 | 0, | - |
2090 | 0, | - |
2091 | 0, | - |
2092 | 0, | - |
2093 | 0 | - |
2094 | }, | - |
2095 | | - |
2096 | { | - |
2097 | 0, | - |
2098 | 0, | - |
2099 | 0, | - |
2100 | 0, | - |
2101 | convert_generic, | - |
2102 | convert_generic, | - |
2103 | convert_generic, | - |
2104 | 0, | - |
2105 | 0, | - |
2106 | 0, | - |
2107 | 0, | - |
2108 | 0, | - |
2109 | 0, | - |
2110 | 0, | - |
2111 | 0, | - |
2112 | 0 | - |
2113 | }, | - |
2114 | | - |
2115 | { | - |
2116 | 0, | - |
2117 | 0, | - |
2118 | 0, | - |
2119 | 0, | - |
2120 | convert_generic, | - |
2121 | convert_generic, | - |
2122 | convert_generic, | - |
2123 | 0, | - |
2124 | 0, | - |
2125 | 0, | - |
2126 | 0, | - |
2127 | 0, | - |
2128 | 0, | - |
2129 | 0, | - |
2130 | 0, | - |
2131 | 0 | - |
2132 | } | - |
2133 | }; | - |
2134 | | - |
2135 | static InPlace_Image_Converter inplace_converter_map[QImage::NImageFormats][QImage::NImageFormats] = | - |
2136 | { | - |
2137 | { | - |
2138 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2139 | }, | - |
2140 | { | - |
2141 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2142 | }, | - |
2143 | { | - |
2144 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2145 | }, | - |
2146 | { | - |
2147 | 0, | - |
2148 | 0, | - |
2149 | 0, | - |
2150 | 0, | - |
2151 | 0, | - |
2152 | convert_indexed8_to_RGB_inplace, | - |
2153 | convert_indexed8_to_ARGB_PM_inplace, | - |
2154 | convert_indexed8_to_RGB16_inplace, | - |
2155 | 0, | - |
2156 | 0, | - |
2157 | 0, | - |
2158 | 0, | - |
2159 | 0, | - |
2160 | 0, | - |
2161 | 0, | - |
2162 | 0, | - |
2163 | }, | - |
2164 | { | - |
2165 | 0, | - |
2166 | 0, | - |
2167 | 0, | - |
2168 | 0, | - |
2169 | 0, | - |
2170 | 0, | - |
2171 | 0, | - |
2172 | convert_RGB_to_RGB16_inplace, | - |
2173 | 0, | - |
2174 | 0, | - |
2175 | 0, | - |
2176 | 0, | - |
2177 | 0, | - |
2178 | 0, | - |
2179 | 0, | - |
2180 | 0, | - |
2181 | }, | - |
2182 | { | - |
2183 | 0, | - |
2184 | 0, | - |
2185 | 0, | - |
2186 | 0, | - |
2187 | 0, | - |
2188 | 0, | - |
2189 | convert_ARGB_to_ARGB_PM_inplace, | - |
2190 | 0, | - |
2191 | 0, | - |
2192 | 0, | - |
2193 | 0, | - |
2194 | 0, | - |
2195 | 0, | - |
2196 | 0, | - |
2197 | 0, | - |
2198 | 0, | - |
2199 | }, | - |
2200 | { | - |
2201 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2202 | }, | - |
2203 | { | - |
2204 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2205 | }, | - |
2206 | { | - |
2207 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2208 | }, | - |
2209 | { | - |
2210 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2211 | }, | - |
2212 | { | - |
2213 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2214 | }, | - |
2215 | { | - |
2216 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2217 | }, | - |
2218 | { | - |
2219 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2220 | }, | - |
2221 | { | - |
2222 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2223 | }, | - |
2224 | { | - |
2225 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2226 | }, | - |
2227 | { | - |
2228 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2229 | } | - |
2230 | }; | - |
2231 | | - |
2232 | void qInitImageConversions() | - |
2233 | { | - |
2234 | | - |
2235 | if (qCpuHasFeature(AVX)) { | - |
2236 | extern bool convert_ARGB_to_ARGB_PM_inplace_avx(QImageData *data, Qt::ImageConversionFlags); | - |
2237 | inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_avx; | - |
2238 | | - |
2239 | extern void convert_RGB888_to_RGB32_avx(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
2240 | converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_avx; | - |
2241 | converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_avx; | - |
2242 | converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_avx; | - |
2243 | return; | - |
2244 | } | - |
2245 | | - |
2246 | | - |
2247 | | - |
2248 | if (qCpuHasFeature(SSE2)) { | - |
2249 | extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags); | - |
2250 | inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2; | - |
2251 | | - |
2252 | if (qCpuHasFeature(SSSE3)) { | - |
2253 | extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
2254 | converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3; | - |
2255 | converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3; | - |
2256 | converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_ssse3; | - |
2257 | } | - |
2258 | | - |
2259 | return; | - |
2260 | } | - |
2261 | } | - |
2262 | | - |
2263 | extern const uchar *qt_pow_rgb_gamma(); | - |
2264 | | - |
2265 | void qGamma_correct_back_to_linear_cs(QImage *image) | - |
2266 | { | - |
2267 | const QDrawHelperGammaTables *tables = QGuiApplicationPrivate::instance()->gammaTables(); | - |
2268 | if (!tables) | - |
2269 | return; | - |
2270 | const uchar *gamma = tables->qt_pow_rgb_gamma; | - |
2271 | | - |
2272 | int h = image->height(); | - |
2273 | int w = image->width(); | - |
2274 | | - |
2275 | for (int y=0; y<h; ++y) { | - |
2276 | uint *pixels = (uint *) image->scanLine(y); | - |
2277 | for (int x=0; x<w; ++x) { | - |
2278 | uint p = pixels[x]; | - |
2279 | uint r = gamma[qRed(p)]; | - |
2280 | uint g = gamma[qGreen(p)]; | - |
2281 | uint b = gamma[qBlue(p)]; | - |
2282 | pixels[x] = (r << 16) | (g << 8) | b | 0xff000000; | - |
2283 | } | - |
2284 | } | - |
2285 | } | - |
2286 | QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const | - |
2287 | { | - |
2288 | if (!d || d->format == format) | - |
2289 | return *this; | - |
2290 | | - |
2291 | if (format == Format_Invalid || d->format == Format_Invalid) | - |
2292 | return QImage(); | - |
2293 | | - |
2294 | const Image_Converter *converterPtr = &converter_map[d->format][format]; | - |
2295 | Image_Converter converter = *converterPtr; | - |
2296 | if (converter) { | - |
2297 | QImage image(d->width, d->height, format); | - |
2298 | | - |
2299 | if ((image).isNull()) { QMessageLogger("image/qimage.cpp", 34073405, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2300 | | - |
2301 | image.setDotsPerMeterY(dotsPerMeterY()); | - |
2302 | image.setDotsPerMeterX(dotsPerMeterX()); | - |
2303 | image.setDevicePixelRatio(devicePixelRatio()); | - |
2304 | | - |
2305 | image.d->text = d->text; | - |
2306 | | - |
2307 | converter(image.d, d, flags); | - |
2308 | return image; | - |
2309 | } | - |
2310 | | - |
2311 | qt_noop(); | - |
2312 | qt_noop(); | - |
2313 | | - |
2314 | QImage image = convertToFormat(Format_ARGB32, flags); | - |
2315 | return image.convertToFormat(format, flags); | - |
2316 | } | - |
2317 | | - |
2318 | | - |
2319 | | - |
2320 | static inline int pixel_distance(QRgb p1, QRgb p2) { | - |
2321 | int r1 = qRed(p1); | - |
2322 | int g1 = qGreen(p1); | - |
2323 | int b1 = qBlue(p1); | - |
2324 | int a1 = qAlpha(p1); | - |
2325 | | - |
2326 | int r2 = qRed(p2); | - |
2327 | int g2 = qGreen(p2); | - |
2328 | int b2 = qBlue(p2); | - |
2329 | int a2 = qAlpha(p2); | - |
2330 | | - |
2331 | return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2); | - |
2332 | } | - |
2333 | | - |
2334 | static inline int closestMatch(QRgb pixel, const QVector<QRgb> &clut) { | - |
2335 | int idx = 0; | - |
2336 | int current_distance = 2147483647; | - |
2337 | for (int i=0; i<clut.size(); ++i) { | - |
2338 | int dist = pixel_distance(pixel, clut.at(i)); | - |
2339 | if (dist < current_distance) { | - |
2340 | current_distance = dist; | - |
2341 | idx = i; | - |
2342 | } | - |
2343 | } | - |
2344 | return idx; | - |
2345 | } | - |
2346 | | - |
2347 | static QImage convertWithPalette(const QImage &src, QImage::Format format, | - |
2348 | const QVector<QRgb> &clut) { | - |
2349 | QImage dest(src.size(), format); | - |
2350 | dest.setColorTable(clut); | - |
2351 | | - |
2352 | QString textsKeys = src.text(); | - |
2353 | QStringList textKeyList = textsKeys.split(QLatin1Char('\n'), QString::SkipEmptyParts); | - |
2354 | for (QForeachContainer<__typeof__(textKeyList)> _container_(textKeyList); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &textKey = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
2355 | QStringList textKeySplitted = textKey.split(QLatin1String(": ")); | - |
2356 | dest.setText(textKeySplitted[0], textKeySplitted[1]); | - |
2357 | } | - |
2358 | | - |
2359 | int h = src.height(); | - |
2360 | int w = src.width(); | - |
2361 | | - |
2362 | QHash<QRgb, int> cache; | - |
2363 | | - |
2364 | if (format == QImage::Format_Indexed8) { | - |
2365 | for (int y=0; y<h; ++y) { | - |
2366 | QRgb *src_pixels = (QRgb *) src.scanLine(y); | - |
2367 | uchar *dest_pixels = (uchar *) dest.scanLine(y); | - |
2368 | for (int x=0; x<w; ++x) { | - |
2369 | int src_pixel = src_pixels[x]; | - |
2370 | int value = cache.value(src_pixel, -1); | - |
2371 | if (value == -1) { | - |
2372 | value = closestMatch(src_pixel, clut); | - |
2373 | cache.insert(src_pixel, value); | - |
2374 | } | - |
2375 | dest_pixels[x] = (uchar) value; | - |
2376 | } | - |
2377 | } | - |
2378 | } else { | - |
2379 | QVector<QRgb> table = clut; | - |
2380 | table.resize(2); | - |
2381 | for (int y=0; y<h; ++y) { | - |
2382 | QRgb *src_pixels = (QRgb *) src.scanLine(y); | - |
2383 | for (int x=0; x<w; ++x) { | - |
2384 | int src_pixel = src_pixels[x]; | - |
2385 | int value = cache.value(src_pixel, -1); | - |
2386 | if (value == -1) { | - |
2387 | value = closestMatch(src_pixel, table); | - |
2388 | cache.insert(src_pixel, value); | - |
2389 | } | - |
2390 | dest.setPixel(x, y, value); | - |
2391 | } | - |
2392 | } | - |
2393 | } | - |
2394 | | - |
2395 | return dest; | - |
2396 | } | - |
2397 | QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags) const | - |
2398 | { | - |
2399 | if (d->format == format) | - |
2400 | return *this; | - |
2401 | | - |
2402 | if (format <= QImage::Format_Indexed8 && depth() == 32) { | - |
2403 | return convertWithPalette(*this, format, colorTable); | - |
2404 | } | - |
2405 | | - |
2406 | const Image_Converter *converterPtr = &converter_map[d->format][format]; | - |
2407 | Image_Converter converter = *converterPtr; | - |
2408 | if (!converter) | - |
2409 | return QImage(); | - |
2410 | | - |
2411 | QImage image(d->width, d->height, format); | - |
2412 | if ((image).isNull()) { QMessageLogger("image/qimage.cpp", 35313529, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2413 | image.setDevicePixelRatio(devicePixelRatio()); | - |
2414 | | - |
2415 | image.d->text = d->text; | - |
2416 | | - |
2417 | converter(image.d, d, flags); | - |
2418 | return image; | - |
2419 | } | - |
2420 | bool QImage::valid(int x, int y) const | - |
2421 | { | - |
2422 | return d | - |
2423 | && x >= 0 && x < d->width | - |
2424 | && y >= 0 && y < d->height; | - |
2425 | } | - |
2426 | int QImage::pixelIndex(int x, int y) const | - |
2427 | { | - |
2428 | if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) { | - |
2429 | QMessageLogger("image/qimage.cpp", 35813579, __PRETTY_FUNCTION__).warning("QImage::pixelIndex: coordinate (%d,%d) out of range", x, y); | - |
2430 | return -12345; | - |
2431 | } | - |
2432 | const uchar * s = scanLine(y); | - |
2433 | switch(d->format) { | - |
2434 | case Format_Mono: | - |
2435 | return (*(s + (x >> 3)) >> (7- (x & 7))) & 1; | - |
2436 | case Format_MonoLSB: | - |
2437 | return (*(s + (x >> 3)) >> (x & 7)) & 1; | - |
2438 | case Format_Indexed8: | - |
2439 | return (int)s[x]; | - |
2440 | default: | - |
2441 | QMessageLogger("image/qimage.cpp", 35933591, __PRETTY_FUNCTION__).warning("QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth); | - |
2442 | } | - |
2443 | return 0; | - |
2444 | } | - |
2445 | QRgb QImage::pixel(int x, int y) const | - |
2446 | { | - |
2447 | if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) { | - |
2448 | QMessageLogger("image/qimage.cpp", 36213619, __PRETTY_FUNCTION__).warning("QImage::pixel: coordinate (%d,%d) out of range", x, y); | - |
2449 | return 12345; | - |
2450 | } | - |
2451 | | - |
2452 | const uchar * s = constScanLine(y); | - |
2453 | switch(d->format) { | - |
2454 | case Format_Mono: | - |
2455 | return d->colortable.at((*(s + (x >> 3)) >> (~x & 7)) & 1); | - |
2456 | case Format_MonoLSB: | - |
2457 | return d->colortable.at((*(s + (x >> 3)) >> (x & 7)) & 1); | - |
2458 | case Format_Indexed8: | - |
2459 | return d->colortable.at((int)s[x]); | - |
2460 | case Format_RGB32: | - |
2461 | case Format_ARGB32: | - |
2462 | case Format_ARGB32_Premultiplied: | - |
2463 | return reinterpret_cast<const QRgb *>(s)[x]; | - |
2464 | case Format_RGB16: | - |
2465 | return qConvertRgb16To32(reinterpret_cast<const quint16 *>(s)[x]); | - |
2466 | default: | - |
2467 | break; | - |
2468 | } | - |
2469 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - |
2470 | uint result; | - |
2471 | const uint *ptr = qFetchPixels[layout->bpp](&result, s, x, 1); | - |
2472 | return *layout->convertToARGB32PM(&result, ptr, 1, layout, 0); | - |
2473 | } | - |
2474 | void QImage::setPixel(int x, int y, uint index_or_rgb) | - |
2475 | { | - |
2476 | if (!d || x < 0 || x >= width() || y < 0 || y >= height()) { | - |
2477 | QMessageLogger("image/qimage.cpp", 36793677, __PRETTY_FUNCTION__).warning("QImage::setPixel: coordinate (%d,%d) out of range", x, y); | - |
2478 | return; | - |
2479 | } | - |
2480 | | - |
2481 | uchar * s = scanLine(y); | - |
2482 | switch(d->format) { | - |
2483 | case Format_Mono: | - |
2484 | case Format_MonoLSB: | - |
2485 | if (index_or_rgb > 1) { | - |
2486 | QMessageLogger("image/qimage.cpp", 36883686, __PRETTY_FUNCTION__).warning("QImage::setPixel: Index %d out of range", index_or_rgb); | - |
2487 | } else if (format() == Format_MonoLSB) { | - |
2488 | if (index_or_rgb==0) | - |
2489 | *(s + (x >> 3)) &= ~(1 << (x & 7)); | - |
2490 | else | - |
2491 | *(s + (x >> 3)) |= (1 << (x & 7)); | - |
2492 | } else { | - |
2493 | if (index_or_rgb==0) | - |
2494 | *(s + (x >> 3)) &= ~(1 << (7-(x & 7))); | - |
2495 | else | - |
2496 | *(s + (x >> 3)) |= (1 << (7-(x & 7))); | - |
2497 | } | - |
2498 | return; | - |
2499 | case Format_Indexed8: | - |
2500 | if (index_or_rgb >= (uint)d->colortable.size()) { | - |
2501 | QMessageLogger("image/qimage.cpp", 37033701, __PRETTY_FUNCTION__).warning("QImage::setPixel: Index %d out of range", index_or_rgb); | - |
2502 | return; | - |
2503 | } | - |
2504 | s[x] = index_or_rgb; | - |
2505 | return; | - |
2506 | case Format_RGB32: | - |
2507 | | - |
2508 | | - |
2509 | ((uint *)s)[x] = uint(255 << 24) | index_or_rgb; | - |
2510 | return; | - |
2511 | case Format_ARGB32: | - |
2512 | case Format_ARGB32_Premultiplied: | - |
2513 | ((uint *)s)[x] = index_or_rgb; | - |
2514 | return; | - |
2515 | case Format_RGB16: | - |
2516 | ((quint16 *)s)[x] = qConvertRgb32To16((qAlpha(index_or_rgb) == 0 ? 0 : ((qAlpha(index_or_rgb) << 24) | (((255*qRed(index_or_rgb))/ qAlpha(index_or_rgb)) << 16) | (((255*qGreen(index_or_rgb)) / qAlpha(index_or_rgb)) << 8) | ((255*qBlue(index_or_rgb)) / qAlpha(index_or_rgb))))); | - |
2517 | return; | - |
2518 | case Format_Invalid: | - |
2519 | case NImageFormats: | - |
2520 | qt_noop(); | - |
2521 | return; | - |
2522 | default: | - |
2523 | break; | - |
2524 | } | - |
2525 | | - |
2526 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - |
2527 | uint result; | - |
2528 | const uint *ptr = layout->convertFromARGB32PM(&result, &index_or_rgb, 1, layout, 0); | - |
2529 | qStorePixels[layout->bpp](s, ptr, x, 1); | - |
2530 | } | - |
2531 | bool QImage::allGray() const | - |
2532 | { | - |
2533 | if (!d) | - |
2534 | return true; | - |
2535 | | - |
2536 | switch (d->format) { | - |
2537 | case Format_Mono: | - |
2538 | case Format_MonoLSB: | - |
2539 | case Format_Indexed8: | - |
2540 | for (int i = 0; i < d->colortable.size(); ++i) { | - |
2541 | if (!qIsGray(d->colortable.at(i))) | - |
2542 | return false; | - |
2543 | } | - |
2544 | return true; | - |
2545 | case Format_RGB32: | - |
2546 | case Format_ARGB32: | - |
2547 | case Format_ARGB32_Premultiplied: | - |
2548 | for (int j = 0; j < d->height; ++j) { | - |
2549 | const QRgb *b = (const QRgb *)constScanLine(j); | - |
2550 | for (int i = 0; i < d->width; ++i) { | - |
2551 | if (!qIsGray(b[i])) | - |
2552 | return false; | - |
2553 | } | - |
2554 | } | - |
2555 | return true; | - |
2556 | case Format_RGB16: | - |
2557 | for (int j = 0; j < d->height; ++j) { | - |
2558 | const quint16 *b = (const quint16 *)constScanLine(j); | - |
2559 | for (int i = 0; i < d->width; ++i) { | - |
2560 | if (!qIsGray(qConvertRgb16To32(b[i]))) | - |
2561 | return false; | - |
2562 | } | - |
2563 | } | - |
2564 | return true; | - |
2565 | default: | - |
2566 | break; | - |
2567 | } | - |
2568 | | - |
2569 | const int buffer_size = 2048; | - |
2570 | uint buffer[buffer_size]; | - |
2571 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - |
2572 | FetchPixelsFunc fetch = qFetchPixels[layout->bpp]; | - |
2573 | for (int j = 0; j < d->height; ++j) { | - |
2574 | const uchar *b = constScanLine(j); | - |
2575 | int x = 0; | - |
2576 | while (x < d->width) { | - |
2577 | int l = qMin(d->width - x, buffer_size); | - |
2578 | const uint *ptr = fetch(buffer, b, x, l); | - |
2579 | ptr = layout->convertToARGB32PM(buffer, ptr, l, layout, 0); | - |
2580 | for (int i = 0; i < l; ++i) { | - |
2581 | if (!qIsGray(ptr[i])) | - |
2582 | return false; | - |
2583 | } | - |
2584 | x += l; | - |
2585 | } | - |
2586 | } | - |
2587 | return true; | - |
2588 | } | - |
2589 | bool QImage::isGrayscale() const | - |
2590 | { | - |
2591 | if (!d) | - |
2592 | return false; | - |
2593 | | - |
2594 | switch (depth()) { | - |
2595 | case 32: | - |
2596 | case 24: | - |
2597 | case 16: | - |
2598 | return allGray(); | - |
2599 | case 8: { | - |
2600 | for (int i = 0; i < colorCount(); i++) | - |
2601 | if (d->colortable.at(i) != qRgb(i,i,i)) | - |
2602 | return false; | - |
2603 | return true; | - |
2604 | } | - |
2605 | } | - |
2606 | return false; | - |
2607 | } | - |
2608 | QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const | - |
2609 | { | - |
2610 | if (!d) { | - |
2611 | QMessageLogger("image/qimage.cpp", 38723870, __PRETTY_FUNCTION__).warning("QImage::scaled: Image is a null image"); | - |
2612 | return QImage(); | - |
2613 | } | - |
2614 | if (s.isEmpty()) | - |
2615 | return QImage(); | - |
2616 | | - |
2617 | QSize newSize = size(); | - |
2618 | newSize.scale(s, aspectMode); | - |
2619 | newSize.rwidth() = qMax(newSize.width(), 1); | - |
2620 | newSize.rheight() = qMax(newSize.height(), 1); | - |
2621 | if (newSize == size()) | - |
2622 | return *this; | - |
2623 | | - |
2624 | QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); | - |
2625 | QImage img = transformed(wm, mode); | - |
2626 | return img; | - |
2627 | } | - |
2628 | QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const | - |
2629 | { | - |
2630 | if (!d) { | - |
2631 | QMessageLogger("image/qimage.cpp", 39073905, __PRETTY_FUNCTION__).warning("QImage::scaleWidth: Image is a null image"); | - |
2632 | return QImage(); | - |
2633 | } | - |
2634 | if (w <= 0) | - |
2635 | return QImage(); | - |
2636 | | - |
2637 | qreal factor = (qreal) w / width(); | - |
2638 | QTransform wm = QTransform::fromScale(factor, factor); | - |
2639 | return transformed(wm, mode); | - |
2640 | } | - |
2641 | QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const | - |
2642 | { | - |
2643 | if (!d) { | - |
2644 | QMessageLogger("image/qimage.cpp", 39353933, __PRETTY_FUNCTION__).warning("QImage::scaleHeight: Image is a null image"); | - |
2645 | return QImage(); | - |
2646 | } | - |
2647 | if (h <= 0) | - |
2648 | return QImage(); | - |
2649 | | - |
2650 | qreal factor = (qreal) h / height(); | - |
2651 | QTransform wm = QTransform::fromScale(factor, factor); | - |
2652 | return transformed(wm, mode); | - |
2653 | } | - |
2654 | QMatrix QImage::trueMatrix(const QMatrix &matrix, int w, int h) | - |
2655 | { | - |
2656 | return trueMatrix(QTransform(matrix), w, h).toAffine(); | - |
2657 | } | - |
2658 | QImage QImage::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const | - |
2659 | { | - |
2660 | return transformed(QTransform(matrix), mode); | - |
2661 | } | - |
2662 | QImage QImage::createAlphaMask(Qt::ImageConversionFlags flags) const | - |
2663 | { | - |
2664 | if (!d || d->format == QImage::Format_RGB32) | - |
2665 | return QImage(); | - |
2666 | | - |
2667 | if (d->depth == 1) { | - |
2668 | | - |
2669 | | - |
2670 | return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags); | - |
2671 | } | - |
2672 | | - |
2673 | QImage mask(d->width, d->height, Format_MonoLSB); | - |
2674 | if (!mask.isNull()) | - |
2675 | dither_to_Mono(mask.d, d, flags, true); | - |
2676 | return mask; | - |
2677 | } | - |
2678 | QImage QImage::createHeuristicMask(bool clipTight) const | - |
2679 | { | - |
2680 | if (!d) | - |
2681 | return QImage(); | - |
2682 | | - |
2683 | if (d->depth != 32) { | - |
2684 | QImage img32 = convertToFormat(Format_RGB32); | - |
2685 | return img32.createHeuristicMask(clipTight); | - |
2686 | } | - |
2687 | | - |
2688 | | - |
2689 | | - |
2690 | int w = width(); | - |
2691 | int h = height(); | - |
2692 | QImage m(w, h, Format_MonoLSB); | - |
2693 | if ((m).isNull()) { QMessageLogger("image/qimage.cpp", 40604058, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2694 | m.setColorCount(2); | - |
2695 | m.setColor(0, QColor(Qt::color0).rgba()); | - |
2696 | m.setColor(1, QColor(Qt::color1).rgba()); | - |
2697 | m.fill(0xff); | - |
2698 | | - |
2699 | QRgb background = (*((QRgb*)scanLine(0)+0) & 0x00ffffff); | - |
2700 | if (background != (*((QRgb*)scanLine(0)+w-1) & 0x00ffffff) && | - |
2701 | background != (*((QRgb*)scanLine(h-1)+0) & 0x00ffffff) && | - |
2702 | background != (*((QRgb*)scanLine(h-1)+w-1) & 0x00ffffff)) { | - |
2703 | background = (*((QRgb*)scanLine(0)+w-1) & 0x00ffffff); | - |
2704 | if (background != (*((QRgb*)scanLine(h-1)+w-1) & 0x00ffffff) && | - |
2705 | background != (*((QRgb*)scanLine(h-1)+0) & 0x00ffffff) && | - |
2706 | (*((QRgb*)scanLine(h-1)+0) & 0x00ffffff) == (*((QRgb*)scanLine(h-1)+w-1) & 0x00ffffff)) { | - |
2707 | background = (*((QRgb*)scanLine(h-1)+w-1) & 0x00ffffff); | - |
2708 | } | - |
2709 | } | - |
2710 | | - |
2711 | int x,y; | - |
2712 | bool done = false; | - |
2713 | uchar *ypp, *ypc, *ypn; | - |
2714 | while(!done) { | - |
2715 | done = true; | - |
2716 | ypn = m.scanLine(0); | - |
2717 | ypc = 0; | - |
2718 | for (y = 0; y < h; y++) { | - |
2719 | ypp = ypc; | - |
2720 | ypc = ypn; | - |
2721 | ypn = (y == h-1) ? 0 : m.scanLine(y+1); | - |
2722 | QRgb *p = (QRgb *)scanLine(y); | - |
2723 | for (x = 0; x < w; x++) { | - |
2724 | | - |
2725 | | - |
2726 | if ((x == 0 || y == 0 || x == w-1 || y == h-1 || | - |
2727 | !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) || | - |
2728 | !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) || | - |
2729 | !(*(ypp + (x >> 3)) & (1 << (x & 7))) || | - |
2730 | !(*(ypn + (x >> 3)) & (1 << (x & 7)))) && | - |
2731 | ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) && | - |
2732 | ((*p & 0x00ffffff) == background)) { | - |
2733 | done = false; | - |
2734 | *(ypc + (x >> 3)) &= ~(1 << (x & 7)); | - |
2735 | } | - |
2736 | p++; | - |
2737 | } | - |
2738 | } | - |
2739 | } | - |
2740 | | - |
2741 | if (!clipTight) { | - |
2742 | ypn = m.scanLine(0); | - |
2743 | ypc = 0; | - |
2744 | for (y = 0; y < h; y++) { | - |
2745 | ypp = ypc; | - |
2746 | ypc = ypn; | - |
2747 | ypn = (y == h-1) ? 0 : m.scanLine(y+1); | - |
2748 | QRgb *p = (QRgb *)scanLine(y); | - |
2749 | for (x = 0; x < w; x++) { | - |
2750 | if ((*p & 0x00ffffff) != background) { | - |
2751 | if (x > 0) | - |
2752 | *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7)); | - |
2753 | if (x < w-1) | - |
2754 | *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7)); | - |
2755 | if (y > 0) | - |
2756 | *(ypp + (x >> 3)) |= (1 << (x & 7)); | - |
2757 | if (y < h-1) | - |
2758 | *(ypn + (x >> 3)) |= (1 << (x & 7)); | - |
2759 | } | - |
2760 | p++; | - |
2761 | } | - |
2762 | } | - |
2763 | } | - |
2764 | | - |
2765 | | - |
2766 | | - |
2767 | return m; | - |
2768 | } | - |
2769 | QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const | - |
2770 | { | - |
2771 | if (!d) | - |
2772 | return QImage(); | - |
2773 | QImage maskImage(size(), QImage::Format_MonoLSB); | - |
2774 | if ((maskImage).isNull()) { QMessageLogger("image/qimage.cpp", 41534151, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2775 | maskImage.fill(0); | - |
2776 | uchar *s = maskImage.bits(); | - |
2777 | | - |
2778 | if (depth() == 32) { | - |
2779 | for (int h = 0; h < d->height; h++) { | - |
2780 | const uint *sl = (uint *) scanLine(h); | - |
2781 | for (int w = 0; w < d->width; w++) { | - |
2782 | if (sl[w] == color) | - |
2783 | *(s + (w >> 3)) |= (1 << (w & 7)); | - |
2784 | } | - |
2785 | s += maskImage.bytesPerLine(); | - |
2786 | } | - |
2787 | } else { | - |
2788 | for (int h = 0; h < d->height; h++) { | - |
2789 | for (int w = 0; w < d->width; w++) { | - |
2790 | if ((uint) pixel(w, h) == color) | - |
2791 | *(s + (w >> 3)) |= (1 << (w & 7)); | - |
2792 | } | - |
2793 | s += maskImage.bytesPerLine(); | - |
2794 | } | - |
2795 | } | - |
2796 | if (mode == Qt::MaskOutColor) | - |
2797 | maskImage.invertPixels(); | - |
2798 | return maskImage; | - |
2799 | } | - |
2800 | QImage QImage::mirrored(bool horizontal, bool vertical) const | - |
2801 | { | - |
2802 | if (!d) | - |
2803 | return QImage(); | - |
2804 | | - |
2805 | if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical)) | - |
2806 | return *this; | - |
2807 | | - |
2808 | int w = d->width; | - |
2809 | int h = d->height; | - |
2810 | | - |
2811 | QImage result(d->width, d->height, d->format); | - |
2812 | if ((result).isNull()) { QMessageLogger("image/qimage.cpp", 42084206, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2813 | | - |
2814 | | - |
2815 | if (!result.d) | - |
2816 | return QImage(); | - |
2817 | | - |
2818 | result.d->colortable = d->colortable; | - |
2819 | result.d->has_alpha_clut = d->has_alpha_clut; | - |
2820 | result.d->devicePixelRatio = d->devicePixelRatio; | - |
2821 | | - |
2822 | if (depth() == 1) | - |
2823 | w = (w+7)/8; | - |
2824 | int dxi = horizontal ? -1 : 1; | - |
2825 | int dxs = horizontal ? w-1 : 0; | - |
2826 | int dyi = vertical ? -1 : 1; | - |
2827 | int dy = vertical ? h-1: 0; | - |
2828 | | - |
2829 | | - |
2830 | if (d->depth == 1 || d->depth == 8) { | - |
2831 | for (int sy = 0; sy < h; sy++, dy += dyi) { | - |
2832 | quint8* ssl = (quint8*)(d->data + sy*d->bytes_per_line); | - |
2833 | quint8* dsl = (quint8*)(result.d->data + dy*result.d->bytes_per_line); | - |
2834 | int dx = dxs; | - |
2835 | for (int sx = 0; sx < w; sx++, dx += dxi) | - |
2836 | dsl[dx] = ssl[sx]; | - |
2837 | } | - |
2838 | } | - |
2839 | | - |
2840 | else if (d->depth == 16) { | - |
2841 | for (int sy = 0; sy < h; sy++, dy += dyi) { | - |
2842 | quint16* ssl = (quint16*)(d->data + sy*d->bytes_per_line); | - |
2843 | quint16* dsl = (quint16*)(result.d->data + dy*result.d->bytes_per_line); | - |
2844 | int dx = dxs; | - |
2845 | for (int sx = 0; sx < w; sx++, dx += dxi) | - |
2846 | dsl[dx] = ssl[sx]; | - |
2847 | } | - |
2848 | } | - |
2849 | | - |
2850 | else if (d->depth == 24) { | - |
2851 | for (int sy = 0; sy < h; sy++, dy += dyi) { | - |
2852 | quint24* ssl = (quint24*)(d->data + sy*d->bytes_per_line); | - |
2853 | quint24* dsl = (quint24*)(result.d->data + dy*result.d->bytes_per_line); | - |
2854 | int dx = dxs; | - |
2855 | for (int sx = 0; sx < w; sx++, dx += dxi) | - |
2856 | dsl[dx] = ssl[sx]; | - |
2857 | } | - |
2858 | } | - |
2859 | | - |
2860 | else if (d->depth == 32) { | - |
2861 | for (int sy = 0; sy < h; sy++, dy += dyi) { | - |
2862 | quint32* ssl = (quint32*)(d->data + sy*d->bytes_per_line); | - |
2863 | quint32* dsl = (quint32*)(result.d->data + dy*result.d->bytes_per_line); | - |
2864 | int dx = dxs; | - |
2865 | for (int sx = 0; sx < w; sx++, dx += dxi) | - |
2866 | dsl[dx] = ssl[sx]; | - |
2867 | } | - |
2868 | } | - |
2869 | | - |
2870 | | - |
2871 | if (horizontal && d->depth == 1) { | - |
2872 | int shift = width() % 8; | - |
2873 | for (int y = h-1; y >= 0; y--) { | - |
2874 | quint8* a0 = (quint8*)(result.d->data + y*d->bytes_per_line); | - |
2875 | | - |
2876 | quint8* a = a0+dxs; | - |
2877 | while (a >= a0) { | - |
2878 | *a = bitflip[*a]; | - |
2879 | a--; | - |
2880 | } | - |
2881 | | - |
2882 | if (shift != 0) { | - |
2883 | a = a0+dxs; | - |
2884 | quint8 c = 0; | - |
2885 | if (format() == Format_MonoLSB) { | - |
2886 | while (a >= a0) { | - |
2887 | quint8 nc = *a << shift; | - |
2888 | *a = (*a >> (8-shift)) | c; | - |
2889 | --a; | - |
2890 | c = nc; | - |
2891 | } | - |
2892 | } else { | - |
2893 | while (a >= a0) { | - |
2894 | quint8 nc = *a >> shift; | - |
2895 | *a = (*a << (8-shift)) | c; | - |
2896 | --a; | - |
2897 | c = nc; | - |
2898 | } | - |
2899 | } | - |
2900 | } | - |
2901 | } | - |
2902 | } | - |
2903 | | - |
2904 | return result; | - |
2905 | } | - |
2906 | QImage QImage::rgbSwapped() const | - |
2907 | { | - |
2908 | if (isNull()) | - |
2909 | return *this; | - |
2910 | QImage res; | - |
2911 | switch (d->format) { | - |
2912 | case Format_Invalid: | - |
2913 | case NImageFormats: | - |
2914 | qt_noop(); | - |
2915 | return res; | - |
2916 | case Format_Mono: | - |
2917 | case Format_MonoLSB: | - |
2918 | case Format_Indexed8: | - |
2919 | res = copy(); | - |
2920 | for (int i = 0; i < res.d->colortable.size(); i++) { | - |
2921 | QRgb c = res.d->colortable.at(i); | - |
2922 | res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00)); | - |
2923 | } | - |
2924 | return res; | - |
2925 | case Format_RGB32: | - |
2926 | case Format_ARGB32: | - |
2927 | case Format_ARGB32_Premultiplied: | - |
2928 | res = QImage(d->width, d->height, d->format); | - |
2929 | if ((res).isNull()) { QMessageLogger("image/qimage.cpp", 43354333, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2930 | for (int i = 0; i < d->height; i++) { | - |
2931 | uint *q = (uint*)res.scanLine(i); | - |
2932 | uint *p = (uint*)constScanLine(i); | - |
2933 | uint *end = p + d->width; | - |
2934 | while (p < end) { | - |
2935 | *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); | - |
2936 | p++; | - |
2937 | q++; | - |
2938 | } | - |
2939 | } | - |
2940 | return res; | - |
2941 | case Format_RGB16: | - |
2942 | res = QImage(d->width, d->height, d->format); | - |
2943 | if ((res).isNull()) { QMessageLogger("image/qimage.cpp", 43494347, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2944 | for (int i = 0; i < d->height; i++) { | - |
2945 | ushort *q = (ushort*)res.scanLine(i); | - |
2946 | const ushort *p = (const ushort*)constScanLine(i); | - |
2947 | const ushort *end = p + d->width; | - |
2948 | while (p < end) { | - |
2949 | *q = ((*p << 11) & 0xf800) | ((*p >> 11) & 0x1f) | (*p & 0x07e0); | - |
2950 | p++; | - |
2951 | q++; | - |
2952 | } | - |
2953 | } | - |
2954 | return res; | - |
2955 | default: | - |
2956 | break; | - |
2957 | } | - |
2958 | | - |
2959 | res = QImage(d->width, d->height, d->format); | - |
2960 | if ((res).isNull()) { QMessageLogger("image/qimage.cpp", 43664364, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
2961 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - |
2962 | qt_noop(); | - |
2963 | FetchPixelsFunc fetch = qFetchPixels[layout->bpp]; | - |
2964 | StorePixelsFunc store = qStorePixels[layout->bpp]; | - |
2965 | | - |
2966 | const uint redBlueMask = (1 << layout->redWidth) - 1; | - |
2967 | const uint alphaGreenMask = (((1 << layout->alphaWidth) - 1) << layout->alphaShift) | - |
2968 | | (((1 << layout->greenWidth) - 1) << layout->greenShift); | - |
2969 | | - |
2970 | const int buffer_size = 2048; | - |
2971 | uint buffer[buffer_size]; | - |
2972 | for (int i = 0; i < d->height; ++i) { | - |
2973 | uchar *q = res.scanLine(i); | - |
2974 | const uchar *p = constScanLine(i); | - |
2975 | int x = 0; | - |
2976 | while (x < d->width) { | - |
2977 | int l = qMin(d->width - x, buffer_size); | - |
2978 | const uint *ptr = fetch(buffer, p, x, l); | - |
2979 | for (int j = 0; j < l; ++j) { | - |
2980 | uint red = (ptr[j] >> layout->redShift) & redBlueMask; | - |
2981 | uint blue = (ptr[j] >> layout->blueShift) & redBlueMask; | - |
2982 | buffer[j] = (ptr[j] & alphaGreenMask) | - |
2983 | | (red << layout->blueShift) | - |
2984 | | (blue << layout->redShift); | - |
2985 | } | - |
2986 | store(q, buffer, x, l); | - |
2987 | x += l; | - |
2988 | } | - |
2989 | } | - |
2990 | return res; | - |
2991 | } | - |
2992 | bool QImage::load(const QString &fileName, const char* format) | - |
2993 | { | - |
2994 | QImage image = QImageReader(fileName, format).read(); | - |
2995 | operator=(image); | - |
2996 | return !isNull(); | - |
2997 | } | - |
2998 | bool QImage::load(QIODevice* device, const char* format) | - |
2999 | { | - |
3000 | QImage image = QImageReader(device, format).read(); | - |
3001 | operator=(image); | - |
3002 | return !isNull(); | - |
3003 | } | - |
3004 | bool QImage::loadFromData(const uchar *data, int len, const char *format) | - |
3005 | { | - |
3006 | QImage image = fromData(data, len, format); | - |
3007 | operator=(image); | - |
3008 | return !isNull(); | - |
3009 | } | - |
3010 | QImage QImage::fromData(const uchar *data, int size, const char *format) | - |
3011 | { | - |
3012 | QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(data), size); | - |
3013 | QBuffer b; | - |
3014 | b.setData(a); | - |
3015 | b.open(QIODevice::ReadOnly); | - |
3016 | return QImageReader(&b, format).read(); | - |
3017 | } | - |
3018 | bool QImage::save(const QString &fileName, const char *format, int quality) const | - |
3019 | { | - |
3020 | if (isNull()) | - |
3021 | return false; | - |
3022 | QImageWriter writer(fileName, format); | - |
3023 | return d->doImageIO(this, &writer, quality); | - |
3024 | } | - |
3025 | bool QImage::save(QIODevice* device, const char* format, int quality) const | - |
3026 | { | - |
3027 | if (isNull()) | - |
3028 | return false; | - |
3029 | QImageWriter writer(device, format); | - |
3030 | return d->doImageIO(this, &writer, quality); | - |
3031 | } | - |
3032 | | - |
3033 | | - |
3034 | | - |
3035 | | - |
3036 | bool QImageData::doImageIO(const QImage *image, QImageWriter *writer, int quality) const | - |
3037 | { | - |
3038 | if (quality > 100 || quality < -1) | - |
3039 | QMessageLogger("image/qimage.cpp", 45534551, __PRETTY_FUNCTION__).warning("QPixmap::save: Quality out of range [-1, 100]"); | - |
3040 | if (quality >= 0) | - |
3041 | writer->setQuality(qMin(quality,100)); | - |
3042 | return writer->write(*image); | - |
3043 | } | - |
3044 | QDataStream &operator<<(QDataStream &s, const QImage &image) | - |
3045 | { | - |
3046 | if (s.version() >= 5) { | - |
3047 | if (image.isNull()) { | - |
3048 | s << (qint32) 0; | - |
3049 | return s; | - |
3050 | } else { | - |
3051 | s << (qint32) 1; | - |
3052 | | - |
3053 | } | - |
3054 | } | - |
3055 | QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png"); | - |
3056 | writer.write(image); | - |
3057 | return s; | - |
3058 | } | - |
3059 | QDataStream &operator>>(QDataStream &s, QImage &image) | - |
3060 | { | - |
3061 | if (s.version() >= 5) { | - |
3062 | qint32 nullMarker; | - |
3063 | s >> nullMarker; | - |
3064 | if (!nullMarker) { | - |
3065 | image = QImage(); | - |
3066 | return s; | - |
3067 | } | - |
3068 | } | - |
3069 | image = QImageReader(s.device(), 0).read(); | - |
3070 | return s; | - |
3071 | } | - |
3072 | bool QImage::operator==(const QImage & i) const | - |
3073 | { | - |
3074 | | - |
3075 | if (i.d == d) | - |
3076 | return true; | - |
3077 | if (!i.d || !d) | - |
3078 | return false; | - |
3079 | | - |
3080 | | - |
3081 | if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format) | - |
3082 | return false; | - |
3083 | | - |
3084 | if (d->format != Format_RGB32) { | - |
3085 | if (d->format >= Format_ARGB32) { | - |
3086 | const int n = d->width * d->depth / 8; | - |
3087 | if (n == d->bytes_per_line && n == i.d->bytes_per_line) { | - |
3088 | if (memcmp(bits(), i.bits(), d->nbytes)) | - |
3089 | return false; | - |
3090 | } else { | - |
3091 | for (int y = 0; y < d->height; ++y) { | - |
3092 | if (memcmp(scanLine(y), i.scanLine(y), n)) | - |
3093 | return false; | - |
3094 | } | - |
3095 | } | - |
3096 | } else { | - |
3097 | const int w = width(); | - |
3098 | const int h = height(); | - |
3099 | const QVector<QRgb> &colortable = d->colortable; | - |
3100 | const QVector<QRgb> &icolortable = i.d->colortable; | - |
3101 | for (int y=0; y<h; ++y) { | - |
3102 | for (int x=0; x<w; ++x) { | - |
3103 | if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)]) | - |
3104 | return false; | - |
3105 | } | - |
3106 | } | - |
3107 | } | - |
3108 | } else { | - |
3109 | | - |
3110 | for(int l = 0; l < d->height; l++) { | - |
3111 | int w = d->width; | - |
3112 | const uint *p1 = reinterpret_cast<const uint*>(scanLine(l)); | - |
3113 | const uint *p2 = reinterpret_cast<const uint*>(i.scanLine(l)); | - |
3114 | while (w--) { | - |
3115 | if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff)) | - |
3116 | return false; | - |
3117 | } | - |
3118 | } | - |
3119 | } | - |
3120 | return true; | - |
3121 | } | - |
3122 | bool QImage::operator!=(const QImage & i) const | - |
3123 | { | - |
3124 | return !(*this == i); | - |
3125 | } | - |
3126 | int QImage::dotsPerMeterX() const | - |
3127 | { | - |
3128 | return d ? qRound(d->dpmx) : 0; | - |
3129 | } | - |
3130 | int QImage::dotsPerMeterY() const | - |
3131 | { | - |
3132 | return d ? qRound(d->dpmy) : 0; | - |
3133 | } | - |
3134 | void QImage::setDotsPerMeterX(int x) | - |
3135 | { | - |
3136 | if (!d || !x) | - |
3137 | return; | - |
3138 | detach(); | - |
3139 | | - |
3140 | if (d) | - |
3141 | d->dpmx = x; | - |
3142 | } | - |
3143 | void QImage::setDotsPerMeterY(int y) | - |
3144 | { | - |
3145 | if (!d || !y) | - |
3146 | return; | - |
3147 | detach(); | - |
3148 | | - |
3149 | if (d) | - |
3150 | d->dpmy = y; | - |
3151 | } | - |
3152 | QPoint QImage::offset() const | - |
3153 | { | - |
3154 | return d ? d->offset : QPoint(); | - |
3155 | } | - |
3156 | void QImage::setOffset(const QPoint& p) | - |
3157 | { | - |
3158 | if (!d) | - |
3159 | return; | - |
3160 | detach(); | - |
3161 | | - |
3162 | if (d) | - |
3163 | d->offset = p; | - |
3164 | } | - |
3165 | QStringList QImage::textKeys() const | - |
3166 | { | - |
3167 | return d ? QStringList(d->text.keys()) : QStringList(); | - |
3168 | } | - |
3169 | QString QImage::text(const QString &key) const | - |
3170 | { | - |
3171 | if (!d) | - |
3172 | return QString(); | - |
3173 | | - |
3174 | if (!key.isEmpty()) | - |
3175 | return d->text.value(key); | - |
3176 | | - |
3177 | QString tmp; | - |
3178 | for (QForeachContainer<__typeof__(d->text.keys())> _container_(d->text.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &key = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
3179 | if (!tmp.isEmpty()) | - |
3180 | tmp += QLatin1String("\n\n"); | - |
3181 | tmp += key + QLatin1String(": ") + d->text.value(key).simplified(); | - |
3182 | } | - |
3183 | return tmp; | - |
3184 | } | - |
3185 | void QImage::setText(const QString &key, const QString &value) | - |
3186 | { | - |
3187 | if (!d) | - |
3188 | return; | - |
3189 | detach(); | - |
3190 | | - |
3191 | if (d) | - |
3192 | d->text.insert(key, value); | - |
3193 | } | - |
3194 | QPaintEngine *QImage::paintEngine() const | - |
3195 | { | - |
3196 | if (!d) evaluated: !d yes Evaluation Count:1 | yes Evaluation Count:78076 |
| 1-78076 |
3197 | return 0; executed: return 0; Execution Count:1 | 1 |
3198 | | - |
3199 | if (!d->paintEngine) { evaluated: !d->paintEngine yes Evaluation Count:5615 | yes Evaluation Count:72461 |
| 5615-72461 |
3200 | QPaintDevice *paintDevice = const_cast<QImage *>(this); | - |
3201 | QPaintEngine *paintEngine = 0; | - |
3202 | QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration()->(); | - |
3203 | if (platformIntegration) evaluated: platformIntegration yes Evaluation Count:5525 | yes Evaluation Count:90 |
| 90-5525 |
3204 | paintEngine = platformIntegration->createImagePaintEngine(paintDevice); executed: paintEngine = platformIntegration->createImagePaintEngine(paintDevice); Execution Count:5525 | 5525 |
3205 | d->paintEngine = paintEngine ? paintEngine : new QRasterPaintEngine(paintDevice); partially evaluated: paintEngine no Evaluation Count:0 | yes Evaluation Count:5615 |
| 0-5615 |
3206 | } executed: } Execution Count:5614 | 5614 |
3207 | | - |
3208 | return d->paintEngine; executed: return d->paintEngine; Execution Count:78075 | 78075 |
3209 | } | - |
3210 | | - |
3211 | | - |
3212 | | - |
3213 | | - |
3214 | | - |
3215 | | - |
3216 | | - |
3217 | int QImage::metric(PaintDeviceMetric metric) const | - |
3218 | { | - |
3219 | if (!d) evaluated: !d yes Evaluation Count:2 | yes Evaluation Count:94656 |
| 2-94656 |
3220 | return 0; executed: return 0; Execution Count:2 | 2 |
3221 | | - |
3222 | switch (metric) { | - |
3223 | case PdmWidth: | - |
3224 | return d->width; executed: return d->width; Execution Count:39268 | 39268 |
3225 | | - |
3226 | case PdmHeight: | - |
3227 | return d->height; executed: return d->height; Execution Count:44882 | 44882 |
3228 | | - |
3229 | case PdmWidthMM: | - |
3230 | return qRound(d->width * 1000 / d->dpmx); never executed: return qRound(d->width * 1000 / d->dpmx); | 0 |
3231 | | - |
3232 | case PdmHeightMM: | - |
3233 | return qRound(d->height * 1000 / d->dpmy); never executed: return qRound(d->height * 1000 / d->dpmy); | 0 |
3234 | | - |
3235 | case PdmNumColors: | - |
3236 | return d->colortable.size(); never executed: return d->colortable.size(); | 0 |
3237 | | - |
3238 | case PdmDepth: | - |
3239 | return d->depth; executed: return d->depth; Execution Count:5615 | 5615 |
3240 | | - |
3241 | case PdmDpiX: | - |
3242 | return qRound(d->ldpmxdpmx * 0.0254); executed: return qRound(d->dpmx * 0.0254); Execution Count:2 | 2 |
3243 | break; | - |
3244 | | - |
3245 | case PdmDpiY: | - |
3246 | return qRound(d->ldpmydpmy * 0.0254); executed: return qRound(d->dpmy * 0.0254); Execution Count:4884 | 4884 |
3247 | break; | - |
3248 | | - |
3249 | case PdmPhysicalDpiX: | - |
3250 | return qRound(d->dpmx * 0.0254 * d->devicePixelRatio); executed: return qRound(d->dpmx * 0.0254 * d->devicePixelRatio); Execution Count:2 | 2 |
3251 | break; | - |
3252 | | - |
3253 | case PdmPhysicalDpiY: | - |
3254 | return qRound(d->dpmy * 0.0254 * d->devicePixelRatio); executed: return qRound(d->dpmy * 0.0254 * d->devicePixelRatio); Execution Count:3 | 3 |
3255 | break; | - |
3256 | default: | - |
3257 | QMessageLogger("image/qimage.cpp", 50025003, __PRETTY_FUNCTION__).warning("QImage::metric(): Unhandled metric type %d", metric); | - |
3258 | break; | 0 |
3259 | } | - |
3260 | return 0; never executed: return 0; | 0 |
3261 | } | - |
3262 | bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth, | - |
3263 | uchar *dptr, int dbpl, int p_inc, int dHeight, | - |
3264 | const uchar *sptr, int sbpl, int sWidth, int sHeight) | - |
3265 | { | - |
3266 | int m11 = int(trueMat.m11()*4096.0); | - |
3267 | int m12 = int(trueMat.m12()*4096.0); | - |
3268 | int m21 = int(trueMat.m21()*4096.0); | - |
3269 | int m22 = int(trueMat.m22()*4096.0); | - |
3270 | int dx = qRound(trueMat.dx()*4096.0); | - |
3271 | int dy = qRound(trueMat.dy()*4096.0); | - |
3272 | | - |
3273 | int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2; | - |
3274 | int m22ydy = dy + (m12 + m22) / 2; | - |
3275 | uint trigx; | - |
3276 | uint trigy; | - |
3277 | uint maxws = sWidth<<12; | - |
3278 | uint maxhs = sHeight<<12; | - |
3279 | | - |
3280 | for (int y=0; y<dHeight; y++) { | - |
3281 | trigx = m21ydx; | - |
3282 | trigy = m22ydy; | - |
3283 | uchar *maxp = dptr + dbpl; | - |
3284 | if (depth != 1) { | - |
3285 | switch (depth) { | - |
3286 | case 8: | - |
3287 | while (dptr < maxp) { | - |
3288 | if (trigx < maxws && trigy < maxhs) | - |
3289 | *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12)); | - |
3290 | trigx += m11; | - |
3291 | trigy += m12; | - |
3292 | dptr++; | - |
3293 | } | - |
3294 | break; | - |
3295 | | - |
3296 | case 16: | - |
3297 | while (dptr < maxp) { | - |
3298 | if (trigx < maxws && trigy < maxhs) | - |
3299 | *((ushort*)dptr) = *((ushort *)(sptr+sbpl*(trigy>>12) + | - |
3300 | ((trigx>>12)<<1))); | - |
3301 | trigx += m11; | - |
3302 | trigy += m12; | - |
3303 | dptr++; | - |
3304 | dptr++; | - |
3305 | } | - |
3306 | break; | - |
3307 | | - |
3308 | case 24: | - |
3309 | while (dptr < maxp) { | - |
3310 | if (trigx < maxws && trigy < maxhs) { | - |
3311 | const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3); | - |
3312 | dptr[0] = p2[0]; | - |
3313 | dptr[1] = p2[1]; | - |
3314 | dptr[2] = p2[2]; | - |
3315 | } | - |
3316 | trigx += m11; | - |
3317 | trigy += m12; | - |
3318 | dptr += 3; | - |
3319 | } | - |
3320 | break; | - |
3321 | | - |
3322 | case 32: | - |
3323 | while (dptr < maxp) { | - |
3324 | if (trigx < maxws && trigy < maxhs) | - |
3325 | *((uint*)dptr) = *((uint *)(sptr+sbpl*(trigy>>12) + | - |
3326 | ((trigx>>12)<<2))); | - |
3327 | trigx += m11; | - |
3328 | trigy += m12; | - |
3329 | dptr += 4; | - |
3330 | } | - |
3331 | break; | - |
3332 | | - |
3333 | default: { | - |
3334 | return false; | - |
3335 | } | - |
3336 | } | - |
3337 | } else { | - |
3338 | switch (type) { | - |
3339 | case 0: | - |
3340 | while (dptr < maxp) { | - |
3341 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 128; } trigx += m11; trigy += m12;; | - |
3342 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 64; } trigx += m11; trigy += m12;; | - |
3343 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 32; } trigx += m11; trigy += m12;; | - |
3344 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 16; } trigx += m11; trigy += m12;; | - |
3345 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 8; } trigx += m11; trigy += m12;; | - |
3346 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 4; } trigx += m11; trigy += m12;; | - |
3347 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 2; } trigx += m11; trigy += m12;; | - |
3348 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 1; } trigx += m11; trigy += m12;; | - |
3349 | dptr++; | - |
3350 | } | - |
3351 | break; | - |
3352 | case 1: | - |
3353 | while (dptr < maxp) { | - |
3354 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 1; } trigx += m11; trigy += m12;; | - |
3355 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 2; } trigx += m11; trigy += m12;; | - |
3356 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 4; } trigx += m11; trigy += m12;; | - |
3357 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 8; } trigx += m11; trigy += m12;; | - |
3358 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 16; } trigx += m11; trigy += m12;; | - |
3359 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 32; } trigx += m11; trigy += m12;; | - |
3360 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 64; } trigx += m11; trigy += m12;; | - |
3361 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 128; } trigx += m11; trigy += m12;; | - |
3362 | dptr++; | - |
3363 | } | - |
3364 | break; | - |
3365 | } | - |
3366 | } | - |
3367 | m21ydx += m21; | - |
3368 | m22ydy += m22; | - |
3369 | dptr += p_inc; | - |
3370 | } | - |
3371 | return true; | - |
3372 | } | - |
3373 | qint64 QImage::cacheKey() const | - |
3374 | { | - |
3375 | if (!d) | - |
3376 | return 0; | - |
3377 | else | - |
3378 | return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no); | - |
3379 | } | - |
3380 | bool QImage::isDetached() const | - |
3381 | { | - |
3382 | return d && d->ref.load() == 1; | - |
3383 | } | - |
3384 | void QImage::setAlphaChannel(const QImage &alphaChannel) | - |
3385 | { | - |
3386 | if (!d) | - |
3387 | return; | - |
3388 | | - |
3389 | int w = d->width; | - |
3390 | int h = d->height; | - |
3391 | | - |
3392 | if (w != alphaChannel.d->width || h != alphaChannel.d->height) { | - |
3393 | QMessageLogger("image/qimage.cpp", 52485249, __PRETTY_FUNCTION__).warning("QImage::setAlphaChannel: " | - |
3394 | "Alpha channel must have same dimensions as the target image"); | - |
3395 | return; | - |
3396 | } | - |
3397 | | - |
3398 | if (d->paintEngine && d->paintEngine->isActive()) { | - |
3399 | QMessageLogger("image/qimage.cpp", 52545255, __PRETTY_FUNCTION__).warning("QImage::setAlphaChannel: " | - |
3400 | "Unable to set alpha channel while image is being painted on"); | - |
3401 | return; | - |
3402 | } | - |
3403 | | - |
3404 | if (d->format == QImage::Format_ARGB32_Premultiplied) | - |
3405 | detach(); | - |
3406 | else | - |
3407 | *this = convertToFormat(QImage::Format_ARGB32_Premultiplied); | - |
3408 | | - |
3409 | if (isNull()) | - |
3410 | return; | - |
3411 | | - |
3412 | | - |
3413 | if (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()) { | - |
3414 | const uchar *src_data = alphaChannel.d->data; | - |
3415 | const uchar *dest_data = d->data; | - |
3416 | for (int y=0; y<h; ++y) { | - |
3417 | const uchar *src = src_data; | - |
3418 | QRgb *dest = (QRgb *)dest_data; | - |
3419 | for (int x=0; x<w; ++x) { | - |
3420 | int alpha = *src; | - |
3421 | int destAlpha = qt_div_255(alpha * qAlpha(*dest)); | - |
3422 | *dest = ((destAlpha << 24) | - |
3423 | | (qt_div_255(qRed(*dest) * alpha) << 16) | - |
3424 | | (qt_div_255(qGreen(*dest) * alpha) << 8) | - |
3425 | | (qt_div_255(qBlue(*dest) * alpha))); | - |
3426 | ++dest; | - |
3427 | ++src; | - |
3428 | } | - |
3429 | src_data += alphaChannel.d->bytes_per_line; | - |
3430 | dest_data += d->bytes_per_line; | - |
3431 | } | - |
3432 | | - |
3433 | } else { | - |
3434 | const QImage sourceImage = alphaChannel.convertToFormat(QImage::Format_RGB32); | - |
3435 | const uchar *src_data = sourceImage.d->data; | - |
3436 | const uchar *dest_data = d->data; | - |
3437 | for (int y=0; y<h; ++y) { | - |
3438 | const QRgb *src = (const QRgb *) src_data; | - |
3439 | QRgb *dest = (QRgb *) dest_data; | - |
3440 | for (int x=0; x<w; ++x) { | - |
3441 | int alpha = qGray(*src); | - |
3442 | int destAlpha = qt_div_255(alpha * qAlpha(*dest)); | - |
3443 | *dest = ((destAlpha << 24) | - |
3444 | | (qt_div_255(qRed(*dest) * alpha) << 16) | - |
3445 | | (qt_div_255(qGreen(*dest) * alpha) << 8) | - |
3446 | | (qt_div_255(qBlue(*dest) * alpha))); | - |
3447 | ++dest; | - |
3448 | ++src; | - |
3449 | } | - |
3450 | src_data += sourceImage.d->bytes_per_line; | - |
3451 | dest_data += d->bytes_per_line; | - |
3452 | } | - |
3453 | } | - |
3454 | } | - |
3455 | QImage QImage::alphaChannel() const | - |
3456 | { | - |
3457 | if (!d) | - |
3458 | return QImage(); | - |
3459 | | - |
3460 | int w = d->width; | - |
3461 | int h = d->height; | - |
3462 | | - |
3463 | QImage image(w, h, Format_Indexed8); | - |
3464 | image.setColorCount(256); | - |
3465 | | - |
3466 | | - |
3467 | for (int i=0; i<256; ++i) | - |
3468 | image.setColor(i, qRgb(i, i, i)); | - |
3469 | | - |
3470 | if (!hasAlphaChannel()) { | - |
3471 | image.fill(255); | - |
3472 | return image; | - |
3473 | } | - |
3474 | | - |
3475 | if (d->format == Format_Indexed8) { | - |
3476 | const uchar *src_data = d->data; | - |
3477 | uchar *dest_data = image.d->data; | - |
3478 | for (int y=0; y<h; ++y) { | - |
3479 | const uchar *src = src_data; | - |
3480 | uchar *dest = dest_data; | - |
3481 | for (int x=0; x<w; ++x) { | - |
3482 | *dest = qAlpha(d->colortable.at(*src)); | - |
3483 | ++dest; | - |
3484 | ++src; | - |
3485 | } | - |
3486 | src_data += d->bytes_per_line; | - |
3487 | dest_data += image.d->bytes_per_line; | - |
3488 | } | - |
3489 | } else { | - |
3490 | QImage alpha32 = *this; | - |
3491 | if (d->format != Format_ARGB32 && d->format != Format_ARGB32_Premultiplied) | - |
3492 | alpha32 = convertToFormat(Format_ARGB32); | - |
3493 | | - |
3494 | const uchar *src_data = alpha32.d->data; | - |
3495 | uchar *dest_data = image.d->data; | - |
3496 | for (int y=0; y<h; ++y) { | - |
3497 | const QRgb *src = (const QRgb *) src_data; | - |
3498 | uchar *dest = dest_data; | - |
3499 | for (int x=0; x<w; ++x) { | - |
3500 | *dest = qAlpha(*src); | - |
3501 | ++dest; | - |
3502 | ++src; | - |
3503 | } | - |
3504 | src_data += alpha32.d->bytes_per_line; | - |
3505 | dest_data += image.d->bytes_per_line; | - |
3506 | } | - |
3507 | } | - |
3508 | | - |
3509 | return image; | - |
3510 | } | - |
3511 | | - |
3512 | | - |
3513 | | - |
3514 | | - |
3515 | | - |
3516 | | - |
3517 | | - |
3518 | bool QImage::hasAlphaChannel() const | - |
3519 | { | - |
3520 | return d && (d->format == Format_ARGB32_Premultiplied | - |
3521 | || d->format == Format_ARGB32 | - |
3522 | || d->format == Format_ARGB8565_Premultiplied | - |
3523 | || d->format == Format_ARGB8555_Premultiplied | - |
3524 | || d->format == Format_ARGB6666_Premultiplied | - |
3525 | || d->format == Format_ARGB4444_Premultiplied | - |
3526 | || (d->has_alpha_clut && (d->format == Format_Indexed8 | - |
3527 | || d->format == Format_Mono | - |
3528 | || d->format == Format_MonoLSB))); | - |
3529 | } | - |
3530 | int QImage::bitPlaneCount() const | - |
3531 | { | - |
3532 | if (!d) | - |
3533 | return 0; | - |
3534 | int bpc = 0; | - |
3535 | switch (d->format) { | - |
3536 | case QImage::Format_Invalid: | - |
3537 | break; | - |
3538 | case QImage::Format_RGB32: | - |
3539 | bpc = 24; | - |
3540 | break; | - |
3541 | case QImage::Format_RGB666: | - |
3542 | bpc = 18; | - |
3543 | break; | - |
3544 | case QImage::Format_RGB555: | - |
3545 | bpc = 15; | - |
3546 | break; | - |
3547 | case QImage::Format_ARGB8555_Premultiplied: | - |
3548 | bpc = 23; | - |
3549 | break; | - |
3550 | case QImage::Format_RGB444: | - |
3551 | bpc = 12; | - |
3552 | break; | - |
3553 | default: | - |
3554 | bpc = qt_depthForFormat(d->format); | - |
3555 | break; | - |
3556 | } | - |
3557 | return bpc; | - |
3558 | } | - |
3559 | | - |
3560 | static QImage smoothScaled(const QImage &source, int w, int h) { | - |
3561 | QImage src = source; | - |
3562 | if (src.format() == QImage::Format_ARGB32) | - |
3563 | src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - |
3564 | else if (src.depth() < 32) { | - |
3565 | if (src.hasAlphaChannel()) | - |
3566 | src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - |
3567 | else | - |
3568 | src = src.convertToFormat(QImage::Format_RGB32); | - |
3569 | } | - |
3570 | | - |
3571 | return qSmoothScaleImage(src, w, h); | - |
3572 | } | - |
3573 | | - |
3574 | | - |
3575 | static QImage rotated90(const QImage &image) { | - |
3576 | QImage out(image.height(), image.width(), image.format()); | - |
3577 | if (image.colorCount() > 0) | - |
3578 | out.setColorTable(image.colorTable()); | - |
3579 | int w = image.width(); | - |
3580 | int h = image.height(); | - |
3581 | switch (image.format()) { | - |
3582 | case QImage::Format_RGB32: | - |
3583 | case QImage::Format_ARGB32: | - |
3584 | case QImage::Format_ARGB32_Premultiplied: | - |
3585 | qt_memrotate270(reinterpret_cast<const quint32*>(image.bits()), | - |
3586 | w, h, image.bytesPerLine(), | - |
3587 | reinterpret_cast<quint32*>(out.bits()), | - |
3588 | out.bytesPerLine()); | - |
3589 | break; | - |
3590 | case QImage::Format_RGB666: | - |
3591 | case QImage::Format_ARGB6666_Premultiplied: | - |
3592 | case QImage::Format_ARGB8565_Premultiplied: | - |
3593 | case QImage::Format_ARGB8555_Premultiplied: | - |
3594 | case QImage::Format_RGB888: | - |
3595 | qt_memrotate270(reinterpret_cast<const quint24*>(image.bits()), | - |
3596 | w, h, image.bytesPerLine(), | - |
3597 | reinterpret_cast<quint24*>(out.bits()), | - |
3598 | out.bytesPerLine()); | - |
3599 | break; | - |
3600 | case QImage::Format_RGB555: | - |
3601 | case QImage::Format_RGB16: | - |
3602 | case QImage::Format_ARGB4444_Premultiplied: | - |
3603 | qt_memrotate270(reinterpret_cast<const quint16*>(image.bits()), | - |
3604 | w, h, image.bytesPerLine(), | - |
3605 | reinterpret_cast<quint16*>(out.bits()), | - |
3606 | out.bytesPerLine()); | - |
3607 | break; | - |
3608 | case QImage::Format_Indexed8: | - |
3609 | qt_memrotate270(reinterpret_cast<const quint8*>(image.bits()), | - |
3610 | w, h, image.bytesPerLine(), | - |
3611 | reinterpret_cast<quint8*>(out.bits()), | - |
3612 | out.bytesPerLine()); | - |
3613 | break; | - |
3614 | default: | - |
3615 | for (int y=0; y<h; ++y) { | - |
3616 | if (image.colorCount()) | - |
3617 | for (int x=0; x<w; ++x) | - |
3618 | out.setPixel(h-y-1, x, image.pixelIndex(x, y)); | - |
3619 | else | - |
3620 | for (int x=0; x<w; ++x) | - |
3621 | out.setPixel(h-y-1, x, image.pixel(x, y)); | - |
3622 | } | - |
3623 | break; | - |
3624 | } | - |
3625 | return out; | - |
3626 | } | - |
3627 | | - |
3628 | | - |
3629 | static QImage rotated180(const QImage &image) { | - |
3630 | return image.mirrored(true, true); | - |
3631 | } | - |
3632 | | - |
3633 | | - |
3634 | static QImage rotated270(const QImage &image) { | - |
3635 | QImage out(image.height(), image.width(), image.format()); | - |
3636 | if (image.colorCount() > 0) | - |
3637 | out.setColorTable(image.colorTable()); | - |
3638 | int w = image.width(); | - |
3639 | int h = image.height(); | - |
3640 | switch (image.format()) { | - |
3641 | case QImage::Format_RGB32: | - |
3642 | case QImage::Format_ARGB32: | - |
3643 | case QImage::Format_ARGB32_Premultiplied: | - |
3644 | qt_memrotate90(reinterpret_cast<const quint32*>(image.bits()), | - |
3645 | w, h, image.bytesPerLine(), | - |
3646 | reinterpret_cast<quint32*>(out.bits()), | - |
3647 | out.bytesPerLine()); | - |
3648 | break; | - |
3649 | case QImage::Format_RGB666: | - |
3650 | case QImage::Format_ARGB6666_Premultiplied: | - |
3651 | case QImage::Format_ARGB8565_Premultiplied: | - |
3652 | case QImage::Format_ARGB8555_Premultiplied: | - |
3653 | case QImage::Format_RGB888: | - |
3654 | qt_memrotate90(reinterpret_cast<const quint24*>(image.bits()), | - |
3655 | w, h, image.bytesPerLine(), | - |
3656 | reinterpret_cast<quint24*>(out.bits()), | - |
3657 | out.bytesPerLine()); | - |
3658 | break; | - |
3659 | case QImage::Format_RGB555: | - |
3660 | case QImage::Format_RGB16: | - |
3661 | case QImage::Format_ARGB4444_Premultiplied: | - |
3662 | qt_memrotate90(reinterpret_cast<const quint16*>(image.bits()), | - |
3663 | w, h, image.bytesPerLine(), | - |
3664 | reinterpret_cast<quint16*>(out.bits()), | - |
3665 | out.bytesPerLine()); | - |
3666 | break; | - |
3667 | case QImage::Format_Indexed8: | - |
3668 | qt_memrotate90(reinterpret_cast<const quint8*>(image.bits()), | - |
3669 | w, h, image.bytesPerLine(), | - |
3670 | reinterpret_cast<quint8*>(out.bits()), | - |
3671 | out.bytesPerLine()); | - |
3672 | break; | - |
3673 | default: | - |
3674 | for (int y=0; y<h; ++y) { | - |
3675 | if (image.colorCount()) | - |
3676 | for (int x=0; x<w; ++x) | - |
3677 | out.setPixel(y, w-x-1, image.pixelIndex(x, y)); | - |
3678 | else | - |
3679 | for (int x=0; x<w; ++x) | - |
3680 | out.setPixel(y, w-x-1, image.pixel(x, y)); | - |
3681 | } | - |
3682 | break; | - |
3683 | } | - |
3684 | return out; | - |
3685 | } | - |
3686 | QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode ) const | - |
3687 | { | - |
3688 | if (!d) | - |
3689 | return QImage(); | - |
3690 | | - |
3691 | | - |
3692 | int ws = width(); | - |
3693 | int hs = height(); | - |
3694 | | - |
3695 | | - |
3696 | int wd; | - |
3697 | int hd; | - |
3698 | | - |
3699 | | - |
3700 | QTransform mat = trueMatrix(matrix, ws, hs); | - |
3701 | bool complex_xform = false; | - |
3702 | bool scale_xform = false; | - |
3703 | if (mat.type() <= QTransform::TxScale) { | - |
3704 | if (mat.type() == QTransform::TxNone) | - |
3705 | return *this; | - |
3706 | else if (mat.m11() == -1. && mat.m22() == -1.) | - |
3707 | return rotated180(*this); | - |
3708 | | - |
3709 | if (mode == Qt::FastTransformation) { | - |
3710 | hd = qRound(qAbs(mat.m22()) * hs); | - |
3711 | wd = qRound(qAbs(mat.m11()) * ws); | - |
3712 | } else { | - |
3713 | hd = int(qAbs(mat.m22()) * hs + 0.9999); | - |
3714 | wd = int(qAbs(mat.m11()) * ws + 0.9999); | - |
3715 | } | - |
3716 | scale_xform = true; | - |
3717 | } else { | - |
3718 | if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) { | - |
3719 | if (mat.m12() == 1. && mat.m21() == -1.) | - |
3720 | return rotated90(*this); | - |
3721 | else if (mat.m12() == -1. && mat.m21() == 1.) | - |
3722 | return rotated270(*this); | - |
3723 | } | - |
3724 | | - |
3725 | QPolygonF a(QRectF(0, 0, ws, hs)); | - |
3726 | a = mat.map(a); | - |
3727 | QRect r = a.boundingRect().toAlignedRect(); | - |
3728 | wd = r.width(); | - |
3729 | hd = r.height(); | - |
3730 | complex_xform = true; | - |
3731 | } | - |
3732 | | - |
3733 | if (wd == 0 || hd == 0) | - |
3734 | return QImage(); | - |
3735 | | - |
3736 | | - |
3737 | if (scale_xform && mode == Qt::SmoothTransformation) { | - |
3738 | if (mat.m11() < 0.0F && mat.m22() < 0.0F) { | - |
3739 | return smoothScaled(mirrored(true, true), wd, hd); | - |
3740 | } else if (mat.m11() < 0.0F) { | - |
3741 | return smoothScaled(mirrored(true, false), wd, hd); | - |
3742 | } else if (mat.m22() < 0.0F) { | - |
3743 | return smoothScaled(mirrored(false, true), wd, hd); | - |
3744 | } else { | - |
3745 | return smoothScaled(*this, wd, hd); | - |
3746 | } | - |
3747 | } | - |
3748 | | - |
3749 | int bpp = depth(); | - |
3750 | | - |
3751 | int sbpl = bytesPerLine(); | - |
3752 | const uchar *sptr = bits(); | - |
3753 | | - |
3754 | QImage::Format target_format = d->format; | - |
3755 | | - |
3756 | if (complex_xform || mode == Qt::SmoothTransformation) { | - |
3757 | if (d->format < QImage::Format_RGB32 || !hasAlphaChannel()) { | - |
3758 | switch(d->format) { | - |
3759 | case QImage::Format_RGB16: | - |
3760 | target_format = Format_ARGB8565_Premultiplied; | - |
3761 | break; | - |
3762 | case QImage::Format_RGB555: | - |
3763 | target_format = Format_ARGB8555_Premultiplied; | - |
3764 | break; | - |
3765 | case QImage::Format_RGB666: | - |
3766 | target_format = Format_ARGB6666_Premultiplied; | - |
3767 | break; | - |
3768 | case QImage::Format_RGB444: | - |
3769 | target_format = Format_ARGB4444_Premultiplied; | - |
3770 | break; | - |
3771 | default: | - |
3772 | target_format = Format_ARGB32_Premultiplied; | - |
3773 | break; | - |
3774 | } | - |
3775 | } | - |
3776 | } | - |
3777 | | - |
3778 | QImage dImage(wd, hd, target_format); | - |
3779 | if ((dImage).isNull()) { QMessageLogger("image/qimage.cpp", 56885689, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - |
3780 | | - |
3781 | if (target_format == QImage::Format_MonoLSB | - |
3782 | || target_format == QImage::Format_Mono | - |
3783 | || target_format == QImage::Format_Indexed8) { | - |
3784 | dImage.d->colortable = d->colortable; | - |
3785 | dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform; | - |
3786 | } | - |
3787 | | - |
3788 | dImage.d->dpmx = dotsPerMeterX(); | - |
3789 | dImage.d->dpmy = dotsPerMeterY(); | - |
3790 | dImage.d->devicePixelRatio = devicePixelRatio(); | - |
3791 | | - |
3792 | switch (bpp) { | - |
3793 | | - |
3794 | case 8: | - |
3795 | if (dImage.d->colortable.size() < 256) { | - |
3796 | | - |
3797 | dImage.d->colortable.append(0x0); | - |
3798 | memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount()); | - |
3799 | } else { | - |
3800 | memset(dImage.bits(), 0, dImage.byteCount()); | - |
3801 | } | - |
3802 | break; | - |
3803 | case 1: | - |
3804 | case 16: | - |
3805 | case 24: | - |
3806 | case 32: | - |
3807 | memset(dImage.bits(), 0x00, dImage.byteCount()); | - |
3808 | break; | - |
3809 | } | - |
3810 | | - |
3811 | if (target_format >= QImage::Format_RGB32) { | - |
3812 | QPainter p(&dImage); | - |
3813 | if (mode == Qt::SmoothTransformation) { | - |
3814 | p.setRenderHint(QPainter::Antialiasing); | - |
3815 | p.setRenderHint(QPainter::SmoothPixmapTransform); | - |
3816 | } | - |
3817 | p.setTransform(mat); | - |
3818 | p.drawImage(QPoint(0, 0), *this); | - |
3819 | } else { | - |
3820 | bool invertible; | - |
3821 | mat = mat.inverted(&invertible); | - |
3822 | if (!invertible) | - |
3823 | return QImage(); | - |
3824 | | - |
3825 | | - |
3826 | int type = format() == Format_Mono ? 0 : 1; | - |
3827 | int dbpl = dImage.bytesPerLine(); | - |
3828 | qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs); | - |
3829 | } | - |
3830 | return dImage; | - |
3831 | } | - |
3832 | QTransform QImage::trueMatrix(const QTransform &matrix, int w, int h) | - |
3833 | { | - |
3834 | const QRectF rect(0, 0, w, h); | - |
3835 | const QRect mapped = matrix.mapRect(rect).toAlignedRect(); | - |
3836 | const QPoint delta = mapped.topLeft(); | - |
3837 | return matrix * QTransform().translate(-delta.x(), -delta.y()); | - |
3838 | } | - |
3839 | | - |
3840 | bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags flags) | - |
3841 | { | - |
3842 | if (format == newFormat) | - |
3843 | return true; | - |
3844 | | - |
3845 | | - |
3846 | if (ref.load() > 1) | - |
3847 | return false; | - |
3848 | | - |
3849 | const InPlace_Image_Converter *const converterPtr = &inplace_converter_map[format][newFormat]; | - |
3850 | InPlace_Image_Converter converter = *converterPtr; | - |
3851 | if (converter) | - |
3852 | return converter(this, flags); | - |
3853 | else | - |
3854 | return false; | - |
3855 | } | - |
3856 | QDebug operator<<(QDebug dbg, const QImage &i) | - |
3857 | { | - |
3858 | dbg.nospace() << "QImage(" << i.size() << ')'; | - |
3859 | return dbg.space(); | - |
3860 | } | - |
3861 | | - |
3862 | | - |
| | |