19#include <qpa/qplatformintegration.h>
20#include <private/qguiapplication_p.h>
24#include <qpa/qplatformpixmap.h>
26#include <private/qcolorspace_p.h>
27#include <private/qcolortransform_p.h>
28#include <private/qmemrotate_p.h>
29#include <private/qimagescale_p.h>
30#include <private/qpixellayout_p.h>
31#include <private/qsimd_p.h>
35#include <private/qpaintengine_raster_p.h>
37#include <private/qimage_p.h>
38#include <private/qfont_p.h>
40#if QT_CONFIG(qtgui_threadpool)
41#include <private/qlatch_p.h>
42#include <qthreadpool.h>
43#include <private/qthreadpool_p.h>
46#include <qtgui_tracepoints_p.h>
53using namespace Qt::StringLiterals;
58QT_WARNING_DISABLE_MSVC(4723)
60#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0
>= 50190001
)
61#pragma message disable narrowptr
65#define QIMAGE_SANITYCHECK_MEMORY(image)
66 if ((image).isNull()) {
67 qWarning("QImage: out of memory, returning null image");
72 "#include <qimagereader.h>"
76"ENUM { } QImage::Format;" \
77"FLAGS { } Qt::ImageConversionFlags;"
80Q_TRACE_PARAM_REPLACE(Qt::AspectRatioMode,
int);
81Q_TRACE_PARAM_REPLACE(Qt::TransformationMode,
int);
83static QImage
rotated90(
const QImage &src);
89 Q_CONSTINIT
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(0);
90 return 1 + serial.fetchAndAddRelaxed(1);
93QImageData::QImageData()
94 : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(
nullptr),
95 format(QImage::Format_ARGB32), bytes_per_line(0),
96 ser_no(next_qimage_serial_number()),
98 dpmx(qt_defaultDpiX() * 100 / qreal(2.54)),
99 dpmy(qt_defaultDpiY() * 100 / qreal(2.54)),
100 offset(0, 0), own_data(
true), ro_data(
false), has_alpha_clut(
false),
101 is_cached(
false), cleanupFunction(
nullptr), cleanupInfo(
nullptr),
107
108
109
110
111
112
113QImageData * Q_TRACE_INSTRUMENT(qtgui) QImageData::create(
const QSize &size, QImage::Format format)
115 if (size.isEmpty() || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
118 Q_TRACE_SCOPE(QImageData_create, size, format);
120 int width = size.width();
121 int height = size.height();
122 int depth = qt_depthForFormat(format);
123 auto params = calculateImageParameters(width, height, depth);
124 if (!params.isValid())
127 auto d = std::make_unique<QImageData>();
130 case QImage::Format_Mono:
131 case QImage::Format_MonoLSB:
132 d->colortable.resize(2);
133 d->colortable[0] = QColor(Qt::black).rgba();
134 d->colortable[1] = QColor(Qt::white).rgba();
144 d->has_alpha_clut =
false;
145 d->is_cached =
false;
147 d->bytes_per_line = params.bytesPerLine;
148 d->nbytes = params.totalSize;
149 d->data = (uchar *)malloc(d->nbytes);
158QImageData::~QImageData()
161 cleanupFunction(cleanupInfo);
163 QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
165 if (data && own_data)
166 QtPrivate::sizedFree(data, nbytes);
170#if defined(_M_ARM) && defined(_MSC_VER)
171#pragma optimize("", off)
174bool QImageData::checkForAlphaPixels()
const
176 bool has_alpha_pixels =
false;
180 case QImage::Format_Mono:
181 case QImage::Format_MonoLSB:
182 case QImage::Format_Indexed8:
183 has_alpha_pixels = has_alpha_clut;
185 case QImage::Format_Alpha8:
186 has_alpha_pixels =
true;
188 case QImage::Format_ARGB32:
189 case QImage::Format_ARGB32_Premultiplied: {
190 const uchar *bits = data;
191 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
192 uint alphaAnd = 0xff000000;
193 for (
int x=0; x<width; ++x)
194 alphaAnd &=
reinterpret_cast<
const uint*>(bits)[x];
195 has_alpha_pixels = (alphaAnd != 0xff000000);
196 bits += bytes_per_line;
200 case QImage::Format_RGBA8888:
201 case QImage::Format_RGBA8888_Premultiplied: {
202 const uchar *bits = data;
203 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
204 uchar alphaAnd = 0xff;
205 for (
int x=0; x<width; ++x)
206 alphaAnd &= bits[x * 4+ 3];
207 has_alpha_pixels = (alphaAnd != 0xff);
208 bits += bytes_per_line;
212 case QImage::Format_A2BGR30_Premultiplied:
213 case QImage::Format_A2RGB30_Premultiplied: {
214 const uchar *bits = data;
215 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
216 uint alphaAnd = 0xc0000000;
217 for (
int x=0; x<width; ++x)
218 alphaAnd &=
reinterpret_cast<
const uint*>(bits)[x];
219 has_alpha_pixels = (alphaAnd != 0xc0000000);
220 bits += bytes_per_line;
224 case QImage::Format_ARGB8555_Premultiplied:
225 case QImage::Format_ARGB8565_Premultiplied: {
226 const uchar *bits = data;
227 const uchar *end_bits = data + bytes_per_line;
229 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
230 uchar alphaAnd = 0xff;
231 while (bits < end_bits) {
235 has_alpha_pixels = (alphaAnd != 0xff);
237 end_bits += bytes_per_line;
241 case QImage::Format_ARGB6666_Premultiplied: {
242 const uchar *bits = data;
243 const uchar *end_bits = data + bytes_per_line;
245 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
246 uchar alphaAnd = 0xfc;
247 while (bits < end_bits) {
251 has_alpha_pixels = (alphaAnd != 0xfc);
253 end_bits += bytes_per_line;
257 case QImage::Format_ARGB4444_Premultiplied: {
258 const uchar *bits = data;
259 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
260 ushort alphaAnd = 0xf000;
261 for (
int x=0; x<width; ++x)
262 alphaAnd &=
reinterpret_cast<
const ushort*>(bits)[x];
263 has_alpha_pixels = (alphaAnd != 0xf000);
264 bits += bytes_per_line;
267 case QImage::Format_RGBA64:
268 case QImage::Format_RGBA64_Premultiplied: {
270 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
271 for (
int x=0; x<width; ++x) {
272 has_alpha_pixels |= !(((QRgba64 *)bits)[x].isOpaque());
274 bits += bytes_per_line;
277 case QImage::Format_RGBA16FPx4:
278 case QImage::Format_RGBA16FPx4_Premultiplied: {
280 for (
int y = 0; y < height && !has_alpha_pixels; ++y) {
281 for (
int x = 0; x < width; ++x)
282 has_alpha_pixels |= ((qfloat16 *)bits)[x * 4 + 3] < 1.0f;
283 bits += bytes_per_line;
286 case QImage::Format_RGBA32FPx4:
287 case QImage::Format_RGBA32FPx4_Premultiplied: {
289 for (
int y = 0; y < height && !has_alpha_pixels; ++y) {
290 for (
int x = 0; x < width; ++x)
291 has_alpha_pixels |= ((
float *)bits)[x * 4 + 3] < 1.0f;
292 bits += bytes_per_line;
296 case QImage::Format_RGB32:
297 case QImage::Format_RGB16:
298 case QImage::Format_RGB444:
299 case QImage::Format_RGB555:
300 case QImage::Format_RGB666:
301 case QImage::Format_RGB888:
302 case QImage::Format_BGR888:
303 case QImage::Format_RGBX8888:
304 case QImage::Format_BGR30:
305 case QImage::Format_RGB30:
306 case QImage::Format_Grayscale8:
307 case QImage::Format_Grayscale16:
308 case QImage::Format_RGBX64:
309 case QImage::Format_RGBX16FPx4:
310 case QImage::Format_RGBX32FPx4:
311 case QImage::Format_CMYK8888:
313 case QImage::Format_Invalid:
314 case QImage::NImageFormats:
319 return has_alpha_pixels;
321#if defined(_M_ARM) && defined(_MSC_VER)
322#pragma optimize("", on)
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
627
628
629
630
631
632
633
636
637
638
639
640
641
645
646
647
648
649
650
651
652
653
654
657
658
659
660
661
662
663
664
665
666
667
668
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
785
786
789
790
791
792
794QImage::QImage()
noexcept
801
802
803
804
805
806
807
808
809
810QImage::QImage(
int width,
int height, Format format)
811 : QImage(QSize(width, height), format)
816
817
818
819
820
821
822
823
824QImage::QImage(
const QSize &size, Format format)
827 d = QImageData::create(size, format);
832QImageData *QImageData::create(uchar *data,
int width,
int height, qsizetype bpl, QImage::Format format,
bool readOnly, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
834 if (width <= 0 || height <= 0 || !data || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
837 const int depth = qt_depthForFormat(format);
838 auto params = calculateImageParameters(width, height, depth);
839 if (!params.isValid())
844 const qsizetype min_bytes_per_line = (qsizetype(width) * depth + 7)/8;
845 if (bpl < min_bytes_per_line)
849 params.bytesPerLine = bpl;
850 if (qMulOverflow<qsizetype>(bpl, height, ¶ms.totalSize))
854 QImageData *d =
new QImageData;
858 d->ro_data = readOnly;
865 d->bytes_per_line = params.bytesPerLine;
866 d->nbytes = params.totalSize;
868 d->cleanupFunction = cleanupFunction;
869 d->cleanupInfo = cleanupInfo;
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891QImage::QImage(uchar* data,
int width,
int height, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
894 d = QImageData::create(data, width, height, 0, format,
false, cleanupFunction, cleanupInfo);
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922QImage::QImage(
const uchar* data,
int width,
int height, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
925 d = QImageData::create(
const_cast<uchar*>(data), width, height, 0, format,
true, cleanupFunction, cleanupInfo);
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
946QImage::QImage(uchar *data,
int width,
int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
949 d = QImageData::create(data, width, height, bytesPerLine, format,
false, cleanupFunction, cleanupInfo);
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
977QImage::QImage(
const uchar *data,
int width,
int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
980 d = QImageData::create(
const_cast<uchar*>(data), width, height, bytesPerLine, format,
true, cleanupFunction, cleanupInfo);
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1003QImage::QImage(
const QString &fileName,
const char *format)
1007 load(fileName, format);
1010#ifndef QT_NO_IMAGEFORMAT_XPM
1011extern bool qt_read_xpm_image_or_array(QIODevice *device,
const char *
const *source, QImage &image);
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1029QImage::QImage(
const char *
const xpm[])
1035 if (!qt_read_xpm_image_or_array(
nullptr, xpm, *
this))
1037 qWarning(
"QImage::QImage(), XPM is not supported");
1042
1043
1044
1045
1046
1047
1048
1050QImage::QImage(
const QImage &image)
1053 if (image.paintingActive()) {
1055 image.copy().swap(*
this);
1064
1065
1069 if (d && !d->ref.deref())
1074
1075
1076
1077
1078
1079
1080
1081
1083QImage &QImage::operator=(
const QImage &image)
1085 if (image.paintingActive()) {
1086 operator=(image.copy());
1090 if (d && !d->ref.deref())
1098
1099
1100
1103
1104
1105int QImage::devType()
const
1107 return QInternal::Image;
1111
1112
1113QImage::operator QVariant()
const
1115 return QVariant::fromValue(*
this);
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129void QImage::detach()
1132 if (d->is_cached && d->ref.loadRelaxed() == 1)
1133 QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
1135 if (d->ref.loadRelaxed() != 1 || d->ro_data)
1145
1146
1147
1148
1149
1150
1151
1152void QImage::detachMetadata(
bool invalidateCache)
1155 if (d->is_cached && d->ref.loadRelaxed() == 1)
1156 QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
1158 if (d->ref.loadRelaxed() != 1)
1161 if (d && invalidateCache)
1168 dst->dpmx = src->dpmx;
1169 dst->dpmy = src->dpmy;
1170 dst->devicePixelRatio = src->devicePixelRatio;
1177 dst->text = src->text;
1178 dst->offset = src->offset;
1179 dst->colorSpace = src->colorSpace;
1184 dst->setDotsPerMeterX(src.dotsPerMeterX());
1185 dst->setDotsPerMeterY(src.dotsPerMeterY());
1186 dst->setDevicePixelRatio(src.devicePixelRatio());
1187 const auto textKeys = src.textKeys();
1188 for (
const auto &key: textKeys)
1189 dst->setText(key, src.text(key));
1194
1195
1196
1197
1198
1199
1200
1201
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223QImage Q_TRACE_INSTRUMENT(qtgui) QImage::copy(
const QRect& r)
const
1225 Q_TRACE_SCOPE(QImage_copy, r);
1230 QImage image(d->width, d->height, d->format);
1236 if (image.d->nbytes != d->nbytes) {
1237 qsizetype bpl = qMin(bytesPerLine(), image.bytesPerLine());
1238 for (
int i = 0; i < height(); i++)
1239 memcpy(image.scanLine(i), scanLine(i), bpl);
1241 memcpy(image.bits(), bits(), d->nbytes);
1242 image.d->colortable = d->colortable;
1243 image.d->has_alpha_clut = d->has_alpha_clut;
1244 copyMetadata(image.d, d);
1255 if (w <= 0 || h <= 0)
1258 QImage image(w, h, d->format);
1262 if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) {
1275 image.d->colortable = d->colortable;
1277 int pixels_to_copy = qMax(w - dx, 0);
1280 else if (pixels_to_copy > d->width - x)
1281 pixels_to_copy = d->width - x;
1282 int lines_to_copy = qMax(h - dy, 0);
1285 else if (lines_to_copy > d->height - y)
1286 lines_to_copy = d->height - y;
1288 bool byteAligned =
true;
1289 if (d->format == Format_Mono || d->format == Format_MonoLSB)
1290 byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7);
1293 const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line;
1294 uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line;
1295 const qsizetype bytes_to_copy = (qsizetype(pixels_to_copy) * d->depth) >> 3;
1296 for (
int i = 0; i < lines_to_copy; ++i) {
1297 memcpy(dest, src, bytes_to_copy);
1298 src += d->bytes_per_line;
1299 dest += image.d->bytes_per_line;
1301 }
else if (d->format == Format_Mono) {
1302 const uchar *src = d->data + y * d->bytes_per_line;
1303 uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1304 for (
int i = 0; i < lines_to_copy; ++i) {
1305 for (
int j = 0; j < pixels_to_copy; ++j) {
1306 if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7)))
1307 dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7));
1309 dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7));
1311 src += d->bytes_per_line;
1312 dest += image.d->bytes_per_line;
1315 Q_ASSERT(d->format == Format_MonoLSB);
1316 const uchar *src = d->data + y * d->bytes_per_line;
1317 uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1318 for (
int i = 0; i < lines_to_copy; ++i) {
1319 for (
int j = 0; j < pixels_to_copy; ++j) {
1320 if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7)))
1321 dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7));
1323 dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7));
1325 src += d->bytes_per_line;
1326 dest += image.d->bytes_per_line;
1330 copyMetadata(image.d, d);
1331 image.d->has_alpha_clut = d->has_alpha_clut;
1338
1339
1340
1341
1342
1343bool QImage::isNull()
const
1349
1350
1351
1352
1353
1354
1355int QImage::width()
const
1357 return d ? d->width : 0;
1361
1362
1363
1364
1365
1366
1367int QImage::height()
const
1369 return d ? d->height : 0;
1373
1374
1375
1376
1377
1378
1379QSize QImage::size()
const
1381 return d ? QSize(d->width, d->height) : QSize(0, 0);
1385
1386
1387
1388
1389
1390
1391
1392QRect QImage::rect()
const
1394 return d ? QRect(0, 0, d->width, d->height) : QRect();
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409int QImage::depth()
const
1411 return d ? d->depth : 0;
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425int QImage::colorCount()
const
1427 return d ? d->colortable.size() : 0;
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441void QImage::setColorTable(
const QList<QRgb> &colors)
1445 detachMetadata(
true);
1451 d->colortable = colors;
1452 d->has_alpha_clut =
false;
1453 for (
int i = 0; i < d->colortable.size(); ++i) {
1454 if (qAlpha(d->colortable.at(i)) != 255) {
1455 d->has_alpha_clut =
true;
1462
1463
1464
1465
1466
1467QList<QRgb> QImage::colorTable()
const
1469 return d ? d->colortable : QList<QRgb>();
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483qreal QImage::devicePixelRatio()
const
1487 return d->devicePixelRatio;
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511void QImage::setDevicePixelRatio(qreal scaleFactor)
1516 if (scaleFactor == d->devicePixelRatio)
1521 d->devicePixelRatio = scaleFactor;
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534QSizeF QImage::deviceIndependentSize()
const
1537 return QSizeF(0, 0);
1538 return QSizeF(d->width, d->height) / d->devicePixelRatio;
1543
1544
1545
1546
1547
1548
1549qsizetype QImage::sizeInBytes()
const
1551 return d ? d->nbytes : 0;
1555
1556
1557
1558
1559
1560
1561qsizetype QImage::bytesPerLine()
const
1563 return d ? d->bytes_per_line : 0;
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578QRgb QImage::color(
int i)
const
1580 Q_ASSERT(i < colorCount());
1581 return d ? d->colortable.at(i) : QRgb(uint(-1));
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596void QImage::setColor(
int i, QRgb c)
1600 if (i < 0 || d->depth > 8 || i >= 1<<d->depth) {
1601 qWarning(
"QImage::setColor: Index out of bound %d", i);
1604 detachMetadata(
true);
1610 if (i >= d->colortable.size())
1612 d->colortable[i] = c;
1613 d->has_alpha_clut |= (qAlpha(c) != 255);
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638uchar *QImage::scanLine(
int i)
1649 return d->data + i * d->bytes_per_line;
1653
1654
1655const uchar *QImage::scanLine(
int i)
const
1660 Q_ASSERT(i >= 0 && i < height());
1661 return d->data + i * d->bytes_per_line;
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679const uchar *QImage::constScanLine(
int i)
const
1684 Q_ASSERT(i >= 0 && i < height());
1685 return d->data + i * d->bytes_per_line;
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699uchar *QImage::bits()
1713
1714
1715
1716
1717
1718
1719const uchar *QImage::bits()
const
1721 return d ? d->data :
nullptr;
1726
1727
1728
1729
1730
1731
1732
1733
1734const uchar *QImage::constBits()
const
1736 return d ? d->data :
nullptr;
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1759void QImage::fill(uint pixel)
1770 if (d->depth == 1 || d->depth == 8) {
1772 if (d->depth == 1) {
1781 qt_rectfill<quint8>(d->data, pixel, 0, 0,
1782 w, d->height, d->bytes_per_line);
1784 }
else if (d->depth == 16) {
1785 if (d->format == Format_RGB444)
1787 qt_rectfill<quint16>(
reinterpret_cast<quint16*>(d->data), pixel,
1788 0, 0, d->width, d->height, d->bytes_per_line);
1790 }
else if (d->depth == 24) {
1791 if (d->format == Format_RGB666)
1793 qt_rectfill<quint24>(
reinterpret_cast<quint24*>(d->data), pixel,
1794 0, 0, d->width, d->height, d->bytes_per_line);
1796 }
else if (d->format >= QImage::Format_RGBX64 && d->format <= QImage::Format_RGBA64_Premultiplied) {
1797 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), QRgba64::fromArgb32(pixel),
1798 0, 0, d->width, d->height, d->bytes_per_line);
1800 }
else if (d->format >= QImage::Format_RGBX16FPx4 && d->format <= QImage::Format_RGBA16FPx4_Premultiplied) {
1802 QRgbaFloat16 cf = QRgbaFloat16::fromArgb32(pixel);
1803 ::memcpy(&cu, &cf,
sizeof(quint64));
1804 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), cu,
1805 0, 0, d->width, d->height, d->bytes_per_line);
1807 }
else if (d->format >= QImage::Format_RGBX32FPx4 && d->format <= QImage::Format_RGBA32FPx4_Premultiplied) {
1808 QRgbaFloat32 cf = QRgbaFloat32::fromArgb32(pixel);
1809 uchar *data = d->data;
1810 for (
int y = 0; y < d->height; ++y) {
1811 QRgbaFloat32 *line =
reinterpret_cast<QRgbaFloat32 *>(data);
1812 for (
int x = 0; x < d->width; ++x)
1814 data += d->bytes_per_line;
1818 Q_ASSERT(d->depth == 32);
1820 if (d->format == Format_RGB32)
1821 pixel |= 0xff000000;
1822 if (d->format == Format_RGBX8888)
1823#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
1824 pixel |= 0xff000000;
1826 pixel |= 0x000000ff;
1828 if (d->format == Format_BGR30 || d->format == Format_RGB30)
1829 pixel |= 0xc0000000;
1831 qt_rectfill<uint>(
reinterpret_cast<uint*>(d->data), pixel,
1832 0, 0, d->width, d->height, d->bytes_per_line);
1837
1838
1839
1840
1841
1842
1844void QImage::fill(Qt::GlobalColor color)
1846 fill(QColor(color));
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1866void QImage::fill(
const QColor &color)
1876 QRgba64 opaque = color.rgba64();
1877 opaque.setAlpha(65535);
1878 switch (d->format) {
1879 case QImage::Format_RGB32:
1880 case QImage::Format_ARGB32:
1883 case QImage::Format_ARGB32_Premultiplied:
1884 fill(qPremultiply(color.rgba()));
1886 case QImage::Format_RGBX8888:
1887 fill(ARGB2RGBA(color.rgba() | 0xff000000));
1889 case QImage::Format_RGBA8888:
1890 fill(ARGB2RGBA(color.rgba()));
1892 case QImage::Format_RGBA8888_Premultiplied:
1893 fill(ARGB2RGBA(qPremultiply(color.rgba())));
1895 case QImage::Format_BGR30:
1896 fill(qConvertRgb64ToRgb30<PixelOrderBGR>(opaque));
1898 case QImage::Format_RGB30:
1899 fill(qConvertRgb64ToRgb30<PixelOrderRGB>(opaque));
1901 case QImage::Format_RGB16:
1902 fill((uint) qConvertRgb32To16(color.rgba()));
1904 case QImage::Format_Indexed8: {
1906 for (
int i=0; i<d->colortable.size(); ++i) {
1907 if (color.rgba() == d->colortable.at(i)) {
1915 case QImage::Format_Mono:
1916 case QImage::Format_MonoLSB:
1917 if (color == Qt::color1)
1922 case QImage::Format_RGBX64:
1923 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), opaque,
1924 0, 0, d->width, d->height, d->bytes_per_line);
1926 case QImage::Format_RGBA64:
1927 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), color.rgba64(),
1928 0, 0, d->width, d->height, d->bytes_per_line);
1930 case QImage::Format_RGBA64_Premultiplied:
1931 qt_rectfill<quint64>(
reinterpret_cast<quint64 *>(d->data), color.rgba64().premultiplied(),
1932 0, 0, d->width, d->height, d->bytes_per_line);
1934 case QImage::Format_RGBX16FPx4:
1935 case QImage::Format_RGBA16FPx4:
1936 case QImage::Format_RGBA16FPx4_Premultiplied:
1937 case QImage::Format_RGBX32FPx4:
1938 case QImage::Format_RGBA32FPx4:
1939 case QImage::Format_RGBA32FPx4_Premultiplied:{
1941 color.getRgbF(&r, &g, &b, &a);
1942 if (!hasAlphaChannel())
1944 if (depth() == 64) {
1945 QRgbaFloat16 c16{qfloat16(r), qfloat16(g), qfloat16(b), qfloat16(a)};
1946 if (d->format == Format_RGBA16FPx4_Premultiplied)
1947 c16 = c16.premultiplied();
1948 qt_rectfill<QRgbaFloat16>(
reinterpret_cast<QRgbaFloat16 *>(d->data), c16,
1949 0, 0, d->width, d->height, d->bytes_per_line);
1951 QRgbaFloat32 c32{r, g, b, a};
1952 if (d->format == Format_RGBA32FPx4_Premultiplied)
1953 c32 = c32.premultiplied();
1954 qt_rectfill<QRgbaFloat32>(
reinterpret_cast<QRgbaFloat32 *>(d->data), c32,
1955 0, 0, d->width, d->height, d->bytes_per_line);
1961 p.setCompositionMode(QPainter::CompositionMode_Source);
1962 p.fillRect(rect(), color);
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1988void QImage::invertPixels(InvertMode mode)
1999 QImage::Format originalFormat = d->format;
2001 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) {
2002 if (d->format == QImage::Format_RGBA16FPx4_Premultiplied) {
2003 if (!d->convertInPlace(QImage::Format_RGBA16FPx4, { }))
2004 *
this = convertToFormat(QImage::Format_RGBA16FPx4);
2005 }
else if (d->format == QImage::Format_RGBA32FPx4_Premultiplied) {
2006 if (!d->convertInPlace(QImage::Format_RGBA32FPx4, { }))
2007 *
this = convertToFormat(QImage::Format_RGBA32FPx4);
2008 }
else if (depth() > 32) {
2009 if (!d->convertInPlace(QImage::Format_RGBA64, { }))
2010 *
this = convertToFormat(QImage::Format_RGBA64);
2012 if (!d->convertInPlace(QImage::Format_ARGB32, { }))
2013 *
this = convertToFormat(QImage::Format_ARGB32);
2019 qsizetype bpl = (qsizetype(d->width) * d->depth + 7) / 8;
2020 int pad = d->bytes_per_line - bpl;
2021 uchar *sl = d->data;
2022 for (
int y=0; y<d->height; ++y) {
2023 for (qsizetype x=0; x<bpl; ++x)
2027 }
else if (format() >= QImage::Format_RGBX16FPx4 && format() <= QImage::Format_RGBA16FPx4_Premultiplied) {
2028 qfloat16 *p =
reinterpret_cast<qfloat16 *>(d->data);
2029 qfloat16 *end =
reinterpret_cast<qfloat16 *>(d->data + d->nbytes);
2031 p[0] = qfloat16(1) - p[0];
2032 p[1] = qfloat16(1) - p[1];
2033 p[2] = qfloat16(1) - p[2];
2034 if (mode == InvertRgba)
2035 p[3] = qfloat16(1) - p[3];
2038 }
else if (format() >= QImage::Format_RGBX32FPx4 && format() <= QImage::Format_RGBA32FPx4_Premultiplied) {
2039 uchar *data = d->data;
2040 for (
int y = 0; y < d->height; ++y) {
2041 float *p =
reinterpret_cast<
float *>(data);
2042 for (
int x = 0; x < d->width; ++x) {
2046 if (mode == InvertRgba)
2050 data += d->bytes_per_line;
2052 }
else if (depth() == 64) {
2053 quint16 *p = (quint16*)d->data;
2054 quint16 *end = (quint16*)(d->data + d->nbytes);
2055 quint16 xorbits = 0xffff;
2060 if (mode == InvertRgba)
2066 quint32 *p = (quint32*)d->data;
2067 quint32 *end = (quint32*)(d->data + d->nbytes);
2068 quint32 xorbits = 0xffffffff;
2069 switch (d->format) {
2070 case QImage::Format_RGBA8888:
2071 if (mode == InvertRgba)
2074 case QImage::Format_RGBX8888:
2075#if Q_BYTE_ORDER == Q_BIG_ENDIAN
2076 xorbits = 0xffffff00;
2079 xorbits = 0x00ffffff;
2082 case QImage::Format_ARGB32:
2083 if (mode == InvertRgba)
2086 case QImage::Format_RGB32:
2087 xorbits = 0x00ffffff;
2089 case QImage::Format_BGR30:
2090 case QImage::Format_RGB30:
2091 xorbits = 0x3fffffff;
2102 if (originalFormat != d->format) {
2103 if (!d->convertInPlace(originalFormat, { }))
2104 *
this = convertToFormat(originalFormat);
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2133void QImage::setColorCount(
int colorCount)
2136 qWarning(
"QImage::setColorCount: null image");
2140 detachMetadata(
true);
2146 if (colorCount == d->colortable.size())
2148 if (colorCount <= 0) {
2149 d->colortable.clear();
2152 int nc = d->colortable.size();
2153 d->colortable.resize(colorCount);
2154 for (
int i = nc; i < colorCount; ++i)
2155 d->colortable[i] = 0;
2159
2160
2161
2162
2163QImage::Format QImage::format()
const
2167 Q_ASSERT(d->format < NImageFormats);
2168 Q_ASSERT(d->format > Format_Invalid);
2170 return d ? d->format : Format_Invalid;
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2199
2200
2201QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags)
const
2203 if (!d || d->format == format)
2206 if (d->format == Format_Invalid || format <= Format_Invalid || format >= NImageFormats)
2209 const QPixelLayout *destLayout = &qPixelLayouts[format];
2210 Image_Converter converter = qimage_converter_map[d->format][format];
2211 if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8) {
2212 if (qt_highColorPrecision(d->format, !destLayout->hasAlphaChannel)
2213 && qt_highColorPrecision(format, !hasAlphaChannel())) {
2214#if QT_CONFIG(raster_fp)
2215 if (qt_fpColorPrecision(d->format) && qt_fpColorPrecision(format))
2216 converter = convert_generic_over_rgba32f;
2219 converter = convert_generic_over_rgb64;
2221 converter = convert_generic;
2224 QImage image(d->width, d->height, format);
2228 copyMetadata(image.d, d);
2230 converter(image.d, d, flags);
2235 Q_ASSERT(format != QImage::Format_ARGB32 && format != QImage::Format_RGB32);
2236 Q_ASSERT(d->format != QImage::Format_ARGB32 && d->format != QImage::Format_RGB32);
2238 if (!hasAlphaChannel())
2239 return convertToFormat(Format_RGB32, flags).convertToFormat(format, flags);
2241 return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
2245
2246
2247bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags)
2249 return d && d->convertInPlace(format, flags);
2252static inline int pixel_distance(QRgb p1, QRgb p2) {
2254 int g1 = qGreen(p1);
2256 int a1 = qAlpha(p1);
2259 int g2 = qGreen(p2);
2261 int a2 = qAlpha(p2);
2263 return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2);
2266static inline int closestMatch(QRgb pixel,
const QList<QRgb> &clut) {
2268 int current_distance = INT_MAX;
2269 for (
int i=0; i<clut.size(); ++i) {
2270 int dist = pixel_distance(pixel, clut.at(i));
2271 if (dist < current_distance) {
2272 current_distance = dist;
2279static QImage convertWithPalette(
const QImage &src, QImage::Format format,
2280 const QList<QRgb> &clut) {
2281 QImage dest(src.size(), format);
2282 dest.setColorTable(clut);
2284 copyMetadata(QImageData::get(dest), QImageData::get(src));
2286 int h = src.height();
2287 int w = src.width();
2289 QHash<QRgb,
int> cache;
2291 if (format == QImage::Format_Indexed8) {
2292 for (
int y=0; y<h; ++y) {
2293 const QRgb *src_pixels = (
const QRgb *) src.scanLine(y);
2294 uchar *dest_pixels = (uchar *) dest.scanLine(y);
2295 for (
int x=0; x<w; ++x) {
2296 int src_pixel = src_pixels[x];
2297 int value = cache.value(src_pixel, -1);
2299 value = closestMatch(src_pixel, clut);
2300 cache.insert(src_pixel, value);
2302 dest_pixels[x] = (uchar) value;
2306 QList<QRgb> table = clut;
2308 for (
int y=0; y<h; ++y) {
2309 const QRgb *src_pixels = (
const QRgb *) src.scanLine(y);
2310 for (
int x=0; x<w; ++x) {
2311 int src_pixel = src_pixels[x];
2312 int value = cache.value(src_pixel, -1);
2314 value = closestMatch(src_pixel, table);
2315 cache.insert(src_pixel, value);
2317 dest.setPixel(x, y, value);
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335QImage QImage::convertToFormat(Format format,
const QList<QRgb> &colorTable, Qt::ImageConversionFlags flags)
const
2337 if (!d || d->format == format)
2340 if (format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
2342 if (format <= QImage::Format_Indexed8)
2343 return convertWithPalette(convertToFormat(QImage::Format_ARGB32, flags), format, colorTable);
2345 return convertToFormat(format, flags);
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2371bool QImage::reinterpretAsFormat(Format format)
2373 if (format <= Format_Invalid || format >= NImageFormats)
2377 if (d->format == format)
2379 if (qt_depthForFormat(format) != qt_depthForFormat(d->format))
2381 if (!isDetached()) {
2382 QImageData *oldD = d;
2397
2398
2399
2400
2401
2402
2403
2404
2405
2407void QImage::convertTo(Format format, Qt::ImageConversionFlags flags)
2409 if (!d || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
2412 if (d->format == format)
2416 if (convertToFormat_inplace(format, flags))
2419 *
this = convertToFormat_helper(format, flags);
2423
2424
2425
2426
2427
2428
2429
2432
2433
2434
2435
2436
2437bool QImage::valid(
int x,
int y)
const
2440 && x >= 0 && x < d->width
2441 && y >= 0 && y < d->height;
2445
2446
2447
2448
2449
2450
2451
2452
2453
2456
2457
2458
2459
2460int QImage::pixelIndex(
int x,
int y)
const
2462 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
2463 qWarning(
"QImage::pixelIndex: coordinate (%d,%d) out of range", x, y);
2466 const uchar * s = scanLine(y);
2469 return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
2470 case Format_MonoLSB:
2471 return (*(s + (x >> 3)) >> (x & 7)) & 1;
2472 case Format_Indexed8:
2475 qWarning(
"QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth);
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2497
2498
2499
2500
2501QRgb QImage::pixel(
int x,
int y)
const
2503 if (!d || x < 0 || x >= d->width || y < 0 || y >= d->height) {
2504 qWarning(
"QImage::pixel: coordinate (%d,%d) out of range", x, y);
2508 const uchar *s = d->data + y * d->bytes_per_line;
2511 switch (d->format) {
2513 index = (*(s + (x >> 3)) >> (~x & 7)) & 1;
2515 case Format_MonoLSB:
2516 index = (*(s + (x >> 3)) >> (x & 7)) & 1;
2518 case Format_Indexed8:
2525 if (index >= d->colortable.size()) {
2526 qWarning(
"QImage::pixel: color table index %d out of range.", index);
2529 return d->colortable.at(index);
2531 std::optional<QRgb> out;
2532 switch (d->format) {
2535 case Format_ARGB32_Premultiplied:
2536 out =
reinterpret_cast<
const QRgb *>(s)[x];
2538 case Format_RGBX8888:
2539 case Format_RGBA8888:
2540 case Format_RGBA8888_Premultiplied:
2541 out = RGBA2ARGB(
reinterpret_cast<
const quint32 *>(s)[x]);
2544 case Format_A2BGR30_Premultiplied:
2545 out = qConvertA2rgb30ToArgb32<PixelOrderBGR>(
reinterpret_cast<
const quint32 *>(s)[x]);
2548 case Format_A2RGB30_Premultiplied:
2549 out = qConvertA2rgb30ToArgb32<PixelOrderRGB>(
reinterpret_cast<
const quint32 *>(s)[x]);
2552 return qConvertRgb16To32(
reinterpret_cast<
const quint16 *>(s)[x]);
2555 case Format_RGBA64_Premultiplied:
2556 out =
reinterpret_cast<
const QRgba64 *>(s)[x].toArgb32();
2558 case Format_RGBX16FPx4:
2559 case Format_RGBA16FPx4:
2560 case Format_RGBA16FPx4_Premultiplied:
2561 out =
reinterpret_cast<
const QRgbaFloat16 *>(s)[x].toArgb32();
2563 case Format_RGBX32FPx4:
2564 case Format_RGBA32FPx4:
2565 case Format_RGBA32FPx4_Premultiplied:
2566 out =
reinterpret_cast<
const QRgbaFloat32 *>(s)[x].toArgb32();
2570 const QPixelLayout *layout = &qPixelLayouts[d->format];
2573 if (!layout->hasAlphaChannel)
2578 return *layout->fetchToARGB32PM(&result, s, x, 1,
nullptr,
nullptr);
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2603
2604
2605
2606
2607void QImage::setPixel(
int x,
int y, uint index_or_rgb)
2609 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
2610 qWarning(
"QImage::setPixel: coordinate (%d,%d) out of range", x, y);
2614 uchar * s = scanLine(y);
2617 case Format_MonoLSB:
2618 if (index_or_rgb > 1) {
2619 qWarning(
"QImage::setPixel: Index %d out of range", index_or_rgb);
2620 }
else if (format() == Format_MonoLSB) {
2621 if (index_or_rgb==0)
2622 *(s + (x >> 3)) &= ~(1 << (x & 7));
2624 *(s + (x >> 3)) |= (1 << (x & 7));
2626 if (index_or_rgb==0)
2627 *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
2629 *(s + (x >> 3)) |= (1 << (7-(x & 7)));
2632 case Format_Indexed8:
2633 if (index_or_rgb >= (uint)d->colortable.size()) {
2634 qWarning(
"QImage::setPixel: Index %d out of range", index_or_rgb);
2637 s[x] = index_or_rgb;
2642 ((uint *)s)[x] = 0xff000000 | index_or_rgb;
2645 case Format_ARGB32_Premultiplied:
2646 ((uint *)s)[x] = index_or_rgb;
2649 ((quint16 *)s)[x] = qConvertRgb32To16(index_or_rgb);
2651 case Format_RGBX8888:
2652 ((uint *)s)[x] = ARGB2RGBA(0xff000000 | index_or_rgb);
2654 case Format_RGBA8888:
2655 case Format_RGBA8888_Premultiplied:
2656 ((uint *)s)[x] = ARGB2RGBA(index_or_rgb);
2659 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderBGR>(index_or_rgb);
2661 case Format_A2BGR30_Premultiplied:
2662 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderBGR>(index_or_rgb);
2665 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderRGB>(index_or_rgb);
2667 case Format_A2RGB30_Premultiplied:
2668 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderRGB>(index_or_rgb);
2671 ((QRgba64 *)s)[x] = QRgba64::fromArgb32(index_or_rgb | 0xff000000);
2674 case Format_RGBA64_Premultiplied:
2675 ((QRgba64 *)s)[x] = QRgba64::fromArgb32(index_or_rgb);
2677 case Format_RGBX16FPx4:
2678 ((QRgbaFloat16 *)s)[x] = QRgbaFloat16::fromArgb32(index_or_rgb | 0xff000000);
2680 case Format_RGBA16FPx4:
2681 case Format_RGBA16FPx4_Premultiplied:
2682 ((QRgbaFloat16 *)s)[x] = QRgbaFloat16::fromArgb32(index_or_rgb);
2684 case Format_RGBX32FPx4:
2685 ((QRgbaFloat32 *)s)[x] = QRgbaFloat32::fromArgb32(index_or_rgb | 0xff000000);
2687 case Format_RGBA32FPx4:
2688 case Format_RGBA32FPx4_Premultiplied:
2689 ((QRgbaFloat32 *)s)[x] = QRgbaFloat32::fromArgb32(index_or_rgb);
2691 case Format_Invalid:
2699 const QPixelLayout *layout = &qPixelLayouts[d->format];
2700 if (!hasAlphaChannel())
2701 layout->storeFromRGB32(s, &index_or_rgb, x, 1,
nullptr,
nullptr);
2703 layout->storeFromARGB32PM(s, &index_or_rgb, x, 1,
nullptr,
nullptr);
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2723
2724
2725
2726
2727
2728QColor QImage::pixelColor(
int x,
int y)
const
2730 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
2731 qWarning(
"QImage::pixelColor: coordinate (%d,%d) out of range", x, y);
2736 const uchar * s = constScanLine(y);
2737 switch (d->format) {
2739 case Format_A2BGR30_Premultiplied:
2740 c = qConvertA2rgb30ToRgb64<PixelOrderBGR>(
reinterpret_cast<
const quint32 *>(s)[x]);
2743 case Format_A2RGB30_Premultiplied:
2744 c = qConvertA2rgb30ToRgb64<PixelOrderRGB>(
reinterpret_cast<
const quint32 *>(s)[x]);
2748 case Format_RGBA64_Premultiplied:
2749 c =
reinterpret_cast<
const QRgba64 *>(s)[x];
2751 case Format_Grayscale16: {
2752 quint16 v =
reinterpret_cast<
const quint16 *>(s)[x];
2753 return QColor(qRgba64(v, v, v, 0xffff));
2755 case Format_RGBX16FPx4:
2756 case Format_RGBA16FPx4:
2757 case Format_RGBA16FPx4_Premultiplied: {
2758 QRgbaFloat16 p =
reinterpret_cast<
const QRgbaFloat16 *>(s)[x];
2759 if (d->format == Format_RGBA16FPx4_Premultiplied)
2760 p = p.unpremultiplied();
2761 else if (d->format == Format_RGBX16FPx4)
2764 color.setRgbF(p.red(), p.green(), p.blue(), p.alpha());
2767 case Format_RGBX32FPx4:
2768 case Format_RGBA32FPx4:
2769 case Format_RGBA32FPx4_Premultiplied: {
2770 QRgbaFloat32 p =
reinterpret_cast<
const QRgbaFloat32 *>(s)[x];
2771 if (d->format == Format_RGBA32FPx4_Premultiplied)
2772 p = p.unpremultiplied();
2773 else if (d->format == Format_RGBX32FPx4)
2776 color.setRgbF(p.red(), p.green(), p.blue(), p.alpha());
2780 c = QRgba64::fromArgb32(pixel(x, y));
2784 switch (d->format) {
2794 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied)
2795 c = c.unpremultiplied();
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2816
2817
2818
2819
2820
2821void QImage::setPixelColor(
int x,
int y,
const QColor &color)
2823 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
2824 qWarning(
"QImage::setPixelColor: coordinate (%d,%d) out of range", x, y);
2828 if (!color.isValid()) {
2829 qWarning(
"QImage::setPixelColor: color is invalid");
2834 QRgba64 c = color.rgba64();
2835 if (!hasAlphaChannel())
2837 else if (qPixelLayouts[d->format].premultiplied)
2838 c = c.premultiplied();
2840 uchar * s = scanLine(y);
2841 switch (d->format) {
2843 case Format_MonoLSB:
2844 case Format_Indexed8:
2845 qWarning(
"QImage::setPixelColor: called on monochrome or indexed format");
2848 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c) | 0xc0000000;
2850 case Format_A2BGR30_Premultiplied:
2851 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c);
2854 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c) | 0xc0000000;
2856 case Format_A2RGB30_Premultiplied:
2857 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c);
2861 case Format_RGBA64_Premultiplied:
2862 ((QRgba64 *)s)[x] = c;
2864 case Format_RGBX16FPx4:
2865 case Format_RGBA16FPx4:
2866 case Format_RGBA16FPx4_Premultiplied: {
2868 color.getRgbF(&r, &g, &b, &a);
2869 if (d->format == Format_RGBX16FPx4)
2871 QRgbaFloat16 c16f{qfloat16(r), qfloat16(g), qfloat16(b), qfloat16(a)};
2872 if (d->format == Format_RGBA16FPx4_Premultiplied)
2873 c16f = c16f.premultiplied();
2874 ((QRgbaFloat16 *)s)[x] = c16f;
2877 case Format_RGBX32FPx4:
2878 case Format_RGBA32FPx4:
2879 case Format_RGBA32FPx4_Premultiplied: {
2881 color.getRgbF(&r, &g, &b, &a);
2882 if (d->format == Format_RGBX32FPx4)
2884 QRgbaFloat32 c32f{r, g, b, a};
2885 if (d->format == Format_RGBA32FPx4_Premultiplied)
2886 c32f = c32f.premultiplied();
2887 ((QRgbaFloat32 *)s)[x] = c32f;
2891 setPixel(x, y, c.toArgb32());
2897
2898
2899
2900
2901
2902
2903
2904
2905bool QImage::allGray()
const
2910 switch (d->format) {
2912 case Format_MonoLSB:
2913 case Format_Indexed8:
2914 for (
int i = 0; i < d->colortable.size(); ++i) {
2915 if (!qIsGray(d->colortable.at(i)))
2921 case Format_Grayscale8:
2922 case Format_Grayscale16:
2926 case Format_ARGB32_Premultiplied:
2927#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
2928 case Format_RGBX8888:
2929 case Format_RGBA8888:
2930 case Format_RGBA8888_Premultiplied:
2932 for (
int j = 0; j < d->height; ++j) {
2933 const QRgb *b = (
const QRgb *)constScanLine(j);
2934 for (
int i = 0; i < d->width; ++i) {
2941 for (
int j = 0; j < d->height; ++j) {
2942 const quint16 *b = (
const quint16 *)constScanLine(j);
2943 for (
int i = 0; i < d->width; ++i) {
2944 if (!qIsGray(qConvertRgb16To32(b[i])))
2953 Q_DECL_UNINITIALIZED uint buffer[BufferSize];
2954 const QPixelLayout *layout = &qPixelLayouts[d->format];
2955 const auto fetch = layout->fetchToARGB32PM;
2956 for (
int j = 0; j < d->height; ++j) {
2957 const uchar *b = constScanLine(j);
2959 while (x < d->width) {
2960 int l = qMin(d->width - x, BufferSize);
2961 const uint *ptr = fetch(buffer, b, x, l,
nullptr,
nullptr);
2962 for (
int i = 0; i < l; ++i) {
2963 if (!qIsGray(ptr[i]))
2973
2974
2975
2976
2977
2978
2979
2980
2981bool QImage::isGrayscale()
const
2986 if (d->format == QImage::Format_Alpha8)
2989 if (d->format == QImage::Format_Grayscale8 || d->format == QImage::Format_Grayscale16)
2998 Q_ASSERT(d->format == QImage::Format_Indexed8);
2999 for (
int i = 0; i < colorCount(); i++)
3000 if (d->colortable.at(i) != qRgb(i,i,i))
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaled(
const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode)
const
3050 qWarning(
"QImage::scaled: Image is a null image");
3056 QSize newSize = size();
3057 newSize.scale(s, aspectMode);
3058 newSize.rwidth() = qMax(newSize.width(), 1);
3059 newSize.rheight() = qMax(newSize.height(), 1);
3060 if (newSize == size())
3063 Q_TRACE_SCOPE(QImage_scaled, s, aspectMode, mode);
3065 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
3066 QImage img = transformed(wm, mode);
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaledToWidth(
int w, Qt::TransformationMode mode)
const
3087 qWarning(
"QImage::scaleWidth: Image is a null image");
3093 Q_TRACE_SCOPE(QImage_scaledToWidth, w, mode);
3095 qreal factor = (qreal) w / width();
3096 QTransform wm = QTransform::fromScale(factor, factor);
3097 return transformed(wm, mode);
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaledToHeight(
int h, Qt::TransformationMode mode)
const
3117 qWarning(
"QImage::scaleHeight: Image is a null image");
3123 Q_TRACE_SCOPE(QImage_scaledToHeight, h, mode);
3125 qreal factor = (qreal) h / height();
3126 QTransform wm = QTransform::fromScale(factor, factor);
3127 return transformed(wm, mode);
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147QImage Q_TRACE_INSTRUMENT(qtgui) QImage::createAlphaMask(Qt::ImageConversionFlags flags)
const
3149 if (!d || d->format == QImage::Format_RGB32)
3152 if (d->depth == 1) {
3155 return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags);
3158 QImage mask(d->width, d->height, Format_MonoLSB);
3159 if (!mask.isNull()) {
3160 dither_to_Mono(mask.d, d, flags,
true);
3161 copyPhysicalMetadata(mask.d, d);
3166#ifndef QT_NO_IMAGE_HEURISTIC_MASK
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3191QImage QImage::createHeuristicMask(
bool clipTight)
const
3196 if (d->depth != 32) {
3197 QImage img32 = convertToFormat(Format_RGB32);
3198 return img32.createHeuristicMask(clipTight);
3201#define PIX(x,y) (*((const QRgb*)scanLine(y)+x) & 0x00ffffff
)
3205 QImage m(w, h, Format_MonoLSB);
3208 m.setColor(0, QColor(Qt::color0).rgba());
3209 m.setColor(1, QColor(Qt::color1).rgba());
3212 QRgb background =
PIX(0,0);
3213 if (background !=
PIX(w-1,0) &&
3214 background !=
PIX(0,h-1) &&
3215 background !=
PIX(w-1,h-1)) {
3216 background =
PIX(w-1,0);
3217 if (background !=
PIX(w-1,h-1) &&
3218 background !=
PIX(0,h-1) &&
3219 PIX(0,h-1) ==
PIX(w-1,h-1)) {
3220 background =
PIX(w-1,h-1);
3226 uchar *ypp, *ypc, *ypn;
3229 ypn = m.scanLine(0);
3231 for (y = 0; y < h; y++) {
3234 ypn = (y == h-1) ?
nullptr : m.scanLine(y+1);
3235 const QRgb *p = (
const QRgb *)scanLine(y);
3236 for (x = 0; x < w; x++) {
3239 if ((x == 0 || y == 0 || x == w-1 || y == h-1 ||
3240 !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) ||
3241 !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) ||
3242 !(*(ypp + (x >> 3)) & (1 << (x & 7))) ||
3243 !(*(ypn + (x >> 3)) & (1 << (x & 7)))) &&
3244 ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) &&
3245 ((*p & 0x00ffffff) == background)) {
3247 *(ypc + (x >> 3)) &= ~(1 << (x & 7));
3255 ypn = m.scanLine(0);
3257 for (y = 0; y < h; y++) {
3260 ypn = (y == h-1) ?
nullptr : m.scanLine(y+1);
3261 const QRgb *p = (
const QRgb *)scanLine(y);
3262 for (x = 0; x < w; x++) {
3263 if ((*p & 0x00ffffff) != background) {
3265 *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
3267 *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
3269 *(ypp + (x >> 3)) |= (1 << (x & 7));
3271 *(ypn + (x >> 3)) |= (1 << (x & 7));
3280 copyPhysicalMetadata(m.d, d);
3286
3287
3288
3289
3290
3291
3292
3293
3295QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode)
const
3299 QImage maskImage(size(), QImage::Format_MonoLSB);
3302 uchar *s = maskImage.bits();
3306 if (depth() == 32) {
3307 for (
int h = 0; h < d->height; h++) {
3308 const uint *sl = (
const uint *) scanLine(h);
3309 for (
int w = 0; w < d->width; w++) {
3311 *(s + (w >> 3)) |= (1 << (w & 7));
3313 s += maskImage.bytesPerLine();
3316 for (
int h = 0; h < d->height; h++) {
3317 for (
int w = 0; w < d->width; w++) {
3318 if ((uint) pixel(w, h) == color)
3319 *(s + (w >> 3)) |= (1 << (w & 7));
3321 s += maskImage.bytesPerLine();
3324 if (mode == Qt::MaskOutColor)
3325 maskImage.invertPixels();
3327 copyPhysicalMetadata(maskImage.d, d);
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3346
3347
3348
3349
3350
3351
3352
3353
3354
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3370
3371
3372
3373
3374
3375
3376
3377
3379template<
class T>
inline void do_mirror_data(QImageData *dst, QImageData *src,
3380 int dstX0,
int dstY0,
3381 int dstXIncr,
int dstYIncr,
3387 const int srcXEnd = (dstX0 && !dstY0) ? w / 2 : w;
3388 const int srcYEnd = dstY0 ? h / 2 : h;
3389 for (
int srcY = 0, dstY = dstY0; srcY < srcYEnd; ++srcY, dstY += dstYIncr) {
3390 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3391 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);
3392 for (
int srcX = 0, dstX = dstX0; srcX < srcXEnd; ++srcX, dstX += dstXIncr)
3393 std::swap(srcPtr[srcX], dstPtr[dstX]);
3396 if (dstX0 && dstY0 && (h & 1)) {
3398 int srcXEnd2 = w / 2;
3399 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3400 for (
int srcX = 0, dstX = dstX0; srcX < srcXEnd2; ++srcX, dstX += dstXIncr)
3401 std::swap(srcPtr[srcX], srcPtr[dstX]);
3404 for (
int srcY = 0, dstY = dstY0; srcY < h; ++srcY, dstY += dstYIncr) {
3405 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3406 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);
3407 for (
int srcX = 0, dstX = dstX0; srcX < w; ++srcX, dstX += dstXIncr)
3408 dstPtr[dstX] = srcPtr[srcX];
3413inline void do_flip(QImageData *dst, QImageData *src,
int w,
int h,
int depth)
3415 const int data_bytes_per_line = w * (depth / 8);
3417 uint *srcPtr =
reinterpret_cast<uint *>(src->data);
3418 uint *dstPtr =
reinterpret_cast<uint *>(dst->data + (h - 1) * dst->bytes_per_line);
3420 const int uint_per_line = (data_bytes_per_line + 3) >> 2;
3421 for (
int y = 0; y < h; ++y) {
3423 for (
int x = 0; x < uint_per_line; x++) {
3424 const uint d = dstPtr[x];
3425 const uint s = srcPtr[x];
3429 srcPtr += src->bytes_per_line >> 2;
3430 dstPtr -= dst->bytes_per_line >> 2;
3434 const uchar *srcPtr = src->data;
3435 uchar *dstPtr = dst->data + (h - 1) * dst->bytes_per_line;
3436 for (
int y = 0; y < h; ++y) {
3437 memcpy(dstPtr, srcPtr, data_bytes_per_line);
3438 srcPtr += src->bytes_per_line;
3439 dstPtr -= dst->bytes_per_line;
3444inline void do_mirror(QImageData *dst, QImageData *src,
bool horizontal,
bool vertical)
3446 Q_ASSERT(src->width == dst->width && src->height == dst->height && src->depth == dst->depth);
3448 int h = src->height;
3449 int depth = src->depth;
3451 if (src->depth == 1) {
3456 if (vertical && !horizontal) {
3458 do_flip(dst, src, w, h, depth);
3462 int dstX0 = 0, dstXIncr = 1;
3463 int dstY0 = 0, dstYIncr = 1;
3477 do_mirror_data<QRgbaFloat32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3480 do_mirror_data<quint64>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3483 do_mirror_data<quint32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3486 do_mirror_data<quint24>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3489 do_mirror_data<quint16>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3492 do_mirror_data<quint8>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3501 if (horizontal && dst->depth == 1) {
3502 Q_ASSERT(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB);
3503 const int shift = 8 - (dst->width % 8);
3504 const uchar *bitflip = qt_get_bitflip_array();
3505 for (
int y = 0; y < h; ++y) {
3506 uchar *begin = dst->data + y * dst->bytes_per_line;
3507 uchar *end = begin + dst->bytes_per_line;
3508 for (uchar *p = begin; p < end; ++p) {
3512 if (shift != 8 && p != begin) {
3513 if (dst->format == QImage::Format_Mono) {
3514 for (
int i = 0; i < shift; ++i) {
3516 p[-1] |= (*p & (128 >> i)) >> (7 - i);
3519 for (
int i = 0; i < shift; ++i) {
3521 p[-1] |= (*p & (1 << i)) << (7 - i);
3527 if (dst->format == QImage::Format_Mono)
3537
3538
3539QImage QImage::mirrored_helper(
bool horizontal,
bool vertical)
const
3544 if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
3548 QImage result(d->width, d->height, d->format);
3555 result.d->colortable = d->colortable;
3556 result.d->has_alpha_clut = d->has_alpha_clut;
3557 copyMetadata(result.d, d);
3559 do_mirror(result.d, d, horizontal, vertical);
3565
3566
3567void QImage::mirrored_inplace(
bool horizontal,
bool vertical)
3569 if (!d || (d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
3578 do_mirror(d, d, horizontal, vertical);
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3595
3596
3597
3598
3599
3600
3601
3602
3604static inline void rgbSwapped_generic(
int width,
int height,
const QImage *src, QImage *dst,
const QPixelLayout* layout)
3606 const RbSwapFunc func = layout->rbSwap;
3608 qWarning(
"Trying to rb-swap an image format where it doesn't make sense");
3614 for (
int i = 0; i < height; ++i) {
3615 uchar *q = dst->scanLine(i);
3616 const uchar *p = src->constScanLine(i);
3622
3623
3624QImage Q_TRACE_INSTRUMENT(qtgui) QImage::rgbSwapped_helper()
const
3629 Q_TRACE_SCOPE(QImage_rgbSwapped_helper);
3633 switch (d->format) {
3634 case Format_Invalid:
3639 case Format_Grayscale8:
3640 case Format_Grayscale16:
3643 case Format_MonoLSB:
3644 case Format_Indexed8:
3646 for (
int i = 0; i < res.d->colortable.size(); i++) {
3647 QRgb c = res.d->colortable.at(i);
3648 res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));
3651 case Format_RGBX8888:
3652 case Format_RGBA8888:
3653 case Format_RGBA8888_Premultiplied:
3654#if Q_BYTE_ORDER == Q_BIG_ENDIAN
3655 res = QImage(d->width, d->height, d->format);
3657 for (
int i = 0; i < d->height; i++) {
3658 uint *q = (uint*)res.scanLine(i);
3659 const uint *p = (
const uint*)constScanLine(i);
3660 const uint *end = p + d->width;
3663 *q = ((c << 16) & 0xff000000) | ((c >> 16) & 0xff00) | (c & 0x00ff00ff);
3675 case Format_ARGB32_Premultiplied:
3676 res = QImage(d->width, d->height, d->format);
3678 for (
int i = 0; i < d->height; i++) {
3679 uint *q = (uint*)res.scanLine(i);
3680 const uint *p = (
const uint*)constScanLine(i);
3681 const uint *end = p + d->width;
3684 *q = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);
3691 res = QImage(d->width, d->height, d->format);
3693 for (
int i = 0; i < d->height; i++) {
3694 ushort *q = (ushort*)res.scanLine(i);
3695 const ushort *p = (
const ushort*)constScanLine(i);
3696 const ushort *end = p + d->width;
3699 *q = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);
3706 res = QImage(d->width, d->height, d->format);
3708 rgbSwapped_generic(d->width, d->height,
this, &res, &qPixelLayouts[d->format]);
3711 copyMetadata(res.d, d);
3716
3717
3718void QImage::rgbSwapped_inplace()
3729 switch (d->format) {
3730 case Format_Invalid:
3735 case Format_Grayscale8:
3736 case Format_Grayscale16:
3739 case Format_MonoLSB:
3740 case Format_Indexed8:
3741 for (
int i = 0; i < d->colortable.size(); i++) {
3742 QRgb c = d->colortable.at(i);
3743 d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));
3746 case Format_RGBX8888:
3747 case Format_RGBA8888:
3748 case Format_RGBA8888_Premultiplied:
3749#if Q_BYTE_ORDER == Q_BIG_ENDIAN
3750 for (
int i = 0; i < d->height; i++) {
3751 uint *p = (uint*)scanLine(i);
3752 uint *end = p + d->width;
3755 *p = ((c << 16) & 0xff000000) | ((c >> 16) & 0xff00) | (c & 0x00ff00ff);
3766 case Format_ARGB32_Premultiplied:
3767 for (
int i = 0; i < d->height; i++) {
3768 uint *p = (uint*)scanLine(i);
3769 uint *end = p + d->width;
3772 *p = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);
3778 for (
int i = 0; i < d->height; i++) {
3779 ushort *p = (ushort*)scanLine(i);
3780 ushort *end = p + d->width;
3783 *p = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);
3789 case Format_A2BGR30_Premultiplied:
3791 case Format_A2RGB30_Premultiplied:
3792 for (
int i = 0; i < d->height; i++) {
3793 uint *p = (uint*)scanLine(i);
3794 uint *end = p + d->width;
3796 *p = qRgbSwapRgb30(*p);
3802 rgbSwapped_generic(d->width, d->height,
this,
this, &qPixelLayouts[d->format]);
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3826bool QImage::load(
const QString &fileName,
const char* format)
3828 *
this = QImageReader(fileName, format).read();
3833
3834
3835
3836
3837
3839bool QImage::load(QIODevice* device,
const char* format)
3841 *
this = QImageReader(device, format).read();
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3858bool QImage::loadFromData(QByteArrayView data,
const char *format)
3860 *
this = fromData(data, format);
3865
3866
3867
3868
3869
3870
3872bool QImage::loadFromData(
const uchar *buf,
int len,
const char *format)
3874 return loadFromData(QByteArrayView(buf, len), format);
3878
3879
3880
3881
3882
3883
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3900QImage QImage::fromData(QByteArrayView data,
const char *format)
3902 QByteArray a = QByteArray::fromRawData(data.constData(), data.size());
3905 b.open(QIODevice::ReadOnly);
3906 return QImageReader(&b, format).read();
3910
3911
3912
3913
3914
3915
3917QImage QImage::fromData(
const uchar *data,
int size,
const char *format)
3919 return fromData(QByteArrayView(data, size), format);
3923
3924
3925
3926
3927
3928
3929
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947bool QImage::save(
const QString &fileName,
const char *format,
int quality)
const
3951 QImageWriter writer(fileName, format);
3952 return d->doImageIO(
this, &writer, quality);
3956
3957
3958
3959
3960
3961
3962
3963
3964
3966bool QImage::save(QIODevice* device,
const char* format,
int quality)
const
3970 QImageWriter writer(device, format);
3971 return d->doImageIO(
this, &writer, quality);
3975
3977bool QImageData::doImageIO(
const QImage *image, QImageWriter *writer,
int quality)
const
3979 if (quality > 100 || quality < -1)
3980 qWarning(
"QImage::save: Quality out of range [-1, 100]");
3982 writer->setQuality(qMin(quality,100));
3983 const bool result = writer->write(*image);
3986 qWarning(
"QImage::save: failed to write image - %s", qPrintable(writer->errorString()));
3992
3993
3994#if !defined(QT_NO_DATASTREAM)
3996
3997
3998
3999
4000
4001
4002
4003
4004
4006QDataStream &operator<<(QDataStream &s,
const QImage &image)
4008 if (s.version() >= 5) {
4009 if (image.isNull()) {
4017 QImageWriter writer(s.device(), s.version() == 1 ?
"bmp" :
"png");
4018 writer.write(image);
4023
4024
4025
4026
4027
4028
4029
4030
4032QDataStream &operator>>(QDataStream &s, QImage &image)
4034 if (s.version() >= 5) {
4042 image = QImageReader(s.device(), s.version() == 1 ?
"bmp" :
"png").read();
4043 if (image.isNull() && s.version() >= 5)
4044 s.setStatus(QDataStream::ReadPastEnd);
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4064bool QImage::operator==(
const QImage & i)
const
4073 if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format || i.d->colorSpace != d->colorSpace)
4076 if (d->format != Format_RGB32) {
4077 if (d->format >= Format_ARGB32) {
4078 const int n = d->width * d->depth / 8;
4079 if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
4080 if (memcmp(bits(), i.bits(), d->nbytes))
4083 for (
int y = 0; y < d->height; ++y) {
4084 if (memcmp(scanLine(y), i.scanLine(y), n))
4089 const int w = width();
4090 const int h = height();
4091 const QList<QRgb> &colortable = d->colortable;
4092 const QList<QRgb> &icolortable = i.d->colortable;
4093 for (
int y=0; y<h; ++y) {
4094 for (
int x=0; x<w; ++x) {
4095 if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
4102 for(
int l = 0; l < d->height; l++) {
4104 const uint *p1 =
reinterpret_cast<
const uint*>(scanLine(l));
4105 const uint *p2 =
reinterpret_cast<
const uint*>(i.scanLine(l));
4107 if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff))
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4129bool QImage::operator!=(
const QImage & i)
const
4131 return !(*
this == i);
4138
4139
4140
4141
4142
4143
4144
4145int QImage::dotsPerMeterX()
const
4147 return d ? qRound(d->dpmx) : 0;
4151
4152
4153
4154
4155
4156
4157
4158int QImage::dotsPerMeterY()
const
4160 return d ? qRound(d->dpmy) : 0;
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175void QImage::setDotsPerMeterX(
int x)
4177 if (!d || !x || d->dpmx == x)
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197void QImage::setDotsPerMeterY(
int y)
4199 if (!d || !y || d->dpmy == y)
4208
4209
4210
4211
4212
4213
4214
4215QPoint QImage::offset()
const
4217 return d ? d->offset : QPoint();
4222
4223
4224
4225
4226
4227
4228
4229void QImage::setOffset(
const QPoint& p)
4231 if (!d || d->offset == p)
4240
4241
4242
4243
4244
4245
4246
4247QStringList QImage::textKeys()
const
4249 return d ? QStringList(d->text.keys()) : QStringList();
4253
4254
4255
4256
4257
4258
4259QString QImage::text(
const QString &key)
const
4265 return d->text.value(key);
4268 for (
auto it = d->text.begin(), end = d->text.end(); it != end; ++it)
4269 tmp += it.key() +
": "_L1 + it.value().simplified() +
"\n\n"_L1;
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299void QImage::setText(
const QString &key,
const QString &value)
4306 d->text.insert(key, value);
4310
4311
4312
4313
4314QPaintEngine *QImage::paintEngine()
const
4319 if (!d->paintEngine) {
4320 QPaintDevice *paintDevice =
const_cast<QImage *>(
this);
4321 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
4322 if (platformIntegration)
4323 d->paintEngine = platformIntegration->createImagePaintEngine(paintDevice);
4324 if (!d->paintEngine)
4325 d->paintEngine =
new QRasterPaintEngine(paintDevice);
4328 return d->paintEngine;
4333
4334
4335
4336
4337int QImage::metric(PaintDeviceMetric metric)
const
4350 return qRound(d->width * 1000 / d->dpmx);
4353 return qRound(d->height * 1000 / d->dpmy);
4356 return d->colortable.size();
4362 return qRound(d->dpmx * 0.0254);
4366 return qRound(d->dpmy * 0.0254);
4369 case PdmPhysicalDpiX:
4370 return qRound(d->dpmx * 0.0254);
4373 case PdmPhysicalDpiY:
4374 return qRound(d->dpmy * 0.0254);
4377 case PdmDevicePixelRatio:
4378 return d->devicePixelRatio;
4381 case PdmDevicePixelRatioScaled:
4382 return d->devicePixelRatio * QPaintDevice::devicePixelRatioFScale();
4385 case PdmDevicePixelRatioF_EncodedA:
4387 case PdmDevicePixelRatioF_EncodedB:
4388 return QPaintDevice::encodeMetricF(metric, d->devicePixelRatio);
4392 qWarning(
"QImage::metric(): Unhandled metric type %d", metric);
4401
4402
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4424#define IWX_MSB(b) if (trigx < maxws && trigy < maxhs) {
4425 if (*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4426 (1
<< (7
-((trigx>>12
)&7
))))
4433#define IWX_LSB(b) if (trigx < maxws && trigy < maxhs) {
4434 if (*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4435 (1
<< ((trigx>>12
)&7
)))
4442#define IWX_PIX(b) if (trigx < maxws && trigy < maxhs) {
4443 if ((*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4444 (1
<< (7
-((trigx>>12
)&7
)))) == 0
)
4450bool qt_xForm_helper(
const QTransform &trueMat,
int xoffset,
int type,
int depth,
4451 uchar *dptr, qsizetype dbpl,
int p_inc,
int dHeight,
4452 const uchar *sptr, qsizetype sbpl,
int sWidth,
int sHeight)
4454 int m11 =
int(trueMat.m11()*4096.0);
4455 int m12 =
int(trueMat.m12()*4096.0);
4456 int m21 =
int(trueMat.m21()*4096.0);
4457 int m22 =
int(trueMat.m22()*4096.0);
4458 int dx = qRound(trueMat.dx()*4096.0);
4459 int dy = qRound(trueMat.dy()*4096.0);
4461 int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2;
4462 int m22ydy = dy + (m12 + m22) / 2;
4465 uint maxws = sWidth<<12;
4466 uint maxhs = sHeight<<12;
4468 for (
int y=0; y<dHeight; y++) {
4471 uchar *maxp = dptr + dbpl;
4475 while (dptr < maxp) {
4476 if (trigx < maxws && trigy < maxhs)
4477 *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12));
4485 while (dptr < maxp) {
4486 if (trigx < maxws && trigy < maxhs)
4487 *((ushort*)dptr) = *((
const ushort *)(sptr+sbpl*(trigy>>12) +
4497 while (dptr < maxp) {
4498 if (trigx < maxws && trigy < maxhs) {
4499 const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3);
4511 while (dptr < maxp) {
4512 if (trigx < maxws && trigy < maxhs)
4513 *((uint*)dptr) = *((
const uint *)(sptr+sbpl*(trigy>>12) +
4527 case QT_XFORM_TYPE_MSBFIRST:
4528 while (dptr < maxp) {
4540 case QT_XFORM_TYPE_LSBFIRST:
4541 while (dptr < maxp) {
4566
4567
4568
4569
4570
4571
4572qint64 QImage::cacheKey()
const
4577 return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
4581
4582
4583
4584
4585
4586
4588bool QImage::isDetached()
const
4590 return d && d->ref.loadRelaxed() == 1;
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4613void QImage::setAlphaChannel(
const QImage &alphaChannel)
4615 if (!d || alphaChannel.isNull())
4618 if (d->paintEngine && d->paintEngine->isActive()) {
4619 qWarning(
"QImage::setAlphaChannel: "
4620 "Unable to set alpha channel while image is being painted on");
4624 const Format alphaFormat = qt_alphaVersionForPainting(d->format);
4625 if (d->format == alphaFormat)
4628 convertTo(alphaFormat);
4634 if (alphaChannel.format() == QImage::Format_Alpha8 || (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()))
4635 sourceImage = alphaChannel;
4637 sourceImage = alphaChannel.convertToFormat(QImage::Format_Grayscale8);
4638 if (!sourceImage.reinterpretAsFormat(QImage::Format_Alpha8))
4641 QPainter painter(
this);
4642 if (sourceImage.size() != size())
4643 painter.setRenderHint(QPainter::SmoothPixmapTransform);
4644 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
4645 painter.drawImage(rect(), sourceImage);
4649
4650
4651
4652
4653
4654bool QImage::hasAlphaChannel()
const
4658 const QPixelFormat format = pixelFormat();
4659 if (format.alphaUsage() == QPixelFormat::UsesAlpha)
4661 if (format.colorModel() == QPixelFormat::Indexed)
4662 return d->has_alpha_clut;
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676int QImage::bitPlaneCount()
const
4681 switch (d->format) {
4682 case QImage::Format_Invalid:
4684 case QImage::Format_BGR30:
4685 case QImage::Format_RGB30:
4688 case QImage::Format_RGB32:
4689 case QImage::Format_RGBX8888:
4692 case QImage::Format_RGB666:
4695 case QImage::Format_RGB555:
4698 case QImage::Format_ARGB8555_Premultiplied:
4701 case QImage::Format_RGB444:
4704 case QImage::Format_RGBX64:
4705 case QImage::Format_RGBX16FPx4:
4708 case QImage::Format_RGBX32FPx4:
4712 bpc = qt_depthForFormat(d->format);
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729QImage QImage::smoothScaled(
int w,
int h)
const
4732 switch (src.format()) {
4733 case QImage::Format_RGB32:
4734 case QImage::Format_ARGB32_Premultiplied:
4735#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
4736 case QImage::Format_RGBX8888:
4738 case QImage::Format_RGBA8888_Premultiplied:
4739#if QT_CONFIG(raster_64bit)
4740 case QImage::Format_RGBX64:
4741 case QImage::Format_RGBA64_Premultiplied:
4743 case QImage::Format_RGBA64:
4744 case QImage::Format_Grayscale16:
4745 src.convertTo(QImage::Format_RGBA64_Premultiplied);
4748#if QT_CONFIG(raster_fp)
4749 case QImage::Format_RGBX32FPx4:
4750 case QImage::Format_RGBA32FPx4_Premultiplied:
4752 case QImage::Format_RGBX16FPx4:
4753 src.convertTo(QImage::Format_RGBX32FPx4);
4755 case QImage::Format_RGBA16FPx4:
4756 case QImage::Format_RGBA16FPx4_Premultiplied:
4757 case QImage::Format_RGBA32FPx4:
4758 src.convertTo(QImage::Format_RGBA32FPx4_Premultiplied);
4761 case QImage::Format_CMYK8888:
4764 if (src.hasAlphaChannel())
4765 src.convertTo(QImage::Format_ARGB32_Premultiplied);
4767 src.convertTo(QImage::Format_RGB32);
4769 src = qSmoothScaleImage(src, w, h);
4771 copyMetadata(src.d, d);
4775static QImage rotated90(
const QImage &image)
4777 QImage out(image.height(), image.width(), image.format());
4780 copyMetadata(QImageData::get(out), QImageData::get(image));
4781 if (image.colorCount() > 0)
4782 out.setColorTable(image.colorTable());
4783 int w = image.width();
4784 int h = image.height();
4785 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][2];
4787 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4789 for (
int y=0; y<h; ++y) {
4790 if (image.colorCount())
4791 for (
int x=0; x<w; ++x)
4792 out.setPixel(h-y-1, x, image.pixelIndex(x, y));
4794 for (
int x=0; x<w; ++x)
4795 out.setPixel(h-y-1, x, image.pixel(x, y));
4801static QImage rotated180(
const QImage &image)
4803 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][1];
4805 return image.flipped(Qt::Horizontal | Qt::Vertical);
4807 QImage out(image.width(), image.height(), image.format());
4810 copyMetadata(QImageData::get(out), QImageData::get(image));
4811 if (image.colorCount() > 0)
4812 out.setColorTable(image.colorTable());
4813 int w = image.width();
4814 int h = image.height();
4815 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4819static QImage rotated270(
const QImage &image)
4821 QImage out(image.height(), image.width(), image.format());
4824 copyMetadata(QImageData::get(out), QImageData::get(image));
4825 if (image.colorCount() > 0)
4826 out.setColorTable(image.colorTable());
4827 int w = image.width();
4828 int h = image.height();
4829 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][0];
4831 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4833 for (
int y=0; y<h; ++y) {
4834 if (image.colorCount())
4835 for (
int x=0; x<w; ++x)
4836 out.setPixel(y, w-x-1, image.pixelIndex(x, y));
4838 for (
int x=0; x<w; ++x)
4839 out.setPixel(y, w-x-1, image.pixel(x, y));
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4869QImage Q_TRACE_INSTRUMENT(qtgui) QImage::transformed(
const QTransform &matrix, Qt::TransformationMode mode )
const
4874 Q_TRACE_PARAM_REPLACE(
const QTransform &,
double[9]);
4875 Q_TRACE_SCOPE(QImage_transformed, QList<
double>({matrix.m11(), matrix.m12(), matrix.m13(),
4876 matrix.m21(), matrix.m22(), matrix.m23(),
4877 matrix.m31(), matrix.m32(), matrix.m33()}).data(), mode);
4880 const int ws = width();
4881 const int hs = height();
4888 QTransform mat = trueMatrix(matrix, ws, hs);
4889 bool complex_xform =
false;
4890 bool scale_xform =
false;
4891 bool nonpaintable_scale_xform =
false;
4892 if (mat.type() <= QTransform::TxScale) {
4893 if (mat.type() == QTransform::TxNone)
4895 else if (mat.m11() == -1. && mat.m22() == -1.)
4896 return rotated180(*
this);
4898 hd = qRound(qAbs(mat.m22()) * hs);
4899 wd = qRound(qAbs(mat.m11()) * ws);
4903 if (hd * 2 < hs || wd * 2 < ws)
4904 nonpaintable_scale_xform =
true;
4906 if (format() == QImage::Format_CMYK8888)
4907 nonpaintable_scale_xform =
true;
4909 if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) {
4910 if (mat.m12() == 1. && mat.m21() == -1.)
4911 return rotated90(*
this);
4912 else if (mat.m12() == -1. && mat.m21() == 1.)
4913 return rotated270(*
this);
4916 QPolygonF a(QRectF(0, 0, ws, hs));
4918 QRect r = a.boundingRect().toAlignedRect();
4921 complex_xform =
true;
4924 if (wd == 0 || hd == 0)
4927 if (scale_xform && mode == Qt::SmoothTransformation) {
4929 case QImage::Format_RGB32:
4930 case QImage::Format_ARGB32_Premultiplied:
4931#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
4932 case QImage::Format_RGBX8888:
4934 case QImage::Format_RGBA8888_Premultiplied:
4935#if QT_CONFIG(raster_64bit)
4936 case QImage::Format_RGBX64:
4937 case QImage::Format_RGBA64_Premultiplied:
4939 case QImage::Format_CMYK8888:
4941 if (mat.m11() > 0.0F && mat.m22() > 0.0F)
4942 return smoothScaled(wd, hd);
4948 if (nonpaintable_scale_xform
4949#if QT_CONFIG(qtgui_threadpool)
4950 || (ws * hs) >= (1<<20)
4954 if (mat.m11() < 0.0F && mat.m22() < 0.0F) {
4955 scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal | Qt::Vertical);
4956 }
else if (mat.m11() < 0.0F) {
4957 scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal);
4958 }
else if (mat.m22() < 0.0F) {
4959 scaledImage = smoothScaled(wd, hd).flipped(Qt::Vertical);
4961 scaledImage = smoothScaled(wd, hd);
4965 case QImage::Format_Mono:
4966 case QImage::Format_MonoLSB:
4967 case QImage::Format_Indexed8:
4970 return scaledImage.convertToFormat(format());
4977 qsizetype sbpl = bytesPerLine();
4978 const uchar *sptr = bits();
4980 QImage::Format target_format = d->format;
4982 if (complex_xform || mode == Qt::SmoothTransformation) {
4983 if (d->format < QImage::Format_RGB32 || (!hasAlphaChannel() && complex_xform)) {
4984 target_format = qt_alphaVersion(d->format);
4988 QImage dImage(wd, hd, target_format);
4991 if (target_format == QImage::Format_MonoLSB
4992 || target_format == QImage::Format_Mono
4993 || target_format == QImage::Format_Indexed8) {
4994 dImage.d->colortable = d->colortable;
4995 dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform;
4999 if (target_format == QImage::Format_Indexed8) {
5000 if (dImage.d->colortable.size() < 256) {
5002 dImage.d->colortable.append(0x0);
5003 memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.d->nbytes);
5005 memset(dImage.bits(), 0, dImage.d->nbytes);
5008 memset(dImage.bits(), 0x00, dImage.d->nbytes);
5010 if (target_format >= QImage::Format_RGB32 && target_format != QImage::Format_CMYK8888) {
5012 QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *
this;
5014 && (d->format == QImage::Format_MonoLSB
5015 || d->format == QImage::Format_Mono
5016 || d->format == QImage::Format_Indexed8)) {
5017 sImage.d->colortable = d->colortable;
5018 sImage.d->has_alpha_clut = d->has_alpha_clut;
5021 Q_ASSERT(sImage.devicePixelRatio() == 1);
5022 Q_ASSERT(sImage.devicePixelRatio() == dImage.devicePixelRatio());
5024 QPainter p(&dImage);
5025 if (mode == Qt::SmoothTransformation) {
5026 p.setRenderHint(QPainter::Antialiasing);
5027 p.setRenderHint(QPainter::SmoothPixmapTransform);
5029 p.setTransform(mat);
5030 p.drawImage(QPoint(0, 0), sImage);
5033 mat = mat.inverted(&invertible);
5038 int type = format() == Format_Mono ? QT_XFORM_TYPE_MSBFIRST : QT_XFORM_TYPE_LSBFIRST;
5039 qsizetype dbpl = dImage.bytesPerLine();
5040 qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs);
5042 copyMetadata(dImage.d, d);
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5068QTransform QImage::trueMatrix(
const QTransform &matrix,
int w,
int h)
5070 const QRectF rect(0, 0, w, h);
5071 const QRect mapped = matrix.mapRect(rect).toAlignedRect();
5072 const QPoint delta = mapped.topLeft();
5073 return matrix * QTransform().translate(-delta.x(), -delta.y());
5077
5078
5079
5080
5081
5082
5083void QImage::setColorSpace(
const QColorSpace &colorSpace)
5087 if (d->colorSpace == colorSpace)
5089 if (colorSpace.isValid() && !qt_compatibleColorModelSource(pixelFormat().colorModel(), colorSpace.colorModel()))
5092 detachMetadata(
false);
5094 d->colorSpace = colorSpace;
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109void QImage::convertToColorSpace(
const QColorSpace &colorSpace)
5111 if (!d || !d->colorSpace.isValid())
5113 if (!colorSpace.isValidTarget()) {
5114 qWarning() <<
"QImage::convertToColorSpace: Output colorspace is not valid";
5117 if (d->colorSpace == colorSpace)
5119 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(),
5120 colorSpace.colorModel(), colorSpace.transformModel())) {
5121 *
this = convertedToColorSpace(colorSpace);
5124 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace));
5125 if (d->ref.loadRelaxed() != 1)
5126 detachMetadata(
false);
5127 d->colorSpace = colorSpace;
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143void QImage::convertToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags)
5145 if (!d || !d->colorSpace.isValid())
5147 if (!colorSpace.isValidTarget()) {
5148 qWarning() <<
"QImage::convertToColorSpace: Output colorspace is not valid";
5151 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5152 colorSpace.colorModel(), colorSpace.transformModel())) {
5153 qWarning() <<
"QImage::convertToColorSpace: Color space is not compatible with format";
5157 if (d->colorSpace == colorSpace)
5158 return convertTo(format, flags);
5159 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5160 d->colorSpace = colorSpace;
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace)
const
5179 if (!d || !d->colorSpace.isValid())
5181 if (!colorSpace.isValidTarget()) {
5182 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5185 if (d->colorSpace == colorSpace)
5187 QImage image = colorTransformed(d->colorSpace.transformationToColorSpace(colorSpace));
5188 image.setColorSpace(colorSpace);
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags)
const &
5208 if (!d || !d->colorSpace.isValid())
5210 if (!colorSpace.isValidTarget()) {
5211 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5214 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5215 colorSpace.colorModel(), colorSpace.transformModel())) {
5216 qWarning() <<
"QImage::convertedToColorSpace: Color space is not compatible with format";
5219 if (d->colorSpace == colorSpace)
5220 return convertedTo(format, flags);
5221 QImage image = colorTransformed(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5222 image.setColorSpace(colorSpace);
5226QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags) &&
5228 if (!d || !d->colorSpace.isValid())
5230 if (!colorSpace.isValidTarget()) {
5231 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5234 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5235 colorSpace.colorModel(), colorSpace.transformModel())) {
5236 qWarning() <<
"QImage::convertedToColorSpace: Color space is not compatible with format";
5239 if (d->colorSpace == colorSpace)
5240 return convertedTo(format, flags);
5241 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5242 return std::move(*
this);
5246
5247
5248
5249
5250QColorSpace QImage::colorSpace()
const
5253 return QColorSpace();
5254 return d->colorSpace;
5258
5259
5260
5261
5262void QImage::applyColorTransform(
const QColorTransform &transform)
5264 if (transform.isIdentity())
5267 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), QColorTransformPrivate::get(transform)->colorSpaceIn->colorModel) ||
5268 !qt_compatibleColorModelTarget(pixelFormat().colorModel(), QColorTransformPrivate::get(transform)->colorSpaceOut->colorModel,
5269 QColorTransformPrivate::get(transform)->colorSpaceOut->transformModel)) {
5270 qWarning() <<
"QImage::applyColorTransform can not apply format switching transform without switching format";
5277 if (pixelFormat().colorModel() == QPixelFormat::Indexed) {
5278 for (
int i = 0; i < d->colortable.size(); ++i)
5279 d->colortable[i] = transform.map(d->colortable[i]);
5282 QImage::Format oldFormat = format();
5283 if (qt_fpColorPrecision(oldFormat)) {
5284 if (oldFormat != QImage::Format_RGBX32FPx4 && oldFormat != QImage::Format_RGBA32FPx4
5285 && oldFormat != QImage::Format_RGBA32FPx4_Premultiplied)
5286 convertTo(QImage::Format_RGBA32FPx4);
5287 }
else if (depth() > 32) {
5288 if (oldFormat != QImage::Format_RGBX64 && oldFormat != QImage::Format_RGBA64
5289 && oldFormat != QImage::Format_RGBA64_Premultiplied)
5290 convertTo(QImage::Format_RGBA64);
5291 }
else if (oldFormat != QImage::Format_ARGB32 && oldFormat != QImage::Format_RGB32
5292 && oldFormat != QImage::Format_ARGB32_Premultiplied && oldFormat != QImage::Format_CMYK8888
5293 && oldFormat != QImage::Format_Grayscale8 && oldFormat != QImage::Format_Grayscale16) {
5294 if (hasAlphaChannel())
5295 convertTo(QImage::Format_ARGB32);
5297 convertTo(QImage::Format_RGB32);
5300 QColorTransformPrivate::TransformFlags flags = QColorTransformPrivate::Unpremultiplied;
5302 case Format_ARGB32_Premultiplied:
5303 case Format_RGBA64_Premultiplied:
5304 case Format_RGBA32FPx4_Premultiplied:
5305 flags = QColorTransformPrivate::Premultiplied;
5307 case Format_Grayscale8:
5308 case Format_Grayscale16:
5310 case Format_CMYK8888:
5312 case Format_RGBX32FPx4:
5313 flags = QColorTransformPrivate::InputOpaque;
5317 case Format_RGBA32FPx4:
5323 std::function<
void(
int,
int)> transformSegment;
5325 if (format() == Format_Grayscale8) {
5326 transformSegment = [&](
int yStart,
int yEnd) {
5327 for (
int y = yStart; y < yEnd; ++y) {
5328 uint8_t *scanline =
reinterpret_cast<uint8_t *>(d->data + y * d->bytes_per_line);
5329 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5332 }
else if (format() == Format_Grayscale16) {
5333 transformSegment = [&](
int yStart,
int yEnd) {
5334 for (
int y = yStart; y < yEnd; ++y) {
5335 uint16_t *scanline =
reinterpret_cast<uint16_t *>(d->data + y * d->bytes_per_line);
5336 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5339 }
else if (qt_fpColorPrecision(format())) {
5340 transformSegment = [&](
int yStart,
int yEnd) {
5341 for (
int y = yStart; y < yEnd; ++y) {
5342 QRgbaFloat32 *scanline =
reinterpret_cast<QRgbaFloat32 *>(d->data + y * d->bytes_per_line);
5343 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5346 }
else if (depth() > 32) {
5347 transformSegment = [&](
int yStart,
int yEnd) {
5348 for (
int y = yStart; y < yEnd; ++y) {
5349 QRgba64 *scanline =
reinterpret_cast<QRgba64 *>(d->data + y * d->bytes_per_line);
5350 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5353 }
else if (oldFormat == QImage::Format_CMYK8888) {
5354 transformSegment = [&](
int yStart,
int yEnd) {
5355 for (
int y = yStart; y < yEnd; ++y) {
5356 QCmyk32 *scanline =
reinterpret_cast<QCmyk32 *>(d->data + y * d->bytes_per_line);
5357 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5361 transformSegment = [&](
int yStart,
int yEnd) {
5362 for (
int y = yStart; y < yEnd; ++y) {
5363 QRgb *scanline =
reinterpret_cast<QRgb *>(d->data + y * d->bytes_per_line);
5364 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5369#if QT_CONFIG(qtgui_threadpool)
5370 int segments = (qsizetype(width()) * height()) >> 16;
5371 segments = std::min(segments, height());
5372 QThreadPool *threadPool = QGuiApplicationPrivate::qtGuiThreadPool();
5373 if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {
5374 QLatch latch(segments);
5376 for (
int i = 0; i < segments; ++i) {
5377 int yn = (height() - y) / (segments - i);
5378 threadPool->start([&, y, yn]() {
5379 transformSegment(y, y + yn);
5387 transformSegment(0, height());
5389 if (oldFormat != format())
5390 *
this = std::move(*
this).convertToFormat(oldFormat);
5394
5395
5396
5397
5398
5399
5400
5401void QImage::applyColorTransform(
const QColorTransform &transform, QImage::Format toFormat, Qt::ImageConversionFlags flags)
5405 if (transform.isIdentity())
5406 return convertTo(toFormat, flags);
5408 *
this = colorTransformed(transform, toFormat, flags);
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423QImage QImage::colorTransformed(
const QColorTransform &transform)
const &
5427 if (transform.isIdentity())
5430 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5431 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5432 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5433 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5436 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5438 switch (outColorSpace->colorModel) {
5439 case QColorSpace::ColorModel::Rgb:
5440 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_RGBX64 : QImage::Format_RGB32);
5441 case QColorSpace::ColorModel::Gray:
5442 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_Grayscale16 : QImage::Format_Grayscale8);
5443 case QColorSpace::ColorModel::Cmyk:
5444 return colorTransformed(transform, QImage::Format_CMYK8888);
5445 case QColorSpace::ColorModel::Undefined:
5451 QImage image = copy();
5452 image.applyColorTransform(transform);
5456static bool isRgb32Data(QImage::Format f)
5459 case QImage::Format_RGB32:
5460 case QImage::Format_ARGB32:
5461 case QImage::Format_ARGB32_Premultiplied:
5469static bool isRgb64Data(QImage::Format f)
5472 case QImage::Format_RGBX64:
5473 case QImage::Format_RGBA64:
5474 case QImage::Format_RGBA64_Premultiplied:
5482static bool isRgb32fpx4Data(QImage::Format f)
5485 case QImage::Format_RGBX32FPx4:
5486 case QImage::Format_RGBA32FPx4:
5487 case QImage::Format_RGBA32FPx4_Premultiplied:
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508QImage QImage::colorTransformed(
const QColorTransform &transform, QImage::Format toFormat, Qt::ImageConversionFlags flags)
const &
5512 if (toFormat == QImage::Format_Invalid)
5513 toFormat = format();
5514 if (transform.isIdentity())
5515 return convertedTo(toFormat, flags);
5517 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5518 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5519 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5520 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5523 if (!qt_compatibleColorModelTarget(toPixelFormat(toFormat).colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5524 qWarning() <<
"QImage::colorTransformed: Invalid output color space for transform";
5528 QImage fromImage = *
this;
5530 QImage::Format tmpFormat = toFormat;
5532 case QImage::Format_RGB32:
5533 case QImage::Format_ARGB32:
5534 case QImage::Format_ARGB32_Premultiplied:
5535 case QImage::Format_RGBX32FPx4:
5536 case QImage::Format_RGBA32FPx4:
5537 case QImage::Format_RGBA32FPx4_Premultiplied:
5538 case QImage::Format_RGBX64:
5539 case QImage::Format_RGBA64:
5540 case QImage::Format_RGBA64_Premultiplied:
5541 case QImage::Format_Grayscale8:
5542 case QImage::Format_Grayscale16:
5543 case QImage::Format_CMYK8888:
5546 case QImage::Format_RGB16:
5547 case QImage::Format_RGB444:
5548 case QImage::Format_RGB555:
5549 case QImage::Format_RGB666:
5550 case QImage::Format_RGB888:
5551 case QImage::Format_BGR888:
5552 case QImage::Format_RGBX8888:
5553 tmpFormat = QImage::Format_RGB32;
5555 case QImage::Format_Mono:
5556 case QImage::Format_MonoLSB:
5557 case QImage::Format_Indexed8:
5558 case QImage::Format_ARGB8565_Premultiplied:
5559 case QImage::Format_ARGB6666_Premultiplied:
5560 case QImage::Format_ARGB8555_Premultiplied:
5561 case QImage::Format_ARGB4444_Premultiplied:
5562 case QImage::Format_RGBA8888:
5563 case QImage::Format_RGBA8888_Premultiplied:
5564 tmpFormat = QImage::Format_ARGB32;
5566 case QImage::Format_BGR30:
5567 case QImage::Format_RGB30:
5568 tmpFormat = QImage::Format_RGBX64;
5570 case QImage::Format_A2BGR30_Premultiplied:
5571 case QImage::Format_A2RGB30_Premultiplied:
5572 tmpFormat = QImage::Format_RGBA64;
5574 case QImage::Format_RGBX16FPx4:
5575 case QImage::Format_RGBA16FPx4:
5576 case QImage::Format_RGBA16FPx4_Premultiplied:
5577 tmpFormat = QImage::Format_RGBA32FPx4;
5579 case QImage::Format_Alpha8:
5580 return convertedTo(QImage::Format_Alpha8);
5581 case QImage::Format_Invalid:
5582 case QImage::NImageFormats:
5586 QColorSpace::ColorModel inColorData = qt_csColorData(pixelFormat().colorModel());
5587 QColorSpace::ColorModel outColorData = qt_csColorData(toPixelFormat(toFormat).colorModel());
5589 if (inColorData != outColorData) {
5590 if (fromImage.format() == QImage::Format_Grayscale8 && outColorData == QColorSpace::ColorModel::Rgb)
5591 tmpFormat = QImage::Format_RGB32;
5592 else if (tmpFormat == QImage::Format_Grayscale8 && qt_highColorPrecision(fromImage.format()))
5593 tmpFormat = QImage::Format_Grayscale16;
5594 else if (fromImage.format() == QImage::Format_Grayscale16 && outColorData == QColorSpace::ColorModel::Rgb)
5595 tmpFormat = QImage::Format_RGBX64;
5597 if (tmpFormat == QImage::Format_Grayscale8 && fromImage.format() == QImage::Format_Grayscale16)
5598 tmpFormat = QImage::Format_Grayscale16;
5599 else if (qt_fpColorPrecision(fromImage.format()) && !qt_fpColorPrecision(tmpFormat))
5600 tmpFormat = QImage::Format_RGBA32FPx4;
5601 else if (isRgb32Data(tmpFormat) && qt_highColorPrecision(fromImage.format(),
true))
5602 tmpFormat = QImage::Format_RGBA64;
5605 QImage toImage(size(), tmpFormat);
5606 copyMetadata(&toImage, *
this);
5608 std::function<
void(
int,
int)> transformSegment;
5609 QColorTransformPrivate::TransformFlags transFlags = QColorTransformPrivate::Unpremultiplied;
5611 if (inColorData != outColorData) {
5613 if (inColorData == QColorSpace::ColorModel::Gray && outColorData == QColorSpace::ColorModel::Rgb) {
5615 if (format() == QImage::Format_Grayscale8) {
5616 transformSegment = [&](
int yStart,
int yEnd) {
5617 for (
int y = yStart; y < yEnd; ++y) {
5618 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(d->data + y * d->bytes_per_line);
5619 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5620 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5624 transformSegment = [&](
int yStart,
int yEnd) {
5625 for (
int y = yStart; y < yEnd; ++y) {
5626 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(d->data + y * d->bytes_per_line);
5627 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5628 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5632 }
else if (inColorData == QColorSpace::ColorModel::Gray && outColorData == QColorSpace::ColorModel::Cmyk) {
5634 if (format() == QImage::Format_Grayscale8) {
5635 transformSegment = [&](
int yStart,
int yEnd) {
5636 for (
int y = yStart; y < yEnd; ++y) {
5637 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(d->data + y * d->bytes_per_line);
5638 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5639 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5643 transformSegment = [&](
int yStart,
int yEnd) {
5644 for (
int y = yStart; y < yEnd; ++y) {
5645 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(d->data + y * d->bytes_per_line);
5646 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5647 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5651 }
else if (inColorData == QColorSpace::ColorModel::Rgb && outColorData == QColorSpace::ColorModel::Gray) {
5653 if (tmpFormat == QImage::Format_Grayscale8) {
5654 fromImage.convertTo(QImage::Format_RGB32);
5655 transformSegment = [&](
int yStart,
int yEnd) {
5656 for (
int y = yStart; y < yEnd; ++y) {
5657 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5658 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5659 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5663 fromImage.convertTo(QImage::Format_RGBX64);
5664 transformSegment = [&](
int yStart,
int yEnd) {
5665 for (
int y = yStart; y < yEnd; ++y) {
5666 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5667 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5668 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5672 }
else if (inColorData == QColorSpace::ColorModel::Cmyk && outColorData == QColorSpace::ColorModel::Gray) {
5674 if (tmpFormat == QImage::Format_Grayscale8) {
5675 transformSegment = [&](
int yStart,
int yEnd) {
5676 for (
int y = yStart; y < yEnd; ++y) {
5677 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5678 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5679 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5683 transformSegment = [&](
int yStart,
int yEnd) {
5684 for (
int y = yStart; y < yEnd; ++y) {
5685 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5686 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5687 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5691 }
else if (inColorData == QColorSpace::ColorModel::Cmyk && outColorData == QColorSpace::ColorModel::Rgb) {
5693 if (isRgb32Data(tmpFormat) ) {
5694 transformSegment = [&](
int yStart,
int yEnd) {
5695 for (
int y = yStart; y < yEnd; ++y) {
5696 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5697 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5698 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5701 }
else if (isRgb64Data(tmpFormat)) {
5702 transformSegment = [&](
int yStart,
int yEnd) {
5703 for (
int y = yStart; y < yEnd; ++y) {
5704 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5705 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5706 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5710 Q_ASSERT(isRgb32fpx4Data(tmpFormat));
5711 transformSegment = [&](
int yStart,
int yEnd) {
5712 for (
int y = yStart; y < yEnd; ++y) {
5713 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5714 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5715 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5719 }
else if (inColorData == QColorSpace::ColorModel::Rgb && outColorData == QColorSpace::ColorModel::Cmyk) {
5721 if (!fromImage.hasAlphaChannel())
5722 transFlags = QColorTransformPrivate::InputOpaque;
5723 else if (qPixelLayouts[fromImage.format()].premultiplied)
5724 transFlags = QColorTransformPrivate::Premultiplied;
5725 if (isRgb32Data(fromImage.format()) ) {
5726 transformSegment = [&](
int yStart,
int yEnd) {
5727 for (
int y = yStart; y < yEnd; ++y) {
5728 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5729 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5730 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5733 }
else if (isRgb64Data(fromImage.format())) {
5734 transformSegment = [&](
int yStart,
int yEnd) {
5735 for (
int y = yStart; y < yEnd; ++y) {
5736 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5737 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5738 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5742 Q_ASSERT(isRgb32fpx4Data(fromImage.format()));
5743 transformSegment = [&](
int yStart,
int yEnd) {
5744 for (
int y = yStart; y < yEnd; ++y) {
5745 const QRgbaFloat32 *in_scanline =
reinterpret_cast<
const QRgbaFloat32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5746 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5747 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5756 if (pixelFormat().colorModel() == QPixelFormat::Indexed) {
5757 for (
int i = 0; i < d->colortable.size(); ++i)
5758 fromImage.d->colortable[i] = transform.map(d->colortable[i]);
5759 return fromImage.convertedTo(toFormat, flags);
5762 QImage::Format oldFormat = format();
5763 if (qt_fpColorPrecision(oldFormat)) {
5764 if (oldFormat != QImage::Format_RGBX32FPx4 && oldFormat != QImage::Format_RGBA32FPx4
5765 && oldFormat != QImage::Format_RGBA32FPx4_Premultiplied)
5766 fromImage.convertTo(QImage::Format_RGBA32FPx4);
5767 }
else if (qt_highColorPrecision(oldFormat,
true)) {
5768 if (oldFormat != QImage::Format_RGBX64 && oldFormat != QImage::Format_RGBA64
5769 && oldFormat != QImage::Format_RGBA64_Premultiplied && oldFormat != QImage::Format_Grayscale16)
5770 fromImage.convertTo(QImage::Format_RGBA64);
5771 }
else if (oldFormat != QImage::Format_ARGB32 && oldFormat != QImage::Format_RGB32
5772 && oldFormat != QImage::Format_ARGB32_Premultiplied && oldFormat != QImage::Format_CMYK8888
5773 && oldFormat != QImage::Format_Grayscale8 && oldFormat != QImage::Format_Grayscale16) {
5774 if (hasAlphaChannel())
5775 fromImage.convertTo(QImage::Format_ARGB32);
5777 fromImage.convertTo(QImage::Format_RGB32);
5780 if (!fromImage.hasAlphaChannel())
5781 transFlags = QColorTransformPrivate::InputOpaque;
5782 else if (qPixelLayouts[fromImage.format()].premultiplied)
5783 transFlags = QColorTransformPrivate::Premultiplied;
5785 if (fromImage.format() == Format_Grayscale8) {
5786 transformSegment = [&](
int yStart,
int yEnd) {
5787 for (
int y = yStart; y < yEnd; ++y) {
5788 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5789 if (tmpFormat == Format_Grayscale8) {
5790 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5791 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5793 Q_ASSERT(tmpFormat == Format_Grayscale16);
5794 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5795 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5799 }
else if (fromImage.format() == Format_Grayscale16) {
5800 transformSegment = [&](
int yStart,
int yEnd) {
5801 for (
int y = yStart; y < yEnd; ++y) {
5802 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5803 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5804 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5807 }
else if (fromImage.format() == Format_CMYK8888) {
5808 Q_ASSERT(tmpFormat == Format_CMYK8888);
5809 transformSegment = [&](
int yStart,
int yEnd) {
5810 for (
int y = yStart; y < yEnd; ++y) {
5811 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5812 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5813 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5816 }
else if (isRgb32fpx4Data(fromImage.format())) {
5817 Q_ASSERT(isRgb32fpx4Data(tmpFormat));
5818 transformSegment = [&](
int yStart,
int yEnd) {
5819 for (
int y = yStart; y < yEnd; ++y) {
5820 const QRgbaFloat32 *in_scanline =
reinterpret_cast<
const QRgbaFloat32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5821 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5822 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5825 }
else if (isRgb64Data(fromImage.format())) {
5826 transformSegment = [&](
int yStart,
int yEnd) {
5827 for (
int y = yStart; y < yEnd; ++y) {
5828 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5829 if (isRgb32fpx4Data(tmpFormat)) {
5830 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5831 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5833 Q_ASSERT(isRgb64Data(tmpFormat));
5834 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5835 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5840 transformSegment = [&](
int yStart,
int yEnd) {
5841 for (
int y = yStart; y < yEnd; ++y) {
5842 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5843 if (isRgb32fpx4Data(tmpFormat)) {
5844 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5845 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5846 }
else if (isRgb64Data(tmpFormat)) {
5847 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5848 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5850 Q_ASSERT(isRgb32Data(tmpFormat));
5851 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5852 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5859#if QT_CONFIG(qtgui_threadpool)
5860 int segments = (qsizetype(width()) * height()) >> 16;
5861 segments = std::min(segments, height());
5862 QThreadPool *threadPool = QGuiApplicationPrivate::qtGuiThreadPool();
5863 if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {
5864 QLatch latch(segments);
5866 for (
int i = 0; i < segments; ++i) {
5867 int yn = (height() - y) / (segments - i);
5868 threadPool->start([&, y, yn]() {
5869 transformSegment(y, y + yn);
5877 transformSegment(0, height());
5879 if (tmpFormat != toFormat)
5880 toImage.convertTo(toFormat);
5886
5887
5888
5889
5890
5891
5892
5893QImage QImage::colorTransformed(
const QColorTransform &transform) &&
5898 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5899 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5900 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5901 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5904 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5906 switch (outColorSpace->colorModel) {
5907 case QColorSpace::ColorModel::Rgb:
5908 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_RGBX64 : QImage::Format_RGB32);
5909 case QColorSpace::ColorModel::Gray:
5910 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_Grayscale16 : QImage::Format_Grayscale8);
5911 case QColorSpace::ColorModel::Cmyk:
5912 return colorTransformed(transform, QImage::Format_CMYK8888);
5913 case QColorSpace::ColorModel::Undefined:
5919 applyColorTransform(transform);
5920 return std::move(*
this);
5924
5925
5926
5927
5928
5929
5930
5931QImage QImage::colorTransformed(
const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags) &&
5934 return colorTransformed(transform, format, flags);
5937bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags flags)
5939 if (format == newFormat)
5943 if (ref.loadRelaxed() > 1 || !own_data)
5946 InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat];
5948 return converter(
this, flags);
5949 if (format > QImage::Format_Indexed8 && newFormat > QImage::Format_Indexed8 && !qimage_converter_map[format][newFormat]) {
5952 if (qt_highColorPrecision(newFormat, !qPixelLayouts[newFormat].hasAlphaChannel)
5953 && qt_highColorPrecision(format, !qPixelLayouts[format].hasAlphaChannel)) {
5954#if QT_CONFIG(raster_fp)
5955 if (qt_fpColorPrecision(format) && qt_fpColorPrecision(newFormat))
5956 return convert_generic_inplace_over_rgba32f(
this, newFormat, flags);
5958 return convert_generic_inplace_over_rgb64(
this, newFormat, flags);
5960 return convert_generic_inplace(
this, newFormat, flags);
5966
5967
5968
5971
5972
5973
5975#ifndef QT_NO_DEBUG_STREAM
5976QDebug operator<<(QDebug dbg,
const QImage &i)
5978 QDebugStateSaver saver(dbg);
5985 dbg << i.size() <<
",format=" << i.format() <<
",depth=" << i.depth();
5987 dbg <<
",colorCount=" << i.colorCount();
5988 const int bytesPerLine = i.bytesPerLine();
5989 dbg <<
",devicePixelRatio=" << i.devicePixelRatio()
5990 <<
",bytesPerLine=" << bytesPerLine <<
",sizeInBytes=" << i.sizeInBytes();
5991 if (dbg.verbosity() > 2 && i.height() > 0) {
5992 const int outputLength = qMin(bytesPerLine, 24);
5994 << QByteArray(
reinterpret_cast<
const char *>(i.scanLine(0)), outputLength).toHex()
6003static constexpr QPixelFormat pixelformats[] = {
6007 QPixelFormat(QPixelFormat::Indexed,
6014 QPixelFormat::IgnoresAlpha,
6015 QPixelFormat::AtBeginning,
6016 QPixelFormat::NotPremultiplied,
6017 QPixelFormat::UnsignedByte,
6018 QPixelFormat::BigEndian),
6020 QPixelFormat(QPixelFormat::Indexed,
6027 QPixelFormat::IgnoresAlpha,
6028 QPixelFormat::AtBeginning,
6029 QPixelFormat::NotPremultiplied,
6030 QPixelFormat::UnsignedByte,
6031 QPixelFormat::BigEndian),
6033 QPixelFormat(QPixelFormat::Indexed,
6040 QPixelFormat::IgnoresAlpha,
6041 QPixelFormat::AtBeginning,
6042 QPixelFormat::NotPremultiplied,
6043 QPixelFormat::UnsignedByte,
6044 QPixelFormat::BigEndian),
6046 QPixelFormat(QPixelFormat::RGB,
6053 QPixelFormat::IgnoresAlpha,
6054 QPixelFormat::AtBeginning,
6055 QPixelFormat::NotPremultiplied,
6056 QPixelFormat::UnsignedInteger,
6057 QPixelFormat::CurrentSystemEndian),
6059 QPixelFormat(QPixelFormat::RGB,
6066 QPixelFormat::UsesAlpha,
6067 QPixelFormat::AtBeginning,
6068 QPixelFormat::NotPremultiplied,
6069 QPixelFormat::UnsignedInteger,
6070 QPixelFormat::CurrentSystemEndian),
6072 QPixelFormat(QPixelFormat::RGB,
6079 QPixelFormat::UsesAlpha,
6080 QPixelFormat::AtBeginning,
6081 QPixelFormat::Premultiplied,
6082 QPixelFormat::UnsignedInteger,
6083 QPixelFormat::CurrentSystemEndian),
6085 QPixelFormat(QPixelFormat::RGB,
6092 QPixelFormat::IgnoresAlpha,
6093 QPixelFormat::AtBeginning,
6094 QPixelFormat::NotPremultiplied,
6095 QPixelFormat::UnsignedShort,
6096 QPixelFormat::CurrentSystemEndian),
6098 QPixelFormat(QPixelFormat::RGB,
6105 QPixelFormat::UsesAlpha,
6106 QPixelFormat::AtBeginning,
6107 QPixelFormat::Premultiplied,
6108 QPixelFormat::UnsignedInteger,
6109 QPixelFormat::CurrentSystemEndian),
6111 QPixelFormat(QPixelFormat::RGB,
6118 QPixelFormat::IgnoresAlpha,
6119 QPixelFormat::AtBeginning,
6120 QPixelFormat::NotPremultiplied,
6121 QPixelFormat::UnsignedInteger,
6122 QPixelFormat::CurrentSystemEndian),
6124 QPixelFormat(QPixelFormat::RGB,
6131 QPixelFormat::UsesAlpha,
6132 QPixelFormat::AtEnd,
6133 QPixelFormat::Premultiplied,
6134 QPixelFormat::UnsignedInteger,
6135 QPixelFormat::CurrentSystemEndian),
6137 QPixelFormat(QPixelFormat::RGB,
6144 QPixelFormat::IgnoresAlpha,
6145 QPixelFormat::AtBeginning,
6146 QPixelFormat::NotPremultiplied,
6147 QPixelFormat::UnsignedShort,
6148 QPixelFormat::CurrentSystemEndian),
6150 QPixelFormat(QPixelFormat::RGB,
6157 QPixelFormat::UsesAlpha,
6158 QPixelFormat::AtBeginning,
6159 QPixelFormat::Premultiplied,
6160 QPixelFormat::UnsignedInteger,
6161 QPixelFormat::CurrentSystemEndian),
6163 QPixelFormat(QPixelFormat::RGB,
6170 QPixelFormat::IgnoresAlpha,
6171 QPixelFormat::AtBeginning,
6172 QPixelFormat::NotPremultiplied,
6173 QPixelFormat::UnsignedByte,
6174 QPixelFormat::BigEndian),
6176 QPixelFormat(QPixelFormat::RGB,
6183 QPixelFormat::IgnoresAlpha,
6184 QPixelFormat::AtBeginning,
6185 QPixelFormat::NotPremultiplied,
6186 QPixelFormat::UnsignedShort,
6187 QPixelFormat::CurrentSystemEndian),
6189 QPixelFormat(QPixelFormat::RGB,
6196 QPixelFormat::UsesAlpha,
6197 QPixelFormat::AtBeginning,
6198 QPixelFormat::Premultiplied,
6199 QPixelFormat::UnsignedShort,
6200 QPixelFormat::CurrentSystemEndian),
6202 QPixelFormat(QPixelFormat::RGB,
6209 QPixelFormat::IgnoresAlpha,
6210 QPixelFormat::AtEnd,
6211 QPixelFormat::NotPremultiplied,
6212 QPixelFormat::UnsignedByte,
6213 QPixelFormat::BigEndian),
6215 QPixelFormat(QPixelFormat::RGB,
6222 QPixelFormat::UsesAlpha,
6223 QPixelFormat::AtEnd,
6224 QPixelFormat::NotPremultiplied,
6225 QPixelFormat::UnsignedByte,
6226 QPixelFormat::BigEndian),
6228 QPixelFormat(QPixelFormat::RGB,
6235 QPixelFormat::UsesAlpha,
6236 QPixelFormat::AtEnd,
6237 QPixelFormat::Premultiplied,
6238 QPixelFormat::UnsignedByte,
6239 QPixelFormat::BigEndian),
6241 QPixelFormat(QPixelFormat::BGR,
6248 QPixelFormat::IgnoresAlpha,
6249 QPixelFormat::AtBeginning,
6250 QPixelFormat::NotPremultiplied,
6251 QPixelFormat::UnsignedInteger,
6252 QPixelFormat::CurrentSystemEndian),
6254 QPixelFormat(QPixelFormat::BGR,
6261 QPixelFormat::UsesAlpha,
6262 QPixelFormat::AtBeginning,
6263 QPixelFormat::Premultiplied,
6264 QPixelFormat::UnsignedInteger,
6265 QPixelFormat::CurrentSystemEndian),
6267 QPixelFormat(QPixelFormat::RGB,
6274 QPixelFormat::IgnoresAlpha,
6275 QPixelFormat::AtBeginning,
6276 QPixelFormat::NotPremultiplied,
6277 QPixelFormat::UnsignedInteger,
6278 QPixelFormat::CurrentSystemEndian),
6280 QPixelFormat(QPixelFormat::RGB,
6287 QPixelFormat::UsesAlpha,
6288 QPixelFormat::AtBeginning,
6289 QPixelFormat::Premultiplied,
6290 QPixelFormat::UnsignedInteger,
6291 QPixelFormat::CurrentSystemEndian),
6293 QPixelFormat(QPixelFormat::Alpha,
6300 QPixelFormat::UsesAlpha,
6301 QPixelFormat::AtBeginning,
6302 QPixelFormat::Premultiplied,
6303 QPixelFormat::UnsignedByte,
6304 QPixelFormat::BigEndian),
6306 QPixelFormat(QPixelFormat::Grayscale,
6313 QPixelFormat::IgnoresAlpha,
6314 QPixelFormat::AtBeginning,
6315 QPixelFormat::NotPremultiplied,
6316 QPixelFormat::UnsignedByte,
6317 QPixelFormat::BigEndian),
6319 QPixelFormat(QPixelFormat::RGB,
6326 QPixelFormat::IgnoresAlpha,
6327 QPixelFormat::AtEnd,
6328 QPixelFormat::NotPremultiplied,
6329 QPixelFormat::UnsignedShort,
6330 QPixelFormat::CurrentSystemEndian),
6332 QPixelFormat(QPixelFormat::RGB,
6339 QPixelFormat::UsesAlpha,
6340 QPixelFormat::AtEnd,
6341 QPixelFormat::NotPremultiplied,
6342 QPixelFormat::UnsignedShort,
6343 QPixelFormat::CurrentSystemEndian),
6345 QPixelFormat(QPixelFormat::RGB,
6352 QPixelFormat::UsesAlpha,
6353 QPixelFormat::AtEnd,
6354 QPixelFormat::Premultiplied,
6355 QPixelFormat::UnsignedShort,
6356 QPixelFormat::CurrentSystemEndian),
6358 QPixelFormat(QPixelFormat::Grayscale,
6365 QPixelFormat::IgnoresAlpha,
6366 QPixelFormat::AtBeginning,
6367 QPixelFormat::NotPremultiplied,
6368 QPixelFormat::UnsignedShort,
6369 QPixelFormat::CurrentSystemEndian),
6371 QPixelFormat(QPixelFormat::BGR,
6378 QPixelFormat::IgnoresAlpha,
6379 QPixelFormat::AtBeginning,
6380 QPixelFormat::NotPremultiplied,
6381 QPixelFormat::UnsignedByte,
6382 QPixelFormat::BigEndian),
6384 QPixelFormat(QPixelFormat::RGB,
6391 QPixelFormat::IgnoresAlpha,
6392 QPixelFormat::AtEnd,
6393 QPixelFormat::NotPremultiplied,
6394 QPixelFormat::FloatingPoint,
6395 QPixelFormat::CurrentSystemEndian),
6397 QPixelFormat(QPixelFormat::RGB,
6404 QPixelFormat::UsesAlpha,
6405 QPixelFormat::AtEnd,
6406 QPixelFormat::NotPremultiplied,
6407 QPixelFormat::FloatingPoint,
6408 QPixelFormat::CurrentSystemEndian),
6410 QPixelFormat(QPixelFormat::RGB,
6417 QPixelFormat::UsesAlpha,
6418 QPixelFormat::AtEnd,
6419 QPixelFormat::Premultiplied,
6420 QPixelFormat::FloatingPoint,
6421 QPixelFormat::CurrentSystemEndian),
6423 QPixelFormat(QPixelFormat::RGB,
6430 QPixelFormat::IgnoresAlpha,
6431 QPixelFormat::AtEnd,
6432 QPixelFormat::NotPremultiplied,
6433 QPixelFormat::FloatingPoint,
6434 QPixelFormat::CurrentSystemEndian),
6436 QPixelFormat(QPixelFormat::RGB,
6443 QPixelFormat::UsesAlpha,
6444 QPixelFormat::AtEnd,
6445 QPixelFormat::NotPremultiplied,
6446 QPixelFormat::FloatingPoint,
6447 QPixelFormat::CurrentSystemEndian),
6449 QPixelFormat(QPixelFormat::RGB,
6456 QPixelFormat::UsesAlpha,
6457 QPixelFormat::AtEnd,
6458 QPixelFormat::Premultiplied,
6459 QPixelFormat::FloatingPoint,
6460 QPixelFormat::CurrentSystemEndian),
6462 QPixelFormat(QPixelFormat::CMYK,
6469 QPixelFormat::IgnoresAlpha,
6470 QPixelFormat::AtBeginning,
6471 QPixelFormat::NotPremultiplied,
6472 QPixelFormat::UnsignedInteger,
6473 QPixelFormat::CurrentSystemEndian),
6475static_assert(
sizeof(pixelformats) /
sizeof(*pixelformats) == QImage::NImageFormats);
6478
6479
6480QPixelFormat QImage::pixelFormat()
const noexcept
6482 return toPixelFormat(format());
6486
6487
6488QPixelFormat QImage::toPixelFormat(QImage::Format format)
noexcept
6490 Q_ASSERT(
static_cast<
int>(format) < NImageFormats &&
static_cast<
int>(format) >= 0);
6491 return pixelformats[format];
6495
6496
6497QImage::Format QImage::toImageFormat(QPixelFormat format)
noexcept
6499 for (
int i = 0; i < NImageFormats; i++) {
6500 if (format == pixelformats[i])
6503 return Format_Invalid;
6508 Qt::Orientations orients = {};
6509 if (orient.testFlag(QImageIOHandler::TransformationMirror))
6510 orients |= Qt::Horizontal;
6511 if (orient.testFlag(QImageIOHandler::TransformationFlip))
6512 orients |= Qt::Vertical;
6518 if (orient == QImageIOHandler::TransformationNone)
6520 if (orient == QImageIOHandler::TransformationRotate270) {
6521 src = rotated270(src);
6523 src.flip(toOrientations(orient));
6524 if (orient & QImageIOHandler::TransformationRotate90)
6525 src = rotated90(src);
6531 QMap<QString, QString> text = qt_getImageTextFromDescription(description);
6532 const auto textKeys = image.textKeys();
6533 for (
const QString &key : textKeys) {
6534 if (!key.isEmpty() && !text.contains(key))
6535 text.insert(key, image.text(key));
6542 QMap<QString, QString> text;
6543 for (
const auto &pair : QStringView{description}.tokenize(u"\n\n")) {
6544 int index = pair.indexOf(u':');
6545 if (index >= 0 && pair.indexOf(u' ') < index) {
6546 if (!pair.trimmed().isEmpty())
6547 text.insert(
"Description"_L1, pair.toString().simplified());
6549 const auto key = pair.left(index);
6550 if (!key.trimmed().isEmpty())
6551 text.insert(key.toString(), pair.mid(index + 2).toString().simplified());
6559#include "moc_qimage.cpp"
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
static QImage rotated90(const QImage &src)
static void copyMetadata(QImage *dst, const QImage &src)
static void copyMetadata(QImageData *dst, const QImageData *src)
static int next_qimage_serial_number()
#define QIMAGE_SANITYCHECK_MEMORY(image)
static void copyPhysicalMetadata(QImageData *dst, const QImageData *src)
static QImage rotated270(const QImage &src)
QMap< QString, QString > qt_getImageText(const QImage &image, const QString &description)
Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
static QImage rotated180(const QImage &src)
static Qt::Orientations toOrientations(QImageIOHandler::Transformations orient)
QMap< QString, QString > qt_getImageTextFromDescription(const QString &description)