OSDN Git Service

fix runtime warning when rotating non-mono images
authorIvailo Monev <xakepa10@gmail.com>
Mon, 11 Apr 2022 17:59:16 +0000 (20:59 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 11 Apr 2022 17:59:16 +0000 (20:59 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/image/qimage.cpp

index 149f0fc..108dbdf 100644 (file)
@@ -57,7 +57,9 @@ QT_BEGIN_NAMESPACE
 static QImage rotated90(const QImage &image) {
     QImage out(image.height(), image.width(), image.format());
     QIMAGE_SANITYCHECK_MEMORY(out);
-    out.setColorTable(image.colorTable());
+    if (out.depth() == 1) {
+        out.setColorTable(image.colorTable());
+    }
     int w = image.width();
     int h = image.height();
     switch (image.format()) {
@@ -92,7 +94,9 @@ static QImage rotated180(const QImage &image) {
 static QImage rotated270(const QImage &image) {
     QImage out(image.height(), image.width(), image.format());
     QIMAGE_SANITYCHECK_MEMORY(out);
-    out.setColorTable(image.colorTable());
+    if (out.depth() == 1) {
+        out.setColorTable(image.colorTable());
+    }
     int w = image.width();
     int h = image.height();
     switch (image.format()) {
@@ -1232,7 +1236,7 @@ int QImage::depth() const
 */
 void QImage::setColorTable(const QVector<QRgb> &colors)
 {
-    if (colors.size() != 2) {
+    if (Q_UNLIKELY(colors.size() != 2)) {
         qWarning("QImage::setColorTable: Color table should have two colors");
         return;
     }