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>
50#define QT_XFORM_TYPE_MSBFIRST 0
51#define QT_XFORM_TYPE_LSBFIRST 1
56using namespace Qt::StringLiterals;
61QT_WARNING_DISABLE_MSVC(4723)
63#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0
>= 50190001
)
64#pragma message disable narrowptr
68#define QIMAGE_SANITYCHECK_MEMORY(image)
69 if ((image).isNull()) {
70 qWarning("QImage: out of memory, returning null image");
75 "#include <qimagereader.h>"
79"ENUM { } QImage::Format;" \
80"FLAGS { } Qt::ImageConversionFlags;"
83Q_TRACE_PARAM_REPLACE(Qt::AspectRatioMode,
int);
84Q_TRACE_PARAM_REPLACE(Qt::TransformationMode,
int);
86static QImage
rotated90(
const QImage &src);
92 Q_CONSTINIT
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(0);
93 return 1 + serial.fetchAndAddRelaxed(1);
96QImageData::QImageData()
97 : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(
nullptr),
98 format(QImage::Format_ARGB32), bytes_per_line(0),
99 ser_no(next_qimage_serial_number()),
101 offset(0, 0), own_data(
true), ro_data(
false), has_alpha_clut(
false),
102 is_cached(
false), cleanupFunction(
nullptr), cleanupInfo(
nullptr),
105 QPoint dpis = qt_defaultDpis();
106 dpmx = dpis.x() * 100 / qreal(2.54);
107 dpmy = dpis.y() * 100 / qreal(2.54);
111
112
113
114
115
116
117QImageData * Q_TRACE_INSTRUMENT(qtgui) QImageData::create(
const QSize &size, QImage::Format format)
119 if (size.isEmpty() || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
122 Q_TRACE_SCOPE(QImageData_create, size, format);
124 int width = size.width();
125 int height = size.height();
126 int depth = qt_depthForFormat(format);
127 auto params = calculateImageParameters(width, height, depth);
128 if (!params.isValid())
131 auto d = std::make_unique<QImageData>();
134 case QImage::Format_Mono:
135 case QImage::Format_MonoLSB:
136 d->colortable.resize(2);
137 d->colortable[0] = QColor(Qt::black).rgba();
138 d->colortable[1] = QColor(Qt::white).rgba();
148 d->has_alpha_clut =
false;
149 d->is_cached =
false;
151 d->bytes_per_line = params.bytesPerLine;
152 d->nbytes = params.totalSize;
153 d->data = (uchar *)malloc(d->nbytes);
162QImageData::~QImageData()
165 cleanupFunction(cleanupInfo);
167 QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
169 if (data && own_data)
170 QtPrivate::sizedFree(data, nbytes);
174#if defined(_M_ARM) && defined(_MSC_VER)
175#pragma optimize("", off)
178bool QImageData::checkForAlphaPixels()
const
180 bool has_alpha_pixels =
false;
184 case QImage::Format_Mono:
185 case QImage::Format_MonoLSB:
186 case QImage::Format_Indexed8:
187 has_alpha_pixels = has_alpha_clut;
189 case QImage::Format_Alpha8:
190 has_alpha_pixels =
true;
192 case QImage::Format_ARGB32:
193 case QImage::Format_ARGB32_Premultiplied: {
194 const uchar *bits = data;
195 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
196 uint alphaAnd = 0xff000000;
197 for (
int x=0; x<width; ++x)
198 alphaAnd &=
reinterpret_cast<
const uint*>(bits)[x];
199 has_alpha_pixels = (alphaAnd != 0xff000000);
200 bits += bytes_per_line;
204 case QImage::Format_RGBA8888:
205 case QImage::Format_RGBA8888_Premultiplied: {
206 const uchar *bits = data;
207 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
208 uchar alphaAnd = 0xff;
209 for (
int x=0; x<width; ++x)
210 alphaAnd &= bits[x * 4+ 3];
211 has_alpha_pixels = (alphaAnd != 0xff);
212 bits += bytes_per_line;
216 case QImage::Format_A2BGR30_Premultiplied:
217 case QImage::Format_A2RGB30_Premultiplied: {
218 const uchar *bits = data;
219 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
220 uint alphaAnd = 0xc0000000;
221 for (
int x=0; x<width; ++x)
222 alphaAnd &=
reinterpret_cast<
const uint*>(bits)[x];
223 has_alpha_pixels = (alphaAnd != 0xc0000000);
224 bits += bytes_per_line;
228 case QImage::Format_ARGB8555_Premultiplied:
229 case QImage::Format_ARGB8565_Premultiplied: {
230 const uchar *bits = data;
231 const uchar *end_bits = data + bytes_per_line;
233 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
234 uchar alphaAnd = 0xff;
235 while (bits < end_bits) {
239 has_alpha_pixels = (alphaAnd != 0xff);
241 end_bits += bytes_per_line;
245 case QImage::Format_ARGB6666_Premultiplied: {
246 const uchar *bits = data;
247 const uchar *end_bits = data + bytes_per_line;
249 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
250 uchar alphaAnd = 0xfc;
251 while (bits < end_bits) {
255 has_alpha_pixels = (alphaAnd != 0xfc);
257 end_bits += bytes_per_line;
261 case QImage::Format_ARGB4444_Premultiplied: {
262 const uchar *bits = data;
263 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
264 ushort alphaAnd = 0xf000;
265 for (
int x=0; x<width; ++x)
266 alphaAnd &=
reinterpret_cast<
const ushort*>(bits)[x];
267 has_alpha_pixels = (alphaAnd != 0xf000);
268 bits += bytes_per_line;
271 case QImage::Format_RGBA64:
272 case QImage::Format_RGBA64_Premultiplied: {
274 for (
int y=0; y<height && !has_alpha_pixels; ++y) {
275 for (
int x=0; x<width; ++x) {
276 has_alpha_pixels |= !(((QRgba64 *)bits)[x].isOpaque());
278 bits += bytes_per_line;
281 case QImage::Format_RGBA16FPx4:
282 case QImage::Format_RGBA16FPx4_Premultiplied: {
284 for (
int y = 0; y < height && !has_alpha_pixels; ++y) {
285 for (
int x = 0; x < width; ++x)
286 has_alpha_pixels |= ((qfloat16 *)bits)[x * 4 + 3] < 1.0f;
287 bits += bytes_per_line;
290 case QImage::Format_RGBA32FPx4:
291 case QImage::Format_RGBA32FPx4_Premultiplied: {
293 for (
int y = 0; y < height && !has_alpha_pixels; ++y) {
294 for (
int x = 0; x < width; ++x)
295 has_alpha_pixels |= ((
float *)bits)[x * 4 + 3] < 1.0f;
296 bits += bytes_per_line;
300 case QImage::Format_RGB32:
301 case QImage::Format_RGB16:
302 case QImage::Format_RGB444:
303 case QImage::Format_RGB555:
304 case QImage::Format_RGB666:
305 case QImage::Format_RGB888:
306 case QImage::Format_BGR888:
307 case QImage::Format_RGBX8888:
308 case QImage::Format_BGR30:
309 case QImage::Format_RGB30:
310 case QImage::Format_Grayscale8:
311 case QImage::Format_Grayscale16:
312 case QImage::Format_RGBX64:
313 case QImage::Format_RGBX16FPx4:
314 case QImage::Format_RGBX32FPx4:
315 case QImage::Format_CMYK8888:
317 case QImage::Format_Invalid:
318 case QImage::NImageFormats:
323 return has_alpha_pixels;
325#if defined(_M_ARM) && defined(_MSC_VER)
326#pragma optimize("", on)
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
625
626
627
628
631
632
633
634
635
636
637
640
641
642
643
644
645
649
650
651
652
653
654
655
656
657
658
661
662
663
664
665
666
667
668
669
670
671
672
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
783
784
785
786
789
790
793
794
795
796
798QImage::QImage()
noexcept
805
806
807
808
809
810
811
812
813
814QImage::QImage(
int width,
int height, Format format)
815 : QImage(QSize(width, height), format)
820
821
822
823
824
825
826
827
828QImage::QImage(
const QSize &size, Format format)
831 d = QImageData::create(size, format);
836QImageData *QImageData::create(uchar *data,
int width,
int height, qsizetype bpl, QImage::Format format,
bool readOnly, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
838 if (width <= 0 || height <= 0 || !data || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
841 const int depth = qt_depthForFormat(format);
842 auto params = calculateImageParameters(width, height, depth);
843 if (!params.isValid())
848 const qsizetype min_bytes_per_line = (qsizetype(width) * depth + 7)/8;
849 if (bpl < min_bytes_per_line)
853 params.bytesPerLine = bpl;
854 if (qMulOverflow<qsizetype>(bpl, height, ¶ms.totalSize))
858 QImageData *d =
new QImageData;
862 d->ro_data = readOnly;
869 d->bytes_per_line = params.bytesPerLine;
870 d->nbytes = params.totalSize;
872 d->cleanupFunction = cleanupFunction;
873 d->cleanupInfo = cleanupInfo;
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895QImage::QImage(uchar* data,
int width,
int height, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
898 d = QImageData::create(data, width, height, 0, format,
false, cleanupFunction, cleanupInfo);
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926QImage::QImage(
const uchar* data,
int width,
int height, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
929 d = QImageData::create(
const_cast<uchar*>(data), width, height, 0, format,
true, cleanupFunction, cleanupInfo);
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
950QImage::QImage(uchar *data,
int width,
int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
953 d = QImageData::create(data, width, height, bytesPerLine, format,
false, cleanupFunction, cleanupInfo);
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
981QImage::QImage(
const uchar *data,
int width,
int height, qsizetype bytesPerLine, Format format, QImageCleanupFunction cleanupFunction,
void *cleanupInfo)
984 d = QImageData::create(
const_cast<uchar*>(data), width, height, bytesPerLine, format,
true, cleanupFunction, cleanupInfo);
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1007QImage::QImage(
const QString &fileName,
const char *format)
1011 load(fileName, format);
1014#ifndef QT_NO_IMAGEFORMAT_XPM
1015extern bool qt_read_xpm_image_or_array(QIODevice *device,
const char *
const *source, QImage &image);
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1033QImage::QImage(
const char *
const xpm[])
1039 if (!qt_read_xpm_image_or_array(
nullptr, xpm, *
this))
1041 qWarning(
"QImage::QImage(), XPM is not supported");
1046
1047
1048
1049
1050
1051
1052
1054QImage::QImage(
const QImage &image)
1057 if (image.paintingActive()) {
1059 image.copy().swap(*
this);
1068
1069
1073 if (d && !d->ref.deref())
1078
1079
1080
1081
1082
1083
1084
1085
1087QImage &QImage::operator=(
const QImage &image)
1089 if (image.paintingActive()) {
1090 operator=(image.copy());
1094 if (d && !d->ref.deref())
1102
1103
1104
1107
1108
1109int QImage::devType()
const
1111 return QInternal::Image;
1115
1116
1117QImage::operator QVariant()
const
1119 return QVariant::fromValue(*
this);
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133void QImage::detach()
1136 if (d->is_cached && d->ref.loadRelaxed() == 1)
1137 QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
1139 if (d->ref.loadRelaxed() != 1 || d->ro_data)
1149
1150
1151
1152
1153
1154
1155
1156void QImage::detachMetadata(
bool invalidateCache)
1159 if (d->is_cached && d->ref.loadRelaxed() == 1)
1160 QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
1162 if (d->ref.loadRelaxed() != 1)
1165 if (d && invalidateCache)
1172 dst->dpmx = src->dpmx;
1173 dst->dpmy = src->dpmy;
1174 dst->devicePixelRatio = src->devicePixelRatio;
1181 dst->text = src->text;
1182 dst->offset = src->offset;
1183 dst->colorSpace = src->colorSpace;
1188 dst->setDotsPerMeterX(src.dotsPerMeterX());
1189 dst->setDotsPerMeterY(src.dotsPerMeterY());
1190 dst->setDevicePixelRatio(src.devicePixelRatio());
1191 const auto textKeys = src.textKeys();
1192 for (
const auto &key: textKeys)
1193 dst->setText(key, src.text(key));
1198
1199
1200
1201
1202
1203
1204
1205
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227QImage Q_TRACE_INSTRUMENT(qtgui) QImage::copy(
const QRect& r)
const
1229 Q_TRACE_SCOPE(QImage_copy, r);
1234 QImage image(d->width, d->height, d->format);
1240 if (image.d->nbytes != d->nbytes) {
1241 qsizetype bpl = qMin(bytesPerLine(), image.bytesPerLine());
1242 for (
int i = 0; i < height(); i++)
1243 memcpy(image.scanLine(i), scanLine(i), bpl);
1245 memcpy(image.bits(), bits(), d->nbytes);
1246 image.d->colortable = d->colortable;
1247 image.d->has_alpha_clut = d->has_alpha_clut;
1248 copyMetadata(image.d, d);
1259 if (w <= 0 || h <= 0)
1262 QImage image(w, h, d->format);
1266 if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) {
1279 image.d->colortable = d->colortable;
1281 int pixels_to_copy = qMax(w - dx, 0);
1284 else if (pixels_to_copy > d->width - x)
1285 pixels_to_copy = d->width - x;
1286 int lines_to_copy = qMax(h - dy, 0);
1289 else if (lines_to_copy > d->height - y)
1290 lines_to_copy = d->height - y;
1292 bool byteAligned =
true;
1293 if (d->format == Format_Mono || d->format == Format_MonoLSB)
1294 byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7);
1297 const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line;
1298 uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line;
1299 const qsizetype bytes_to_copy = (qsizetype(pixels_to_copy) * d->depth) >> 3;
1300 for (
int i = 0; i < lines_to_copy; ++i) {
1301 memcpy(dest, src, bytes_to_copy);
1302 src += d->bytes_per_line;
1303 dest += image.d->bytes_per_line;
1305 }
else if (d->format == Format_Mono) {
1306 const uchar *src = d->data + y * d->bytes_per_line;
1307 uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1308 for (
int i = 0; i < lines_to_copy; ++i) {
1309 for (
int j = 0; j < pixels_to_copy; ++j) {
1310 if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7)))
1311 dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7));
1313 dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7));
1315 src += d->bytes_per_line;
1316 dest += image.d->bytes_per_line;
1319 Q_ASSERT(d->format == Format_MonoLSB);
1320 const uchar *src = d->data + y * d->bytes_per_line;
1321 uchar *dest = image.d->data + dy * image.d->bytes_per_line;
1322 for (
int i = 0; i < lines_to_copy; ++i) {
1323 for (
int j = 0; j < pixels_to_copy; ++j) {
1324 if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7)))
1325 dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7));
1327 dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7));
1329 src += d->bytes_per_line;
1330 dest += image.d->bytes_per_line;
1334 copyMetadata(image.d, d);
1335 image.d->has_alpha_clut = d->has_alpha_clut;
1342
1343
1344
1345
1346
1347bool QImage::isNull()
const
1353
1354
1355
1356
1357
1358
1359int QImage::width()
const
1361 return d ? d->width : 0;
1365
1366
1367
1368
1369
1370
1371int QImage::height()
const
1373 return d ? d->height : 0;
1377
1378
1379
1380
1381
1382
1383QSize QImage::size()
const
1385 return d ? QSize(d->width, d->height) : QSize(0, 0);
1389
1390
1391
1392
1393
1394
1395
1396QRect QImage::rect()
const
1398 return d ? QRect(0, 0, d->width, d->height) : QRect();
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413int QImage::depth()
const
1415 return d ? d->depth : 0;
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429int QImage::colorCount()
const
1431 return d ? d->colortable.size() : 0;
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445void QImage::setColorTable(
const QList<QRgb> &colors)
1449 detachMetadata(
true);
1455 d->colortable = colors;
1456 d->has_alpha_clut =
false;
1457 for (
int i = 0; i < d->colortable.size(); ++i) {
1458 if (qAlpha(d->colortable.at(i)) != 255) {
1459 d->has_alpha_clut =
true;
1466
1467
1468
1469
1470
1471QList<QRgb> QImage::colorTable()
const
1473 return d ? d->colortable : QList<QRgb>();
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487qreal QImage::devicePixelRatio()
const
1491 return d->devicePixelRatio;
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515void QImage::setDevicePixelRatio(qreal scaleFactor)
1520 if (scaleFactor == d->devicePixelRatio)
1525 d->devicePixelRatio = scaleFactor;
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538QSizeF QImage::deviceIndependentSize()
const
1541 return QSizeF(0, 0);
1542 return QSizeF(d->width, d->height) / d->devicePixelRatio;
1547
1548
1549
1550
1551
1552
1553qsizetype QImage::sizeInBytes()
const
1555 return d ? d->nbytes : 0;
1559
1560
1561
1562
1563
1564
1565qsizetype QImage::bytesPerLine()
const
1567 return d ? d->bytes_per_line : 0;
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582QRgb QImage::color(
int i)
const
1584 Q_ASSERT(i < colorCount());
1585 return d ? d->colortable.at(i) : QRgb(uint(-1));
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600void QImage::setColor(
int i, QRgb c)
1604 if (i < 0 || d->depth > 8 || i >= 1<<d->depth) {
1605 qWarning(
"QImage::setColor: Index out of bound %d", i);
1608 detachMetadata(
true);
1614 if (i >= d->colortable.size())
1616 d->colortable[i] = c;
1617 d->has_alpha_clut |= (qAlpha(c) != 255);
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642uchar *QImage::scanLine(
int i)
1653 return d->data + i * d->bytes_per_line;
1657
1658
1659const uchar *QImage::scanLine(
int i)
const
1664 Q_ASSERT(i >= 0 && i < height());
1665 return d->data + i * d->bytes_per_line;
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683const uchar *QImage::constScanLine(
int i)
const
1688 Q_ASSERT(i >= 0 && i < height());
1689 return d->data + i * d->bytes_per_line;
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703uchar *QImage::bits()
1717
1718
1719
1720
1721
1722
1723const uchar *QImage::bits()
const
1725 return d ? d->data :
nullptr;
1730
1731
1732
1733
1734
1735
1736
1737
1738const uchar *QImage::constBits()
const
1740 return d ? d->data :
nullptr;
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1763void QImage::fill(uint pixel)
1774 if (d->depth == 1 || d->depth == 8) {
1776 if (d->depth == 1) {
1785 qt_rectfill<quint8>(d->data, pixel, 0, 0,
1786 w, d->height, d->bytes_per_line);
1788 }
else if (d->depth == 16) {
1789 if (d->format == Format_RGB444)
1791 qt_rectfill<quint16>(
reinterpret_cast<quint16*>(d->data), pixel,
1792 0, 0, d->width, d->height, d->bytes_per_line);
1794 }
else if (d->depth == 24) {
1795 if (d->format == Format_RGB666)
1797 qt_rectfill<quint24>(
reinterpret_cast<quint24*>(d->data), pixel,
1798 0, 0, d->width, d->height, d->bytes_per_line);
1800 }
else if (d->format >= QImage::Format_RGBX64 && d->format <= QImage::Format_RGBA64_Premultiplied) {
1801 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), QRgba64::fromArgb32(pixel),
1802 0, 0, d->width, d->height, d->bytes_per_line);
1804 }
else if (d->format >= QImage::Format_RGBX16FPx4 && d->format <= QImage::Format_RGBA16FPx4_Premultiplied) {
1806 QRgbaFloat16 cf = QRgbaFloat16::fromArgb32(pixel);
1807 ::memcpy(&cu, &cf,
sizeof(quint64));
1808 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), cu,
1809 0, 0, d->width, d->height, d->bytes_per_line);
1811 }
else if (d->format >= QImage::Format_RGBX32FPx4 && d->format <= QImage::Format_RGBA32FPx4_Premultiplied) {
1812 QRgbaFloat32 cf = QRgbaFloat32::fromArgb32(pixel);
1813 uchar *data = d->data;
1814 for (
int y = 0; y < d->height; ++y) {
1815 QRgbaFloat32 *line =
reinterpret_cast<QRgbaFloat32 *>(data);
1816 for (
int x = 0; x < d->width; ++x)
1818 data += d->bytes_per_line;
1822 Q_ASSERT(d->depth == 32);
1824 if (d->format == Format_RGB32)
1825 pixel |= 0xff000000;
1826 if (d->format == Format_RGBX8888)
1827#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
1828 pixel |= 0xff000000;
1830 pixel |= 0x000000ff;
1832 if (d->format == Format_BGR30 || d->format == Format_RGB30)
1833 pixel |= 0xc0000000;
1835 qt_rectfill<uint>(
reinterpret_cast<uint*>(d->data), pixel,
1836 0, 0, d->width, d->height, d->bytes_per_line);
1841
1842
1843
1844
1845
1846
1848void QImage::fill(Qt::GlobalColor color)
1850 fill(QColor(color));
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1870void QImage::fill(
const QColor &color)
1880 QRgba64 opaque = color.rgba64();
1881 opaque.setAlpha(65535);
1882 switch (d->format) {
1883 case QImage::Format_RGB32:
1884 case QImage::Format_ARGB32:
1887 case QImage::Format_ARGB32_Premultiplied:
1888 fill(qPremultiply(color.rgba()));
1890 case QImage::Format_RGBX8888:
1891 fill(ARGB2RGBA(color.rgba() | 0xff000000));
1893 case QImage::Format_RGBA8888:
1894 fill(ARGB2RGBA(color.rgba()));
1896 case QImage::Format_RGBA8888_Premultiplied:
1897 fill(ARGB2RGBA(qPremultiply(color.rgba())));
1899 case QImage::Format_BGR30:
1900 fill(qConvertRgb64ToRgb30<PixelOrderBGR>(opaque));
1902 case QImage::Format_RGB30:
1903 fill(qConvertRgb64ToRgb30<PixelOrderRGB>(opaque));
1905 case QImage::Format_RGB16:
1906 fill((uint) qConvertRgb32To16(color.rgba()));
1908 case QImage::Format_Indexed8: {
1910 for (
int i=0; i<d->colortable.size(); ++i) {
1911 if (color.rgba() == d->colortable.at(i)) {
1919 case QImage::Format_Mono:
1920 case QImage::Format_MonoLSB:
1921 if (color == Qt::color1)
1926 case QImage::Format_RGBX64:
1927 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), opaque,
1928 0, 0, d->width, d->height, d->bytes_per_line);
1930 case QImage::Format_RGBA64:
1931 qt_rectfill<quint64>(
reinterpret_cast<quint64*>(d->data), color.rgba64(),
1932 0, 0, d->width, d->height, d->bytes_per_line);
1934 case QImage::Format_RGBA64_Premultiplied:
1935 qt_rectfill<quint64>(
reinterpret_cast<quint64 *>(d->data), color.rgba64().premultiplied(),
1936 0, 0, d->width, d->height, d->bytes_per_line);
1938 case QImage::Format_RGBX16FPx4:
1939 case QImage::Format_RGBA16FPx4:
1940 case QImage::Format_RGBA16FPx4_Premultiplied:
1941 case QImage::Format_RGBX32FPx4:
1942 case QImage::Format_RGBA32FPx4:
1943 case QImage::Format_RGBA32FPx4_Premultiplied:{
1945 color.getRgbF(&r, &g, &b, &a);
1946 if (!hasAlphaChannel())
1948 if (depth() == 64) {
1949 QRgbaFloat16 c16{qfloat16(r), qfloat16(g), qfloat16(b), qfloat16(a)};
1950 if (d->format == Format_RGBA16FPx4_Premultiplied)
1951 c16 = c16.premultiplied();
1952 qt_rectfill<QRgbaFloat16>(
reinterpret_cast<QRgbaFloat16 *>(d->data), c16,
1953 0, 0, d->width, d->height, d->bytes_per_line);
1955 QRgbaFloat32 c32{r, g, b, a};
1956 if (d->format == Format_RGBA32FPx4_Premultiplied)
1957 c32 = c32.premultiplied();
1958 qt_rectfill<QRgbaFloat32>(
reinterpret_cast<QRgbaFloat32 *>(d->data), c32,
1959 0, 0, d->width, d->height, d->bytes_per_line);
1965 p.setCompositionMode(QPainter::CompositionMode_Source);
1966 p.fillRect(rect(), color);
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1992void QImage::invertPixels(InvertMode mode)
2003 QImage::Format originalFormat = d->format;
2005 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) {
2006 if (d->format == QImage::Format_RGBA16FPx4_Premultiplied) {
2007 if (!d->convertInPlace(QImage::Format_RGBA16FPx4, { }))
2008 *
this = convertToFormat(QImage::Format_RGBA16FPx4);
2009 }
else if (d->format == QImage::Format_RGBA32FPx4_Premultiplied) {
2010 if (!d->convertInPlace(QImage::Format_RGBA32FPx4, { }))
2011 *
this = convertToFormat(QImage::Format_RGBA32FPx4);
2012 }
else if (depth() > 32) {
2013 if (!d->convertInPlace(QImage::Format_RGBA64, { }))
2014 *
this = convertToFormat(QImage::Format_RGBA64);
2016 if (!d->convertInPlace(QImage::Format_ARGB32, { }))
2017 *
this = convertToFormat(QImage::Format_ARGB32);
2023 qsizetype bpl = (qsizetype(d->width) * d->depth + 7) / 8;
2024 int pad = d->bytes_per_line - bpl;
2025 uchar *sl = d->data;
2026 for (
int y=0; y<d->height; ++y) {
2027 for (qsizetype x=0; x<bpl; ++x)
2031 }
else if (format() >= QImage::Format_RGBX16FPx4 && format() <= QImage::Format_RGBA16FPx4_Premultiplied) {
2032 qfloat16 *p =
reinterpret_cast<qfloat16 *>(d->data);
2033 qfloat16 *end =
reinterpret_cast<qfloat16 *>(d->data + d->nbytes);
2035 p[0] = qfloat16(1) - p[0];
2036 p[1] = qfloat16(1) - p[1];
2037 p[2] = qfloat16(1) - p[2];
2038 if (mode == InvertRgba)
2039 p[3] = qfloat16(1) - p[3];
2042 }
else if (format() >= QImage::Format_RGBX32FPx4 && format() <= QImage::Format_RGBA32FPx4_Premultiplied) {
2043 uchar *data = d->data;
2044 for (
int y = 0; y < d->height; ++y) {
2045 float *p =
reinterpret_cast<
float *>(data);
2046 for (
int x = 0; x < d->width; ++x) {
2050 if (mode == InvertRgba)
2054 data += d->bytes_per_line;
2056 }
else if (depth() == 64) {
2057 quint16 *p = (quint16*)d->data;
2058 quint16 *end = (quint16*)(d->data + d->nbytes);
2059 quint16 xorbits = 0xffff;
2064 if (mode == InvertRgba)
2070 quint32 *p = (quint32*)d->data;
2071 quint32 *end = (quint32*)(d->data + d->nbytes);
2072 quint32 xorbits = 0xffffffff;
2073 switch (d->format) {
2074 case QImage::Format_RGBA8888:
2075 if (mode == InvertRgba)
2078 case QImage::Format_RGBX8888:
2079#if Q_BYTE_ORDER == Q_BIG_ENDIAN
2080 xorbits = 0xffffff00;
2083 xorbits = 0x00ffffff;
2086 case QImage::Format_ARGB32:
2087 if (mode == InvertRgba)
2090 case QImage::Format_RGB32:
2091 xorbits = 0x00ffffff;
2093 case QImage::Format_BGR30:
2094 case QImage::Format_RGB30:
2095 xorbits = 0x3fffffff;
2106 if (originalFormat != d->format) {
2107 if (!d->convertInPlace(originalFormat, { }))
2108 *
this = convertToFormat(originalFormat);
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2137void QImage::setColorCount(
int colorCount)
2140 qWarning(
"QImage::setColorCount: null image");
2144 detachMetadata(
true);
2150 if (colorCount == d->colortable.size())
2152 if (colorCount <= 0) {
2153 d->colortable.clear();
2156 int nc = d->colortable.size();
2157 d->colortable.resize(colorCount);
2158 for (
int i = nc; i < colorCount; ++i)
2159 d->colortable[i] = 0;
2163
2164
2165
2166
2167QImage::Format QImage::format()
const
2171 Q_ASSERT(d->format < NImageFormats);
2172 Q_ASSERT(d->format > Format_Invalid);
2174 return d ? d->format : Format_Invalid;
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2203
2204
2205QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags)
const
2207 if (!d || d->format == format)
2210 if (d->format == Format_Invalid || format <= Format_Invalid || format >= NImageFormats)
2213 const QPixelLayout *destLayout = &qPixelLayouts[format];
2214 Image_Converter converter = qimage_converter_map[d->format][format];
2215 if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8) {
2216 if (qt_highColorPrecision(d->format, !destLayout->hasAlphaChannel)
2217 && qt_highColorPrecision(format, !hasAlphaChannel())) {
2218#if QT_CONFIG(raster_fp)
2219 if (qt_fpColorPrecision(d->format) && qt_fpColorPrecision(format))
2220 converter = convert_generic_over_rgba32f;
2223 converter = convert_generic_over_rgb64;
2225 converter = convert_generic;
2228 QImage image(d->width, d->height, format);
2232 copyMetadata(image.d, d);
2234 converter(image.d, d, flags);
2239 Q_ASSERT(format != QImage::Format_ARGB32 && format != QImage::Format_RGB32);
2240 Q_ASSERT(d->format != QImage::Format_ARGB32 && d->format != QImage::Format_RGB32);
2242 if (!hasAlphaChannel())
2243 return convertToFormat(Format_RGB32, flags).convertToFormat(format, flags);
2245 return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
2249
2250
2251bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags)
2253 return d && d->convertInPlace(format, flags);
2256static inline int pixel_distance(QRgb p1, QRgb p2) {
2258 int g1 = qGreen(p1);
2260 int a1 = qAlpha(p1);
2263 int g2 = qGreen(p2);
2265 int a2 = qAlpha(p2);
2267 return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2);
2270static inline int closestMatch(QRgb pixel,
const QList<QRgb> &clut) {
2272 int current_distance = INT_MAX;
2273 for (
int i=0; i<clut.size(); ++i) {
2274 int dist = pixel_distance(pixel, clut.at(i));
2275 if (dist < current_distance) {
2276 current_distance = dist;
2283static QImage convertWithPalette(
const QImage &src, QImage::Format format,
2284 const QList<QRgb> &clut) {
2285 QImage dest(src.size(), format);
2286 dest.setColorTable(clut);
2288 copyMetadata(QImageData::get(dest), QImageData::get(src));
2290 int h = src.height();
2291 int w = src.width();
2293 QHash<QRgb,
int> cache;
2295 if (format == QImage::Format_Indexed8) {
2296 for (
int y=0; y<h; ++y) {
2297 const QRgb *src_pixels = (
const QRgb *) src.scanLine(y);
2298 uchar *dest_pixels = (uchar *) dest.scanLine(y);
2299 for (
int x=0; x<w; ++x) {
2300 int src_pixel = src_pixels[x];
2301 int value = cache.value(src_pixel, -1);
2303 value = closestMatch(src_pixel, clut);
2304 cache.insert(src_pixel, value);
2306 dest_pixels[x] = (uchar) value;
2310 QList<QRgb> table = clut;
2312 for (
int y=0; y<h; ++y) {
2313 const QRgb *src_pixels = (
const QRgb *) src.scanLine(y);
2314 for (
int x=0; x<w; ++x) {
2315 int src_pixel = src_pixels[x];
2316 int value = cache.value(src_pixel, -1);
2318 value = closestMatch(src_pixel, table);
2319 cache.insert(src_pixel, value);
2321 dest.setPixel(x, y, value);
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339QImage QImage::convertToFormat(Format format,
const QList<QRgb> &colorTable, Qt::ImageConversionFlags flags)
const
2341 if (!d || d->format == format)
2344 if (format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
2346 if (format <= QImage::Format_Indexed8)
2347 return convertWithPalette(convertToFormat(QImage::Format_ARGB32, flags), format, colorTable);
2349 return convertToFormat(format, flags);
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2375bool QImage::reinterpretAsFormat(Format format)
2377 if (format <= Format_Invalid || format >= NImageFormats)
2381 if (d->format == format)
2383 if (qt_depthForFormat(format) != qt_depthForFormat(d->format))
2385 if (!isDetached()) {
2386 QImageData *oldD = d;
2401
2402
2403
2404
2405
2406
2407
2408
2409
2411void QImage::convertTo(Format format, Qt::ImageConversionFlags flags)
2413 if (!d || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
2416 if (d->format == format)
2420 if (convertToFormat_inplace(format, flags))
2423 *
this = convertToFormat_helper(format, flags);
2427
2428
2429
2430
2431
2432
2433
2436
2437
2438
2439
2440
2441bool QImage::valid(
int x,
int y)
const
2444 && x >= 0 && x < d->width
2445 && y >= 0 && y < d->height;
2449
2450
2451
2452
2453
2454
2455
2456
2457
2460
2461
2462
2463
2464int QImage::pixelIndex(
int x,
int y)
const
2466 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
2467 qWarning(
"QImage::pixelIndex: coordinate (%d,%d) out of range", x, y);
2470 const uchar * s = scanLine(y);
2473 return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
2474 case Format_MonoLSB:
2475 return (*(s + (x >> 3)) >> (x & 7)) & 1;
2476 case Format_Indexed8:
2479 qWarning(
"QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth);
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2501
2502
2503
2504
2505QRgb QImage::pixel(
int x,
int y)
const
2507 if (!d || x < 0 || x >= d->width || y < 0 || y >= d->height) {
2508 qWarning(
"QImage::pixel: coordinate (%d,%d) out of range", x, y);
2512 const uchar *s = d->data + y * d->bytes_per_line;
2515 switch (d->format) {
2517 index = (*(s + (x >> 3)) >> (~x & 7)) & 1;
2519 case Format_MonoLSB:
2520 index = (*(s + (x >> 3)) >> (x & 7)) & 1;
2522 case Format_Indexed8:
2529 if (index >= d->colortable.size()) {
2530 qWarning(
"QImage::pixel: color table index %d out of range.", index);
2533 return d->colortable.at(index);
2535 std::optional<QRgb> out;
2536 switch (d->format) {
2539 case Format_ARGB32_Premultiplied:
2540 out =
reinterpret_cast<
const QRgb *>(s)[x];
2542 case Format_RGBX8888:
2543 case Format_RGBA8888:
2544 case Format_RGBA8888_Premultiplied:
2545 out = RGBA2ARGB(
reinterpret_cast<
const quint32 *>(s)[x]);
2548 case Format_A2BGR30_Premultiplied:
2549 out = qConvertA2rgb30ToArgb32<PixelOrderBGR>(
reinterpret_cast<
const quint32 *>(s)[x]);
2552 case Format_A2RGB30_Premultiplied:
2553 out = qConvertA2rgb30ToArgb32<PixelOrderRGB>(
reinterpret_cast<
const quint32 *>(s)[x]);
2556 return qConvertRgb16To32(
reinterpret_cast<
const quint16 *>(s)[x]);
2559 case Format_RGBA64_Premultiplied:
2560 out =
reinterpret_cast<
const QRgba64 *>(s)[x].toArgb32();
2562 case Format_RGBX16FPx4:
2563 case Format_RGBA16FPx4:
2564 case Format_RGBA16FPx4_Premultiplied:
2565 out =
reinterpret_cast<
const QRgbaFloat16 *>(s)[x].toArgb32();
2567 case Format_RGBX32FPx4:
2568 case Format_RGBA32FPx4:
2569 case Format_RGBA32FPx4_Premultiplied:
2570 out =
reinterpret_cast<
const QRgbaFloat32 *>(s)[x].toArgb32();
2574 const QPixelLayout *layout = &qPixelLayouts[d->format];
2577 if (!layout->hasAlphaChannel)
2582 return *layout->fetchToARGB32PM(&result, s, x, 1,
nullptr,
nullptr);
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2607
2608
2609
2610
2611void QImage::setPixel(
int x,
int y, uint index_or_rgb)
2613 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
2614 qWarning(
"QImage::setPixel: coordinate (%d,%d) out of range", x, y);
2618 uchar * s = scanLine(y);
2621 case Format_MonoLSB:
2622 if (index_or_rgb > 1) {
2623 qWarning(
"QImage::setPixel: Index %d out of range", index_or_rgb);
2624 }
else if (format() == Format_MonoLSB) {
2625 if (index_or_rgb==0)
2626 *(s + (x >> 3)) &= ~(1 << (x & 7));
2628 *(s + (x >> 3)) |= (1 << (x & 7));
2630 if (index_or_rgb==0)
2631 *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
2633 *(s + (x >> 3)) |= (1 << (7-(x & 7)));
2636 case Format_Indexed8:
2637 if (index_or_rgb >= (uint)d->colortable.size()) {
2638 qWarning(
"QImage::setPixel: Index %d out of range", index_or_rgb);
2641 s[x] = index_or_rgb;
2646 ((uint *)s)[x] = 0xff000000 | index_or_rgb;
2649 case Format_ARGB32_Premultiplied:
2650 ((uint *)s)[x] = index_or_rgb;
2653 ((quint16 *)s)[x] = qConvertRgb32To16(index_or_rgb);
2655 case Format_RGBX8888:
2656 ((uint *)s)[x] = ARGB2RGBA(0xff000000 | index_or_rgb);
2658 case Format_RGBA8888:
2659 case Format_RGBA8888_Premultiplied:
2660 ((uint *)s)[x] = ARGB2RGBA(index_or_rgb);
2663 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderBGR>(index_or_rgb);
2665 case Format_A2BGR30_Premultiplied:
2666 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderBGR>(index_or_rgb);
2669 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderRGB>(index_or_rgb);
2671 case Format_A2RGB30_Premultiplied:
2672 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderRGB>(index_or_rgb);
2675 ((QRgba64 *)s)[x] = QRgba64::fromArgb32(index_or_rgb | 0xff000000);
2678 case Format_RGBA64_Premultiplied:
2679 ((QRgba64 *)s)[x] = QRgba64::fromArgb32(index_or_rgb);
2681 case Format_RGBX16FPx4:
2682 ((QRgbaFloat16 *)s)[x] = QRgbaFloat16::fromArgb32(index_or_rgb | 0xff000000);
2684 case Format_RGBA16FPx4:
2685 case Format_RGBA16FPx4_Premultiplied:
2686 ((QRgbaFloat16 *)s)[x] = QRgbaFloat16::fromArgb32(index_or_rgb);
2688 case Format_RGBX32FPx4:
2689 ((QRgbaFloat32 *)s)[x] = QRgbaFloat32::fromArgb32(index_or_rgb | 0xff000000);
2691 case Format_RGBA32FPx4:
2692 case Format_RGBA32FPx4_Premultiplied:
2693 ((QRgbaFloat32 *)s)[x] = QRgbaFloat32::fromArgb32(index_or_rgb);
2695 case Format_Invalid:
2703 const QPixelLayout *layout = &qPixelLayouts[d->format];
2704 if (!hasAlphaChannel())
2705 layout->storeFromRGB32(s, &index_or_rgb, x, 1,
nullptr,
nullptr);
2707 layout->storeFromARGB32PM(s, &index_or_rgb, x, 1,
nullptr,
nullptr);
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2727
2728
2729
2730
2731
2732QColor QImage::pixelColor(
int x,
int y)
const
2734 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
2735 qWarning(
"QImage::pixelColor: coordinate (%d,%d) out of range", x, y);
2740 const uchar * s = constScanLine(y);
2741 switch (d->format) {
2743 case Format_A2BGR30_Premultiplied:
2744 c = qConvertA2rgb30ToRgb64<PixelOrderBGR>(
reinterpret_cast<
const quint32 *>(s)[x]);
2747 case Format_A2RGB30_Premultiplied:
2748 c = qConvertA2rgb30ToRgb64<PixelOrderRGB>(
reinterpret_cast<
const quint32 *>(s)[x]);
2752 case Format_RGBA64_Premultiplied:
2753 c =
reinterpret_cast<
const QRgba64 *>(s)[x];
2755 case Format_Grayscale16: {
2756 quint16 v =
reinterpret_cast<
const quint16 *>(s)[x];
2757 return QColor(qRgba64(v, v, v, 0xffff));
2759 case Format_RGBX16FPx4:
2760 case Format_RGBA16FPx4:
2761 case Format_RGBA16FPx4_Premultiplied: {
2762 QRgbaFloat16 p =
reinterpret_cast<
const QRgbaFloat16 *>(s)[x];
2763 if (d->format == Format_RGBA16FPx4_Premultiplied)
2764 p = p.unpremultiplied();
2765 else if (d->format == Format_RGBX16FPx4)
2768 color.setRgbF(p.red(), p.green(), p.blue(), p.alpha());
2771 case Format_RGBX32FPx4:
2772 case Format_RGBA32FPx4:
2773 case Format_RGBA32FPx4_Premultiplied: {
2774 QRgbaFloat32 p =
reinterpret_cast<
const QRgbaFloat32 *>(s)[x];
2775 if (d->format == Format_RGBA32FPx4_Premultiplied)
2776 p = p.unpremultiplied();
2777 else if (d->format == Format_RGBX32FPx4)
2780 color.setRgbF(p.red(), p.green(), p.blue(), p.alpha());
2784 c = QRgba64::fromArgb32(pixel(x, y));
2788 switch (d->format) {
2798 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied)
2799 c = c.unpremultiplied();
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2820
2821
2822
2823
2824
2825void QImage::setPixelColor(
int x,
int y,
const QColor &color)
2827 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
2828 qWarning(
"QImage::setPixelColor: coordinate (%d,%d) out of range", x, y);
2832 if (!color.isValid()) {
2833 qWarning(
"QImage::setPixelColor: color is invalid");
2838 QRgba64 c = color.rgba64();
2839 if (!hasAlphaChannel())
2841 else if (qPixelLayouts[d->format].premultiplied)
2842 c = c.premultiplied();
2844 uchar * s = scanLine(y);
2845 switch (d->format) {
2847 case Format_MonoLSB:
2848 case Format_Indexed8:
2849 qWarning(
"QImage::setPixelColor: called on monochrome or indexed format");
2852 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c) | 0xc0000000;
2854 case Format_A2BGR30_Premultiplied:
2855 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c);
2858 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c) | 0xc0000000;
2860 case Format_A2RGB30_Premultiplied:
2861 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c);
2865 case Format_RGBA64_Premultiplied:
2866 ((QRgba64 *)s)[x] = c;
2868 case Format_RGBX16FPx4:
2869 case Format_RGBA16FPx4:
2870 case Format_RGBA16FPx4_Premultiplied: {
2872 color.getRgbF(&r, &g, &b, &a);
2873 if (d->format == Format_RGBX16FPx4)
2875 QRgbaFloat16 c16f{qfloat16(r), qfloat16(g), qfloat16(b), qfloat16(a)};
2876 if (d->format == Format_RGBA16FPx4_Premultiplied)
2877 c16f = c16f.premultiplied();
2878 ((QRgbaFloat16 *)s)[x] = c16f;
2881 case Format_RGBX32FPx4:
2882 case Format_RGBA32FPx4:
2883 case Format_RGBA32FPx4_Premultiplied: {
2885 color.getRgbF(&r, &g, &b, &a);
2886 if (d->format == Format_RGBX32FPx4)
2888 QRgbaFloat32 c32f{r, g, b, a};
2889 if (d->format == Format_RGBA32FPx4_Premultiplied)
2890 c32f = c32f.premultiplied();
2891 ((QRgbaFloat32 *)s)[x] = c32f;
2895 setPixel(x, y, c.toArgb32());
2901
2902
2903
2904
2905
2906
2907
2908
2909bool QImage::allGray()
const
2914 switch (d->format) {
2916 case Format_MonoLSB:
2917 case Format_Indexed8:
2918 for (
int i = 0; i < d->colortable.size(); ++i) {
2919 if (!qIsGray(d->colortable.at(i)))
2925 case Format_Grayscale8:
2926 case Format_Grayscale16:
2930 case Format_ARGB32_Premultiplied:
2931#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
2932 case Format_RGBX8888:
2933 case Format_RGBA8888:
2934 case Format_RGBA8888_Premultiplied:
2936 for (
int j = 0; j < d->height; ++j) {
2937 const QRgb *b = (
const QRgb *)constScanLine(j);
2938 for (
int i = 0; i < d->width; ++i) {
2945 for (
int j = 0; j < d->height; ++j) {
2946 const quint16 *b = (
const quint16 *)constScanLine(j);
2947 for (
int i = 0; i < d->width; ++i) {
2948 if (!qIsGray(qConvertRgb16To32(b[i])))
2957 Q_DECL_UNINITIALIZED uint buffer[BufferSize];
2958 const QPixelLayout *layout = &qPixelLayouts[d->format];
2959 const auto fetch = layout->fetchToARGB32PM;
2960 for (
int j = 0; j < d->height; ++j) {
2961 const uchar *b = constScanLine(j);
2963 while (x < d->width) {
2964 int l = qMin(d->width - x, BufferSize);
2965 const uint *ptr = fetch(buffer, b, x, l,
nullptr,
nullptr);
2966 for (
int i = 0; i < l; ++i) {
2967 if (!qIsGray(ptr[i]))
2977
2978
2979
2980
2981
2982
2983
2984
2985bool QImage::isGrayscale()
const
2990 if (d->format == QImage::Format_Alpha8)
2993 if (d->format == QImage::Format_Grayscale8 || d->format == QImage::Format_Grayscale16)
3002 Q_ASSERT(d->format == QImage::Format_Indexed8);
3003 for (
int i = 0; i < colorCount(); i++)
3004 if (d->colortable.at(i) != qRgb(i,i,i))
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaled(
const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode)
const
3054 qWarning(
"QImage::scaled: Image is a null image");
3060 QSize newSize = size();
3061 newSize.scale(s, aspectMode);
3062 newSize.rwidth() = qMax(newSize.width(), 1);
3063 newSize.rheight() = qMax(newSize.height(), 1);
3064 if (newSize == size())
3067 Q_TRACE_SCOPE(QImage_scaled, s, aspectMode, mode);
3069 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());
3070 QImage img = transformed(wm, mode);
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaledToWidth(
int w, Qt::TransformationMode mode)
const
3091 qWarning(
"QImage::scaleWidth: Image is a null image");
3097 Q_TRACE_SCOPE(QImage_scaledToWidth, w, mode);
3099 qreal factor = (qreal) w / width();
3100 QTransform wm = QTransform::fromScale(factor, factor);
3101 return transformed(wm, mode);
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118QImage Q_TRACE_INSTRUMENT(qtgui) QImage::scaledToHeight(
int h, Qt::TransformationMode mode)
const
3121 qWarning(
"QImage::scaleHeight: Image is a null image");
3127 Q_TRACE_SCOPE(QImage_scaledToHeight, h, mode);
3129 qreal factor = (qreal) h / height();
3130 QTransform wm = QTransform::fromScale(factor, factor);
3131 return transformed(wm, mode);
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151QImage Q_TRACE_INSTRUMENT(qtgui) QImage::createAlphaMask(Qt::ImageConversionFlags flags)
const
3153 if (!d || d->format == QImage::Format_RGB32)
3156 if (d->depth == 1) {
3159 return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags);
3162 QImage mask(d->width, d->height, Format_MonoLSB);
3163 if (!mask.isNull()) {
3164 dither_to_Mono(mask.d, d, flags,
true);
3165 copyPhysicalMetadata(mask.d, d);
3170#ifndef QT_NO_IMAGE_HEURISTIC_MASK
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3195QImage QImage::createHeuristicMask(
bool clipTight)
const
3200 if (d->depth != 32) {
3201 QImage img32 = convertToFormat(Format_RGB32);
3202 return img32.createHeuristicMask(clipTight);
3205#define PIX(x,y) (*((const QRgb*)scanLine(y)+x) & 0x00ffffff
)
3209 QImage m(w, h, Format_MonoLSB);
3212 m.setColor(0, QColor(Qt::color0).rgba());
3213 m.setColor(1, QColor(Qt::color1).rgba());
3216 QRgb background =
PIX(0,0);
3217 if (background !=
PIX(w-1,0) &&
3218 background !=
PIX(0,h-1) &&
3219 background !=
PIX(w-1,h-1)) {
3220 background =
PIX(w-1,0);
3221 if (background !=
PIX(w-1,h-1) &&
3222 background !=
PIX(0,h-1) &&
3223 PIX(0,h-1) ==
PIX(w-1,h-1)) {
3224 background =
PIX(w-1,h-1);
3230 uchar *ypp, *ypc, *ypn;
3233 ypn = m.scanLine(0);
3235 for (y = 0; y < h; y++) {
3238 ypn = (y == h-1) ?
nullptr : m.scanLine(y+1);
3239 const QRgb *p = (
const QRgb *)scanLine(y);
3240 for (x = 0; x < w; x++) {
3243 if ((x == 0 || y == 0 || x == w-1 || y == h-1 ||
3244 !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) ||
3245 !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) ||
3246 !(*(ypp + (x >> 3)) & (1 << (x & 7))) ||
3247 !(*(ypn + (x >> 3)) & (1 << (x & 7)))) &&
3248 ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) &&
3249 ((*p & 0x00ffffff) == background)) {
3251 *(ypc + (x >> 3)) &= ~(1 << (x & 7));
3259 ypn = m.scanLine(0);
3261 for (y = 0; y < h; y++) {
3264 ypn = (y == h-1) ?
nullptr : m.scanLine(y+1);
3265 const QRgb *p = (
const QRgb *)scanLine(y);
3266 for (x = 0; x < w; x++) {
3267 if ((*p & 0x00ffffff) != background) {
3269 *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
3271 *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
3273 *(ypp + (x >> 3)) |= (1 << (x & 7));
3275 *(ypn + (x >> 3)) |= (1 << (x & 7));
3284 copyPhysicalMetadata(m.d, d);
3290
3291
3292
3293
3294
3295
3296
3297
3299QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode)
const
3303 QImage maskImage(size(), QImage::Format_MonoLSB);
3306 uchar *s = maskImage.bits();
3310 if (depth() == 32) {
3311 for (
int h = 0; h < d->height; h++) {
3312 const uint *sl = (
const uint *) scanLine(h);
3313 for (
int w = 0; w < d->width; w++) {
3315 *(s + (w >> 3)) |= (1 << (w & 7));
3317 s += maskImage.bytesPerLine();
3320 for (
int h = 0; h < d->height; h++) {
3321 for (
int w = 0; w < d->width; w++) {
3322 if ((uint) pixel(w, h) == color)
3323 *(s + (w >> 3)) |= (1 << (w & 7));
3325 s += maskImage.bytesPerLine();
3328 if (mode == Qt::MaskOutColor)
3329 maskImage.invertPixels();
3331 copyPhysicalMetadata(maskImage.d, d);
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3350
3351
3352
3353
3354
3355
3356
3357
3358
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3374
3375
3376
3377
3378
3379
3380
3381
3383template<
class T>
inline void do_mirror_data(QImageData *dst, QImageData *src,
3384 int dstX0,
int dstY0,
3385 int dstXIncr,
int dstYIncr,
3391 const int srcXEnd = (dstX0 && !dstY0) ? w / 2 : w;
3392 const int srcYEnd = dstY0 ? h / 2 : h;
3393 for (
int srcY = 0, dstY = dstY0; srcY < srcYEnd; ++srcY, dstY += dstYIncr) {
3394 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3395 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);
3396 for (
int srcX = 0, dstX = dstX0; srcX < srcXEnd; ++srcX, dstX += dstXIncr)
3397 std::swap(srcPtr[srcX], dstPtr[dstX]);
3400 if (dstX0 && dstY0 && (h & 1)) {
3402 int srcXEnd2 = w / 2;
3403 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3404 for (
int srcX = 0, dstX = dstX0; srcX < srcXEnd2; ++srcX, dstX += dstXIncr)
3405 std::swap(srcPtr[srcX], srcPtr[dstX]);
3408 for (
int srcY = 0, dstY = dstY0; srcY < h; ++srcY, dstY += dstYIncr) {
3409 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
3410 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);
3411 for (
int srcX = 0, dstX = dstX0; srcX < w; ++srcX, dstX += dstXIncr)
3412 dstPtr[dstX] = srcPtr[srcX];
3417inline void do_flip(QImageData *dst, QImageData *src,
int w,
int h,
int depth)
3419 const int data_bytes_per_line = w * (depth / 8);
3421 uint *srcPtr =
reinterpret_cast<uint *>(src->data);
3422 uint *dstPtr =
reinterpret_cast<uint *>(dst->data + (h - 1) * dst->bytes_per_line);
3424 const int uint_per_line = (data_bytes_per_line + 3) >> 2;
3425 for (
int y = 0; y < h; ++y) {
3427 for (
int x = 0; x < uint_per_line; x++) {
3428 const uint d = dstPtr[x];
3429 const uint s = srcPtr[x];
3433 srcPtr += src->bytes_per_line >> 2;
3434 dstPtr -= dst->bytes_per_line >> 2;
3438 const uchar *srcPtr = src->data;
3439 uchar *dstPtr = dst->data + (h - 1) * dst->bytes_per_line;
3440 for (
int y = 0; y < h; ++y) {
3441 memcpy(dstPtr, srcPtr, data_bytes_per_line);
3442 srcPtr += src->bytes_per_line;
3443 dstPtr -= dst->bytes_per_line;
3448inline void do_mirror(QImageData *dst, QImageData *src,
bool horizontal,
bool vertical)
3450 Q_ASSERT(src->width == dst->width && src->height == dst->height && src->depth == dst->depth);
3452 int h = src->height;
3453 int depth = src->depth;
3455 if (src->depth == 1) {
3460 if (vertical && !horizontal) {
3462 do_flip(dst, src, w, h, depth);
3466 int dstX0 = 0, dstXIncr = 1;
3467 int dstY0 = 0, dstYIncr = 1;
3481 do_mirror_data<QRgbaFloat32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3484 do_mirror_data<quint64>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3487 do_mirror_data<quint32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3490 do_mirror_data<quint24>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3493 do_mirror_data<quint16>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3496 do_mirror_data<quint8>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);
3505 if (horizontal && dst->depth == 1) {
3506 Q_ASSERT(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB);
3507 const int shift = 8 - (dst->width % 8);
3508 const uchar *bitflip = qt_get_bitflip_array();
3509 for (
int y = 0; y < h; ++y) {
3510 uchar *begin = dst->data + y * dst->bytes_per_line;
3511 uchar *end = begin + dst->bytes_per_line;
3512 for (uchar *p = begin; p < end; ++p) {
3516 if (shift != 8 && p != begin) {
3517 if (dst->format == QImage::Format_Mono) {
3518 for (
int i = 0; i < shift; ++i) {
3520 p[-1] |= (*p & (128 >> i)) >> (7 - i);
3523 for (
int i = 0; i < shift; ++i) {
3525 p[-1] |= (*p & (1 << i)) << (7 - i);
3531 if (dst->format == QImage::Format_Mono)
3541
3542
3543QImage QImage::mirrored_helper(
bool horizontal,
bool vertical)
const
3548 if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
3552 QImage result(d->width, d->height, d->format);
3559 result.d->colortable = d->colortable;
3560 result.d->has_alpha_clut = d->has_alpha_clut;
3561 copyMetadata(result.d, d);
3563 do_mirror(result.d, d, horizontal, vertical);
3569
3570
3571void QImage::mirrored_inplace(
bool horizontal,
bool vertical)
3573 if (!d || (d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
3582 do_mirror(d, d, horizontal, vertical);
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3599
3600
3601
3602
3603
3604
3605
3606
3608static inline void rgbSwapped_generic(
int width,
int height,
const QImage *src, QImage *dst,
const QPixelLayout* layout)
3610 const RbSwapFunc func = layout->rbSwap;
3612 qWarning(
"Trying to rb-swap an image format where it doesn't make sense");
3618 for (
int i = 0; i < height; ++i) {
3619 uchar *q = dst->scanLine(i);
3620 const uchar *p = src->constScanLine(i);
3626
3627
3628QImage Q_TRACE_INSTRUMENT(qtgui) QImage::rgbSwapped_helper()
const
3633 Q_TRACE_SCOPE(QImage_rgbSwapped_helper);
3637 switch (d->format) {
3638 case Format_Invalid:
3643 case Format_Grayscale8:
3644 case Format_Grayscale16:
3647 case Format_MonoLSB:
3648 case Format_Indexed8:
3650 for (
int i = 0; i < res.d->colortable.size(); i++) {
3651 QRgb c = res.d->colortable.at(i);
3652 res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));
3655 case Format_RGBX8888:
3656 case Format_RGBA8888:
3657 case Format_RGBA8888_Premultiplied:
3658#if Q_BYTE_ORDER == Q_BIG_ENDIAN
3659 res = QImage(d->width, d->height, d->format);
3661 for (
int i = 0; i < d->height; i++) {
3662 uint *q = (uint*)res.scanLine(i);
3663 const uint *p = (
const uint*)constScanLine(i);
3664 const uint *end = p + d->width;
3667 *q = ((c << 16) & 0xff000000) | ((c >> 16) & 0xff00) | (c & 0x00ff00ff);
3679 case Format_ARGB32_Premultiplied:
3680 res = QImage(d->width, d->height, d->format);
3682 for (
int i = 0; i < d->height; i++) {
3683 uint *q = (uint*)res.scanLine(i);
3684 const uint *p = (
const uint*)constScanLine(i);
3685 const uint *end = p + d->width;
3688 *q = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);
3695 res = QImage(d->width, d->height, d->format);
3697 for (
int i = 0; i < d->height; i++) {
3698 ushort *q = (ushort*)res.scanLine(i);
3699 const ushort *p = (
const ushort*)constScanLine(i);
3700 const ushort *end = p + d->width;
3703 *q = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);
3710 res = QImage(d->width, d->height, d->format);
3712 rgbSwapped_generic(d->width, d->height,
this, &res, &qPixelLayouts[d->format]);
3715 copyMetadata(res.d, d);
3720
3721
3722void QImage::rgbSwapped_inplace()
3733 switch (d->format) {
3734 case Format_Invalid:
3739 case Format_Grayscale8:
3740 case Format_Grayscale16:
3743 case Format_MonoLSB:
3744 case Format_Indexed8:
3745 for (
int i = 0; i < d->colortable.size(); i++) {
3746 QRgb c = d->colortable.at(i);
3747 d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));
3750 case Format_RGBX8888:
3751 case Format_RGBA8888:
3752 case Format_RGBA8888_Premultiplied:
3753#if Q_BYTE_ORDER == Q_BIG_ENDIAN
3754 for (
int i = 0; i < d->height; i++) {
3755 uint *p = (uint*)scanLine(i);
3756 uint *end = p + d->width;
3759 *p = ((c << 16) & 0xff000000) | ((c >> 16) & 0xff00) | (c & 0x00ff00ff);
3770 case Format_ARGB32_Premultiplied:
3771 for (
int i = 0; i < d->height; i++) {
3772 uint *p = (uint*)scanLine(i);
3773 uint *end = p + d->width;
3776 *p = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);
3782 for (
int i = 0; i < d->height; i++) {
3783 ushort *p = (ushort*)scanLine(i);
3784 ushort *end = p + d->width;
3787 *p = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);
3793 case Format_A2BGR30_Premultiplied:
3795 case Format_A2RGB30_Premultiplied:
3796 for (
int i = 0; i < d->height; i++) {
3797 uint *p = (uint*)scanLine(i);
3798 uint *end = p + d->width;
3800 *p = qRgbSwapRgb30(*p);
3806 rgbSwapped_generic(d->width, d->height,
this,
this, &qPixelLayouts[d->format]);
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3830bool QImage::load(
const QString &fileName,
const char* format)
3832 *
this = QImageReader(fileName, format).read();
3837
3838
3839
3840
3841
3843bool QImage::load(QIODevice* device,
const char* format)
3845 *
this = QImageReader(device, format).read();
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3862bool QImage::loadFromData(QByteArrayView data,
const char *format)
3864 *
this = fromData(data, format);
3869
3870
3871
3872
3873
3874
3876bool QImage::loadFromData(
const uchar *buf,
int len,
const char *format)
3878 return loadFromData(QByteArrayView(buf, len), format);
3882
3883
3884
3885
3886
3887
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3904QImage QImage::fromData(QByteArrayView data,
const char *format)
3906 QByteArray a = QByteArray::fromRawData(data.constData(), data.size());
3909 b.open(QIODevice::ReadOnly);
3910 return QImageReader(&b, format).read();
3914
3915
3916
3917
3918
3919
3921QImage QImage::fromData(
const uchar *data,
int size,
const char *format)
3923 return fromData(QByteArrayView(data, size), format);
3927
3928
3929
3930
3931
3932
3933
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951bool QImage::save(
const QString &fileName,
const char *format,
int quality)
const
3955 QImageWriter writer(fileName, format);
3956 return d->doImageIO(
this, &writer, quality);
3960
3961
3962
3963
3964
3965
3966
3967
3968
3970bool QImage::save(QIODevice* device,
const char* format,
int quality)
const
3974 QImageWriter writer(device, format);
3975 return d->doImageIO(
this, &writer, quality);
3979
3981bool QImageData::doImageIO(
const QImage *image, QImageWriter *writer,
int quality)
const
3983 if (quality > 100 || quality < -1)
3984 qWarning(
"QImage::save: Quality out of range [-1, 100]");
3986 writer->setQuality(qMin(quality,100));
3987 const bool result = writer->write(*image);
3990 qWarning(
"QImage::save: failed to write image - %s", qPrintable(writer->errorString()));
3996
3997
3998#if !defined(QT_NO_DATASTREAM)
4000
4001
4002
4003
4004
4005
4006
4007
4008
4010QDataStream &operator<<(QDataStream &s,
const QImage &image)
4012 if (s.version() >= 5) {
4013 if (image.isNull()) {
4021 QImageWriter writer(s.device(), s.version() == 1 ?
"bmp" :
"png");
4022 writer.write(image);
4027
4028
4029
4030
4031
4032
4033
4034
4036QDataStream &operator>>(QDataStream &s, QImage &image)
4038 if (s.version() >= 5) {
4046 image = QImageReader(s.device(), s.version() == 1 ?
"bmp" :
"png").read();
4047 if (image.isNull() && s.version() >= 5)
4048 s.setStatus(QDataStream::ReadPastEnd);
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4068bool QImage::operator==(
const QImage & i)
const
4077 if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format || i.d->colorSpace != d->colorSpace)
4080 if (d->format != Format_RGB32) {
4081 if (d->format >= Format_ARGB32) {
4082 const int n = d->width * d->depth / 8;
4083 if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
4084 if (memcmp(bits(), i.bits(), d->nbytes))
4087 for (
int y = 0; y < d->height; ++y) {
4088 if (memcmp(scanLine(y), i.scanLine(y), n))
4093 const int w = width();
4094 const int h = height();
4095 const QList<QRgb> &colortable = d->colortable;
4096 const QList<QRgb> &icolortable = i.d->colortable;
4097 for (
int y=0; y<h; ++y) {
4098 for (
int x=0; x<w; ++x) {
4099 if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
4106 for(
int l = 0; l < d->height; l++) {
4108 const uint *p1 =
reinterpret_cast<
const uint*>(scanLine(l));
4109 const uint *p2 =
reinterpret_cast<
const uint*>(i.scanLine(l));
4111 if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff))
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4133bool QImage::operator!=(
const QImage & i)
const
4135 return !(*
this == i);
4142
4143
4144
4145
4146
4147
4148
4149int QImage::dotsPerMeterX()
const
4151 return d ? qRound(d->dpmx) : 0;
4155
4156
4157
4158
4159
4160
4161
4162int QImage::dotsPerMeterY()
const
4164 return d ? qRound(d->dpmy) : 0;
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179void QImage::setDotsPerMeterX(
int x)
4181 if (!d || !x || d->dpmx == x)
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201void QImage::setDotsPerMeterY(
int y)
4203 if (!d || !y || d->dpmy == y)
4212
4213
4214
4215
4216
4217
4218
4219QPoint QImage::offset()
const
4221 return d ? d->offset : QPoint();
4226
4227
4228
4229
4230
4231
4232
4233void QImage::setOffset(
const QPoint& p)
4235 if (!d || d->offset == p)
4244
4245
4246
4247
4248
4249
4250
4251QStringList QImage::textKeys()
const
4253 return d ? QStringList(d->text.keys()) : QStringList();
4257
4258
4259
4260
4261
4262
4263QString QImage::text(
const QString &key)
const
4269 return d->text.value(key);
4272 for (
auto it = d->text.begin(), end = d->text.end(); it != end; ++it)
4273 tmp += it.key() +
": "_L1 + it.value().simplified() +
"\n\n"_L1;
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303void QImage::setText(
const QString &key,
const QString &value)
4310 d->text.insert(key, value);
4314
4315
4316
4317
4318QPaintEngine *QImage::paintEngine()
const
4323 if (!d->paintEngine) {
4324 QPaintDevice *paintDevice =
const_cast<QImage *>(
this);
4325 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
4326 if (platformIntegration)
4327 d->paintEngine = platformIntegration->createImagePaintEngine(paintDevice);
4328 if (!d->paintEngine)
4329 d->paintEngine =
new QRasterPaintEngine(paintDevice);
4332 return d->paintEngine;
4337
4338
4339
4340
4341int QImage::metric(PaintDeviceMetric metric)
const
4354 return qRound(d->width * 1000 / d->dpmx);
4357 return qRound(d->height * 1000 / d->dpmy);
4360 return d->colortable.size();
4366 return qRound(d->dpmx * 0.0254);
4370 return qRound(d->dpmy * 0.0254);
4373 case PdmPhysicalDpiX:
4374 return qRound(d->dpmx * 0.0254);
4377 case PdmPhysicalDpiY:
4378 return qRound(d->dpmy * 0.0254);
4381 case PdmDevicePixelRatio:
4382 return d->devicePixelRatio;
4385 case PdmDevicePixelRatioScaled:
4386 return d->devicePixelRatio * QPaintDevice::devicePixelRatioFScale();
4389 case PdmDevicePixelRatioF_EncodedA:
4391 case PdmDevicePixelRatioF_EncodedB:
4392 return QPaintDevice::encodeMetricF(metric, d->devicePixelRatio);
4396 qWarning(
"QImage::metric(): Unhandled metric type %d", metric);
4405
4406
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4428#define IWX_MSB(b) if (trigx < maxws && trigy < maxhs) {
4429 if (*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4430 (1
<< (7
-((trigx>>12
)&7
))))
4437#define IWX_LSB(b) if (trigx < maxws && trigy < maxhs) {
4438 if (*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4439 (1
<< ((trigx>>12
)&7
)))
4446#define IWX_PIX(b) if (trigx < maxws && trigy < maxhs) {
4447 if ((*(sptr+sbpl*(trigy>>12
)+(trigx>>15
)) &
4448 (1
<< (7
-((trigx>>12
)&7
)))) == 0
)
4456bool qt_xForm_helper(
const QTransform &trueMat,
int xoffset,
int type,
int depth,
4457 uchar *dptr, qsizetype dbpl,
int p_inc,
int dHeight,
4458 const uchar *sptr, qsizetype sbpl,
int sWidth,
int sHeight)
4460 int m11 =
int(trueMat.m11()*4096.0);
4461 int m12 =
int(trueMat.m12()*4096.0);
4462 int m21 =
int(trueMat.m21()*4096.0);
4463 int m22 =
int(trueMat.m22()*4096.0);
4464 int dx = qRound(trueMat.dx()*4096.0);
4465 int dy = qRound(trueMat.dy()*4096.0);
4467 int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2;
4468 int m22ydy = dy + (m12 + m22) / 2;
4471 uint maxws = sWidth<<12;
4472 uint maxhs = sHeight<<12;
4474 for (
int y=0; y<dHeight; y++) {
4477 uchar *maxp = dptr + dbpl;
4481 while (dptr < maxp) {
4482 if (trigx < maxws && trigy < maxhs)
4483 *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12));
4491 while (dptr < maxp) {
4492 if (trigx < maxws && trigy < maxhs)
4493 *((ushort*)dptr) = *((
const ushort *)(sptr+sbpl*(trigy>>12) +
4503 while (dptr < maxp) {
4504 if (trigx < maxws && trigy < maxhs) {
4505 const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3);
4517 while (dptr < maxp) {
4518 if (trigx < maxws && trigy < maxhs)
4519 *((uint*)dptr) = *((
const uint *)(sptr+sbpl*(trigy>>12) +
4534 while (dptr < maxp) {
4547 while (dptr < maxp) {
4572
4573
4574
4575
4576
4577
4578qint64 QImage::cacheKey()
const
4583 return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
4587
4588
4589
4590
4591
4592
4594bool QImage::isDetached()
const
4596 return d && d->ref.loadRelaxed() == 1;
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4619void QImage::setAlphaChannel(
const QImage &alphaChannel)
4621 if (!d || alphaChannel.isNull())
4624 if (d->paintEngine && d->paintEngine->isActive()) {
4625 qWarning(
"QImage::setAlphaChannel: "
4626 "Unable to set alpha channel while image is being painted on");
4630 const Format alphaFormat = qt_alphaVersionForPainting(d->format);
4631 if (d->format == alphaFormat)
4634 convertTo(alphaFormat);
4640 if (alphaChannel.format() == QImage::Format_Alpha8 || (alphaChannel.d->depth == 8 && alphaChannel.isGrayscale()))
4641 sourceImage = alphaChannel;
4643 sourceImage = alphaChannel.convertToFormat(QImage::Format_Grayscale8);
4644 if (!sourceImage.reinterpretAsFormat(QImage::Format_Alpha8))
4647 QPainter painter(
this);
4648 if (sourceImage.size() != size())
4649 painter.setRenderHint(QPainter::SmoothPixmapTransform);
4650 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
4651 painter.drawImage(rect(), sourceImage);
4655
4656
4657
4658
4659
4660bool QImage::hasAlphaChannel()
const
4664 const QPixelFormat format = pixelFormat();
4665 if (format.alphaUsage() == QPixelFormat::UsesAlpha)
4667 if (format.colorModel() == QPixelFormat::Indexed)
4668 return d->has_alpha_clut;
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682int QImage::bitPlaneCount()
const
4687 switch (d->format) {
4688 case QImage::Format_Invalid:
4690 case QImage::Format_BGR30:
4691 case QImage::Format_RGB30:
4694 case QImage::Format_RGB32:
4695 case QImage::Format_RGBX8888:
4698 case QImage::Format_RGB666:
4701 case QImage::Format_RGB555:
4704 case QImage::Format_ARGB8555_Premultiplied:
4707 case QImage::Format_RGB444:
4710 case QImage::Format_RGBX64:
4711 case QImage::Format_RGBX16FPx4:
4714 case QImage::Format_RGBX32FPx4:
4718 bpc = qt_depthForFormat(d->format);
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735QImage QImage::smoothScaled(
int w,
int h)
const
4738 switch (src.format()) {
4739 case QImage::Format_RGB32:
4740 case QImage::Format_ARGB32_Premultiplied:
4741#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
4742 case QImage::Format_RGBX8888:
4744 case QImage::Format_RGBA8888_Premultiplied:
4745#if QT_CONFIG(raster_64bit)
4746 case QImage::Format_RGBX64:
4747 case QImage::Format_RGBA64_Premultiplied:
4749 case QImage::Format_RGBA64:
4750 case QImage::Format_Grayscale16:
4751 src.convertTo(QImage::Format_RGBA64_Premultiplied);
4754#if QT_CONFIG(raster_fp)
4755 case QImage::Format_RGBX32FPx4:
4756 case QImage::Format_RGBA32FPx4_Premultiplied:
4758 case QImage::Format_RGBX16FPx4:
4759 src.convertTo(QImage::Format_RGBX32FPx4);
4761 case QImage::Format_RGBA16FPx4:
4762 case QImage::Format_RGBA16FPx4_Premultiplied:
4763 case QImage::Format_RGBA32FPx4:
4764 src.convertTo(QImage::Format_RGBA32FPx4_Premultiplied);
4767 case QImage::Format_CMYK8888:
4770 if (src.hasAlphaChannel())
4771 src.convertTo(QImage::Format_ARGB32_Premultiplied);
4773 src.convertTo(QImage::Format_RGB32);
4775 src = qSmoothScaleImage(src, w, h);
4777 copyMetadata(src.d, d);
4781static QImage rotated90(
const QImage &image)
4783 QImage out(image.height(), image.width(), image.format());
4786 copyMetadata(QImageData::get(out), QImageData::get(image));
4787 if (image.colorCount() > 0)
4788 out.setColorTable(image.colorTable());
4789 int w = image.width();
4790 int h = image.height();
4791 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][2];
4793 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4795 for (
int y=0; y<h; ++y) {
4796 if (image.colorCount())
4797 for (
int x=0; x<w; ++x)
4798 out.setPixel(h-y-1, x, image.pixelIndex(x, y));
4800 for (
int x=0; x<w; ++x)
4801 out.setPixel(h-y-1, x, image.pixel(x, y));
4807static QImage rotated180(
const QImage &image)
4809 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][1];
4811 return image.flipped(Qt::Horizontal | Qt::Vertical);
4813 QImage out(image.width(), image.height(), image.format());
4816 copyMetadata(QImageData::get(out), QImageData::get(image));
4817 if (image.colorCount() > 0)
4818 out.setColorTable(image.colorTable());
4819 int w = image.width();
4820 int h = image.height();
4821 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4825static QImage rotated270(
const QImage &image)
4827 QImage out(image.height(), image.width(), image.format());
4830 copyMetadata(QImageData::get(out), QImageData::get(image));
4831 if (image.colorCount() > 0)
4832 out.setColorTable(image.colorTable());
4833 int w = image.width();
4834 int h = image.height();
4835 const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][0];
4837 memrotate(image.constBits(), w, h, image.bytesPerLine(), out.bits(), out.bytesPerLine());
4839 for (
int y=0; y<h; ++y) {
4840 if (image.colorCount())
4841 for (
int x=0; x<w; ++x)
4842 out.setPixel(y, w-x-1, image.pixelIndex(x, y));
4844 for (
int x=0; x<w; ++x)
4845 out.setPixel(y, w-x-1, image.pixel(x, y));
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4875QImage Q_TRACE_INSTRUMENT(qtgui) QImage::transformed(
const QTransform &matrix, Qt::TransformationMode mode )
const
4880 Q_TRACE_PARAM_REPLACE(
const QTransform &,
double[9]);
4881 Q_TRACE_SCOPE(QImage_transformed, QList<
double>({matrix.m11(), matrix.m12(), matrix.m13(),
4882 matrix.m21(), matrix.m22(), matrix.m23(),
4883 matrix.m31(), matrix.m32(), matrix.m33()}).data(), mode);
4886 const int ws = width();
4887 const int hs = height();
4894 QTransform mat = trueMatrix(matrix, ws, hs);
4895 bool complex_xform =
false;
4896 bool scale_xform =
false;
4897 bool nonpaintable_scale_xform =
false;
4898 if (mat.type() <= QTransform::TxScale) {
4899 if (mat.type() == QTransform::TxNone)
4901 else if (mat.m11() == -1. && mat.m22() == -1.)
4902 return rotated180(*
this);
4904 hd = qRound(qAbs(mat.m22()) * hs);
4905 wd = qRound(qAbs(mat.m11()) * ws);
4909 if (hd * 2 < hs || wd * 2 < ws)
4910 nonpaintable_scale_xform =
true;
4912 if (format() == QImage::Format_CMYK8888)
4913 nonpaintable_scale_xform =
true;
4915 if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) {
4916 if (mat.m12() == 1. && mat.m21() == -1.)
4917 return rotated90(*
this);
4918 else if (mat.m12() == -1. && mat.m21() == 1.)
4919 return rotated270(*
this);
4922 QPolygonF a(QRectF(0, 0, ws, hs));
4924 QRect r = a.boundingRect().toAlignedRect();
4927 complex_xform =
true;
4930 if (wd == 0 || hd == 0)
4933 if (scale_xform && mode == Qt::SmoothTransformation) {
4935 case QImage::Format_RGB32:
4936 case QImage::Format_ARGB32_Premultiplied:
4937#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
4938 case QImage::Format_RGBX8888:
4940 case QImage::Format_RGBA8888_Premultiplied:
4941#if QT_CONFIG(raster_64bit)
4942 case QImage::Format_RGBX64:
4943 case QImage::Format_RGBA64_Premultiplied:
4945 case QImage::Format_CMYK8888:
4947 if (mat.m11() > 0.0F && mat.m22() > 0.0F)
4948 return smoothScaled(wd, hd);
4954 if (nonpaintable_scale_xform
4955#if QT_CONFIG(qtgui_threadpool)
4956 || (ws * hs) >= (1<<20)
4960 if (mat.m11() < 0.0F && mat.m22() < 0.0F) {
4961 scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal | Qt::Vertical);
4962 }
else if (mat.m11() < 0.0F) {
4963 scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal);
4964 }
else if (mat.m22() < 0.0F) {
4965 scaledImage = smoothScaled(wd, hd).flipped(Qt::Vertical);
4967 scaledImage = smoothScaled(wd, hd);
4971 case QImage::Format_Mono:
4972 case QImage::Format_MonoLSB:
4973 case QImage::Format_Indexed8:
4976 return scaledImage.convertToFormat(format());
4983 qsizetype sbpl = bytesPerLine();
4984 const uchar *sptr = bits();
4986 QImage::Format target_format = d->format;
4988 if (complex_xform || mode == Qt::SmoothTransformation) {
4989 if (d->format < QImage::Format_RGB32 || (!hasAlphaChannel() && complex_xform)) {
4990 target_format = qt_alphaVersion(d->format);
4994 QImage dImage(wd, hd, target_format);
4997 if (target_format == QImage::Format_MonoLSB
4998 || target_format == QImage::Format_Mono
4999 || target_format == QImage::Format_Indexed8) {
5000 dImage.d->colortable = d->colortable;
5001 dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform;
5005 if (target_format == QImage::Format_Indexed8) {
5006 if (dImage.d->colortable.size() < 256) {
5008 dImage.d->colortable.append(0x0);
5009 memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.d->nbytes);
5011 memset(dImage.bits(), 0, dImage.d->nbytes);
5014 memset(dImage.bits(), 0x00, dImage.d->nbytes);
5016 if (target_format >= QImage::Format_RGB32 && target_format != QImage::Format_CMYK8888) {
5018 QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *
this;
5020 && (d->format == QImage::Format_MonoLSB
5021 || d->format == QImage::Format_Mono
5022 || d->format == QImage::Format_Indexed8)) {
5023 sImage.d->colortable = d->colortable;
5024 sImage.d->has_alpha_clut = d->has_alpha_clut;
5027 Q_ASSERT(sImage.devicePixelRatio() == 1);
5028 Q_ASSERT(sImage.devicePixelRatio() == dImage.devicePixelRatio());
5030 QPainter p(&dImage);
5031 if (mode == Qt::SmoothTransformation) {
5032 p.setRenderHint(QPainter::Antialiasing);
5033 p.setRenderHint(QPainter::SmoothPixmapTransform);
5035 p.setTransform(mat);
5036 p.drawImage(QPoint(0, 0), sImage);
5039 mat = mat.inverted(&invertible);
5045 qsizetype dbpl = dImage.bytesPerLine();
5046 qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs);
5048 copyMetadata(dImage.d, d);
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5074QTransform QImage::trueMatrix(
const QTransform &matrix,
int w,
int h)
5076 const QRectF rect(0, 0, w, h);
5077 const QRect mapped = matrix.mapRect(rect).toAlignedRect();
5078 const QPoint delta = mapped.topLeft();
5079 return matrix * QTransform().translate(-delta.x(), -delta.y());
5083
5084
5085
5086
5087
5088
5089void QImage::setColorSpace(
const QColorSpace &colorSpace)
5093 if (d->colorSpace == colorSpace)
5095 if (colorSpace.isValid() && !qt_compatibleColorModelSource(pixelFormat().colorModel(), colorSpace.colorModel()))
5098 detachMetadata(
false);
5100 d->colorSpace = colorSpace;
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115void QImage::convertToColorSpace(
const QColorSpace &colorSpace)
5117 if (!d || !d->colorSpace.isValid())
5119 if (!colorSpace.isValidTarget()) {
5120 qWarning() <<
"QImage::convertToColorSpace: Output colorspace is not valid";
5123 if (d->colorSpace == colorSpace)
5125 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(),
5126 colorSpace.colorModel(), colorSpace.transformModel())) {
5127 *
this = convertedToColorSpace(colorSpace);
5130 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace));
5131 if (d->ref.loadRelaxed() != 1)
5132 detachMetadata(
false);
5133 d->colorSpace = colorSpace;
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149void QImage::convertToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags)
5151 if (!d || !d->colorSpace.isValid())
5153 if (!colorSpace.isValidTarget()) {
5154 qWarning() <<
"QImage::convertToColorSpace: Output colorspace is not valid";
5157 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5158 colorSpace.colorModel(), colorSpace.transformModel())) {
5159 qWarning() <<
"QImage::convertToColorSpace: Color space is not compatible with format";
5163 if (d->colorSpace == colorSpace)
5164 return convertTo(format, flags);
5165 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5166 d->colorSpace = colorSpace;
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace)
const
5185 if (!d || !d->colorSpace.isValid())
5187 if (!colorSpace.isValidTarget()) {
5188 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5191 if (d->colorSpace == colorSpace)
5193 QImage image = colorTransformed(d->colorSpace.transformationToColorSpace(colorSpace));
5194 image.setColorSpace(colorSpace);
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags)
const &
5214 if (!d || !d->colorSpace.isValid())
5216 if (!colorSpace.isValidTarget()) {
5217 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5220 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5221 colorSpace.colorModel(), colorSpace.transformModel())) {
5222 qWarning() <<
"QImage::convertedToColorSpace: Color space is not compatible with format";
5225 if (d->colorSpace == colorSpace)
5226 return convertedTo(format, flags);
5227 QImage image = colorTransformed(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5228 image.setColorSpace(colorSpace);
5232QImage QImage::convertedToColorSpace(
const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags) &&
5234 if (!d || !d->colorSpace.isValid())
5236 if (!colorSpace.isValidTarget()) {
5237 qWarning() <<
"QImage::convertedToColorSpace: Output colorspace is not valid";
5240 if (!qt_compatibleColorModelTarget(toPixelFormat(format).colorModel(),
5241 colorSpace.colorModel(), colorSpace.transformModel())) {
5242 qWarning() <<
"QImage::convertedToColorSpace: Color space is not compatible with format";
5245 if (d->colorSpace == colorSpace)
5246 return convertedTo(format, flags);
5247 applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace), format, flags);
5248 return std::move(*
this);
5252
5253
5254
5255
5256QColorSpace QImage::colorSpace()
const
5259 return QColorSpace();
5260 return d->colorSpace;
5264
5265
5266
5267
5268void QImage::applyColorTransform(
const QColorTransform &transform)
5270 if (transform.isIdentity())
5273 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), QColorTransformPrivate::get(transform)->colorSpaceIn->colorModel) ||
5274 !qt_compatibleColorModelTarget(pixelFormat().colorModel(), QColorTransformPrivate::get(transform)->colorSpaceOut->colorModel,
5275 QColorTransformPrivate::get(transform)->colorSpaceOut->transformModel)) {
5276 qWarning() <<
"QImage::applyColorTransform can not apply format switching transform without switching format";
5283 if (pixelFormat().colorModel() == QPixelFormat::Indexed) {
5284 for (
int i = 0; i < d->colortable.size(); ++i)
5285 d->colortable[i] = transform.map(d->colortable[i]);
5288 QImage::Format oldFormat = format();
5289 if (qt_fpColorPrecision(oldFormat)) {
5290 if (oldFormat != QImage::Format_RGBX32FPx4 && oldFormat != QImage::Format_RGBA32FPx4
5291 && oldFormat != QImage::Format_RGBA32FPx4_Premultiplied)
5292 convertTo(QImage::Format_RGBA32FPx4);
5293 }
else if (depth() > 32) {
5294 if (oldFormat != QImage::Format_RGBX64 && oldFormat != QImage::Format_RGBA64
5295 && oldFormat != QImage::Format_RGBA64_Premultiplied)
5296 convertTo(QImage::Format_RGBA64);
5297 }
else if (oldFormat != QImage::Format_ARGB32 && oldFormat != QImage::Format_RGB32
5298 && oldFormat != QImage::Format_ARGB32_Premultiplied && oldFormat != QImage::Format_CMYK8888
5299 && oldFormat != QImage::Format_Grayscale8 && oldFormat != QImage::Format_Grayscale16) {
5300 if (hasAlphaChannel())
5301 convertTo(QImage::Format_ARGB32);
5303 convertTo(QImage::Format_RGB32);
5306 QColorTransformPrivate::TransformFlags flags = QColorTransformPrivate::Unpremultiplied;
5308 case Format_ARGB32_Premultiplied:
5309 case Format_RGBA64_Premultiplied:
5310 case Format_RGBA32FPx4_Premultiplied:
5311 flags = QColorTransformPrivate::Premultiplied;
5313 case Format_Grayscale8:
5314 case Format_Grayscale16:
5316 case Format_CMYK8888:
5318 case Format_RGBX32FPx4:
5319 flags = QColorTransformPrivate::InputOpaque;
5323 case Format_RGBA32FPx4:
5329 std::function<
void(
int,
int)> transformSegment;
5331 if (format() == Format_Grayscale8) {
5332 transformSegment = [&](
int yStart,
int yEnd) {
5333 for (
int y = yStart; y < yEnd; ++y) {
5334 uint8_t *scanline =
reinterpret_cast<uint8_t *>(d->data + y * d->bytes_per_line);
5335 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5338 }
else if (format() == Format_Grayscale16) {
5339 transformSegment = [&](
int yStart,
int yEnd) {
5340 for (
int y = yStart; y < yEnd; ++y) {
5341 uint16_t *scanline =
reinterpret_cast<uint16_t *>(d->data + y * d->bytes_per_line);
5342 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5345 }
else if (qt_fpColorPrecision(format())) {
5346 transformSegment = [&](
int yStart,
int yEnd) {
5347 for (
int y = yStart; y < yEnd; ++y) {
5348 QRgbaFloat32 *scanline =
reinterpret_cast<QRgbaFloat32 *>(d->data + y * d->bytes_per_line);
5349 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5352 }
else if (depth() > 32) {
5353 transformSegment = [&](
int yStart,
int yEnd) {
5354 for (
int y = yStart; y < yEnd; ++y) {
5355 QRgba64 *scanline =
reinterpret_cast<QRgba64 *>(d->data + y * d->bytes_per_line);
5356 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5359 }
else if (oldFormat == QImage::Format_CMYK8888) {
5360 transformSegment = [&](
int yStart,
int yEnd) {
5361 for (
int y = yStart; y < yEnd; ++y) {
5362 QCmyk32 *scanline =
reinterpret_cast<QCmyk32 *>(d->data + y * d->bytes_per_line);
5363 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5367 transformSegment = [&](
int yStart,
int yEnd) {
5368 for (
int y = yStart; y < yEnd; ++y) {
5369 QRgb *scanline =
reinterpret_cast<QRgb *>(d->data + y * d->bytes_per_line);
5370 QColorTransformPrivate::get(transform)->apply(scanline, scanline, width(), flags);
5375#if QT_CONFIG(qtgui_threadpool)
5376 int segments = (qsizetype(width()) * height()) >> 16;
5377 segments = std::min(segments, height());
5378 QThreadPool *threadPool = QGuiApplicationPrivate::qtGuiThreadPool();
5379 if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {
5380 QLatch latch(segments);
5382 for (
int i = 0; i < segments; ++i) {
5383 int yn = (height() - y) / (segments - i);
5384 threadPool->start([&, y, yn]() {
5385 transformSegment(y, y + yn);
5393 transformSegment(0, height());
5395 if (oldFormat != format())
5396 *
this = std::move(*
this).convertToFormat(oldFormat);
5400
5401
5402
5403
5404
5405
5406
5407void QImage::applyColorTransform(
const QColorTransform &transform, QImage::Format toFormat, Qt::ImageConversionFlags flags)
5411 if (transform.isIdentity())
5412 return convertTo(toFormat, flags);
5414 *
this = colorTransformed(transform, toFormat, flags);
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429QImage QImage::colorTransformed(
const QColorTransform &transform)
const &
5433 if (transform.isIdentity())
5436 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5437 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5438 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5439 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5442 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5444 switch (outColorSpace->colorModel) {
5445 case QColorSpace::ColorModel::Rgb:
5446 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_RGBX64 : QImage::Format_RGB32);
5447 case QColorSpace::ColorModel::Gray:
5448 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_Grayscale16 : QImage::Format_Grayscale8);
5449 case QColorSpace::ColorModel::Cmyk:
5450 return colorTransformed(transform, QImage::Format_CMYK8888);
5451 case QColorSpace::ColorModel::Undefined:
5457 QImage image = copy();
5458 image.applyColorTransform(transform);
5462static bool isRgb32Data(QImage::Format f)
5465 case QImage::Format_RGB32:
5466 case QImage::Format_ARGB32:
5467 case QImage::Format_ARGB32_Premultiplied:
5475static bool isRgb64Data(QImage::Format f)
5478 case QImage::Format_RGBX64:
5479 case QImage::Format_RGBA64:
5480 case QImage::Format_RGBA64_Premultiplied:
5488static bool isRgb32fpx4Data(QImage::Format f)
5491 case QImage::Format_RGBX32FPx4:
5492 case QImage::Format_RGBA32FPx4:
5493 case QImage::Format_RGBA32FPx4_Premultiplied:
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514QImage QImage::colorTransformed(
const QColorTransform &transform, QImage::Format toFormat, Qt::ImageConversionFlags flags)
const &
5518 if (toFormat == QImage::Format_Invalid)
5519 toFormat = format();
5520 if (transform.isIdentity())
5521 return convertedTo(toFormat, flags);
5523 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5524 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5525 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5526 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5529 if (!qt_compatibleColorModelTarget(toPixelFormat(toFormat).colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5530 qWarning() <<
"QImage::colorTransformed: Invalid output color space for transform";
5534 QImage fromImage = *
this;
5536 QImage::Format tmpFormat = toFormat;
5538 case QImage::Format_RGB32:
5539 case QImage::Format_ARGB32:
5540 case QImage::Format_ARGB32_Premultiplied:
5541 case QImage::Format_RGBX32FPx4:
5542 case QImage::Format_RGBA32FPx4:
5543 case QImage::Format_RGBA32FPx4_Premultiplied:
5544 case QImage::Format_RGBX64:
5545 case QImage::Format_RGBA64:
5546 case QImage::Format_RGBA64_Premultiplied:
5547 case QImage::Format_Grayscale8:
5548 case QImage::Format_Grayscale16:
5549 case QImage::Format_CMYK8888:
5552 case QImage::Format_RGB16:
5553 case QImage::Format_RGB444:
5554 case QImage::Format_RGB555:
5555 case QImage::Format_RGB666:
5556 case QImage::Format_RGB888:
5557 case QImage::Format_BGR888:
5558 case QImage::Format_RGBX8888:
5559 tmpFormat = QImage::Format_RGB32;
5561 case QImage::Format_Mono:
5562 case QImage::Format_MonoLSB:
5563 case QImage::Format_Indexed8:
5564 case QImage::Format_ARGB8565_Premultiplied:
5565 case QImage::Format_ARGB6666_Premultiplied:
5566 case QImage::Format_ARGB8555_Premultiplied:
5567 case QImage::Format_ARGB4444_Premultiplied:
5568 case QImage::Format_RGBA8888:
5569 case QImage::Format_RGBA8888_Premultiplied:
5570 tmpFormat = QImage::Format_ARGB32;
5572 case QImage::Format_BGR30:
5573 case QImage::Format_RGB30:
5574 tmpFormat = QImage::Format_RGBX64;
5576 case QImage::Format_A2BGR30_Premultiplied:
5577 case QImage::Format_A2RGB30_Premultiplied:
5578 tmpFormat = QImage::Format_RGBA64;
5580 case QImage::Format_RGBX16FPx4:
5581 case QImage::Format_RGBA16FPx4:
5582 case QImage::Format_RGBA16FPx4_Premultiplied:
5583 tmpFormat = QImage::Format_RGBA32FPx4;
5585 case QImage::Format_Alpha8:
5586 return convertedTo(QImage::Format_Alpha8);
5587 case QImage::Format_Invalid:
5588 case QImage::NImageFormats:
5592 QColorSpace::ColorModel inColorData = qt_csColorData(pixelFormat().colorModel());
5593 QColorSpace::ColorModel outColorData = qt_csColorData(toPixelFormat(toFormat).colorModel());
5595 if (inColorData != outColorData) {
5596 if (fromImage.format() == QImage::Format_Grayscale8 && outColorData == QColorSpace::ColorModel::Rgb)
5597 tmpFormat = QImage::Format_RGB32;
5598 else if (tmpFormat == QImage::Format_Grayscale8 && qt_highColorPrecision(fromImage.format()))
5599 tmpFormat = QImage::Format_Grayscale16;
5600 else if (fromImage.format() == QImage::Format_Grayscale16 && outColorData == QColorSpace::ColorModel::Rgb)
5601 tmpFormat = QImage::Format_RGBX64;
5603 if (tmpFormat == QImage::Format_Grayscale8 && fromImage.format() == QImage::Format_Grayscale16)
5604 tmpFormat = QImage::Format_Grayscale16;
5605 else if (qt_fpColorPrecision(fromImage.format()) && !qt_fpColorPrecision(tmpFormat))
5606 tmpFormat = QImage::Format_RGBA32FPx4;
5607 else if (isRgb32Data(tmpFormat) && qt_highColorPrecision(fromImage.format(),
true))
5608 tmpFormat = QImage::Format_RGBA64;
5611 QImage toImage(size(), tmpFormat);
5612 copyMetadata(&toImage, *
this);
5614 std::function<
void(
int,
int)> transformSegment;
5615 QColorTransformPrivate::TransformFlags transFlags = QColorTransformPrivate::Unpremultiplied;
5617 if (inColorData != outColorData) {
5619 if (inColorData == QColorSpace::ColorModel::Gray && outColorData == QColorSpace::ColorModel::Rgb) {
5621 if (format() == QImage::Format_Grayscale8) {
5622 transformSegment = [&](
int yStart,
int yEnd) {
5623 for (
int y = yStart; y < yEnd; ++y) {
5624 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(d->data + y * d->bytes_per_line);
5625 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5626 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5630 transformSegment = [&](
int yStart,
int yEnd) {
5631 for (
int y = yStart; y < yEnd; ++y) {
5632 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(d->data + y * d->bytes_per_line);
5633 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5634 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5638 }
else if (inColorData == QColorSpace::ColorModel::Gray && outColorData == QColorSpace::ColorModel::Cmyk) {
5640 if (format() == QImage::Format_Grayscale8) {
5641 transformSegment = [&](
int yStart,
int yEnd) {
5642 for (
int y = yStart; y < yEnd; ++y) {
5643 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(d->data + y * d->bytes_per_line);
5644 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5645 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5649 transformSegment = [&](
int yStart,
int yEnd) {
5650 for (
int y = yStart; y < yEnd; ++y) {
5651 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(d->data + y * d->bytes_per_line);
5652 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5653 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5657 }
else if (inColorData == QColorSpace::ColorModel::Rgb && outColorData == QColorSpace::ColorModel::Gray) {
5659 if (tmpFormat == QImage::Format_Grayscale8) {
5660 fromImage.convertTo(QImage::Format_RGB32);
5661 transformSegment = [&](
int yStart,
int yEnd) {
5662 for (
int y = yStart; y < yEnd; ++y) {
5663 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5664 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5665 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5669 fromImage.convertTo(QImage::Format_RGBX64);
5670 transformSegment = [&](
int yStart,
int yEnd) {
5671 for (
int y = yStart; y < yEnd; ++y) {
5672 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5673 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5674 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5678 }
else if (inColorData == QColorSpace::ColorModel::Cmyk && outColorData == QColorSpace::ColorModel::Gray) {
5680 if (tmpFormat == QImage::Format_Grayscale8) {
5681 transformSegment = [&](
int yStart,
int yEnd) {
5682 for (
int y = yStart; y < yEnd; ++y) {
5683 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5684 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5685 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5689 transformSegment = [&](
int yStart,
int yEnd) {
5690 for (
int y = yStart; y < yEnd; ++y) {
5691 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5692 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5693 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5697 }
else if (inColorData == QColorSpace::ColorModel::Cmyk && outColorData == QColorSpace::ColorModel::Rgb) {
5699 if (isRgb32Data(tmpFormat) ) {
5700 transformSegment = [&](
int yStart,
int yEnd) {
5701 for (
int y = yStart; y < yEnd; ++y) {
5702 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5703 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5704 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5707 }
else if (isRgb64Data(tmpFormat)) {
5708 transformSegment = [&](
int yStart,
int yEnd) {
5709 for (
int y = yStart; y < yEnd; ++y) {
5710 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5711 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5712 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5716 Q_ASSERT(isRgb32fpx4Data(tmpFormat));
5717 transformSegment = [&](
int yStart,
int yEnd) {
5718 for (
int y = yStart; y < yEnd; ++y) {
5719 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5720 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5721 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), QColorTransformPrivate::InputOpaque);
5725 }
else if (inColorData == QColorSpace::ColorModel::Rgb && outColorData == QColorSpace::ColorModel::Cmyk) {
5727 if (!fromImage.hasAlphaChannel())
5728 transFlags = QColorTransformPrivate::InputOpaque;
5729 else if (qPixelLayouts[fromImage.format()].premultiplied)
5730 transFlags = QColorTransformPrivate::Premultiplied;
5731 if (isRgb32Data(fromImage.format()) ) {
5732 transformSegment = [&](
int yStart,
int yEnd) {
5733 for (
int y = yStart; y < yEnd; ++y) {
5734 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5735 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5736 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5739 }
else if (isRgb64Data(fromImage.format())) {
5740 transformSegment = [&](
int yStart,
int yEnd) {
5741 for (
int y = yStart; y < yEnd; ++y) {
5742 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5743 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5744 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5748 Q_ASSERT(isRgb32fpx4Data(fromImage.format()));
5749 transformSegment = [&](
int yStart,
int yEnd) {
5750 for (
int y = yStart; y < yEnd; ++y) {
5751 const QRgbaFloat32 *in_scanline =
reinterpret_cast<
const QRgbaFloat32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5752 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5753 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5762 if (pixelFormat().colorModel() == QPixelFormat::Indexed) {
5763 for (
int i = 0; i < d->colortable.size(); ++i)
5764 fromImage.d->colortable[i] = transform.map(d->colortable[i]);
5765 return fromImage.convertedTo(toFormat, flags);
5768 QImage::Format oldFormat = format();
5769 if (qt_fpColorPrecision(oldFormat)) {
5770 if (oldFormat != QImage::Format_RGBX32FPx4 && oldFormat != QImage::Format_RGBA32FPx4
5771 && oldFormat != QImage::Format_RGBA32FPx4_Premultiplied)
5772 fromImage.convertTo(QImage::Format_RGBA32FPx4);
5773 }
else if (qt_highColorPrecision(oldFormat,
true)) {
5774 if (oldFormat != QImage::Format_RGBX64 && oldFormat != QImage::Format_RGBA64
5775 && oldFormat != QImage::Format_RGBA64_Premultiplied && oldFormat != QImage::Format_Grayscale16)
5776 fromImage.convertTo(QImage::Format_RGBA64);
5777 }
else if (oldFormat != QImage::Format_ARGB32 && oldFormat != QImage::Format_RGB32
5778 && oldFormat != QImage::Format_ARGB32_Premultiplied && oldFormat != QImage::Format_CMYK8888
5779 && oldFormat != QImage::Format_Grayscale8 && oldFormat != QImage::Format_Grayscale16) {
5780 if (hasAlphaChannel())
5781 fromImage.convertTo(QImage::Format_ARGB32);
5783 fromImage.convertTo(QImage::Format_RGB32);
5786 if (!fromImage.hasAlphaChannel())
5787 transFlags = QColorTransformPrivate::InputOpaque;
5788 else if (qPixelLayouts[fromImage.format()].premultiplied)
5789 transFlags = QColorTransformPrivate::Premultiplied;
5791 if (fromImage.format() == Format_Grayscale8) {
5792 transformSegment = [&](
int yStart,
int yEnd) {
5793 for (
int y = yStart; y < yEnd; ++y) {
5794 const quint8 *in_scanline =
reinterpret_cast<
const quint8 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5795 if (tmpFormat == Format_Grayscale8) {
5796 quint8 *out_scanline =
reinterpret_cast<quint8 *>(toImage.d->data + y * toImage.bytesPerLine());
5797 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5799 Q_ASSERT(tmpFormat == Format_Grayscale16);
5800 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5801 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5805 }
else if (fromImage.format() == Format_Grayscale16) {
5806 transformSegment = [&](
int yStart,
int yEnd) {
5807 for (
int y = yStart; y < yEnd; ++y) {
5808 const quint16 *in_scanline =
reinterpret_cast<
const quint16 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5809 quint16 *out_scanline =
reinterpret_cast<quint16 *>(toImage.d->data + y * toImage.bytesPerLine());
5810 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5813 }
else if (fromImage.format() == Format_CMYK8888) {
5814 Q_ASSERT(tmpFormat == Format_CMYK8888);
5815 transformSegment = [&](
int yStart,
int yEnd) {
5816 for (
int y = yStart; y < yEnd; ++y) {
5817 const QCmyk32 *in_scanline =
reinterpret_cast<
const QCmyk32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5818 QCmyk32 *out_scanline =
reinterpret_cast<QCmyk32 *>(toImage.d->data + y * toImage.bytesPerLine());
5819 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5822 }
else if (isRgb32fpx4Data(fromImage.format())) {
5823 Q_ASSERT(isRgb32fpx4Data(tmpFormat));
5824 transformSegment = [&](
int yStart,
int yEnd) {
5825 for (
int y = yStart; y < yEnd; ++y) {
5826 const QRgbaFloat32 *in_scanline =
reinterpret_cast<
const QRgbaFloat32 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5827 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5828 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5831 }
else if (isRgb64Data(fromImage.format())) {
5832 transformSegment = [&](
int yStart,
int yEnd) {
5833 for (
int y = yStart; y < yEnd; ++y) {
5834 const QRgba64 *in_scanline =
reinterpret_cast<
const QRgba64 *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5835 if (isRgb32fpx4Data(tmpFormat)) {
5836 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5837 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5839 Q_ASSERT(isRgb64Data(tmpFormat));
5840 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5841 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5846 transformSegment = [&](
int yStart,
int yEnd) {
5847 for (
int y = yStart; y < yEnd; ++y) {
5848 const QRgb *in_scanline =
reinterpret_cast<
const QRgb *>(fromImage.constBits() + y * fromImage.bytesPerLine());
5849 if (isRgb32fpx4Data(tmpFormat)) {
5850 QRgbaFloat32 *out_scanline =
reinterpret_cast<QRgbaFloat32 *>(toImage.d->data + y * toImage.bytesPerLine());
5851 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5852 }
else if (isRgb64Data(tmpFormat)) {
5853 QRgba64 *out_scanline =
reinterpret_cast<QRgba64 *>(toImage.d->data + y * toImage.bytesPerLine());
5854 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5856 Q_ASSERT(isRgb32Data(tmpFormat));
5857 QRgb *out_scanline =
reinterpret_cast<QRgb *>(toImage.d->data + y * toImage.bytesPerLine());
5858 QColorTransformPrivate::get(transform)->apply(out_scanline, in_scanline, width(), transFlags);
5865#if QT_CONFIG(qtgui_threadpool)
5866 int segments = (qsizetype(width()) * height()) >> 16;
5867 segments = std::min(segments, height());
5868 QThreadPool *threadPool = QGuiApplicationPrivate::qtGuiThreadPool();
5869 if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {
5870 QLatch latch(segments);
5872 for (
int i = 0; i < segments; ++i) {
5873 int yn = (height() - y) / (segments - i);
5874 threadPool->start([&, y, yn]() {
5875 transformSegment(y, y + yn);
5883 transformSegment(0, height());
5885 if (tmpFormat != toFormat)
5886 toImage.convertTo(toFormat);
5892
5893
5894
5895
5896
5897
5898
5899QImage QImage::colorTransformed(
const QColorTransform &transform) &&
5904 const QColorSpacePrivate *inColorSpace = QColorTransformPrivate::get(transform)->colorSpaceIn.constData();
5905 const QColorSpacePrivate *outColorSpace = QColorTransformPrivate::get(transform)->colorSpaceOut.constData();
5906 if (!qt_compatibleColorModelSource(pixelFormat().colorModel(), inColorSpace->colorModel)) {
5907 qWarning() <<
"QImage::colorTransformed: Invalid input color space for transform";
5910 if (!qt_compatibleColorModelTarget(pixelFormat().colorModel(), outColorSpace->colorModel, outColorSpace->transformModel)) {
5912 switch (outColorSpace->colorModel) {
5913 case QColorSpace::ColorModel::Rgb:
5914 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_RGBX64 : QImage::Format_RGB32);
5915 case QColorSpace::ColorModel::Gray:
5916 return colorTransformed(transform, qt_highColorPrecision(format(),
true) ? QImage::Format_Grayscale16 : QImage::Format_Grayscale8);
5917 case QColorSpace::ColorModel::Cmyk:
5918 return colorTransformed(transform, QImage::Format_CMYK8888);
5919 case QColorSpace::ColorModel::Undefined:
5925 applyColorTransform(transform);
5926 return std::move(*
this);
5930
5931
5932
5933
5934
5935
5936
5937QImage QImage::colorTransformed(
const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags) &&
5940 return colorTransformed(transform, format, flags);
5943bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags flags)
5945 if (format == newFormat)
5949 if (ref.loadRelaxed() > 1 || !own_data)
5952 InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat];
5954 return converter(
this, flags);
5955 if (format > QImage::Format_Indexed8 && newFormat > QImage::Format_Indexed8 && !qimage_converter_map[format][newFormat]) {
5958 if (qt_highColorPrecision(newFormat, !qPixelLayouts[newFormat].hasAlphaChannel)
5959 && qt_highColorPrecision(format, !qPixelLayouts[format].hasAlphaChannel)) {
5960#if QT_CONFIG(raster_fp)
5961 if (qt_fpColorPrecision(format) && qt_fpColorPrecision(newFormat))
5962 return convert_generic_inplace_over_rgba32f(
this, newFormat, flags);
5964 return convert_generic_inplace_over_rgb64(
this, newFormat, flags);
5966 return convert_generic_inplace(
this, newFormat, flags);
5972
5973
5974
5977
5978
5979
5981#ifndef QT_NO_DEBUG_STREAM
5982QDebug operator<<(QDebug dbg,
const QImage &i)
5984 QDebugStateSaver saver(dbg);
5991 dbg << i.size() <<
",format=" << i.format() <<
",depth=" << i.depth();
5993 dbg <<
",colorCount=" << i.colorCount();
5994 const int bytesPerLine = i.bytesPerLine();
5995 dbg <<
",devicePixelRatio=" << i.devicePixelRatio()
5996 <<
",bytesPerLine=" << bytesPerLine <<
",sizeInBytes=" << i.sizeInBytes();
5997 if (dbg.verbosity() > 2 && i.height() > 0) {
5998 const int outputLength = qMin(bytesPerLine, 24);
6000 << QByteArray(
reinterpret_cast<
const char *>(i.scanLine(0)), outputLength).toHex()
6009static constexpr QPixelFormat pixelformats[] = {
6013 QPixelFormat(QPixelFormat::Indexed,
6020 QPixelFormat::IgnoresAlpha,
6021 QPixelFormat::AtBeginning,
6022 QPixelFormat::NotPremultiplied,
6023 QPixelFormat::UnsignedByte,
6024 QPixelFormat::BigEndian),
6026 QPixelFormat(QPixelFormat::Indexed,
6033 QPixelFormat::IgnoresAlpha,
6034 QPixelFormat::AtBeginning,
6035 QPixelFormat::NotPremultiplied,
6036 QPixelFormat::UnsignedByte,
6037 QPixelFormat::BigEndian),
6039 QPixelFormat(QPixelFormat::Indexed,
6046 QPixelFormat::IgnoresAlpha,
6047 QPixelFormat::AtBeginning,
6048 QPixelFormat::NotPremultiplied,
6049 QPixelFormat::UnsignedByte,
6050 QPixelFormat::BigEndian),
6052 QPixelFormat(QPixelFormat::RGB,
6059 QPixelFormat::IgnoresAlpha,
6060 QPixelFormat::AtBeginning,
6061 QPixelFormat::NotPremultiplied,
6062 QPixelFormat::UnsignedInteger,
6063 QPixelFormat::CurrentSystemEndian),
6065 QPixelFormat(QPixelFormat::RGB,
6072 QPixelFormat::UsesAlpha,
6073 QPixelFormat::AtBeginning,
6074 QPixelFormat::NotPremultiplied,
6075 QPixelFormat::UnsignedInteger,
6076 QPixelFormat::CurrentSystemEndian),
6078 QPixelFormat(QPixelFormat::RGB,
6085 QPixelFormat::UsesAlpha,
6086 QPixelFormat::AtBeginning,
6087 QPixelFormat::Premultiplied,
6088 QPixelFormat::UnsignedInteger,
6089 QPixelFormat::CurrentSystemEndian),
6091 QPixelFormat(QPixelFormat::RGB,
6098 QPixelFormat::IgnoresAlpha,
6099 QPixelFormat::AtBeginning,
6100 QPixelFormat::NotPremultiplied,
6101 QPixelFormat::UnsignedShort,
6102 QPixelFormat::CurrentSystemEndian),
6104 QPixelFormat(QPixelFormat::RGB,
6111 QPixelFormat::UsesAlpha,
6112 QPixelFormat::AtBeginning,
6113 QPixelFormat::Premultiplied,
6114 QPixelFormat::UnsignedInteger,
6115 QPixelFormat::CurrentSystemEndian),
6117 QPixelFormat(QPixelFormat::RGB,
6124 QPixelFormat::IgnoresAlpha,
6125 QPixelFormat::AtBeginning,
6126 QPixelFormat::NotPremultiplied,
6127 QPixelFormat::UnsignedInteger,
6128 QPixelFormat::CurrentSystemEndian),
6130 QPixelFormat(QPixelFormat::RGB,
6137 QPixelFormat::UsesAlpha,
6138 QPixelFormat::AtEnd,
6139 QPixelFormat::Premultiplied,
6140 QPixelFormat::UnsignedInteger,
6141 QPixelFormat::CurrentSystemEndian),
6143 QPixelFormat(QPixelFormat::RGB,
6150 QPixelFormat::IgnoresAlpha,
6151 QPixelFormat::AtBeginning,
6152 QPixelFormat::NotPremultiplied,
6153 QPixelFormat::UnsignedShort,
6154 QPixelFormat::CurrentSystemEndian),
6156 QPixelFormat(QPixelFormat::RGB,
6163 QPixelFormat::UsesAlpha,
6164 QPixelFormat::AtBeginning,
6165 QPixelFormat::Premultiplied,
6166 QPixelFormat::UnsignedInteger,
6167 QPixelFormat::CurrentSystemEndian),
6169 QPixelFormat(QPixelFormat::RGB,
6176 QPixelFormat::IgnoresAlpha,
6177 QPixelFormat::AtBeginning,
6178 QPixelFormat::NotPremultiplied,
6179 QPixelFormat::UnsignedByte,
6180 QPixelFormat::BigEndian),
6182 QPixelFormat(QPixelFormat::RGB,
6189 QPixelFormat::IgnoresAlpha,
6190 QPixelFormat::AtBeginning,
6191 QPixelFormat::NotPremultiplied,
6192 QPixelFormat::UnsignedShort,
6193 QPixelFormat::CurrentSystemEndian),
6195 QPixelFormat(QPixelFormat::RGB,
6202 QPixelFormat::UsesAlpha,
6203 QPixelFormat::AtBeginning,
6204 QPixelFormat::Premultiplied,
6205 QPixelFormat::UnsignedShort,
6206 QPixelFormat::CurrentSystemEndian),
6208 QPixelFormat(QPixelFormat::RGB,
6215 QPixelFormat::IgnoresAlpha,
6216 QPixelFormat::AtEnd,
6217 QPixelFormat::NotPremultiplied,
6218 QPixelFormat::UnsignedByte,
6219 QPixelFormat::BigEndian),
6221 QPixelFormat(QPixelFormat::RGB,
6228 QPixelFormat::UsesAlpha,
6229 QPixelFormat::AtEnd,
6230 QPixelFormat::NotPremultiplied,
6231 QPixelFormat::UnsignedByte,
6232 QPixelFormat::BigEndian),
6234 QPixelFormat(QPixelFormat::RGB,
6241 QPixelFormat::UsesAlpha,
6242 QPixelFormat::AtEnd,
6243 QPixelFormat::Premultiplied,
6244 QPixelFormat::UnsignedByte,
6245 QPixelFormat::BigEndian),
6247 QPixelFormat(QPixelFormat::BGR,
6254 QPixelFormat::IgnoresAlpha,
6255 QPixelFormat::AtBeginning,
6256 QPixelFormat::NotPremultiplied,
6257 QPixelFormat::UnsignedInteger,
6258 QPixelFormat::CurrentSystemEndian),
6260 QPixelFormat(QPixelFormat::BGR,
6267 QPixelFormat::UsesAlpha,
6268 QPixelFormat::AtBeginning,
6269 QPixelFormat::Premultiplied,
6270 QPixelFormat::UnsignedInteger,
6271 QPixelFormat::CurrentSystemEndian),
6273 QPixelFormat(QPixelFormat::RGB,
6280 QPixelFormat::IgnoresAlpha,
6281 QPixelFormat::AtBeginning,
6282 QPixelFormat::NotPremultiplied,
6283 QPixelFormat::UnsignedInteger,
6284 QPixelFormat::CurrentSystemEndian),
6286 QPixelFormat(QPixelFormat::RGB,
6293 QPixelFormat::UsesAlpha,
6294 QPixelFormat::AtBeginning,
6295 QPixelFormat::Premultiplied,
6296 QPixelFormat::UnsignedInteger,
6297 QPixelFormat::CurrentSystemEndian),
6299 QPixelFormat(QPixelFormat::Alpha,
6306 QPixelFormat::UsesAlpha,
6307 QPixelFormat::AtBeginning,
6308 QPixelFormat::Premultiplied,
6309 QPixelFormat::UnsignedByte,
6310 QPixelFormat::BigEndian),
6312 QPixelFormat(QPixelFormat::Grayscale,
6319 QPixelFormat::IgnoresAlpha,
6320 QPixelFormat::AtBeginning,
6321 QPixelFormat::NotPremultiplied,
6322 QPixelFormat::UnsignedByte,
6323 QPixelFormat::BigEndian),
6325 QPixelFormat(QPixelFormat::RGB,
6332 QPixelFormat::IgnoresAlpha,
6333 QPixelFormat::AtEnd,
6334 QPixelFormat::NotPremultiplied,
6335 QPixelFormat::UnsignedShort,
6336 QPixelFormat::CurrentSystemEndian),
6338 QPixelFormat(QPixelFormat::RGB,
6345 QPixelFormat::UsesAlpha,
6346 QPixelFormat::AtEnd,
6347 QPixelFormat::NotPremultiplied,
6348 QPixelFormat::UnsignedShort,
6349 QPixelFormat::CurrentSystemEndian),
6351 QPixelFormat(QPixelFormat::RGB,
6358 QPixelFormat::UsesAlpha,
6359 QPixelFormat::AtEnd,
6360 QPixelFormat::Premultiplied,
6361 QPixelFormat::UnsignedShort,
6362 QPixelFormat::CurrentSystemEndian),
6364 QPixelFormat(QPixelFormat::Grayscale,
6371 QPixelFormat::IgnoresAlpha,
6372 QPixelFormat::AtBeginning,
6373 QPixelFormat::NotPremultiplied,
6374 QPixelFormat::UnsignedShort,
6375 QPixelFormat::CurrentSystemEndian),
6377 QPixelFormat(QPixelFormat::BGR,
6384 QPixelFormat::IgnoresAlpha,
6385 QPixelFormat::AtBeginning,
6386 QPixelFormat::NotPremultiplied,
6387 QPixelFormat::UnsignedByte,
6388 QPixelFormat::BigEndian),
6390 QPixelFormat(QPixelFormat::RGB,
6397 QPixelFormat::IgnoresAlpha,
6398 QPixelFormat::AtEnd,
6399 QPixelFormat::NotPremultiplied,
6400 QPixelFormat::FloatingPoint,
6401 QPixelFormat::CurrentSystemEndian),
6403 QPixelFormat(QPixelFormat::RGB,
6410 QPixelFormat::UsesAlpha,
6411 QPixelFormat::AtEnd,
6412 QPixelFormat::NotPremultiplied,
6413 QPixelFormat::FloatingPoint,
6414 QPixelFormat::CurrentSystemEndian),
6416 QPixelFormat(QPixelFormat::RGB,
6423 QPixelFormat::UsesAlpha,
6424 QPixelFormat::AtEnd,
6425 QPixelFormat::Premultiplied,
6426 QPixelFormat::FloatingPoint,
6427 QPixelFormat::CurrentSystemEndian),
6429 QPixelFormat(QPixelFormat::RGB,
6436 QPixelFormat::IgnoresAlpha,
6437 QPixelFormat::AtEnd,
6438 QPixelFormat::NotPremultiplied,
6439 QPixelFormat::FloatingPoint,
6440 QPixelFormat::CurrentSystemEndian),
6442 QPixelFormat(QPixelFormat::RGB,
6449 QPixelFormat::UsesAlpha,
6450 QPixelFormat::AtEnd,
6451 QPixelFormat::NotPremultiplied,
6452 QPixelFormat::FloatingPoint,
6453 QPixelFormat::CurrentSystemEndian),
6455 QPixelFormat(QPixelFormat::RGB,
6462 QPixelFormat::UsesAlpha,
6463 QPixelFormat::AtEnd,
6464 QPixelFormat::Premultiplied,
6465 QPixelFormat::FloatingPoint,
6466 QPixelFormat::CurrentSystemEndian),
6468 QPixelFormat(QPixelFormat::CMYK,
6475 QPixelFormat::IgnoresAlpha,
6476 QPixelFormat::AtBeginning,
6477 QPixelFormat::NotPremultiplied,
6478 QPixelFormat::UnsignedInteger,
6479 QPixelFormat::CurrentSystemEndian),
6481static_assert(
sizeof(pixelformats) /
sizeof(*pixelformats) == QImage::NImageFormats);
6484
6485
6486QPixelFormat QImage::pixelFormat()
const noexcept
6488 return toPixelFormat(format());
6492
6493
6494QPixelFormat QImage::toPixelFormat(QImage::Format format)
noexcept
6496 Q_ASSERT(
static_cast<
int>(format) < NImageFormats &&
static_cast<
int>(format) >= 0);
6497 return pixelformats[format];
6501
6502
6503QImage::Format QImage::toImageFormat(QPixelFormat format)
noexcept
6505 for (
int i = 0; i < NImageFormats; i++) {
6506 if (format == pixelformats[i])
6509 return Format_Invalid;
6514 Qt::Orientations orients = {};
6515 if (orient.testFlag(QImageIOHandler::TransformationMirror))
6516 orients |= Qt::Horizontal;
6517 if (orient.testFlag(QImageIOHandler::TransformationFlip))
6518 orients |= Qt::Vertical;
6524 if (orient == QImageIOHandler::TransformationNone)
6526 if (orient == QImageIOHandler::TransformationRotate270) {
6527 src = rotated270(src);
6529 src.flip(toOrientations(orient));
6530 if (orient & QImageIOHandler::TransformationRotate90)
6531 src = rotated90(src);
6537 QMap<QString, QString> text = qt_getImageTextFromDescription(description);
6538 const auto textKeys = image.textKeys();
6539 for (
const QString &key : textKeys) {
6540 if (!key.isEmpty() && !text.contains(key))
6541 text.insert(key, image.text(key));
6548 QMap<QString, QString> text;
6549 for (
const auto &pair : QStringView{description}.tokenize(u"\n\n")) {
6550 int index = pair.indexOf(u':');
6551 if (index >= 0 && pair.indexOf(u' ') < index) {
6552 if (!pair.trimmed().isEmpty())
6553 text.insert(
"Description"_L1, pair.toString().simplified());
6555 const auto key = pair.left(index);
6556 if (!key.trimmed().isEmpty())
6557 text.insert(key.toString(), pair.mid(index + 2).toString().simplified());
6565#include "moc_qimage.cpp"
Combined button and popup list for selecting options.
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)
#define QT_XFORM_TYPE_LSBFIRST
static void copyMetadata(QImageData *dst, const QImageData *src)
#define QT_XFORM_TYPE_MSBFIRST
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)