diff options
-rw-r--r-- | src/gui/image/qimage.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qimage/tst_qimage.cpp | 28 |
2 files changed, 33 insertions, 5 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 25c68bc..c1c5631 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4853,8 +4853,6 @@ bool QImage::operator==(const QImage & i) const return false; if (d->format != Format_RGB32) { - if (d->colortable != i.d->colortable) - return false; if (d->format >= Format_ARGB32) { // all bits defined const int n = d->width * d->depth / 8; if (n == d->bytes_per_line && n == i.d->bytes_per_line) { @@ -4867,11 +4865,13 @@ bool QImage::operator==(const QImage & i) const } } } else { - int w = width(); - int h = height(); + const int w = width(); + const int h = height(); + const QVector<QRgb> &colortable = d->colortable; + const QVector<QRgb> &icolortable = i.d->colortable; for (int y=0; y<h; ++y) { for (int x=0; x<w; ++x) { - if (pixelIndex(x, y) != i.pixelIndex(x, y)) + if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)]) return false; } } diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index c6b0560..b7199f3 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -131,6 +131,8 @@ private slots: void nullSize(); void premultipliedAlphaConsistency(); + + void compareIndexed(); }; tst_QImage::tst_QImage() @@ -1762,5 +1764,31 @@ void tst_QImage::premultipliedAlphaConsistency() } } +void tst_QImage::compareIndexed() +{ + QImage img(256, 1, QImage::Format_Indexed8); + + QVector<QRgb> colorTable(256); + for (int i = 0; i < 256; ++i) + colorTable[i] = qRgb(i, i, i); + img.setColorTable(colorTable); + + for (int i = 0; i < 256; ++i) { + img.setPixel(i, 0, i); + } + + QImage imgInverted(256, 1, QImage::Format_Indexed8); + QVector<QRgb> invertedColorTable(256); + for (int i = 0; i < 256; ++i) + invertedColorTable[255-i] = qRgb(i, i, i); + imgInverted.setColorTable(invertedColorTable); + + for (int i = 0; i < 256; ++i) { + imgInverted.setPixel(i, 0, (255-i)); + } + + QCOMPARE(img, imgInverted); +} + QTEST_MAIN(tst_QImage) #include "tst_qimage.moc" |