QImage::setPixelColor: warn about invalid colors

Task-number: QTBUG-52142
Change-Id: I9f390bd332f8edabaece75a6b36830c691ff4b9e
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
bb10
Mitch Curtis 2016-05-10 14:47:31 +02:00
parent 361564dacf
commit e64b2234e8
2 changed files with 15 additions and 1 deletions

View File

@ -2455,10 +2455,16 @@ QColor QImage::pixelColor(int x, int y) const
*/
void QImage::setPixelColor(int x, int y, const QColor &color)
{
if (!d || x < 0 || x >= width() || y < 0 || y >= height() || !color.isValid()) {
if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
qWarning("QImage::setPixelColor: coordinate (%d,%d) out of range", x, y);
return;
}
if (!color.isValid()) {
qWarning("QImage::setPixelColor: color is invalid");
return;
}
// QColor is always unpremultiplied
QRgba64 c = color.rgba64();
if (!hasAlphaChannel())

View File

@ -3084,6 +3084,14 @@ void tst_QImage::pixelColor()
QImage t = argb32.convertToFormat(QImage::Format_ARGB32_Premultiplied);
QCOMPARE(t.pixel(0,0), argb32pm.pixel(0,0));
// Try specifying an invalid position.
QTest::ignoreMessage(QtWarningMsg, "QImage::setPixelColor: coordinate (-1,-1) out of range");
argb32.setPixelColor(-1, -1, QColor(Qt::red));
// Try setting an invalid color.
QTest::ignoreMessage(QtWarningMsg, "QImage::setPixelColor: color is invalid");
argb32.setPixelColor(0, 0, QColor());
}
void tst_QImage::pixel()