From 71cb35e942b94e4dba2055acdebbf90c352da762 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Wed, 27 May 2009 13:23:53 +0200 Subject: Add comparation of images with indexed color Previously, two images with indexed colors were not equal if their color tables were not the same. The image are not compared by the value of the pixels Reviewed-by: Samuel --- src/gui/image/qimage.cpp | 10 +++++----- 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 &colortable = d->colortable; + const QVector &icolortable = i.d->colortable; for (int y=0; y 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 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" -- cgit v0.12