diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-06-17 13:31:00 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-06-20 16:08:28 +0200 |
commit | 70dd5630463cb8aabd927a3a4944aedbd90b70af (patch) | |
tree | 54dad54feff32e13a2539f303d6b31bec480b0e1 /src | |
parent | e98c461d43ea07c73898c93debe9285029ba0416 (diff) |
Correct QImage::fill(uint) on RGBA8888 formats
QImage::fill(uint) was incorrectly performing ARGB->RGBA conversion when
called on RGBA8888 formated images.
This patch moves the color conversion to QImage::fill(QColor) where it
belongs so that fill(uint) can behave consistent with documentation and
how it treats other formats.
The fill(uint) method had no automated tests, and this patch adds one.
[ChangeLog][QtGui][QImage] QImage::fill(uint) now fills the given pixel
value unconverted when used on RGBA8888 image, making it consistent with
the documentation and treatment of all other image formats.
Change-Id: I00a9d810c61d350dbdd7c4b9ad09e5ce11896b6d
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/image/qimage.cpp | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 3998bbf3ff..cbdac4af95 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1662,11 +1662,14 @@ void QImage::fill(uint pixel) return; } - if (d->format == Format_RGB32 || d->format == Format_RGBX8888) + if (d->format == Format_RGB32) pixel |= 0xff000000; - - if (d->format == Format_RGBX8888 || d->format == Format_RGBA8888 || d->format == Format_RGBA8888_Premultiplied) - pixel = ARGB2RGBA(pixel); + if (d->format == Format_RGBX8888) +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN + pixel |= 0xff000000; +#else + pixel |= 0x000000ff; +#endif qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel, 0, 0, d->width, d->height, d->bytes_per_line); @@ -1716,22 +1719,27 @@ void QImage::fill(const QColor &color) if (!d) return; - if (d->depth == 32) { - uint pixel = color.rgba(); - if (d->format == QImage::Format_ARGB32_Premultiplied || d->format == QImage::Format_RGBA8888_Premultiplied) - pixel = qPremultiply(pixel); - fill((uint) pixel); - - } else if (d->format == QImage::Format_RGB16) { + switch (d->format) { + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + fill(color.rgba()); + break; + case QImage::Format_ARGB32_Premultiplied: + fill(qPremultiply(color.rgba())); + break; + case QImage::Format_RGBX8888: + fill(ARGB2RGBA(color.rgba() | 0xff000000)); + break; + case QImage::Format_RGBA8888: + fill(ARGB2RGBA(color.rgba())); + break; + case QImage::Format_RGBA8888_Premultiplied: + fill(ARGB2RGBA(qPremultiply(color.rgba()))); + break; + case QImage::Format_RGB16: fill((uint) qConvertRgb32To16(color.rgba())); - - } else if (d->depth == 1) { - if (color == Qt::color1) - fill((uint) 1); - else - fill((uint) 0); - - } else if (d->depth == 8) { + break; + case QImage::Format_Indexed8: { uint pixel = 0; for (int i=0; i<d->colortable.size(); ++i) { if (color.rgba() == d->colortable.at(i)) { @@ -1740,20 +1748,24 @@ void QImage::fill(const QColor &color) } } fill(pixel); - - } else { + break; + } + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + if (color == Qt::color1) + fill((uint) 1); + else + fill((uint) 0); + break; + default: { QPainter p(this); p.setCompositionMode(QPainter::CompositionMode_Source); p.fillRect(rect(), color); - } - + }} } - - - /*! Inverts all pixel values in the image. |