summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2009-05-27 11:23:53 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2009-05-27 11:30:06 (GMT)
commit71cb35e942b94e4dba2055acdebbf90c352da762 (patch)
tree9b1e845fc52698051badc263bb4cc01345c9f01f
parent73e7d0cbed0261715f534d95f81055bf97ce4314 (diff)
downloadQt-71cb35e942b94e4dba2055acdebbf90c352da762.zip
Qt-71cb35e942b94e4dba2055acdebbf90c352da762.tar.gz
Qt-71cb35e942b94e4dba2055acdebbf90c352da762.tar.bz2
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
-rw-r--r--src/gui/image/qimage.cpp10
-rw-r--r--tests/auto/qimage/tst_qimage.cpp28
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"