Fix comparisons of image with different color spaces

Take color space into account when comparing images, and fix gamma
comparison that was trying to be too accurate.

Change-Id: I3674653abb21b66aaacb557addc4afb4ee75cfdd
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2019-07-19 11:30:29 +02:00
parent b6f7efba48
commit 733ca2230c
3 changed files with 22 additions and 2 deletions

View File

@ -3834,7 +3834,9 @@ bool QImage::operator==(const QImage & i) const
return false;
// obviously different stuff?
if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format)
if (i.d->height != d->height || i.d->width != d->width)
return false;
if (i.d->format != d->format || i.d->colorSpace != d->colorSpace)
return false;
if (d->format != Format_RGB32) {

View File

@ -651,7 +651,7 @@ bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
if (colorSpace1.transferFunction() != colorSpace2.transferFunction())
return false;
if (colorSpace1.transferFunction() == QColorSpace::TransferFunction::Gamma)
return colorSpace1.gamma() == colorSpace2.gamma();
return (qAbs(colorSpace1.gamma() - colorSpace2.gamma()) <= (1.0f / 512.0f));
return true;
}

View File

@ -232,6 +232,8 @@ private slots:
void wideImage();
void colorspaceEquality();
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
void toWinHBITMAP_data();
void toWinHBITMAP();
@ -3618,6 +3620,22 @@ void tst_QImage::wideImage()
// Qt6: Test that it actually works on 64bit architectures.
}
void tst_QImage::colorspaceEquality()
{
QImage image1(10, 10, QImage::Format_RGB32);
image1.fill(Qt::red);
QImage image2(image1);
QCOMPARE(image1, image2);
image1.setColorSpace(QColorSpace::SRgbLinear);
QVERIFY(image1 != image2);
image2.setColorSpace(QColorSpace::SRgbLinear);
QVERIFY(image1 == image2);
image1.setColorSpace(QColorSpace(QColorSpace::Gamut::DciP3D65, QColorSpace::TransferFunction::Gamma, 2.2f));
QVERIFY(image1 != image2);
image2.setColorSpace(QColorSpace(QColorSpace::Gamut::DciP3D65, QColorSpace::TransferFunction::Gamma, 2.2001f));
QVERIFY(image1 == image2);
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
QT_BEGIN_NAMESPACE
Q_GUI_EXPORT HBITMAP qt_imageToWinHBITMAP(const QImage &p, int hbitmapFormat = 0);