Ensure QImage::pixel() on RGB32 images returns valid QRgb values
Currently QImage::pixel() returns the raw underlying pixel values for RGB32. For all other pixel formats the returned value is either valid ARGB32 or ARGB32PM. This patch masks the undefined alpha field in RGB32 so that the return value is well defined QRgb. It also fixes one test that relied on the previous behavior. Change-Id: If37463528268b7419733499d1f7bfd0d1097d21e Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
This commit is contained in:
parent
0226795cf3
commit
ff70c39ebc
@ -2122,6 +2122,7 @@ QRgb QImage::pixel(int x, int y) const
|
|||||||
case Format_Indexed8:
|
case Format_Indexed8:
|
||||||
return d->colortable.at((int)s[x]);
|
return d->colortable.at((int)s[x]);
|
||||||
case Format_RGB32:
|
case Format_RGB32:
|
||||||
|
return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x];
|
||||||
case Format_ARGB32: // Keep old behaviour.
|
case Format_ARGB32: // Keep old behaviour.
|
||||||
case Format_ARGB32_Premultiplied:
|
case Format_ARGB32_Premultiplied:
|
||||||
return reinterpret_cast<const QRgb *>(s)[x];
|
return reinterpret_cast<const QRgb *>(s)[x];
|
||||||
|
@ -220,15 +220,10 @@ void tst_QImage::createInvalidXPM()
|
|||||||
|
|
||||||
void tst_QImage::createFromUChar()
|
void tst_QImage::createFromUChar()
|
||||||
{
|
{
|
||||||
uchar data[] = {
|
uint data[] = { 0xff010101U,
|
||||||
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
|
0xff020202U,
|
||||||
0xFF,
|
0xff030303U,
|
||||||
#endif
|
0xff040404U };
|
||||||
1,1,1, 0xFF, 2,2,2, 0xFF, 3,3,3, 0xFF, 4,4,4,
|
|
||||||
#if Q_BYTE_ORDER != Q_BIG_ENDIAN
|
|
||||||
0xFF,
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
// When the data is const, nothing you do to the image will change the source data.
|
// When the data is const, nothing you do to the image will change the source data.
|
||||||
QImage i1((const uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
QImage i1((const uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
||||||
@ -242,8 +237,8 @@ void tst_QImage::createFromUChar()
|
|||||||
}
|
}
|
||||||
QCOMPARE(i1.pixel(0,0), 0xFF010101U);
|
QCOMPARE(i1.pixel(0,0), 0xFF010101U);
|
||||||
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
||||||
*((QRgb*)i1.bits()) = 7U;
|
*((QRgb*)i1.bits()) = 0xFF070707U;
|
||||||
QCOMPARE(i1.pixel(0,0), 7U);
|
QCOMPARE(i1.pixel(0,0), 0xFF070707U);
|
||||||
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
||||||
|
|
||||||
// Changing copies should not change the original image or data.
|
// Changing copies should not change the original image or data.
|
||||||
@ -270,16 +265,16 @@ void tst_QImage::createFromUChar()
|
|||||||
}
|
}
|
||||||
QCOMPARE(i2.pixel(0,0), 0xFF010101U);
|
QCOMPARE(i2.pixel(0,0), 0xFF010101U);
|
||||||
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
QCOMPARE(*(QRgb*)data, 0xFF010101U);
|
||||||
*((QRgb*)i2.bits()) = 7U;
|
*((QRgb*)i2.bits()) = 0xFF070707U;
|
||||||
QCOMPARE(i2.pixel(0,0), 7U);
|
QCOMPARE(i2.pixel(0,0), 0xFF070707U);
|
||||||
QCOMPARE(*(QRgb*)data, 7U);
|
QCOMPARE(*(QRgb*)data, 0xFF070707U);
|
||||||
|
|
||||||
// Changing the data will change the image in either case.
|
// Changing the data will change the image in either case.
|
||||||
QImage i3((uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
QImage i3((uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
||||||
QImage i4((const uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
QImage i4((const uchar*)data, 2, 2, 8, QImage::Format_RGB32);
|
||||||
*(QRgb*)data = 6U;
|
*(QRgb*)data = 0xFF060606U;
|
||||||
QCOMPARE(i3.pixel(0,0), 6U);
|
QCOMPARE(i3.pixel(0,0), 0xFF060606U);
|
||||||
QCOMPARE(i4.pixel(0,0), 6U);
|
QCOMPARE(i4.pixel(0,0), 0xFF060606U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QImage::formatHandlersInput_data()
|
void tst_QImage::formatHandlersInput_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user