Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | static const uchar bitflip[256] = { | - |
6 | 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, | - |
7 | 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, | - |
8 | 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, | - |
9 | 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, | - |
10 | 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, | - |
11 | 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, | - |
12 | 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, | - |
13 | 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, | - |
14 | 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, | - |
15 | 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, | - |
16 | 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, | - |
17 | 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, | - |
18 | 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, | - |
19 | 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, | - |
20 | 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, | - |
21 | 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 | - |
22 | }; | - |
23 | | - |
24 | const uchar *qt_get_bitflip_array() | - |
25 | { | - |
26 | return bitflip; | - |
27 | } | - |
28 | | - |
29 | void qGamma_correct_back_to_linear_cs(QImage *image) | - |
30 | { | - |
31 | const QDrawHelperGammaTables *tables = QGuiApplicationPrivate::instance()->gammaTables(); | - |
32 | if (!tables) | - |
33 | return; | - |
34 | const uchar *gamma = tables->qt_pow_rgb_gamma; | - |
35 | | - |
36 | int h = image->height(); | - |
37 | int w = image->width(); | - |
38 | | - |
39 | for (int y=0; y<h; ++y) { | - |
40 | uint *pixels = (uint *) image->scanLine(y); | - |
41 | for (int x=0; x<w; ++x) { | - |
42 | uint p = pixels[x]; | - |
43 | uint r = gamma[qRed(p)]; | - |
44 | uint g = gamma[qGreen(p)]; | - |
45 | uint b = gamma[qBlue(p)]; | - |
46 | pixels[x] = (r << 16) | (g << 8) | b | 0xff000000; | - |
47 | } | - |
48 | } | - |
49 | } | - |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | static const uint * convertRGB32FromARGB32PM(uint *buffer, const uint *src, int count, | - |
57 | const QPixelLayout *, const QRgb *) | - |
58 | { | - |
59 | for (int i = 0; i < count; ++i) | - |
60 | buffer[i] = 0xff000000 | qUnpremultiply(src[i]); | - |
61 | return buffer; | - |
62 | } | - |
63 | | - |
64 | static const uint * convertRGB32ToARGB32PM(uint *buffer, const uint *src, int count, | - |
65 | const QPixelLayout *, const QRgb *) | - |
66 | { | - |
67 | for (int i = 0; i < count; ++i) | - |
68 | buffer[i] = 0xff000000 |src[i]; | - |
69 | return buffer; | - |
70 | } | - |
71 | | - |
72 | | - |
73 | extern const uint * convertRGB32FromARGB32PM_sse4(uint *buffer, const uint *src, int count, const QPixelLayout *, const QRgb *); | - |
74 | | - |
75 | | - |
76 | void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
77 | { | - |
78 | | - |
79 | ((!(dest->format > QImage::Format_Indexed8)) ? qt_assert("dest->format > QImage::Format_Indexed8",__FILE__,127133) : qt_noop()); | - |
80 | ((!(src->format > QImage::Format_Indexed8)) ? qt_assert("src->format > QImage::Format_Indexed8",__FILE__,128134) : qt_noop()); | - |
81 | const int buffer_size = 2048; | - |
82 | uint buffer[buffer_size]; | - |
83 | const QPixelLayout *srcLayout = &qPixelLayouts[src->format]; | - |
84 | const QPixelLayout *destLayout = &qPixelLayouts[dest->format]; | - |
85 | const uchar *srcData = src->data; | - |
86 | uchar *destData = dest->data; | - |
87 | | - |
88 | const FetchPixelsFunc fetch = qFetchPixels[srcLayout->bpp]; | - |
89 | const StorePixelsFunc store = qStorePixels[destLayout->bpp]; | - |
90 | ConvertFunc convertToARGB32PM = srcLayout->convertToARGB32PM; | - |
91 | ConvertFunc convertFromARGB32PM = destLayout->convertFromARGB32PM; | - |
92 | if (srcLayout->alphaWidth == 0 && destLayout->convertFromRGB32) { | - |
93 | | - |
94 | convertFromARGB32PM = destLayout->convertFromRGB32; | - |
95 | } else { | - |
96 | if (src->format == QImage::Format_RGB32) | - |
97 | convertToARGB32PM = convertRGB32ToARGB32PM; | - |
98 | if (dest->format == QImage::Format_RGB32) { | - |
99 | | - |
100 | if (((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)))) | - |
101 | convertFromARGB32PM = convertRGB32FromARGB32PM_sse4; | - |
102 | else | - |
103 | | - |
104 | convertFromARGB32PM = convertRGB32FromARGB32PM; | - |
105 | } | - |
106 | } | - |
107 | | - |
108 | for (int y = 0; y < src->height; ++y) { | - |
109 | int x = 0; | - |
110 | while (x < src->width) { | - |
111 | int l = qMin(src->width - x, buffer_size); | - |
112 | const uint *ptr = fetch(buffer, srcData, x, l); | - |
113 | ptr = convertToARGB32PM(buffer, ptr, l, srcLayout, 0); | - |
114 | ptr = convertFromARGB32PM(buffer, ptr, l, destLayout, 0); | - |
115 | store(destData, ptr, x, l); | - |
116 | x += l; | - |
117 | } | - |
118 | srcData += src->bytes_per_line; | - |
119 | destData += dest->bytes_per_line; | - |
120 | } | - |
121 | } | - |
122 | | - |
123 | bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::ImageConversionFlags) | - |
124 | { | - |
125 | | - |
126 | ((!(dst_format > QImage::Format_Indexed8)) ? qt_assert("dst_format > QImage::Format_Indexed8",__FILE__,174180) : qt_noop()); | - |
127 | ((!(data->format > QImage::Format_Indexed8)) ? qt_assert("data->format > QImage::Format_Indexed8",__FILE__,175181) : qt_noop()); | - |
128 | if (data->depth != qt_depthForFormat(dst_format)) | - |
129 | return false; | - |
130 | | - |
131 | const int buffer_size = 2048; | - |
132 | uint buffer[buffer_size]; | - |
133 | const QPixelLayout *srcLayout = &qPixelLayouts[data->format]; | - |
134 | const QPixelLayout *destLayout = &qPixelLayouts[dst_format]; | - |
135 | uchar *srcData = data->data; | - |
136 | | - |
137 | const FetchPixelsFunc fetch = qFetchPixels[srcLayout->bpp]; | - |
138 | const StorePixelsFunc store = qStorePixels[destLayout->bpp]; | - |
139 | ConvertFunc convertToARGB32PM = srcLayout->convertToARGB32PM; | - |
140 | ConvertFunc convertFromARGB32PM = destLayout->convertFromARGB32PM; | - |
141 | if (srcLayout->alphaWidth == 0 && destLayout->convertFromRGB32) { | - |
142 | | - |
143 | convertFromARGB32PM = destLayout->convertFromRGB32; | - |
144 | } else { | - |
145 | if (data->format == QImage::Format_RGB32) | - |
146 | convertToARGB32PM = convertRGB32ToARGB32PM; | - |
147 | if (dst_format == QImage::Format_RGB32) { | - |
148 | | - |
149 | if (((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)))) | - |
150 | convertFromARGB32PM = convertRGB32FromARGB32PM_sse4; | - |
151 | else | - |
152 | | - |
153 | convertFromARGB32PM = convertRGB32FromARGB32PM; | - |
154 | } | - |
155 | } | - |
156 | | - |
157 | for (int y = 0; y < data->height; ++y) { | - |
158 | int x = 0; | - |
159 | while (x < data->width) { | - |
160 | int l = qMin(data->width - x, buffer_size); | - |
161 | const uint *ptr = fetch(buffer, srcData, x, l); | - |
162 | ptr = convertToARGB32PM(buffer, ptr, l, srcLayout, 0); | - |
163 | ptr = convertFromARGB32PM(buffer, ptr, l, destLayout, 0); | - |
164 | | - |
165 | if (srcData != (const uchar*)ptr) | - |
166 | store(srcData, ptr, x, l); | - |
167 | x += l; | - |
168 | } | - |
169 | srcData += data->bytes_per_line; | - |
170 | } | - |
171 | data->format = dst_format; | - |
172 | return true; | - |
173 | } | - |
174 | | - |
175 | static void convert_passthrough(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
176 | { | - |
177 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,225231) : qt_noop()); | - |
178 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,226232) : qt_noop()); | - |
179 | | - |
180 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
181 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
182 | const quint32 *src_data = (quint32 *) src->data; | - |
183 | quint32 *dest_data = (quint32 *) dest->data; | - |
184 | | - |
185 | for (int i = 0; i < src->height; ++i) { | - |
186 | const quint32 *end = src_data + src->width; | - |
187 | while (src_data < end) { | - |
188 | *dest_data = *src_data; | - |
189 | ++src_data; | - |
190 | ++dest_data; | - |
191 | } | - |
192 | src_data += src_pad; | - |
193 | dest_data += dest_pad; | - |
194 | } | - |
195 | } | - |
196 | | - |
197 | template<QImage::Format Format> | - |
198 | static bool convert_passthrough_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
199 | { | - |
200 | data->format = Format; | - |
201 | return true; | - |
202 | } | - |
203 | | - |
204 | static void convert_ARGB_to_ARGB_PM(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
205 | { | - |
206 | ((!(src->format == QImage::Format_ARGB32 || src->format == QImage::Format_RGBA8888)) ? qt_assert("src->format == QImage::Format_ARGB32 || src->format == QImage::Format_RGBA8888",__FILE__,254260) : qt_noop()); | - |
207 | ((!(dest->format == QImage::Format_ARGB32_Premultiplied || dest->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("dest->format == QImage::Format_ARGB32_Premultiplied || dest->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,255261) : qt_noop()); | - |
208 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,256262) : qt_noop()); | - |
209 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,257263) : qt_noop()); | - |
210 | | - |
211 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
212 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
213 | const QRgb *src_data = (QRgb *) src->data; | - |
214 | QRgb *dest_data = (QRgb *) dest->data; | - |
215 | | - |
216 | for (int i = 0; i < src->height; ++i) { | - |
217 | const QRgb *end = src_data + src->width; | - |
218 | while (src_data < end) { | - |
219 | *dest_data = qPremultiply(*src_data); | - |
220 | ++src_data; | - |
221 | ++dest_data; | - |
222 | } | - |
223 | src_data += src_pad; | - |
224 | dest_data += dest_pad; | - |
225 | } | - |
226 | } | - |
227 | | - |
228 | __attribute__((visibility("default"))) void qt_convert_rgb888_to_rgb32(quint32 *dest_data, const uchar *src_data, int len) | - |
229 | { | - |
230 | int pixel = 0; | - |
231 | | - |
232 | while ((quintptr(src_data) & 0x3) && pixel < len) { | - |
233 | *dest_data = 0xff000000 | (src_data[0] << 16) | (src_data[1] << 8) | (src_data[2]); | - |
234 | src_data += 3; | - |
235 | ++dest_data; | - |
236 | ++pixel; | - |
237 | } | - |
238 | | - |
239 | | - |
240 | for (; pixel + 3 < len; pixel += 4) { | - |
241 | const quint32 *src_packed = (const quint32 *) src_data; | - |
242 | const quint32 src1 = qFromBigEndian(src_packed[0]); | - |
243 | const quint32 src2 = qFromBigEndian(src_packed[1]); | - |
244 | const quint32 src3 = qFromBigEndian(src_packed[2]); | - |
245 | | - |
246 | dest_data[0] = 0xff000000 | (src1 >> 8); | - |
247 | dest_data[1] = 0xff000000 | (src1 << 16) | (src2 >> 16); | - |
248 | dest_data[2] = 0xff000000 | (src2 << 8) | (src3 >> 24); | - |
249 | dest_data[3] = 0xff000000 | src3; | - |
250 | | - |
251 | src_data += 12; | - |
252 | dest_data += 4; | - |
253 | } | - |
254 | | - |
255 | | - |
256 | for (; pixel < len; ++pixel) { | - |
257 | *dest_data = 0xff000000 | (src_data[0] << 16) | (src_data[1] << 8) | (src_data[2]); | - |
258 | src_data += 3; | - |
259 | ++dest_data; | - |
260 | } | - |
261 | } | - |
262 | | - |
263 | __attribute__((visibility("default"))) void qt_convert_rgb888_to_rgbx8888(quint32 *dest_data, const uchar *src_data, int len) | - |
264 | { | - |
265 | int pixel = 0; | - |
266 | | - |
267 | while ((quintptr(src_data) & 0x3) && pixel < len) { | - |
268 | *dest_data = ARGB2RGBA(0xff000000 | (src_data[0] << 16) | (src_data[1] << 8) | (src_data[2])); | - |
269 | src_data += 3; | - |
270 | ++dest_data; | - |
271 | ++pixel; | - |
272 | } | - |
273 | | - |
274 | | - |
275 | for (; pixel + 3 < len; pixel += 4) { | - |
276 | const quint32 *src_packed = (const quint32 *) src_data; | - |
277 | const quint32 src1 = src_packed[0]; | - |
278 | const quint32 src2 = src_packed[1]; | - |
279 | const quint32 src3 = src_packed[2]; | - |
280 | | - |
281 | | - |
282 | dest_data[0] = 0xff000000 | src1; | - |
283 | dest_data[1] = 0xff000000 | (src1 >> 24) | (src2 << 8); | - |
284 | dest_data[2] = 0xff000000 | (src2 >> 16) | (src3 << 16); | - |
285 | dest_data[3] = 0xff000000 | (src3 >> 8); | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | src_data += 12; | - |
294 | dest_data += 4; | - |
295 | } | - |
296 | | - |
297 | | - |
298 | for (; pixel < len; ++pixel) { | - |
299 | *dest_data = ARGB2RGBA(0xff000000 | (src_data[0] << 16) | (src_data[1] << 8) | (src_data[2])); | - |
300 | src_data += 3; | - |
301 | ++dest_data; | - |
302 | } | - |
303 | } | - |
304 | | - |
305 | typedef void ( *Rgb888ToRgbConverter)(quint32 *dst, const uchar *src, int len); | - |
306 | | - |
307 | template <bool rgbx> | - |
308 | static void convert_RGB888_to_RGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
309 | { | - |
310 | ((!(src->format == QImage::Format_RGB888)) ? qt_assert("src->format == QImage::Format_RGB888",__FILE__,358364) : qt_noop()); | - |
311 | if (rgbx) | - |
312 | ((!(dest->format == QImage::Format_RGBX8888 || dest->format == QImage::Format_RGBA8888 || dest->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGBX8888 || dest->format == QImage::Format_RGBA8888 || dest->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,360366) : qt_noop()); | - |
313 | else | - |
314 | ((!(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied",__FILE__,362368) : qt_noop()); | - |
315 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,363369) : qt_noop()); | - |
316 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,364370) : qt_noop()); | - |
317 | | - |
318 | const uchar *src_data = (uchar *) src->data; | - |
319 | quint32 *dest_data = (quint32 *) dest->data; | - |
320 | | - |
321 | Rgb888ToRgbConverter line_converter= rgbx ? qt_convert_rgb888_to_rgbx8888 : qt_convert_rgb888_to_rgb32; | - |
322 | | - |
323 | for (int i = 0; i < src->height; ++i) { | - |
324 | line_converter(dest_data, src_data, src->width); | - |
325 | src_data += src->bytes_per_line; | - |
326 | dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line); | - |
327 | } | - |
328 | } | - |
329 | | - |
330 | | - |
331 | extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags); | - |
332 | static void convert_ARGB_to_RGBx(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
333 | { | - |
334 | ((!(src->format == QImage::Format_ARGB32)) ? qt_assert("src->format == QImage::Format_ARGB32",__FILE__,407413) : qt_noop()); | - |
335 | ((!(dest->format == QImage::Format_RGBX8888)) ? qt_assert("dest->format == QImage::Format_RGBX8888",__FILE__,408414) : qt_noop()); | - |
336 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,409415) : qt_noop()); | - |
337 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,410416) : qt_noop()); | - |
338 | | - |
339 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
340 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
341 | const quint32 *src_data = (quint32 *) src->data; | - |
342 | quint32 *dest_data = (quint32 *) dest->data; | - |
343 | | - |
344 | for (int i = 0; i < src->height; ++i) { | - |
345 | const quint32 *end = src_data + src->width; | - |
346 | while (src_data < end) { | - |
347 | *dest_data = ARGB2RGBA(0xff000000 | *src_data); | - |
348 | ++src_data; | - |
349 | ++dest_data; | - |
350 | } | - |
351 | src_data += src_pad; | - |
352 | dest_data += dest_pad; | - |
353 | } | - |
354 | } | - |
355 | | - |
356 | static void convert_ARGB_to_RGBA(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
357 | { | - |
358 | ((!(src->format == QImage::Format_ARGB32 || src->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("src->format == QImage::Format_ARGB32 || src->format == QImage::Format_ARGB32_Premultiplied",__FILE__,431437) : qt_noop()); | - |
359 | ((!(dest->format == QImage::Format_RGBA8888 || dest->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGBA8888 || dest->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,432438) : qt_noop()); | - |
360 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,433439) : qt_noop()); | - |
361 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,434440) : qt_noop()); | - |
362 | | - |
363 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
364 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
365 | const quint32 *src_data = (quint32 *) src->data; | - |
366 | quint32 *dest_data = (quint32 *) dest->data; | - |
367 | | - |
368 | for (int i = 0; i < src->height; ++i) { | - |
369 | const quint32 *end = src_data + src->width; | - |
370 | while (src_data < end) { | - |
371 | *dest_data = ARGB2RGBA(*src_data); | - |
372 | ++src_data; | - |
373 | ++dest_data; | - |
374 | } | - |
375 | src_data += src_pad; | - |
376 | dest_data += dest_pad; | - |
377 | } | - |
378 | } | - |
379 | | - |
380 | template<QImage::Format DestFormat> | - |
381 | static bool convert_ARGB_to_RGBA_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
382 | { | - |
383 | ((!(data->format == QImage::Format_ARGB32 || data->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("data->format == QImage::Format_ARGB32 || data->format == QImage::Format_ARGB32_Premultiplied",__FILE__,456462) : qt_noop()); | - |
384 | | - |
385 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
386 | quint32 *rgb_data = (quint32 *) data->data; | - |
387 | constexpr uint mask = (DestFormat == QImage::Format_RGBX8888) ? 0xff000000 : 0; | - |
388 | | - |
389 | for (int i = 0; i < data->height; ++i) { | - |
390 | const quint32 *end = rgb_data + data->width; | - |
391 | while (rgb_data < end) { | - |
392 | *rgb_data = ARGB2RGBA(*rgb_data | mask); | - |
393 | ++rgb_data; | - |
394 | } | - |
395 | rgb_data += pad; | - |
396 | } | - |
397 | | - |
398 | data->format = DestFormat; | - |
399 | return true; | - |
400 | } | - |
401 | | - |
402 | static void convert_RGBA_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
403 | { | - |
404 | ((!(src->format == QImage::Format_RGBX8888 || src->format == QImage::Format_RGBA8888 || src->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("src->format == QImage::Format_RGBX8888 || src->format == QImage::Format_RGBA8888 || src->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,477483) : qt_noop()); | - |
405 | ((!(dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied",__FILE__,478484) : qt_noop()); | - |
406 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,479485) : qt_noop()); | - |
407 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,480486) : qt_noop()); | - |
408 | | - |
409 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
410 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
411 | const quint32 *src_data = (quint32 *) src->data; | - |
412 | quint32 *dest_data = (quint32 *) dest->data; | - |
413 | | - |
414 | for (int i = 0; i < src->height; ++i) { | - |
415 | const quint32 *end = src_data + src->width; | - |
416 | while (src_data < end) { | - |
417 | *dest_data = RGBA2ARGB(*src_data); | - |
418 | ++src_data; | - |
419 | ++dest_data; | - |
420 | } | - |
421 | src_data += src_pad; | - |
422 | dest_data += dest_pad; | - |
423 | } | - |
424 | } | - |
425 | | - |
426 | template<QImage::Format DestFormat> | - |
427 | static bool convert_RGBA_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
428 | { | - |
429 | ((!(data->format == QImage::Format_RGBX8888 || data->format == QImage::Format_RGBA8888 || data->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("data->format == QImage::Format_RGBX8888 || data->format == QImage::Format_RGBA8888 || data->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,502508) : qt_noop()); | - |
430 | | - |
431 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
432 | QRgb *rgb_data = (QRgb *) data->data; | - |
433 | constexpr uint mask = (DestFormat == QImage::Format_RGB32) ? 0xff000000 : 0; | - |
434 | | - |
435 | for (int i = 0; i < data->height; ++i) { | - |
436 | const QRgb *end = rgb_data + data->width; | - |
437 | while (rgb_data < end) { | - |
438 | *rgb_data = mask | RGBA2ARGB(*rgb_data); | - |
439 | ++rgb_data; | - |
440 | } | - |
441 | rgb_data += pad; | - |
442 | } | - |
443 | data->format = DestFormat; | - |
444 | return true; | - |
445 | } | - |
446 | | - |
447 | template<QtPixelOrder PixelOrder> | - |
448 | static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
449 | { | - |
450 | | - |
451 | ((!(src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32)) ? qt_assert("src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32",__FILE__,524530) : qt_noop()); | - |
452 | ((!(dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_RGB30)) ? qt_assert("dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_RGB30",__FILE__,525531) : qt_noop()); | - |
453 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,526532) : qt_noop()); | - |
454 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,527533) : qt_noop()); | - |
455 | | - |
456 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
457 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
458 | const quint32 *src_data = (quint32 *) src->data; | - |
459 | quint32 *dest_data = (quint32 *) dest->data; | - |
460 | | - |
461 | for (int i = 0; i < src->height; ++i) { | - |
462 | const quint32 *end = src_data + src->width; | - |
463 | while (src_data < end) { | - |
464 | *dest_data = qConvertRgb32ToRgb30<PixelOrder>(*src_data); | - |
465 | ++src_data; | - |
466 | ++dest_data; | - |
467 | } | - |
468 | src_data += src_pad; | - |
469 | dest_data += dest_pad; | - |
470 | } | - |
471 | } | - |
472 | | - |
473 | template<QtPixelOrder PixelOrder> | - |
474 | static bool convert_RGB_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
475 | { | - |
476 | ((!(data->format == QImage::Format_RGB32 || data->format == QImage::Format_ARGB32)) ? qt_assert("data->format == QImage::Format_RGB32 || data->format == QImage::Format_ARGB32",__FILE__,549555) : qt_noop()); | - |
477 | | - |
478 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
479 | QRgb *rgb_data = (QRgb *) data->data; | - |
480 | | - |
481 | for (int i = 0; i < data->height; ++i) { | - |
482 | const QRgb *end = rgb_data + data->width; | - |
483 | while (rgb_data < end) { | - |
484 | *rgb_data = qConvertRgb32ToRgb30<PixelOrder>(*rgb_data); | - |
485 | ++rgb_data; | - |
486 | } | - |
487 | rgb_data += pad; | - |
488 | } | - |
489 | | - |
490 | data->format = (PixelOrder == PixelOrderRGB) ? QImage::Format_RGB30 : QImage::Format_BGR30; | - |
491 | return true; | - |
492 | } | - |
493 | | - |
494 | static inline uint qUnpremultiplyRgb30(uint rgb30) | - |
495 | { | - |
496 | const uint a = rgb30 >> 30; | - |
497 | switch (a) { | - |
498 | case 0: | - |
499 | return 0; | - |
500 | case 1: { | - |
501 | uint rgb = rgb30 & 0x3fffffff; | - |
502 | rgb *= 3; | - |
503 | return (a << 30) | rgb; | - |
504 | } | - |
505 | case 2: { | - |
506 | uint rgb = rgb30 & 0x3fffffff; | - |
507 | rgb += (rgb >> 1) & 0x5ff7fdff; | - |
508 | return (a << 30) | rgb; | - |
509 | } | - |
510 | case 3: | - |
511 | return rgb30; | - |
512 | } | - |
513 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,586592) : qt_noop()); __builtin_unreachable(); } while (0); | - |
514 | return 0; | - |
515 | } | - |
516 | | - |
517 | template<bool rgbswap> | - |
518 | static void convert_A2RGB30_PM_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
519 | { | - |
520 | ((!(src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied",__FILE__,593599) : qt_noop()); | - |
521 | ((!(dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30)) ? qt_assert("dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30",__FILE__,594600) : qt_noop()); | - |
522 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,595601) : qt_noop()); | - |
523 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,596602) : qt_noop()); | - |
524 | | - |
525 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
526 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
527 | const quint32 *src_data = (quint32 *) src->data; | - |
528 | quint32 *dest_data = (quint32 *) dest->data; | - |
529 | | - |
530 | for (int i = 0; i < src->height; ++i) { | - |
531 | const quint32 *end = src_data + src->width; | - |
532 | while (src_data < end) { | - |
533 | const uint p = 0xc0000000 | qUnpremultiplyRgb30(*src_data); | - |
534 | *dest_data = (rgbswap) ? qRgbSwapRgb30(p) : p; | - |
535 | ++src_data; | - |
536 | ++dest_data; | - |
537 | } | - |
538 | src_data += src_pad; | - |
539 | dest_data += dest_pad; | - |
540 | } | - |
541 | } | - |
542 | | - |
543 | template<bool rgbswap> | - |
544 | static bool convert_A2RGB30_PM_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
545 | { | - |
546 | ((!(data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied",__FILE__,619625) : qt_noop()); | - |
547 | | - |
548 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
549 | uint *rgb_data = (uint *) data->data; | - |
550 | | - |
551 | for (int i = 0; i < data->height; ++i) { | - |
552 | const uint *end = rgb_data + data->width; | - |
553 | while (rgb_data < end) { | - |
554 | const uint p = 0xc0000000 | qUnpremultiplyRgb30(*rgb_data); | - |
555 | *rgb_data = (rgbswap) ? qRgbSwapRgb30(p) : p; | - |
556 | ++rgb_data; | - |
557 | } | - |
558 | rgb_data += pad; | - |
559 | } | - |
560 | | - |
561 | if (data->format == QImage::Format_A2RGB30_Premultiplied) | - |
562 | data->format = (rgbswap) ? QImage::Format_BGR30 : QImage::Format_RGB30; | - |
563 | else | - |
564 | data->format = (rgbswap) ? QImage::Format_RGB30 : QImage::Format_BGR30; | - |
565 | return true; | - |
566 | } | - |
567 | | - |
568 | static void convert_BGR30_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
569 | { | - |
570 | ((!(src->format == QImage::Format_RGB30 || src->format == QImage::Format_BGR30 || src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("src->format == QImage::Format_RGB30 || src->format == QImage::Format_BGR30 || src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied", | - |
571 | __FILE__ | - |
572 | , | - |
573 | 644650 | - |
574 | ) : qt_noop()) | - |
575 | ; | - |
576 | ((!(dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_A2RGB30_Premultiplied || dest->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30 || dest->format == QImage::Format_A2RGB30_Premultiplied || dest->format == QImage::Format_A2BGR30_Premultiplied", | - |
577 | __FILE__ | - |
578 | , | - |
579 | 646652 | - |
580 | ) : qt_noop()) | - |
581 | ; | - |
582 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,647653) : qt_noop()); | - |
583 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,648654) : qt_noop()); | - |
584 | | - |
585 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
586 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
587 | const quint32 *src_data = (quint32 *) src->data; | - |
588 | quint32 *dest_data = (quint32 *) dest->data; | - |
589 | | - |
590 | for (int i = 0; i < src->height; ++i) { | - |
591 | const quint32 *end = src_data + src->width; | - |
592 | while (src_data < end) { | - |
593 | *dest_data = qRgbSwapRgb30(*src_data); | - |
594 | ++src_data; | - |
595 | ++dest_data; | - |
596 | } | - |
597 | src_data += src_pad; | - |
598 | dest_data += dest_pad; | - |
599 | } | - |
600 | } | - |
601 | | - |
602 | static bool convert_BGR30_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
603 | { | - |
604 | ((!(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30 || data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30 || data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied", | - |
605 | __FILE__ | - |
606 | , | - |
607 | 670676 | - |
608 | ) : qt_noop()) | - |
609 | ; | - |
610 | | - |
611 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
612 | uint *rgb_data = (uint *) data->data; | - |
613 | | - |
614 | for (int i = 0; i < data->height; ++i) { | - |
615 | const uint *end = rgb_data + data->width; | - |
616 | while (rgb_data < end) { | - |
617 | *rgb_data = qRgbSwapRgb30(*rgb_data); | - |
618 | ++rgb_data; | - |
619 | } | - |
620 | rgb_data += pad; | - |
621 | } | - |
622 | | - |
623 | switch (data->format) { | - |
624 | case QImage::Format_BGR30: | - |
625 | data->format = QImage::Format_RGB30; | - |
626 | break; | - |
627 | case QImage::Format_A2BGR30_Premultiplied: | - |
628 | data->format = QImage::Format_A2RGB30_Premultiplied; | - |
629 | break; | - |
630 | case QImage::Format_RGB30: | - |
631 | data->format = QImage::Format_BGR30; | - |
632 | break; | - |
633 | case QImage::Format_A2RGB30_Premultiplied: | - |
634 | data->format = QImage::Format_A2BGR30_Premultiplied; | - |
635 | break; | - |
636 | default: | - |
637 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,698704) : qt_noop()); __builtin_unreachable(); } while (0); | - |
638 | data->format = QImage::Format_Invalid; | - |
639 | return false; | - |
640 | } | - |
641 | return true; | - |
642 | } | - |
643 | | - |
644 | static bool convert_BGR30_to_A2RGB30_inplace(QImageData *data, Qt::ImageConversionFlags flags) | - |
645 | { | - |
646 | ((!(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30)) ? qt_assert("data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30",__FILE__,707713) : qt_noop()); | - |
647 | if (!convert_BGR30_to_RGB30_inplace(data, flags)) | - |
648 | return false; | - |
649 | | - |
650 | if (data->format == QImage::Format_RGB30) | - |
651 | data->format = QImage::Format_A2RGB30_Premultiplied; | - |
652 | else | - |
653 | data->format = QImage::Format_A2BGR30_Premultiplied; | - |
654 | return true; | - |
655 | } | - |
656 | | - |
657 | template<QtPixelOrder PixelOrder> | - |
658 | static void convert_A2RGB30_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
659 | { | - |
660 | ((!(src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied",__FILE__,721727) : qt_noop()); | - |
661 | ((!(dest->format == QImage::Format_ARGB32)) ? qt_assert("dest->format == QImage::Format_ARGB32",__FILE__,722728) : qt_noop()); | - |
662 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,723729) : qt_noop()); | - |
663 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,724730) : qt_noop()); | - |
664 | | - |
665 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
666 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
667 | const quint32 *src_data = (quint32 *) src->data; | - |
668 | quint32 *dest_data = (quint32 *) dest->data; | - |
669 | | - |
670 | for (int i = 0; i < src->height; ++i) { | - |
671 | const quint32 *end = src_data + src->width; | - |
672 | while (src_data < end) { | - |
673 | *dest_data = qConvertA2rgb30ToArgb32<PixelOrder>(qUnpremultiplyRgb30(*src_data)); | - |
674 | ++src_data; | - |
675 | ++dest_data; | - |
676 | } | - |
677 | src_data += src_pad; | - |
678 | dest_data += dest_pad; | - |
679 | } | - |
680 | } | - |
681 | | - |
682 | template<QtPixelOrder PixelOrder> | - |
683 | static bool convert_A2RGB30_PM_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
684 | { | - |
685 | ((!(data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied)) ? qt_assert("data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied",__FILE__,746752) : qt_noop()); | - |
686 | | - |
687 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
688 | uint *rgb_data = (uint *) data->data; | - |
689 | | - |
690 | for (int i = 0; i < data->height; ++i) { | - |
691 | const uint *end = rgb_data + data->width; | - |
692 | while (rgb_data < end) { | - |
693 | *rgb_data = qConvertA2rgb30ToArgb32<PixelOrder>(qUnpremultiplyRgb30(*rgb_data)); | - |
694 | ++rgb_data; | - |
695 | } | - |
696 | rgb_data += pad; | - |
697 | } | - |
698 | data->format = QImage::Format_ARGB32; | - |
699 | return true; | - |
700 | } | - |
701 | | - |
702 | static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
703 | { | - |
704 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,765771) : qt_noop()); | - |
705 | ((!(data->own_data)) ? qt_assert("data->own_data",__FILE__,766772) : qt_noop()); | - |
706 | | - |
707 | const int depth = 32; | - |
708 | | - |
709 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
710 | const int nbytes = dst_bytes_per_line * data->height; | - |
711 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
712 | if (!newData) | - |
713 | return false; | - |
714 | | - |
715 | data->data = newData; | - |
716 | | - |
717 | | - |
718 | uchar *src_data = newData + data->nbytes; | - |
719 | quint32 *dest_data = (quint32 *) (newData + nbytes); | - |
720 | const int width = data->width; | - |
721 | const int src_pad = data->bytes_per_line - width; | - |
722 | const int dest_pad = (dst_bytes_per_line >> 2) - width; | - |
723 | if (data->colortable.size() == 0) { | - |
724 | data->colortable.resize(256); | - |
725 | for (int i = 0; i < 256; ++i) | - |
726 | data->colortable[i] = qRgb(i, i, i); | - |
727 | } else { | - |
728 | for (int i = 0; i < data->colortable.size(); ++i) | - |
729 | data->colortable[i] = qPremultiply(data->colortable.at(i)); | - |
730 | | - |
731 | | - |
732 | const int oldSize = data->colortable.size(); | - |
733 | const QRgb lastColor = data->colortable.at(oldSize - 1); | - |
734 | data->colortable.insert(oldSize, 256 - oldSize, lastColor); | - |
735 | } | - |
736 | | - |
737 | for (int i = 0; i < data->height; ++i) { | - |
738 | src_data -= src_pad; | - |
739 | dest_data -= dest_pad; | - |
740 | for (int pixI = 0; pixI < width; ++pixI) { | - |
741 | --src_data; | - |
742 | --dest_data; | - |
743 | *dest_data = data->colortable.at(*src_data); | - |
744 | } | - |
745 | } | - |
746 | | - |
747 | data->colortable = QVector<QRgb>(); | - |
748 | data->format = QImage::Format_ARGB32_Premultiplied; | - |
749 | data->bytes_per_line = dst_bytes_per_line; | - |
750 | data->depth = depth; | - |
751 | data->nbytes = nbytes; | - |
752 | | - |
753 | return true; | - |
754 | } | - |
755 | | - |
756 | static bool convert_indexed8_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
757 | { | - |
758 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,819825) : qt_noop()); | - |
759 | ((!(data->own_data)) ? qt_assert("data->own_data",__FILE__,820826) : qt_noop()); | - |
760 | | - |
761 | const int depth = 32; | - |
762 | | - |
763 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
764 | const int nbytes = dst_bytes_per_line * data->height; | - |
765 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
766 | if (!newData) | - |
767 | return false; | - |
768 | | - |
769 | data->data = newData; | - |
770 | | - |
771 | | - |
772 | uchar *src_data = newData + data->nbytes; | - |
773 | quint32 *dest_data = (quint32 *) (newData + nbytes); | - |
774 | const int width = data->width; | - |
775 | const int src_pad = data->bytes_per_line - width; | - |
776 | const int dest_pad = (dst_bytes_per_line >> 2) - width; | - |
777 | if (data->colortable.size() == 0) { | - |
778 | data->colortable.resize(256); | - |
779 | for (int i = 0; i < 256; ++i) | - |
780 | data->colortable[i] = qRgb(i, i, i); | - |
781 | } else { | - |
782 | | - |
783 | const int oldSize = data->colortable.size(); | - |
784 | const QRgb lastColor = data->colortable.at(oldSize - 1); | - |
785 | data->colortable.insert(oldSize, 256 - oldSize, lastColor); | - |
786 | } | - |
787 | | - |
788 | for (int i = 0; i < data->height; ++i) { | - |
789 | src_data -= src_pad; | - |
790 | dest_data -= dest_pad; | - |
791 | for (int pixI = 0; pixI < width; ++pixI) { | - |
792 | --src_data; | - |
793 | --dest_data; | - |
794 | *dest_data = (quint32) data->colortable.at(*src_data); | - |
795 | } | - |
796 | } | - |
797 | | - |
798 | data->colortable = QVector<QRgb>(); | - |
799 | data->format = QImage::Format_ARGB32; | - |
800 | data->bytes_per_line = dst_bytes_per_line; | - |
801 | data->depth = depth; | - |
802 | data->nbytes = nbytes; | - |
803 | | - |
804 | return true; | - |
805 | } | - |
806 | | - |
807 | static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversionFlags flags) | - |
808 | { | - |
809 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,870876) : qt_noop()); | - |
810 | ((!(data->own_data)) ? qt_assert("data->own_data",__FILE__,871877) : qt_noop()); | - |
811 | | - |
812 | if (data->has_alpha_clut) { | - |
813 | for (int i = 0; i < data->colortable.size(); ++i) | - |
814 | data->colortable[i] |= 0xff000000; | - |
815 | } | - |
816 | | - |
817 | if (!convert_indexed8_to_ARGB_inplace(data, flags)) | - |
818 | return false; | - |
819 | | - |
820 | data->format = QImage::Format_RGB32; | - |
821 | return true; | - |
822 | } | - |
823 | | - |
824 | static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
825 | { | - |
826 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,887893) : qt_noop()); | - |
827 | ((!(data->own_data)) ? qt_assert("data->own_data",__FILE__,888894) : qt_noop()); | - |
828 | | - |
829 | const int depth = 16; | - |
830 | | - |
831 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
832 | const int nbytes = dst_bytes_per_line * data->height; | - |
833 | uchar *const newData = (uchar *)realloc(data->data, nbytes); | - |
834 | if (!newData) | - |
835 | return false; | - |
836 | | - |
837 | data->data = newData; | - |
838 | | - |
839 | | - |
840 | uchar *src_data = newData + data->nbytes; | - |
841 | quint16 *dest_data = (quint16 *) (newData + nbytes); | - |
842 | const int width = data->width; | - |
843 | const int src_pad = data->bytes_per_line - width; | - |
844 | const int dest_pad = (dst_bytes_per_line >> 1) - width; | - |
845 | | - |
846 | quint16 colorTableRGB16[256]; | - |
847 | const int tableSize = data->colortable.size(); | - |
848 | if (tableSize == 0) { | - |
849 | for (int i = 0; i < 256; ++i) | - |
850 | colorTableRGB16[i] = qConvertRgb32To16(qRgb(i, i, i)); | - |
851 | } else { | - |
852 | | - |
853 | for (int i = 0; i < tableSize; ++i) | - |
854 | colorTableRGB16[i] = qConvertRgb32To16(data->colortable.at(i)); | - |
855 | data->colortable = QVector<QRgb>(); | - |
856 | | - |
857 | | - |
858 | const quint16 lastColor = colorTableRGB16[tableSize - 1]; | - |
859 | for (int i = tableSize; i < 256; ++i) | - |
860 | colorTableRGB16[i] = lastColor; | - |
861 | } | - |
862 | | - |
863 | for (int i = 0; i < data->height; ++i) { | - |
864 | src_data -= src_pad; | - |
865 | dest_data -= dest_pad; | - |
866 | for (int pixI = 0; pixI < width; ++pixI) { | - |
867 | --src_data; | - |
868 | --dest_data; | - |
869 | *dest_data = colorTableRGB16[*src_data]; | - |
870 | } | - |
871 | } | - |
872 | | - |
873 | data->format = QImage::Format_RGB16; | - |
874 | data->bytes_per_line = dst_bytes_per_line; | - |
875 | data->depth = depth; | - |
876 | data->nbytes = nbytes; | - |
877 | | - |
878 | return true; | - |
879 | } | - |
880 | | - |
881 | static bool convert_RGB_to_RGB16_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
882 | { | - |
883 | ((!(data->format == QImage::Format_RGB32)) ? qt_assert("data->format == QImage::Format_RGB32",__FILE__,944950) : qt_noop()); | - |
884 | ((!(data->own_data)) ? qt_assert("data->own_data",__FILE__,945951) : qt_noop()); | - |
885 | | - |
886 | const int depth = 16; | - |
887 | | - |
888 | const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2; | - |
889 | const int src_bytes_per_line = data->bytes_per_line; | - |
890 | quint32 *src_data = (quint32 *) data->data; | - |
891 | quint16 *dst_data = (quint16 *) data->data; | - |
892 | | - |
893 | for (int i = 0; i < data->height; ++i) { | - |
894 | for (int j = 0; j < data->width; ++j) | - |
895 | dst_data[j] = qConvertRgb32To16(src_data[j]); | - |
896 | src_data = (quint32 *) (((char*)src_data) + src_bytes_per_line); | - |
897 | dst_data = (quint16 *) (((char*)dst_data) + dst_bytes_per_line); | - |
898 | } | - |
899 | data->format = QImage::Format_RGB16; | - |
900 | data->bytes_per_line = dst_bytes_per_line; | - |
901 | data->depth = depth; | - |
902 | data->nbytes = dst_bytes_per_line * data->height; | - |
903 | uchar *const newData = (uchar *)realloc(data->data, data->nbytes); | - |
904 | if (newData) { | - |
905 | data->data = newData; | - |
906 | return true; | - |
907 | } else { | - |
908 | return false; | - |
909 | } | - |
910 | } | - |
911 | | - |
912 | static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src) | - |
913 | { | - |
914 | ((!(src->format == QImage::Format_ARGB32_Premultiplied || src->format == QImage::Format_RGBA8888_Premultiplied)) ? qt_assert("src->format == QImage::Format_ARGB32_Premultiplied || src->format == QImage::Format_RGBA8888_Premultiplied",__FILE__,975981) : qt_noop()); | - |
915 | ((!(dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_RGBA8888)) ? qt_assert("dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_RGBA8888",__FILE__,976982) : qt_noop()); | - |
916 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,977983) : qt_noop()); | - |
917 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,978984) : qt_noop()); | - |
918 | | - |
919 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
920 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
921 | const QRgb *src_data = (QRgb *) src->data; | - |
922 | QRgb *dest_data = (QRgb *) dest->data; | - |
923 | | - |
924 | for (int i = 0; i < src->height; ++i) { | - |
925 | const QRgb *end = src_data + src->width; | - |
926 | while (src_data < end) { | - |
927 | *dest_data = qUnpremultiply(*src_data); | - |
928 | ++src_data; | - |
929 | ++dest_data; | - |
930 | } | - |
931 | src_data += src_pad; | - |
932 | dest_data += dest_pad; | - |
933 | } | - |
934 | } | - |
935 | | - |
936 | static void convert_RGBA_to_RGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
937 | { | - |
938 | ((!(src->format == QImage::Format_RGBA8888 || src->format == QImage::Format_RGBX8888)) ? qt_assert("src->format == QImage::Format_RGBA8888 || src->format == QImage::Format_RGBX8888",__FILE__,9991005) : qt_noop()); | - |
939 | ((!(dest->format == QImage::Format_RGB32)) ? qt_assert("dest->format == QImage::Format_RGB32",__FILE__,10001006) : qt_noop()); | - |
940 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,10011007) : qt_noop()); | - |
941 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,10021008) : qt_noop()); | - |
942 | | - |
943 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
944 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
945 | const uint *src_data = (const uint *)src->data; | - |
946 | uint *dest_data = (uint *)dest->data; | - |
947 | | - |
948 | for (int i = 0; i < src->height; ++i) { | - |
949 | const uint *end = src_data + src->width; | - |
950 | while (src_data < end) { | - |
951 | *dest_data = RGBA2ARGB(*src_data) | 0xff000000; | - |
952 | ++src_data; | - |
953 | ++dest_data; | - |
954 | } | - |
955 | src_data += src_pad; | - |
956 | dest_data += dest_pad; | - |
957 | } | - |
958 | } | - |
959 | | - |
960 | static void swap_bit_order(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
961 | { | - |
962 | ((!(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB)) ? qt_assert("src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB",__FILE__,10231029) : qt_noop()); | - |
963 | ((!(dest->format == QImage::Format_Mono || dest->format == QImage::Format_MonoLSB)) ? qt_assert("dest->format == QImage::Format_Mono || dest->format == QImage::Format_MonoLSB",__FILE__,10241030) : qt_noop()); | - |
964 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,10251031) : qt_noop()); | - |
965 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,10261032) : qt_noop()); | - |
966 | ((!(src->nbytes == dest->nbytes)) ? qt_assert("src->nbytes == dest->nbytes",__FILE__,10271033) : qt_noop()); | - |
967 | ((!(src->bytes_per_line == dest->bytes_per_line)) ? qt_assert("src->bytes_per_line == dest->bytes_per_line",__FILE__,10281034) : qt_noop()); | - |
968 | | - |
969 | dest->colortable = src->colortable; | - |
970 | | - |
971 | const uchar *src_data = src->data; | - |
972 | const uchar *end = src->data + src->nbytes; | - |
973 | uchar *dest_data = dest->data; | - |
974 | while (src_data < end) { | - |
975 | *dest_data = bitflip[*src_data]; | - |
976 | ++src_data; | - |
977 | ++dest_data; | - |
978 | } | - |
979 | } | - |
980 | | - |
981 | static void mask_alpha_converter(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
982 | { | - |
983 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,10441050) : qt_noop()); | - |
984 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,10451051) : qt_noop()); | - |
985 | | - |
986 | const int src_pad = (src->bytes_per_line >> 2) - src->width; | - |
987 | const int dest_pad = (dest->bytes_per_line >> 2) - dest->width; | - |
988 | const uint *src_data = (const uint *)src->data; | - |
989 | uint *dest_data = (uint *)dest->data; | - |
990 | | - |
991 | for (int i = 0; i < src->height; ++i) { | - |
992 | const uint *end = src_data + src->width; | - |
993 | while (src_data < end) { | - |
994 | *dest_data = *src_data | 0xff000000; | - |
995 | ++src_data; | - |
996 | ++dest_data; | - |
997 | } | - |
998 | src_data += src_pad; | - |
999 | dest_data += dest_pad; | - |
1000 | } | - |
1001 | } | - |
1002 | | - |
1003 | template<QImage::Format DestFormat> | - |
1004 | static bool mask_alpha_converter_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
1005 | { | - |
1006 | ((!(data->format == QImage::Format_RGB32 || DestFormat == QImage::Format_RGB32 || DestFormat == QImage::Format_RGBX8888)) ? qt_assert("data->format == QImage::Format_RGB32 || DestFormat == QImage::Format_RGB32 || DestFormat == QImage::Format_RGBX8888", | - |
1007 | | - |
1008 | __FILE__ | - |
1009 | , | - |
1010 | | - |
1011 | 10691075 | - |
1012 | ) : qt_noop()) | - |
1013 | | - |
1014 | ; | - |
1015 | const int pad = (data->bytes_per_line >> 2) - data->width; | - |
1016 | QRgb *rgb_data = (QRgb *) data->data; | - |
1017 | | - |
1018 | for (int i = 0; i < data->height; ++i) { | - |
1019 | const QRgb *end = rgb_data + data->width; | - |
1020 | while (rgb_data < end) { | - |
1021 | *rgb_data = *rgb_data | 0xff000000; | - |
1022 | ++rgb_data; | - |
1023 | } | - |
1024 | rgb_data += pad; | - |
1025 | } | - |
1026 | data->format = DestFormat; | - |
1027 | return true; | - |
1028 | } | - |
1029 | | - |
1030 | static void mask_alpha_converter_RGBx(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1031 | { | - |
1032 | | - |
1033 | return mask_alpha_converter(dest, src, flags); | - |
1034 | } | - |
1035 | | - |
1036 | static bool mask_alpha_converter_rgbx_inplace(QImageData *data, Qt::ImageConversionFlags flags) | - |
1037 | { | - |
1038 | | - |
1039 | return mask_alpha_converter_inplace<QImage::Format_RGBX8888>(data, flags); | - |
1040 | } | - |
1041 | | - |
1042 | static QVector<QRgb> fix_color_table(const QVector<QRgb> &ctbl, QImage::Format format) | - |
1043 | { | - |
1044 | QVector<QRgb> colorTable = ctbl; | - |
1045 | if (format == QImage::Format_RGB32) { | - |
1046 | | - |
1047 | for (int i = 0; i < colorTable.size(); ++i) | - |
1048 | if (qAlpha(colorTable.at(i) != 0xff)) | - |
1049 | colorTable[i] = colorTable.at(i) | 0xff000000; | - |
1050 | } else if (format == QImage::Format_ARGB32_Premultiplied) { | - |
1051 | | - |
1052 | for (int i = 0; i < colorTable.size(); ++i) | - |
1053 | colorTable[i] = qPremultiply(colorTable.at(i)); | - |
1054 | } | - |
1055 | return colorTable; | - |
1056 | } | - |
1057 | | - |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | - |
1062 | void dither_to_Mono(QImageData *dst, const QImageData *src, | - |
1063 | Qt::ImageConversionFlags flags, bool fromalpha) | - |
1064 | { | - |
1065 | ((!(src->width == dst->width)) ? qt_assert("src->width == dst->width",__FILE__,11581164) : qt_noop()); | - |
1066 | ((!(src->height == dst->height)) ? qt_assert("src->height == dst->height",__FILE__,11591165) : qt_noop()); | - |
1067 | ((!(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB)) ? qt_assert("dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB",__FILE__,11601166) : qt_noop()); | - |
1068 | | - |
1069 | dst->colortable.clear(); | - |
1070 | dst->colortable.append(0xffffffff); | - |
1071 | dst->colortable.append(0xff000000); | - |
1072 | | - |
1073 | enum { Threshold, Ordered, Diffuse } dithermode; | - |
1074 | | - |
1075 | if (fromalpha) { | - |
1076 | if ((flags & Qt::AlphaDither_Mask) == Qt::DiffuseAlphaDither) | - |
1077 | dithermode = Diffuse; | - |
1078 | else if ((flags & Qt::AlphaDither_Mask) == Qt::OrderedAlphaDither) | - |
1079 | dithermode = Ordered; | - |
1080 | else | - |
1081 | dithermode = Threshold; | - |
1082 | } else { | - |
1083 | if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) | - |
1084 | dithermode = Threshold; | - |
1085 | else if ((flags & Qt::Dither_Mask) == Qt::OrderedDither) | - |
1086 | dithermode = Ordered; | - |
1087 | else | - |
1088 | dithermode = Diffuse; | - |
1089 | } | - |
1090 | | - |
1091 | int w = src->width; | - |
1092 | int h = src->height; | - |
1093 | int d = src->depth; | - |
1094 | uchar gray[256]; | - |
1095 | bool use_gray = (d == 8); | - |
1096 | if (use_gray) { | - |
1097 | if (fromalpha) { | - |
1098 | | - |
1099 | | - |
1100 | for (int i = 0; i < src->colortable.size(); i++) | - |
1101 | gray[i] = (255 - (src->colortable.at(i) >> 24)); | - |
1102 | } else { | - |
1103 | | - |
1104 | | - |
1105 | for (int i = 0; i < src->colortable.size(); i++) | - |
1106 | gray[i] = qGray(src->colortable.at(i)); | - |
1107 | } | - |
1108 | } | - |
1109 | | - |
1110 | uchar *dst_data = dst->data; | - |
1111 | int dst_bpl = dst->bytes_per_line; | - |
1112 | const uchar *src_data = src->data; | - |
1113 | int src_bpl = src->bytes_per_line; | - |
1114 | | - |
1115 | switch (dithermode) { | - |
1116 | case Diffuse: { | - |
1117 | QScopedArrayPointer<int> lineBuffer(new int[w * 2]); | - |
1118 | int *line1 = lineBuffer.data(); | - |
1119 | int *line2 = lineBuffer.data() + w; | - |
1120 | int bmwidth = (w+7)/8; | - |
1121 | | - |
1122 | int *b1, *b2; | - |
1123 | int wbytes = w * (d/8); | - |
1124 | const uchar *p = src->data; | - |
1125 | const uchar *end = p + wbytes; | - |
1126 | b2 = line2; | - |
1127 | if (use_gray) { | - |
1128 | while (p < end) | - |
1129 | *b2++ = gray[*p++]; | - |
1130 | } else { | - |
1131 | if (fromalpha) { | - |
1132 | while (p < end) { | - |
1133 | *b2++ = 255 - (*(const uint*)p >> 24); | - |
1134 | p += 4; | - |
1135 | } | - |
1136 | } else { | - |
1137 | while (p < end) { | - |
1138 | *b2++ = qGray(*(const uint*)p); | - |
1139 | p += 4; | - |
1140 | } | - |
1141 | } | - |
1142 | } | - |
1143 | for (int y=0; y<h; y++) { | - |
1144 | int *tmp = line1; line1 = line2; line2 = tmp; | - |
1145 | bool not_last_line = y < h - 1; | - |
1146 | if (not_last_line) { | - |
1147 | p = src->data + (y+1)*src->bytes_per_line; | - |
1148 | end = p + wbytes; | - |
1149 | b2 = line2; | - |
1150 | if (use_gray) { | - |
1151 | while (p < end) | - |
1152 | *b2++ = gray[*p++]; | - |
1153 | } else { | - |
1154 | if (fromalpha) { | - |
1155 | while (p < end) { | - |
1156 | *b2++ = 255 - (*(const uint*)p >> 24); | - |
1157 | p += 4; | - |
1158 | } | - |
1159 | } else { | - |
1160 | while (p < end) { | - |
1161 | *b2++ = qGray(*(const uint*)p); | - |
1162 | p += 4; | - |
1163 | } | - |
1164 | } | - |
1165 | } | - |
1166 | } | - |
1167 | | - |
1168 | int err; | - |
1169 | uchar *p = dst->data + y*dst->bytes_per_line; | - |
1170 | memset(p, 0, bmwidth); | - |
1171 | b1 = line1; | - |
1172 | b2 = line2; | - |
1173 | int bit = 7; | - |
1174 | for (int x=1; x<=w; x++) { | - |
1175 | if (*b1 < 128) { | - |
1176 | err = *b1++; | - |
1177 | *p |= 1 << bit; | - |
1178 | } else { | - |
1179 | err = *b1++ - 255; | - |
1180 | } | - |
1181 | if (bit == 0) { | - |
1182 | p++; | - |
1183 | bit = 7; | - |
1184 | } else { | - |
1185 | bit--; | - |
1186 | } | - |
1187 | if (x < w) | - |
1188 | *b1 += (err*7)>>4; | - |
1189 | if (not_last_line) { | - |
1190 | b2[0] += (err*5)>>4; | - |
1191 | if (x > 1) | - |
1192 | b2[-1] += (err*3)>>4; | - |
1193 | if (x < w) | - |
1194 | b2[1] += err>>4; | - |
1195 | } | - |
1196 | b2++; | - |
1197 | } | - |
1198 | } | - |
1199 | } break; | - |
1200 | case Ordered: { | - |
1201 | | - |
1202 | memset(dst->data, 0, dst->nbytes); | - |
1203 | if (d == 32) { | - |
1204 | for (int i=0; i<h; i++) { | - |
1205 | const uint *p = (const uint *)src_data; | - |
1206 | const uint *end = p + w; | - |
1207 | uchar *m = dst_data; | - |
1208 | int bit = 7; | - |
1209 | int j = 0; | - |
1210 | if (fromalpha) { | - |
1211 | while (p < end) { | - |
1212 | if ((*p++ >> 24) >= qt_bayer_matrix[j++&15][i&15]) | - |
1213 | *m |= 1 << bit; | - |
1214 | if (bit == 0) { | - |
1215 | m++; | - |
1216 | bit = 7; | - |
1217 | } else { | - |
1218 | bit--; | - |
1219 | } | - |
1220 | } | - |
1221 | } else { | - |
1222 | while (p < end) { | - |
1223 | if ((uint)qGray(*p++) < qt_bayer_matrix[j++&15][i&15]) | - |
1224 | *m |= 1 << bit; | - |
1225 | if (bit == 0) { | - |
1226 | m++; | - |
1227 | bit = 7; | - |
1228 | } else { | - |
1229 | bit--; | - |
1230 | } | - |
1231 | } | - |
1232 | } | - |
1233 | dst_data += dst_bpl; | - |
1234 | src_data += src_bpl; | - |
1235 | } | - |
1236 | } else if (d == 8) { | - |
1237 | for (int i=0; i<h; i++) { | - |
1238 | const uchar *p = src_data; | - |
1239 | const uchar *end = p + w; | - |
1240 | uchar *m = dst_data; | - |
1241 | int bit = 7; | - |
1242 | int j = 0; | - |
1243 | while (p < end) { | - |
1244 | if ((uint)gray[*p++] < qt_bayer_matrix[j++&15][i&15]) | - |
1245 | *m |= 1 << bit; | - |
1246 | if (bit == 0) { | - |
1247 | m++; | - |
1248 | bit = 7; | - |
1249 | } else { | - |
1250 | bit--; | - |
1251 | } | - |
1252 | } | - |
1253 | dst_data += dst_bpl; | - |
1254 | src_data += src_bpl; | - |
1255 | } | - |
1256 | } | - |
1257 | } break; | - |
1258 | default: { | - |
1259 | memset(dst->data, 0, dst->nbytes); | - |
1260 | if (d == 32) { | - |
1261 | for (int i=0; i<h; i++) { | - |
1262 | const uint *p = (const uint *)src_data; | - |
1263 | const uint *end = p + w; | - |
1264 | uchar *m = dst_data; | - |
1265 | int bit = 7; | - |
1266 | if (fromalpha) { | - |
1267 | while (p < end) { | - |
1268 | if ((*p++ >> 24) >= 128) | - |
1269 | *m |= 1 << bit; | - |
1270 | if (bit == 0) { | - |
1271 | m++; | - |
1272 | bit = 7; | - |
1273 | } else { | - |
1274 | bit--; | - |
1275 | } | - |
1276 | } | - |
1277 | } else { | - |
1278 | while (p < end) { | - |
1279 | if (qGray(*p++) < 128) | - |
1280 | *m |= 1 << bit; | - |
1281 | if (bit == 0) { | - |
1282 | m++; | - |
1283 | bit = 7; | - |
1284 | } else { | - |
1285 | bit--; | - |
1286 | } | - |
1287 | } | - |
1288 | } | - |
1289 | dst_data += dst_bpl; | - |
1290 | src_data += src_bpl; | - |
1291 | } | - |
1292 | } else | - |
1293 | if (d == 8) { | - |
1294 | for (int i=0; i<h; i++) { | - |
1295 | const uchar *p = src_data; | - |
1296 | const uchar *end = p + w; | - |
1297 | uchar *m = dst_data; | - |
1298 | int bit = 7; | - |
1299 | while (p < end) { | - |
1300 | if (gray[*p++] < 128) | - |
1301 | *m |= 1 << bit; | - |
1302 | if (bit == 0) { | - |
1303 | m++; | - |
1304 | bit = 7; | - |
1305 | } else { | - |
1306 | bit--; | - |
1307 | } | - |
1308 | } | - |
1309 | dst_data += dst_bpl; | - |
1310 | src_data += src_bpl; | - |
1311 | } | - |
1312 | } | - |
1313 | } | - |
1314 | } | - |
1315 | | - |
1316 | if (dst->format == QImage::Format_MonoLSB) { | - |
1317 | | - |
1318 | uchar *sl = dst->data; | - |
1319 | int bpl = (dst->width + 7) * dst->depth / 8; | - |
1320 | int pad = dst->bytes_per_line - bpl; | - |
1321 | for (int y=0; y<dst->height; ++y) { | - |
1322 | for (int x=0; x<bpl; ++x) { | - |
1323 | *sl = bitflip[*sl]; | - |
1324 | ++sl; | - |
1325 | } | - |
1326 | sl += pad; | - |
1327 | } | - |
1328 | } | - |
1329 | } | - |
1330 | | - |
1331 | static void convert_X_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1332 | { | - |
1333 | dither_to_Mono(dst, src, flags, false); | - |
1334 | } | - |
1335 | | - |
1336 | static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1337 | { | - |
1338 | QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32)); | - |
1339 | convert_ARGB_PM_to_ARGB(tmp.data(), src); | - |
1340 | dither_to_Mono(dst, tmp.data(), flags, false); | - |
1341 | } | - |
1342 | struct QRgbMap { | - |
1343 | inline QRgbMap() : used(0) { } | - |
1344 | uchar pix; | - |
1345 | uchar used; | - |
1346 | QRgb rgb; | - |
1347 | }; | - |
1348 | | - |
1349 | static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1350 | { | - |
1351 | ((!(src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32)) ? qt_assert("src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32",__FILE__,14531459) : qt_noop()); | - |
1352 | ((!(dst->format == QImage::Format_Indexed8)) ? qt_assert("dst->format == QImage::Format_Indexed8",__FILE__,14541460) : qt_noop()); | - |
1353 | ((!(src->width == dst->width)) ? qt_assert("src->width == dst->width",__FILE__,14551461) : qt_noop()); | - |
1354 | ((!(src->height == dst->height)) ? qt_assert("src->height == dst->height",__FILE__,14561462) : qt_noop()); | - |
1355 | | - |
1356 | bool do_quant = (flags & Qt::DitherMode_Mask) == Qt::PreferDither | - |
1357 | || src->format == QImage::Format_ARGB32; | - |
1358 | uint alpha_mask = src->format == QImage::Format_RGB32 ? 0xff000000 : 0; | - |
1359 | | - |
1360 | const int tablesize = 997; | - |
1361 | QRgbMap table[tablesize]; | - |
1362 | int pix=0; | - |
1363 | | - |
1364 | if (!dst->colortable.isEmpty()) { | - |
1365 | QVector<QRgb> ctbl = dst->colortable; | - |
1366 | dst->colortable.resize(256); | - |
1367 | | - |
1368 | | - |
1369 | for (int i = 0; i < dst->colortable.size(); ++i) { | - |
1370 | | - |
1371 | QRgb p = ctbl.at(i) | alpha_mask; | - |
1372 | int hash = p % tablesize; | - |
1373 | for (;;) { | - |
1374 | if (table[hash].used) { | - |
1375 | if (table[hash].rgb == p) { | - |
1376 | | - |
1377 | break; | - |
1378 | } else { | - |
1379 | | - |
1380 | if (++hash == tablesize) hash = 0; | - |
1381 | } | - |
1382 | } else { | - |
1383 | | - |
1384 | ((!(pix != 256)) ? qt_assert("pix != 256",__FILE__,14861492) : qt_noop()); | - |
1385 | | - |
1386 | dst->colortable[pix] = p; | - |
1387 | table[hash].pix = pix++; | - |
1388 | table[hash].rgb = p; | - |
1389 | table[hash].used = 1; | - |
1390 | break; | - |
1391 | } | - |
1392 | } | - |
1393 | } | - |
1394 | } | - |
1395 | | - |
1396 | if ((flags & Qt::DitherMode_Mask) != Qt::PreferDither) { | - |
1397 | dst->colortable.resize(256); | - |
1398 | const uchar *src_data = src->data; | - |
1399 | uchar *dest_data = dst->data; | - |
1400 | for (int y = 0; y < src->height; y++) { | - |
1401 | const QRgb *s = (const QRgb *)src_data; | - |
1402 | uchar *b = dest_data; | - |
1403 | for (int x = 0; x < src->width; ++x) { | - |
1404 | QRgb p = s[x] | alpha_mask; | - |
1405 | int hash = p % tablesize; | - |
1406 | for (;;) { | - |
1407 | if (table[hash].used) { | - |
1408 | if (table[hash].rgb == (p)) { | - |
1409 | | - |
1410 | break; | - |
1411 | } else { | - |
1412 | | - |
1413 | if (++hash == tablesize) hash = 0; | - |
1414 | } | - |
1415 | } else { | - |
1416 | | - |
1417 | if (pix == 256) { | - |
1418 | do_quant = true; | - |
1419 | | - |
1420 | x = src->width; | - |
1421 | y = src->height; | - |
1422 | } else { | - |
1423 | | - |
1424 | dst->colortable[pix] = p; | - |
1425 | table[hash].pix = pix++; | - |
1426 | table[hash].rgb = p; | - |
1427 | table[hash].used = 1; | - |
1428 | } | - |
1429 | break; | - |
1430 | } | - |
1431 | } | - |
1432 | *b++ = table[hash].pix; | - |
1433 | } | - |
1434 | src_data += src->bytes_per_line; | - |
1435 | dest_data += dst->bytes_per_line; | - |
1436 | } | - |
1437 | } | - |
1438 | int numColors = do_quant ? 256 : pix; | - |
1439 | | - |
1440 | dst->colortable.resize(numColors); | - |
1441 | | - |
1442 | if (do_quant) { | - |
1443 | | - |
1444 | | - |
1445 | | - |
1446 | | - |
1447 | | - |
1448 | | - |
1449 | for (int rc=0; rc<=5; rc++) | - |
1450 | for (int gc=0; gc<=5; gc++) | - |
1451 | for (int bc=0; bc<=5; bc++) | - |
1452 | dst->colortable[(((rc)*(5 +1)+(gc))*(5 +1)+(bc))] = 0xff000000 | qRgb(rc*255/5, gc*255/5, bc*255/5); | - |
1453 | | - |
1454 | const uchar *src_data = src->data; | - |
1455 | uchar *dest_data = dst->data; | - |
1456 | if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) { | - |
1457 | for (int y = 0; y < src->height; y++) { | - |
1458 | const QRgb *p = (const QRgb *)src_data; | - |
1459 | const QRgb *end = p + src->width; | - |
1460 | uchar *b = dest_data; | - |
1461 | | - |
1462 | while (p < end) { | - |
1463 | | - |
1464 | *b++ = | - |
1465 | (((((uchar) ((qRed(*p) * (5) + 127) / 255)))*(5 +1)+(((uchar) ((qGreen(*p) * (5) + 127) / 255))))*(5 +1)+(((uchar) ((qBlue(*p) * (5) + 127) / 255)))) | - |
1466 | | - |
1467 | | - |
1468 | | - |
1469 | ; | - |
1470 | | - |
1471 | p++; | - |
1472 | } | - |
1473 | src_data += src->bytes_per_line; | - |
1474 | dest_data += dst->bytes_per_line; | - |
1475 | } | - |
1476 | } else if ((flags & Qt::Dither_Mask) == Qt::DiffuseDither) { | - |
1477 | int* line1[3]; | - |
1478 | int* line2[3]; | - |
1479 | int* pv[3]; | - |
1480 | QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]); | - |
1481 | line1[0] = lineBuffer.data(); | - |
1482 | line2[0] = lineBuffer.data() + src->width; | - |
1483 | line1[1] = lineBuffer.data() + src->width * 2; | - |
1484 | line2[1] = lineBuffer.data() + src->width * 3; | - |
1485 | line1[2] = lineBuffer.data() + src->width * 4; | - |
1486 | line2[2] = lineBuffer.data() + src->width * 5; | - |
1487 | pv[0] = lineBuffer.data() + src->width * 6; | - |
1488 | pv[1] = lineBuffer.data() + src->width * 7; | - |
1489 | pv[2] = lineBuffer.data() + src->width * 8; | - |
1490 | | - |
1491 | int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian); | - |
1492 | for (int y = 0; y < src->height; y++) { | - |
1493 | const uchar* q = src_data; | - |
1494 | const uchar* q2 = y < src->height - 1 ? q + src->bytes_per_line : src->data; | - |
1495 | uchar *b = dest_data; | - |
1496 | for (int chan = 0; chan < 3; chan++) { | - |
1497 | int *l1 = (y&1) ? line2[chan] : line1[chan]; | - |
1498 | int *l2 = (y&1) ? line1[chan] : line2[chan]; | - |
1499 | if (y == 0) { | - |
1500 | for (int i = 0; i < src->width; i++) | - |
1501 | l1[i] = q[i*4+chan+endian]; | - |
1502 | } | - |
1503 | if (y+1 < src->height) { | - |
1504 | for (int i = 0; i < src->width; i++) | - |
1505 | l2[i] = q2[i*4+chan+endian]; | - |
1506 | } | - |
1507 | | - |
1508 | if (y&1) { | - |
1509 | for (int x = 0; x < src->width; x++) { | - |
1510 | int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); | - |
1511 | int err = l1[x] - pix * 255 / 5; | - |
1512 | pv[chan][x] = pix; | - |
1513 | | - |
1514 | | - |
1515 | if (x + 1< src->width) { | - |
1516 | l1[x+1] += (err*7)>>4; | - |
1517 | l2[x+1] += err>>4; | - |
1518 | } | - |
1519 | l2[x]+=(err*5)>>4; | - |
1520 | if (x>1) | - |
1521 | l2[x-1]+=(err*3)>>4; | - |
1522 | } | - |
1523 | } else { | - |
1524 | for (int x = src->width; x-- > 0;) { | - |
1525 | int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); | - |
1526 | int err = l1[x] - pix * 255 / 5; | - |
1527 | pv[chan][x] = pix; | - |
1528 | | - |
1529 | | - |
1530 | if (x > 0) { | - |
1531 | l1[x-1] += (err*7)>>4; | - |
1532 | l2[x-1] += err>>4; | - |
1533 | } | - |
1534 | l2[x]+=(err*5)>>4; | - |
1535 | if (x + 1 < src->width) | - |
1536 | l2[x+1]+=(err*3)>>4; | - |
1537 | } | - |
1538 | } | - |
1539 | } | - |
1540 | if (endian) { | - |
1541 | for (int x = 0; x < src->width; x++) { | - |
1542 | *b++ = (((pv[0][x])*(5 +1)+(pv[1][x]))*(5 +1)+(pv[2][x])); | - |
1543 | } | - |
1544 | } else { | - |
1545 | for (int x = 0; x < src->width; x++) { | - |
1546 | *b++ = (((pv[2][x])*(5 +1)+(pv[1][x]))*(5 +1)+(pv[0][x])); | - |
1547 | } | - |
1548 | } | - |
1549 | src_data += src->bytes_per_line; | - |
1550 | dest_data += dst->bytes_per_line; | - |
1551 | } | - |
1552 | } else { | - |
1553 | for (int y = 0; y < src->height; y++) { | - |
1554 | const QRgb *p = (const QRgb *)src_data; | - |
1555 | const QRgb *end = p + src->width; | - |
1556 | uchar *b = dest_data; | - |
1557 | | - |
1558 | int x = 0; | - |
1559 | while (p < end) { | - |
1560 | uint d = qt_bayer_matrix[y & 15][x & 15] << 8; | - |
1561 | | - |
1562 | | - |
1563 | *b++ = | - |
1564 | (((((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)))) | - |
1565 | | - |
1566 | | - |
1567 | | - |
1568 | ; | - |
1569 | | - |
1570 | | - |
1571 | p++; | - |
1572 | x++; | - |
1573 | } | - |
1574 | src_data += src->bytes_per_line; | - |
1575 | dest_data += dst->bytes_per_line; | - |
1576 | } | - |
1577 | } | - |
1578 | | - |
1579 | if (src->format != QImage::Format_RGB32 | - |
1580 | && src->format != QImage::Format_RGB16) { | - |
1581 | const int trans = 216; | - |
1582 | ((!(dst->colortable.size() > trans)) ? qt_assert("dst->colortable.size() > trans",__FILE__,16841690) : qt_noop()); | - |
1583 | dst->colortable[trans] = 0; | - |
1584 | QScopedPointer<QImageData> mask(QImageData::create(QSize(src->width, src->height), QImage::Format_Mono)); | - |
1585 | dither_to_Mono(mask.data(), src, flags, true); | - |
1586 | uchar *dst_data = dst->data; | - |
1587 | const uchar *mask_data = mask->data; | - |
1588 | for (int y = 0; y < src->height; y++) { | - |
1589 | for (int x = 0; x < src->width ; x++) { | - |
1590 | if (!(mask_data[x>>3] & (0x80 >> (x & 7)))) | - |
1591 | dst_data[x] = trans; | - |
1592 | } | - |
1593 | mask_data += mask->bytes_per_line; | - |
1594 | dst_data += dst->bytes_per_line; | - |
1595 | } | - |
1596 | dst->has_alpha_clut = true; | - |
1597 | } | - |
1598 | | - |
1599 | | - |
1600 | | - |
1601 | | - |
1602 | | - |
1603 | | - |
1604 | } | - |
1605 | } | - |
1606 | | - |
1607 | static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1608 | { | - |
1609 | QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32)); | - |
1610 | convert_ARGB_PM_to_ARGB(tmp.data(), src); | - |
1611 | convert_RGB_to_Indexed8(dst, tmp.data(), flags); | - |
1612 | } | - |
1613 | | - |
1614 | static void convert_ARGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) | - |
1615 | { | - |
1616 | convert_RGB_to_Indexed8(dst, src, flags); | - |
1617 | } | - |
1618 | | - |
1619 | static void convert_Indexed8_to_X32(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1620 | { | - |
1621 | ((!(src->format == QImage::Format_Indexed8)) ? qt_assert("src->format == QImage::Format_Indexed8",__FILE__,17231729) : qt_noop()); | - |
1622 | ((!(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied", | - |
1623 | | - |
1624 | __FILE__ | - |
1625 | , | - |
1626 | | - |
1627 | 17261732 | - |
1628 | ) : qt_noop()) | - |
1629 | | - |
1630 | ; | - |
1631 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,17271733) : qt_noop()); | - |
1632 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,17281734) : qt_noop()); | - |
1633 | | - |
1634 | QVector<QRgb> colorTable = src->has_alpha_clutTRUE | never evaluated | FALSE | never evaluated |
? fix_color_table(src->colortable, dest->format);) : src->colortable; | 0 |
1635 | if (colorTable.size() == 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1636 | colorTable.resize(256); | - |
1637 | for (int i=0; i<256TRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
1638 | colorTable[i] = qRgb(i, i, i); never executed: colorTable[i] = qRgb(i, i, i); | 0 |
1639 | } never executed: end of block | 0 |
1640 | if (colorTable.size() < 256TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
1641 | int tableSize = colorTable.size(); | - |
1642 | colorTable.resize(256); | - |
1643 | for (int i=tableSize; i<256TRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
1644 | colorTable[i] = 0; never executed: colorTable[i] = 0; | 0 |
1645 | } never executed: end of block | 0 |
1646 | | - |
1647 | int w = src->width; | - |
1648 | const uchar *src_data = src->data; | - |
1649 | uchar *dest_data = dest->data; | - |
1650 | int tableSizeconst QRgb *colorTablePtr = colorTable.size() - 1;constData(); | - |
1651 | for (int y = 0; y < src->heightTRUE | never evaluated | FALSE | never evaluated |
; y++) { | 0 |
1652 | uint *p = (reinterpret_cast<uint *)*>(dest_data;); | - |
1653 | const uchar *b = src_data; | - |
1654 | uint *end = p + w; | - |
1655 | | - |
1656 | while (p < endTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
1657 | * never executed: *p++ = colorTablePtr[*b++]; p++ = colorTable.at(qMin<int>(tableSize, *colorTablePtr[*b++));++];never executed: *p++ = colorTablePtr[*b++]; | 0 |
1658 | | - |
1659 | src_data += src->bytes_per_line; | - |
1660 | dest_data += dest->bytes_per_line; | - |
1661 | } never executed: end of block | 0 |
1662 | } never executed: end of block | 0 |
1663 | | - |
1664 | static void convert_Mono_to_X32(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1665 | { | - |
1666 | ((!(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB)) ? qt_assert("src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB",__FILE__,17561768) : qt_noop()); | - |
1667 | ((!(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied)) ? qt_assert("dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied", | - |
1668 | | - |
1669 | __FILE__ | - |
1670 | , | - |
1671 | | - |
1672 | 17591771 | - |
1673 | ) : qt_noop()) | - |
1674 | | - |
1675 | ; | - |
1676 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,17601772) : qt_noop()); | - |
1677 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,17611773) : qt_noop()); | - |
1678 | | - |
1679 | QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); | - |
1680 | | - |
1681 | | - |
1682 | if (colorTable.size() < 2) { | - |
1683 | if (colorTable.size() == 0) | - |
1684 | colorTable << 0xff000000; | - |
1685 | colorTable << 0xffffffff; | - |
1686 | } | - |
1687 | | - |
1688 | const uchar *src_data = src->data; | - |
1689 | uchar *dest_data = dest->data; | - |
1690 | if (src->format == QImage::Format_Mono) { | - |
1691 | for (int y = 0; y < dest->height; y++) { | - |
1692 | uint *p = (uint *)dest_data; | - |
1693 | for (int x = 0; x < dest->width; x++) | - |
1694 | *p++ = colorTable.at((src_data[x>>3] >> (7 - (x & 7))) & 1); | - |
1695 | | - |
1696 | src_data += src->bytes_per_line; | - |
1697 | dest_data += dest->bytes_per_line; | - |
1698 | } | - |
1699 | } else { | - |
1700 | for (int y = 0; y < dest->height; y++) { | - |
1701 | uint *p = (uint *)dest_data; | - |
1702 | for (int x = 0; x < dest->width; x++) | - |
1703 | *p++ = colorTable.at((src_data[x>>3] >> (x & 7)) & 1); | - |
1704 | | - |
1705 | src_data += src->bytes_per_line; | - |
1706 | dest_data += dest->bytes_per_line; | - |
1707 | } | - |
1708 | } | - |
1709 | } | - |
1710 | | - |
1711 | | - |
1712 | static void convert_Mono_to_Indexed8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1713 | { | - |
1714 | ((!(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB)) ? qt_assert("src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB",__FILE__,17981810) : qt_noop()); | - |
1715 | ((!(dest->format == QImage::Format_Indexed8)) ? qt_assert("dest->format == QImage::Format_Indexed8",__FILE__,17991811) : qt_noop()); | - |
1716 | ((!(src->width == dest->width)) ? qt_assert("src->width == dest->width",__FILE__,18001812) : qt_noop()); | - |
1717 | ((!(src->height == dest->height)) ? qt_assert("src->height == dest->height",__FILE__,18011813) : qt_noop()); | - |
1718 | | - |
1719 | QVector<QRgb> ctbl = src->colortable; | - |
1720 | if (ctbl.size() > 2) { | - |
1721 | ctbl.resize(2); | - |
1722 | } else if (ctbl.size() < 2) { | - |
1723 | if (ctbl.size() == 0) | - |
1724 | ctbl << 0xff000000; | - |
1725 | ctbl << 0xffffffff; | - |
1726 | } | - |
1727 | dest->colortable = ctbl; | - |
1728 | dest->has_alpha_clut = src->has_alpha_clut; | - |
1729 | | - |
1730 | | - |
1731 | const uchar *src_data = src->data; | - |
1732 | uchar *dest_data = dest->data; | - |
1733 | if (src->format == QImage::Format_Mono) { | - |
1734 | for (int y = 0; y < dest->height; y++) { | - |
1735 | uchar *p = dest_data; | - |
1736 | for (int x = 0; x < dest->width; x++) | - |
1737 | *p++ = (src_data[x>>3] >> (7 - (x & 7))) & 1; | - |
1738 | src_data += src->bytes_per_line; | - |
1739 | dest_data += dest->bytes_per_line; | - |
1740 | } | - |
1741 | } else { | - |
1742 | for (int y = 0; y < dest->height; y++) { | - |
1743 | uchar *p = dest_data; | - |
1744 | for (int x = 0; x < dest->width; x++) | - |
1745 | *p++ = (src_data[x>>3] >> (x & 7)) & 1; | - |
1746 | src_data += src->bytes_per_line; | - |
1747 | dest_data += dest->bytes_per_line; | - |
1748 | } | - |
1749 | } | - |
1750 | } | - |
1751 | | - |
1752 | static void convert_Indexed8_to_Alpha8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1753 | { | - |
1754 | ((!(src->format == QImage::Format_Indexed8)) ? qt_assert("src->format == QImage::Format_Indexed8",__FILE__,18381850) : qt_noop()); | - |
1755 | ((!(dest->format == QImage::Format_Alpha8)) ? qt_assert("dest->format == QImage::Format_Alpha8",__FILE__,18391851) : qt_noop()); | - |
1756 | | - |
1757 | uchar translate[256]; | - |
1758 | const QVector<QRgb> &colors = src->colortable; | - |
1759 | bool simpleCase = (colors.size() == 256); | - |
1760 | for (int i = 0; i < colors.size(); ++i) { | - |
1761 | uchar alpha = qAlpha(colors[i]); | - |
1762 | translate[i] = alpha; | - |
1763 | simpleCase = simpleCase && (alpha == i); | - |
1764 | } | - |
1765 | | - |
1766 | if (simpleCase) | - |
1767 | memcpy(dest->data, src->data, src->bytes_per_line * src->height); | - |
1768 | else { | - |
1769 | int size = src->bytes_per_line * src->height; | - |
1770 | for (int i = 0; i < size; ++i) { | - |
1771 | dest->data[i] = translate[src->data[i]]; | - |
1772 | } | - |
1773 | } | - |
1774 | } | - |
1775 | | - |
1776 | static void convert_Indexed8_to_Grayscale8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1777 | { | - |
1778 | ((!(src->format == QImage::Format_Indexed8)) ? qt_assert("src->format == QImage::Format_Indexed8",__FILE__,18621874) : qt_noop()); | - |
1779 | ((!(dest->format == QImage::Format_Grayscale8)) ? qt_assert("dest->format == QImage::Format_Grayscale8",__FILE__,18631875) : qt_noop()); | - |
1780 | | - |
1781 | uchar translate[256]; | - |
1782 | const QVector<QRgb> &colors = src->colortable; | - |
1783 | bool simpleCase = (colors.size() == 256); | - |
1784 | for (int i = 0; i < colors.size(); ++i) { | - |
1785 | uchar gray = qGray(colors[i]); | - |
1786 | translate[i] = gray; | - |
1787 | simpleCase = simpleCase && (gray == i); | - |
1788 | } | - |
1789 | | - |
1790 | if (simpleCase) | - |
1791 | memcpy(dest->data, src->data, src->bytes_per_line * src->height); | - |
1792 | else { | - |
1793 | int size = src->bytes_per_line * src->height; | - |
1794 | for (int i = 0; i < size; ++i) { | - |
1795 | dest->data[i] = translate[src->data[i]]; | - |
1796 | } | - |
1797 | } | - |
1798 | } | - |
1799 | | - |
1800 | static bool convert_Indexed8_to_Alpha8_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
1801 | { | - |
1802 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,18861898) : qt_noop()); | - |
1803 | | - |
1804 | | - |
1805 | const QVector<QRgb> &colors = data->colortable; | - |
1806 | if (colors.size() != 256) | - |
1807 | return false; | - |
1808 | for (int i = 0; i < colors.size(); ++i) { | - |
1809 | if (i != qAlpha(colors[i])) | - |
1810 | return false; | - |
1811 | } | - |
1812 | | - |
1813 | data->colortable.clear(); | - |
1814 | data->format = QImage::Format_Alpha8; | - |
1815 | | - |
1816 | return true; | - |
1817 | } | - |
1818 | | - |
1819 | static bool convert_Indexed8_to_Grayscale8_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
1820 | { | - |
1821 | ((!(data->format == QImage::Format_Indexed8)) ? qt_assert("data->format == QImage::Format_Indexed8",__FILE__,19051917) : qt_noop()); | - |
1822 | | - |
1823 | | - |
1824 | const QVector<QRgb> &colors = data->colortable; | - |
1825 | if (colors.size() != 256) | - |
1826 | return false; | - |
1827 | for (int i = 0; i < colors.size(); ++i) { | - |
1828 | if (i != qGray(colors[i])) | - |
1829 | return false; | - |
1830 | } | - |
1831 | | - |
1832 | data->colortable.clear(); | - |
1833 | data->format = QImage::Format_Grayscale8; | - |
1834 | | - |
1835 | return true; | - |
1836 | } | - |
1837 | | - |
1838 | static void convert_Alpha8_to_Indexed8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1839 | { | - |
1840 | ((!(src->format == QImage::Format_Alpha8)) ? qt_assert("src->format == QImage::Format_Alpha8",__FILE__,19241936) : qt_noop()); | - |
1841 | ((!(dest->format == QImage::Format_Indexed8)) ? qt_assert("dest->format == QImage::Format_Indexed8",__FILE__,19251937) : qt_noop()); | - |
1842 | | - |
1843 | memcpy(dest->data, src->data, src->bytes_per_line * src->height); | - |
1844 | | - |
1845 | QVector<QRgb> colors(256); | - |
1846 | for (int i=0; i<256; ++i) | - |
1847 | colors[i] = qRgba(0, 0, 0, i); | - |
1848 | | - |
1849 | dest->colortable = colors; | - |
1850 | } | - |
1851 | | - |
1852 | static void convert_Grayscale8_to_Indexed8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) | - |
1853 | { | - |
1854 | ((!(src->format == QImage::Format_Grayscale8)) ? qt_assert("src->format == QImage::Format_Grayscale8",__FILE__,19381950) : qt_noop()); | - |
1855 | ((!(dest->format == QImage::Format_Indexed8)) ? qt_assert("dest->format == QImage::Format_Indexed8",__FILE__,19391951) : qt_noop()); | - |
1856 | | - |
1857 | memcpy(dest->data, src->data, src->bytes_per_line * src->height); | - |
1858 | | - |
1859 | QVector<QRgb> colors(256); | - |
1860 | for (int i=0; i<256; ++i) | - |
1861 | colors[i] = qRgb(i, i, i); | - |
1862 | | - |
1863 | dest->colortable = colors; | - |
1864 | } | - |
1865 | | - |
1866 | static bool convert_Alpha8_to_Indexed8_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
1867 | { | - |
1868 | ((!(data->format == QImage::Format_Alpha8)) ? qt_assert("data->format == QImage::Format_Alpha8",__FILE__,19521964) : qt_noop()); | - |
1869 | | - |
1870 | QVector<QRgb> colors(256); | - |
1871 | for (int i=0; i<256; ++i) | - |
1872 | colors[i] = qRgba(0, 0, 0, i); | - |
1873 | | - |
1874 | data->colortable = colors; | - |
1875 | data->format = QImage::Format_Indexed8; | - |
1876 | | - |
1877 | return true; | - |
1878 | } | - |
1879 | | - |
1880 | static bool convert_Grayscale8_to_Indexed8_inplace(QImageData *data, Qt::ImageConversionFlags) | - |
1881 | { | - |
1882 | ((!(data->format == QImage::Format_Grayscale8)) ? qt_assert("data->format == QImage::Format_Grayscale8",__FILE__,19661978) : qt_noop()); | - |
1883 | | - |
1884 | QVector<QRgb> colors(256); | - |
1885 | for (int i=0; i<256; ++i) | - |
1886 | colors[i] = qRgb(i, i, i); | - |
1887 | | - |
1888 | data->colortable = colors; | - |
1889 | data->format = QImage::Format_Indexed8; | - |
1890 | | - |
1891 | return true; | - |
1892 | } | - |
1893 | | - |
1894 | | - |
1895 | | - |
1896 | Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormats] = | - |
1897 | { | - |
1898 | { | - |
1899 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
1900 | }, | - |
1901 | { | - |
1902 | 0, | - |
1903 | 0, | - |
1904 | swap_bit_order, | - |
1905 | convert_Mono_to_Indexed8, | - |
1906 | convert_Mono_to_X32, | - |
1907 | convert_Mono_to_X32, | - |
1908 | convert_Mono_to_X32, | - |
1909 | 0, | - |
1910 | 0, | - |
1911 | 0, | - |
1912 | 0, | - |
1913 | 0, | - |
1914 | 0, | - |
1915 | 0, | - |
1916 | 0, | - |
1917 | 0, | - |
1918 | 0, | - |
1919 | 0, | - |
1920 | 0, 0, 0, 0, 0, 0, 0 | - |
1921 | }, | - |
1922 | | - |
1923 | { | - |
1924 | 0, | - |
1925 | swap_bit_order, | - |
1926 | 0, | - |
1927 | convert_Mono_to_Indexed8, | - |
1928 | convert_Mono_to_X32, | - |
1929 | convert_Mono_to_X32, | - |
1930 | convert_Mono_to_X32, | - |
1931 | 0, | - |
1932 | 0, | - |
1933 | 0, | - |
1934 | 0, | - |
1935 | 0, | - |
1936 | 0, | - |
1937 | 0, | - |
1938 | 0, | - |
1939 | 0, | - |
1940 | 0, | - |
1941 | 0, | - |
1942 | 0, 0, 0, 0, 0, 0, 0 | - |
1943 | }, | - |
1944 | | - |
1945 | { | - |
1946 | 0, | - |
1947 | convert_X_to_Mono, | - |
1948 | convert_X_to_Mono, | - |
1949 | 0, | - |
1950 | convert_Indexed8_to_X32, | - |
1951 | convert_Indexed8_to_X32, | - |
1952 | convert_Indexed8_to_X32, | - |
1953 | 0, | - |
1954 | 0, | - |
1955 | 0, | - |
1956 | 0, | - |
1957 | 0, | - |
1958 | 0, | - |
1959 | 0, | - |
1960 | 0, | - |
1961 | 0, | - |
1962 | 0, | - |
1963 | 0, | - |
1964 | 0, 0, 0, 0, 0, | - |
1965 | convert_Indexed8_to_Alpha8, | - |
1966 | convert_Indexed8_to_Grayscale8, | - |
1967 | }, | - |
1968 | | - |
1969 | { | - |
1970 | 0, | - |
1971 | convert_X_to_Mono, | - |
1972 | convert_X_to_Mono, | - |
1973 | convert_RGB_to_Indexed8, | - |
1974 | 0, | - |
1975 | mask_alpha_converter, | - |
1976 | mask_alpha_converter, | - |
1977 | 0, | - |
1978 | 0, | - |
1979 | 0, | - |
1980 | 0, | - |
1981 | 0, | - |
1982 | 0, | - |
1983 | 0, | - |
1984 | 0, | - |
1985 | 0, | - |
1986 | 0, | - |
1987 | 0, | - |
1988 | 0, | - |
1989 | convert_RGB_to_RGB30<PixelOrderBGR>, | - |
1990 | 0, | - |
1991 | convert_RGB_to_RGB30<PixelOrderRGB>, | - |
1992 | 0, | - |
1993 | 0, 0 | - |
1994 | }, | - |
1995 | | - |
1996 | { | - |
1997 | 0, | - |
1998 | convert_X_to_Mono, | - |
1999 | convert_X_to_Mono, | - |
2000 | convert_ARGB_to_Indexed8, | - |
2001 | mask_alpha_converter, | - |
2002 | 0, | - |
2003 | convert_ARGB_to_ARGB_PM, | - |
2004 | 0, | - |
2005 | 0, | - |
2006 | 0, | - |
2007 | 0, | - |
2008 | 0, | - |
2009 | 0, | - |
2010 | 0, | - |
2011 | 0, | - |
2012 | 0, | - |
2013 | convert_ARGB_to_RGBx, | - |
2014 | convert_ARGB_to_RGBA, | - |
2015 | 0, | - |
2016 | convert_RGB_to_RGB30<PixelOrderBGR>, | - |
2017 | 0, | - |
2018 | convert_RGB_to_RGB30<PixelOrderRGB>, | - |
2019 | 0, | - |
2020 | 0, 0 | - |
2021 | }, | - |
2022 | | - |
2023 | { | - |
2024 | 0, | - |
2025 | convert_ARGB_PM_to_Mono, | - |
2026 | convert_ARGB_PM_to_Mono, | - |
2027 | convert_ARGB_PM_to_Indexed8, | - |
2028 | 0, | - |
2029 | 0, | - |
2030 | 0, | - |
2031 | 0, | - |
2032 | 0, | - |
2033 | 0, | - |
2034 | 0, | - |
2035 | 0, | - |
2036 | 0, | - |
2037 | 0, | - |
2038 | 0, | - |
2039 | 0, | - |
2040 | 0, | - |
2041 | 0, | - |
2042 | convert_ARGB_to_RGBA, | - |
2043 | 0, | - |
2044 | 0, | - |
2045 | 0, | - |
2046 | 0, | - |
2047 | 0, 0 | - |
2048 | }, | - |
2049 | | - |
2050 | { | - |
2051 | 0, | - |
2052 | 0, | - |
2053 | 0, | - |
2054 | 0, | - |
2055 | 0, | - |
2056 | 0, | - |
2057 | 0, | - |
2058 | 0, | - |
2059 | 0, | - |
2060 | 0, | - |
2061 | 0, | - |
2062 | 0, | - |
2063 | 0, | - |
2064 | 0, | - |
2065 | 0, | - |
2066 | 0, | - |
2067 | 0, | - |
2068 | 0, | - |
2069 | 0, 0, 0, 0, 0, 0, 0 | - |
2070 | }, | - |
2071 | | - |
2072 | { | - |
2073 | 0, | - |
2074 | 0, | - |
2075 | 0, | - |
2076 | 0, | - |
2077 | 0, | - |
2078 | 0, | - |
2079 | 0, | - |
2080 | 0, | - |
2081 | 0, | - |
2082 | 0, | - |
2083 | 0, | - |
2084 | 0, | - |
2085 | 0, | - |
2086 | 0, | - |
2087 | 0, | - |
2088 | 0, | - |
2089 | 0, | - |
2090 | 0, | - |
2091 | 0, 0, 0, 0, 0, 0, 0 | - |
2092 | }, | - |
2093 | | - |
2094 | { | - |
2095 | 0, | - |
2096 | 0, | - |
2097 | 0, | - |
2098 | 0, | - |
2099 | 0, | - |
2100 | 0, | - |
2101 | 0, | - |
2102 | 0, | - |
2103 | 0, | - |
2104 | 0, | - |
2105 | 0, | - |
2106 | 0, | - |
2107 | 0, | - |
2108 | 0, | - |
2109 | 0, | - |
2110 | 0, | - |
2111 | 0, | - |
2112 | 0, | - |
2113 | 0, 0, 0, 0, 0, 0, 0 | - |
2114 | }, | - |
2115 | | - |
2116 | { | - |
2117 | 0, | - |
2118 | 0, | - |
2119 | 0, | - |
2120 | 0, | - |
2121 | 0, | - |
2122 | 0, | - |
2123 | 0, | - |
2124 | 0, | - |
2125 | 0, | - |
2126 | 0, | - |
2127 | 0, | - |
2128 | 0, | - |
2129 | 0, | - |
2130 | 0, | - |
2131 | 0, | - |
2132 | 0, | - |
2133 | 0, | - |
2134 | 0, | - |
2135 | 0, 0, 0, 0, 0, 0, 0 | - |
2136 | }, | - |
2137 | | - |
2138 | { | - |
2139 | 0, | - |
2140 | 0, | - |
2141 | 0, | - |
2142 | 0, | - |
2143 | 0, | - |
2144 | 0, | - |
2145 | 0, | - |
2146 | 0, | - |
2147 | 0, | - |
2148 | 0, | - |
2149 | 0, | - |
2150 | 0, | - |
2151 | 0, | - |
2152 | 0, | - |
2153 | 0, | - |
2154 | 0, | - |
2155 | 0, | - |
2156 | 0, | - |
2157 | 0, 0, 0, 0, 0, 0, 0 | - |
2158 | }, | - |
2159 | | - |
2160 | { | - |
2161 | 0, | - |
2162 | 0, | - |
2163 | 0, | - |
2164 | 0, | - |
2165 | 0, | - |
2166 | 0, | - |
2167 | 0, | - |
2168 | 0, | - |
2169 | 0, | - |
2170 | 0, | - |
2171 | 0, | - |
2172 | 0, | - |
2173 | 0, | - |
2174 | 0, | - |
2175 | 0, | - |
2176 | 0, | - |
2177 | 0, | - |
2178 | 0, | - |
2179 | 0, 0, 0, 0, 0, 0, 0 | - |
2180 | }, | - |
2181 | | - |
2182 | { | - |
2183 | 0, | - |
2184 | 0, | - |
2185 | 0, | - |
2186 | 0, | - |
2187 | convert_RGB888_to_RGB<false>, | - |
2188 | convert_RGB888_to_RGB<false>, | - |
2189 | convert_RGB888_to_RGB<false>, | - |
2190 | 0, | - |
2191 | 0, | - |
2192 | 0, | - |
2193 | 0, | - |
2194 | 0, | - |
2195 | 0, | - |
2196 | 0, | - |
2197 | 0, | - |
2198 | 0, | - |
2199 | convert_RGB888_to_RGB<true>, | - |
2200 | convert_RGB888_to_RGB<true>, | - |
2201 | convert_RGB888_to_RGB<true>, | - |
2202 | 0, 0, 0, 0, 0, 0 | - |
2203 | }, | - |
2204 | | - |
2205 | { | - |
2206 | 0, | - |
2207 | 0, | - |
2208 | 0, | - |
2209 | 0, | - |
2210 | 0, | - |
2211 | 0, | - |
2212 | 0, | - |
2213 | 0, | - |
2214 | 0, | - |
2215 | 0, | - |
2216 | 0, | - |
2217 | 0, | - |
2218 | 0, | - |
2219 | 0, | - |
2220 | 0, | - |
2221 | 0, | - |
2222 | 0, | - |
2223 | 0, | - |
2224 | 0, 0, 0, 0, 0, 0, 0 | - |
2225 | }, | - |
2226 | | - |
2227 | { | - |
2228 | 0, | - |
2229 | 0, | - |
2230 | 0, | - |
2231 | 0, | - |
2232 | 0, | - |
2233 | 0, | - |
2234 | 0, | - |
2235 | 0, | - |
2236 | 0, | - |
2237 | 0, | - |
2238 | 0, | - |
2239 | 0, | - |
2240 | 0, | - |
2241 | 0, | - |
2242 | 0, | - |
2243 | 0, | - |
2244 | 0, | - |
2245 | 0, 0, 0, 0, 0, 0, 0 | - |
2246 | }, | - |
2247 | { | - |
2248 | 0, | - |
2249 | 0, | - |
2250 | 0, | - |
2251 | 0, | - |
2252 | convert_RGBA_to_RGB, | - |
2253 | convert_RGBA_to_ARGB, | - |
2254 | convert_RGBA_to_ARGB, | - |
2255 | 0, | - |
2256 | 0, | - |
2257 | 0, | - |
2258 | 0, | - |
2259 | 0, | - |
2260 | 0, | - |
2261 | 0, | - |
2262 | 0, | - |
2263 | 0, | - |
2264 | 0, | - |
2265 | mask_alpha_converter_RGBx, | - |
2266 | mask_alpha_converter_RGBx, | - |
2267 | 0, 0, 0, 0, 0, 0 | - |
2268 | }, | - |
2269 | { | - |
2270 | 0, | - |
2271 | 0, | - |
2272 | 0, | - |
2273 | 0, | - |
2274 | convert_RGBA_to_RGB, | - |
2275 | convert_RGBA_to_ARGB, | - |
2276 | 0, | - |
2277 | 0, | - |
2278 | 0, | - |
2279 | 0, | - |
2280 | 0, | - |
2281 | 0, | - |
2282 | 0, | - |
2283 | 0, | - |
2284 | 0, | - |
2285 | 0, | - |
2286 | mask_alpha_converter_RGBx, | - |
2287 | | - |
2288 | 0, | - |
2289 | convert_ARGB_to_ARGB_PM, | - |
2290 | | - |
2291 | | - |
2292 | | - |
2293 | | - |
2294 | 0, 0, 0, 0, 0, 0 | - |
2295 | }, | - |
2296 | | - |
2297 | { | - |
2298 | 0, | - |
2299 | 0, | - |
2300 | 0, | - |
2301 | 0, | - |
2302 | 0, | - |
2303 | 0, | - |
2304 | convert_RGBA_to_ARGB, | - |
2305 | 0, | - |
2306 | 0, | - |
2307 | 0, | - |
2308 | 0, | - |
2309 | 0, | - |
2310 | 0, | - |
2311 | 0, | - |
2312 | 0, | - |
2313 | 0, | - |
2314 | 0, | - |
2315 | 0, | - |
2316 | 0, 0, 0, 0, 0, 0 | - |
2317 | }, | - |
2318 | | - |
2319 | { | - |
2320 | 0, | - |
2321 | 0, | - |
2322 | 0, | - |
2323 | 0, | - |
2324 | 0, | - |
2325 | 0, | - |
2326 | 0, | - |
2327 | 0, | - |
2328 | 0, | - |
2329 | 0, | - |
2330 | 0, | - |
2331 | 0, | - |
2332 | 0, | - |
2333 | 0, | - |
2334 | 0, | - |
2335 | 0, | - |
2336 | 0, | - |
2337 | 0, | - |
2338 | 0, | - |
2339 | 0, | - |
2340 | convert_passthrough, | - |
2341 | convert_BGR30_to_RGB30, | - |
2342 | convert_BGR30_to_RGB30, | - |
2343 | 0, 0 | - |
2344 | }, | - |
2345 | { | - |
2346 | 0, | - |
2347 | 0, | - |
2348 | 0, | - |
2349 | 0, | - |
2350 | 0, | - |
2351 | convert_A2RGB30_PM_to_ARGB<PixelOrderBGR>, | - |
2352 | 0, | - |
2353 | 0, | - |
2354 | 0, | - |
2355 | 0, | - |
2356 | 0, | - |
2357 | 0, | - |
2358 | 0, | - |
2359 | 0, | - |
2360 | 0, | - |
2361 | 0, | - |
2362 | 0, | - |
2363 | 0, | - |
2364 | 0, | - |
2365 | convert_A2RGB30_PM_to_RGB30<false>, | - |
2366 | 0, | - |
2367 | convert_A2RGB30_PM_to_RGB30<true>, | - |
2368 | convert_BGR30_to_RGB30, | - |
2369 | 0, 0 | - |
2370 | }, | - |
2371 | { | - |
2372 | 0, | - |
2373 | 0, | - |
2374 | 0, | - |
2375 | 0, | - |
2376 | 0, | - |
2377 | 0, | - |
2378 | 0, | - |
2379 | 0, | - |
2380 | 0, | - |
2381 | 0, | - |
2382 | 0, | - |
2383 | 0, | - |
2384 | 0, | - |
2385 | 0, | - |
2386 | 0, | - |
2387 | 0, | - |
2388 | 0, | - |
2389 | 0, | - |
2390 | 0, | - |
2391 | convert_BGR30_to_RGB30, | - |
2392 | convert_BGR30_to_RGB30, | - |
2393 | 0, | - |
2394 | convert_passthrough, | - |
2395 | 0, 0 | - |
2396 | }, | - |
2397 | { | - |
2398 | 0, | - |
2399 | 0, | - |
2400 | 0, | - |
2401 | 0, | - |
2402 | 0, | - |
2403 | convert_A2RGB30_PM_to_ARGB<PixelOrderRGB>, | - |
2404 | 0, | - |
2405 | 0, | - |
2406 | 0, | - |
2407 | 0, | - |
2408 | 0, | - |
2409 | 0, | - |
2410 | 0, | - |
2411 | 0, | - |
2412 | 0, | - |
2413 | 0, | - |
2414 | 0, | - |
2415 | 0, | - |
2416 | 0, | - |
2417 | convert_A2RGB30_PM_to_RGB30<true>, | - |
2418 | convert_BGR30_to_RGB30, | - |
2419 | convert_A2RGB30_PM_to_RGB30<false>, | - |
2420 | 0, | - |
2421 | 0, 0 | - |
2422 | }, | - |
2423 | { | - |
2424 | 0, | - |
2425 | 0, | - |
2426 | 0, | - |
2427 | convert_Alpha8_to_Indexed8, | - |
2428 | 0, | - |
2429 | 0, | - |
2430 | 0, | - |
2431 | 0, | - |
2432 | 0, | - |
2433 | 0, | - |
2434 | 0, | - |
2435 | 0, | - |
2436 | 0, | - |
2437 | 0, | - |
2438 | 0, | - |
2439 | 0, | - |
2440 | 0, | - |
2441 | 0, 0, 0, 0, 0, 0, 0 | - |
2442 | }, | - |
2443 | { | - |
2444 | 0, | - |
2445 | 0, | - |
2446 | 0, | - |
2447 | convert_Grayscale8_to_Indexed8, | - |
2448 | 0, | - |
2449 | 0, | - |
2450 | 0, | - |
2451 | 0, | - |
2452 | 0, | - |
2453 | 0, | - |
2454 | 0, | - |
2455 | 0, | - |
2456 | 0, | - |
2457 | 0, | - |
2458 | 0, | - |
2459 | 0, | - |
2460 | 0, | - |
2461 | 0, 0, 0, 0, 0, 0, 0 | - |
2462 | } | - |
2463 | }; | - |
2464 | | - |
2465 | InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QImage::NImageFormats] = | - |
2466 | { | - |
2467 | { | - |
2468 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2469 | }, | - |
2470 | { | - |
2471 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2472 | }, | - |
2473 | { | - |
2474 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2475 | }, | - |
2476 | { | - |
2477 | 0, | - |
2478 | 0, | - |
2479 | 0, | - |
2480 | 0, | - |
2481 | convert_indexed8_to_RGB_inplace, | - |
2482 | convert_indexed8_to_ARGB_inplace, | - |
2483 | convert_indexed8_to_ARGB_PM_inplace, | - |
2484 | convert_indexed8_to_RGB16_inplace, | - |
2485 | 0, | - |
2486 | 0, | - |
2487 | 0, | - |
2488 | 0, | - |
2489 | 0, | - |
2490 | 0, | - |
2491 | 0, | - |
2492 | 0, | - |
2493 | 0, | - |
2494 | 0, | - |
2495 | 0, 0, 0, 0, 0, | - |
2496 | convert_Indexed8_to_Alpha8_inplace, | - |
2497 | convert_Indexed8_to_Grayscale8_inplace, | - |
2498 | }, | - |
2499 | { | - |
2500 | 0, | - |
2501 | 0, | - |
2502 | 0, | - |
2503 | 0, | - |
2504 | 0, | - |
2505 | mask_alpha_converter_inplace<QImage::Format_ARGB32>, | - |
2506 | mask_alpha_converter_inplace<QImage::Format_ARGB32_Premultiplied>, | - |
2507 | convert_RGB_to_RGB16_inplace, | - |
2508 | 0, | - |
2509 | 0, | - |
2510 | 0, | - |
2511 | 0, | - |
2512 | 0, | - |
2513 | 0, | - |
2514 | 0, | - |
2515 | 0, | - |
2516 | 0, | - |
2517 | 0, | - |
2518 | 0, | - |
2519 | convert_RGB_to_RGB30_inplace<PixelOrderBGR>, | - |
2520 | 0, | - |
2521 | convert_RGB_to_RGB30_inplace<PixelOrderRGB>, | - |
2522 | 0, | - |
2523 | 0, 0 | - |
2524 | }, | - |
2525 | { | - |
2526 | 0, | - |
2527 | 0, | - |
2528 | 0, | - |
2529 | 0, | - |
2530 | mask_alpha_converter_inplace<QImage::Format_RGB32>, | - |
2531 | 0, | - |
2532 | | - |
2533 | convert_ARGB_to_ARGB_PM_inplace_sse2, | - |
2534 | | - |
2535 | | - |
2536 | | - |
2537 | 0, | - |
2538 | 0, | - |
2539 | 0, | - |
2540 | 0, | - |
2541 | 0, | - |
2542 | 0, | - |
2543 | 0, | - |
2544 | 0, | - |
2545 | 0, | - |
2546 | convert_ARGB_to_RGBA_inplace<QImage::Format_RGBX8888>, | - |
2547 | convert_ARGB_to_RGBA_inplace<QImage::Format_RGBA8888>, | - |
2548 | 0, | - |
2549 | convert_RGB_to_RGB30_inplace<PixelOrderBGR>, | - |
2550 | 0, | - |
2551 | convert_RGB_to_RGB30_inplace<PixelOrderRGB>, | - |
2552 | 0, | - |
2553 | 0, 0 | - |
2554 | }, | - |
2555 | { | - |
2556 | 0, | - |
2557 | 0, | - |
2558 | 0, | - |
2559 | 0, | - |
2560 | 0, | - |
2561 | 0, | - |
2562 | 0, | - |
2563 | 0, | - |
2564 | 0, | - |
2565 | 0, | - |
2566 | 0, | - |
2567 | 0, | - |
2568 | 0, | - |
2569 | 0, | - |
2570 | 0, | - |
2571 | 0, | - |
2572 | 0, | - |
2573 | 0, | - |
2574 | convert_ARGB_to_RGBA_inplace<QImage::Format_RGBA8888_Premultiplied>, | - |
2575 | 0, | - |
2576 | 0, | - |
2577 | 0, | - |
2578 | 0, | - |
2579 | 0, 0 | - |
2580 | }, | - |
2581 | { | - |
2582 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2583 | }, | - |
2584 | { | - |
2585 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2586 | }, | - |
2587 | { | - |
2588 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2589 | }, | - |
2590 | { | - |
2591 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2592 | }, | - |
2593 | { | - |
2594 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2595 | }, | - |
2596 | { | - |
2597 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2598 | }, | - |
2599 | { | - |
2600 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2601 | }, | - |
2602 | { | - |
2603 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2604 | }, | - |
2605 | { | - |
2606 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
2607 | }, | - |
2608 | { | - |
2609 | 0, | - |
2610 | 0, | - |
2611 | 0, | - |
2612 | 0, | - |
2613 | convert_RGBA_to_ARGB_inplace<QImage::Format_RGB32>, | - |
2614 | convert_RGBA_to_ARGB_inplace<QImage::Format_ARGB32>, | - |
2615 | convert_RGBA_to_ARGB_inplace<QImage::Format_ARGB32_Premultiplied>, | - |
2616 | 0, | - |
2617 | 0, | - |
2618 | 0, | - |
2619 | 0, | - |
2620 | 0, | - |
2621 | 0, | - |
2622 | 0, | - |
2623 | 0, | - |
2624 | 0, | - |
2625 | 0, | - |
2626 | convert_passthrough_inplace<QImage::Format_RGBA8888>, | - |
2627 | convert_passthrough_inplace<QImage::Format_RGBA8888_Premultiplied>, | - |
2628 | 0, 0, 0, 0, 0, 0 | - |
2629 | }, | - |
2630 | { | - |
2631 | 0, | - |
2632 | 0, | - |
2633 | 0, | - |
2634 | 0, | - |
2635 | convert_RGBA_to_ARGB_inplace<QImage::Format_RGB32>, | - |
2636 | convert_RGBA_to_ARGB_inplace<QImage::Format_ARGB32>, | - |
2637 | 0, | - |
2638 | 0, | - |
2639 | 0, | - |
2640 | 0, | - |
2641 | 0, | - |
2642 | 0, | - |
2643 | 0, | - |
2644 | 0, | - |
2645 | 0, | - |
2646 | 0, | - |
2647 | mask_alpha_converter_rgbx_inplace, | - |
2648 | 0, | - |
2649 | | - |
2650 | convert_ARGB_to_ARGB_PM_inplace_sse2, | - |
2651 | | - |
2652 | | - |
2653 | | - |
2654 | | - |
2655 | | - |
2656 | 0, 0, 0, 0, 0, 0 | - |
2657 | }, | - |
2658 | { | - |
2659 | 0, | - |
2660 | 0, | - |
2661 | 0, | - |
2662 | 0, | - |
2663 | 0, | - |
2664 | 0, | - |
2665 | convert_RGBA_to_ARGB_inplace<QImage::Format_ARGB32_Premultiplied>, | - |
2666 | 0, | - |
2667 | 0, | - |
2668 | 0, | - |
2669 | 0, | - |
2670 | 0, | - |
2671 | 0, | - |
2672 | 0, | - |
2673 | 0, | - |
2674 | 0, | - |
2675 | 0, | - |
2676 | 0, | - |
2677 | 0, | - |
2678 | 0, 0, 0, 0, 0, 0 | - |
2679 | }, | - |
2680 | { | - |
2681 | 0, | - |
2682 | 0, | - |
2683 | 0, | - |
2684 | 0, | - |
2685 | 0, | - |
2686 | 0, | - |
2687 | 0, | - |
2688 | 0, | - |
2689 | 0, | - |
2690 | 0, | - |
2691 | 0, | - |
2692 | 0, | - |
2693 | 0, | - |
2694 | 0, | - |
2695 | 0, | - |
2696 | 0, | - |
2697 | 0, | - |
2698 | 0, | - |
2699 | 0, | - |
2700 | 0, | - |
2701 | convert_passthrough_inplace<QImage::Format_A2BGR30_Premultiplied>, | - |
2702 | convert_BGR30_to_RGB30_inplace, | - |
2703 | convert_BGR30_to_A2RGB30_inplace, | - |
2704 | 0, 0 | - |
2705 | }, | - |
2706 | { | - |
2707 | 0, | - |
2708 | 0, | - |
2709 | 0, | - |
2710 | 0, | - |
2711 | 0, | - |
2712 | convert_A2RGB30_PM_to_ARGB_inplace<PixelOrderBGR>, | - |
2713 | 0, | - |
2714 | 0, | - |
2715 | 0, | - |
2716 | 0, | - |
2717 | 0, | - |
2718 | 0, | - |
2719 | 0, | - |
2720 | 0, | - |
2721 | 0, | - |
2722 | 0, | - |
2723 | 0, | - |
2724 | 0, | - |
2725 | 0, | - |
2726 | convert_A2RGB30_PM_to_RGB30_inplace<false>, | - |
2727 | 0, | - |
2728 | convert_A2RGB30_PM_to_RGB30_inplace<true>, | - |
2729 | convert_BGR30_to_RGB30_inplace, | - |
2730 | 0, 0 | - |
2731 | }, | - |
2732 | { | - |
2733 | 0, | - |
2734 | 0, | - |
2735 | 0, | - |
2736 | 0, | - |
2737 | 0, | - |
2738 | 0, | - |
2739 | 0, | - |
2740 | 0, | - |
2741 | 0, | - |
2742 | 0, | - |
2743 | 0, | - |
2744 | 0, | - |
2745 | 0, | - |
2746 | 0, | - |
2747 | 0, | - |
2748 | 0, | - |
2749 | 0, | - |
2750 | 0, | - |
2751 | 0, | - |
2752 | convert_BGR30_to_RGB30_inplace, | - |
2753 | convert_BGR30_to_A2RGB30_inplace, | - |
2754 | 0, | - |
2755 | convert_passthrough_inplace<QImage::Format_A2RGB30_Premultiplied>, | - |
2756 | 0, 0 | - |
2757 | }, | - |
2758 | { | - |
2759 | 0, | - |
2760 | 0, | - |
2761 | 0, | - |
2762 | 0, | - |
2763 | 0, | - |
2764 | convert_A2RGB30_PM_to_ARGB_inplace<PixelOrderRGB>, | - |
2765 | 0, | - |
2766 | 0, | - |
2767 | 0, | - |
2768 | 0, | - |
2769 | 0, | - |
2770 | 0, | - |
2771 | 0, | - |
2772 | 0, | - |
2773 | 0, | - |
2774 | 0, | - |
2775 | 0, | - |
2776 | 0, | - |
2777 | 0, | - |
2778 | convert_A2RGB30_PM_to_RGB30_inplace<true>, | - |
2779 | convert_BGR30_to_RGB30_inplace, | - |
2780 | convert_A2RGB30_PM_to_RGB30_inplace<false>, | - |
2781 | 0, | - |
2782 | 0, 0 | - |
2783 | }, | - |
2784 | { | - |
2785 | 0, | - |
2786 | 0, | - |
2787 | 0, | - |
2788 | convert_Alpha8_to_Indexed8_inplace, | - |
2789 | 0, | - |
2790 | 0, | - |
2791 | 0, | - |
2792 | 0, | - |
2793 | 0, | - |
2794 | 0, | - |
2795 | 0, | - |
2796 | 0, | - |
2797 | 0, | - |
2798 | 0, | - |
2799 | 0, | - |
2800 | 0, | - |
2801 | 0, | - |
2802 | 0, | - |
2803 | 0, | - |
2804 | 0, | - |
2805 | 0, | - |
2806 | 0, | - |
2807 | 0, | - |
2808 | 0, 0 | - |
2809 | }, | - |
2810 | { | - |
2811 | 0, | - |
2812 | 0, | - |
2813 | 0, | - |
2814 | convert_Grayscale8_to_Indexed8_inplace, | - |
2815 | 0, | - |
2816 | 0, | - |
2817 | 0, | - |
2818 | 0, | - |
2819 | 0, | - |
2820 | 0, | - |
2821 | 0, | - |
2822 | 0, | - |
2823 | 0, | - |
2824 | 0, | - |
2825 | 0, | - |
2826 | 0, | - |
2827 | 0, | - |
2828 | 0, | - |
2829 | 0, | - |
2830 | 0, | - |
2831 | 0, | - |
2832 | 0, | - |
2833 | 0, | - |
2834 | 0, 0 | - |
2835 | } | - |
2836 | }; | - |
2837 | | - |
2838 | static void qInitImageConversions() | - |
2839 | { | - |
2840 | | - |
2841 | if (((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSSE3)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSSE3)))) { | - |
2842 | extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
2843 | qimage_converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3; | - |
2844 | qimage_converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3; | - |
2845 | qimage_converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_ssse3; | - |
2846 | } | - |
2847 | | - |
2848 | | - |
2849 | | - |
2850 | if (((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_1)))) { | - |
2851 | extern void convert_ARGB_to_ARGB_PM_sse4(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
2852 | qimage_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_sse4; | - |
2853 | qimage_converter_map[QImage::Format_RGBA8888][QImage::Format_RGBA8888_Premultiplied] = convert_ARGB_to_ARGB_PM_sse4; | - |
2854 | } | - |
2855 | | - |
2856 | | - |
2857 | | - |
2858 | if (((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureAVX2)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureAVX2)))) { | - |
2859 | extern void convert_ARGB_to_ARGB_PM_avx2(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); | - |
2860 | qimage_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_avx2; | - |
2861 | qimage_converter_map[QImage::Format_RGBA8888][QImage::Format_RGBA8888_Premultiplied] = convert_ARGB_to_ARGB_PM_avx2; | - |
2862 | } | - |
2863 | } | - |
2864 | | - |
2865 | namespace { static const struct qInitImageConversions_ctor_class_ { inline qInitImageConversions_ctor_class_() { qInitImageConversions(); } } qInitImageConversions_ctor_instance_; }; | - |
2866 | | - |
2867 | | - |
| | |