From a7b8ef08415b8056661c3db5950842ee546891b9 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 29 Jan 2014 11:41:31 +0100 Subject: Export optimized premultiply and unpremultiply methods This patch optimizes the unpremultiply method further by using a lookup table to avoid any divisions at all. The opportunity is taken to export both premultiply and unpremultiply since they are commonly used methods relevant to the exported QRgb type that can be both premultiplied and unpremultipled ARGB. [ChangeLog][QtGui][QColor] Exported highly optimized methods for premultiply and unpremultiply of QRgb values. Change-Id: I658bcf57b0bc73c34c1765b64617d43b63ae820b Reviewed-by: Thiago Macieira Reviewed-by: Gunnar Sletta --- src/gui/image/qimage.cpp | 8 ++++---- src/gui/image/qimage_conversions.cpp | 26 +++++++++++++------------- src/gui/image/qimage_sse2.cpp | 2 +- src/gui/image/qpixmap_blitter.cpp | 2 +- src/gui/image/qpixmap_raster.cpp | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index f549a04dfb..48c262ae7a 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1719,7 +1719,7 @@ void QImage::fill(const QColor &color) if (d->depth == 32) { uint pixel = color.rgba(); if (d->format == QImage::Format_ARGB32_Premultiplied || d->format == QImage::Format_RGBA8888_Premultiplied) - pixel = PREMUL(pixel); + pixel = qPremultiply(pixel); fill((uint) pixel); } else if (d->format == QImage::Format_RGB16) { @@ -2204,17 +2204,17 @@ void QImage::setPixel(int x, int y, uint index_or_rgb) case Format_RGB32: //make sure alpha is 255, we depend on it in qdrawhelper for cases // when image is set as a texture pattern on a qbrush - ((uint *)s)[x] = uint(255 << 24) | index_or_rgb; + ((uint *)s)[x] = 0xff000000 | index_or_rgb; return; case Format_ARGB32: case Format_ARGB32_Premultiplied: ((uint *)s)[x] = index_or_rgb; return; case Format_RGB16: - ((quint16 *)s)[x] = qConvertRgb32To16(INV_PREMUL(index_or_rgb)); + ((quint16 *)s)[x] = qConvertRgb32To16(qUnpremultiply(index_or_rgb)); return; case Format_RGBX8888: - ((uint *)s)[x] = ARGB2RGBA(index_or_rgb | 0xff000000); + ((uint *)s)[x] = ARGB2RGBA(0xff000000 | index_or_rgb); return; case Format_RGBA8888: case Format_RGBA8888_Premultiplied: diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 9b79f4ccc0..e856959d51 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -77,7 +77,7 @@ static const uchar bitflip[256] = { 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 }; -const uchar *qt_get_bitflip_array() // called from QPixmap code +const uchar *qt_get_bitflip_array() { return bitflip; } @@ -187,7 +187,7 @@ static void convert_ARGB_to_ARGB_PM(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = PREMUL(*src_data); + *dest_data = qPremultiply(*src_data); ++src_data; ++dest_data; } @@ -304,7 +304,7 @@ static void convert_ARGB_to_RGBA_PM(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const quint32 *end = src_data + src->width; while (src_data < end) { - *dest_data = ARGB2RGBA(PREMUL(*src_data)); + *dest_data = ARGB2RGBA(qPremultiply(*src_data)); ++src_data; ++dest_data; } @@ -376,7 +376,7 @@ static void convert_RGBA_to_ARGB_PM(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const quint32 *end = src_data + src->width; while (src_data < end) { - *dest_data = PREMUL(RGBA2ARGB(*src_data)); + *dest_data = qPremultiply(RGBA2ARGB(*src_data)); ++src_data; ++dest_data; } @@ -395,7 +395,7 @@ static bool convert_RGBA_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConversio for (int i = 0; i < data->height; ++i) { const QRgb *end = rgb_data + data->width; while (rgb_data < end) { - *rgb_data = PREMUL(RGBA2ARGB(*rgb_data)); + *rgb_data = qPremultiply(RGBA2ARGB(*rgb_data)); ++rgb_data; } rgb_data += pad; @@ -429,7 +429,7 @@ static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConve data->colortable[i] = qRgb(i, i, i); } else { for (int i = 0; i < data->colortable.size(); ++i) - data->colortable[i] = PREMUL(data->colortable.at(i)); + data->colortable[i] = qPremultiply(data->colortable.at(i)); // Fill the rest of the table in case src_data > colortable.size() const int oldSize = data->colortable.size(); @@ -604,7 +604,7 @@ static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = INV_PREMUL(*src_data); + *dest_data = qUnpremultiply(*src_data); ++src_data; ++dest_data; } @@ -628,7 +628,7 @@ static void convert_ARGB_PM_to_RGB(QImageData *dest, const QImageData *src, Qt:: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = 0xff000000 | INV_PREMUL(*src_data); + *dest_data = 0xff000000 | qUnpremultiply(*src_data); ++src_data; ++dest_data; } @@ -652,7 +652,7 @@ static void convert_ARGB_PM_to_RGBx(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = ARGB2RGBA(0xff000000 | INV_PREMUL(*src_data)); + *dest_data = ARGB2RGBA(0xff000000 | qUnpremultiply(*src_data)); ++src_data; ++dest_data; } @@ -676,7 +676,7 @@ static void convert_ARGB_PM_to_RGBA(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = ARGB2RGBA(INV_PREMUL(*src_data)); + *dest_data = ARGB2RGBA(qUnpremultiply(*src_data)); ++src_data; ++dest_data; } @@ -748,7 +748,7 @@ static void convert_RGBA_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = INV_PREMUL(RGBA2ARGB(*src_data)); + *dest_data = qUnpremultiply(RGBA2ARGB(*src_data)); ++src_data; ++dest_data; } @@ -772,7 +772,7 @@ static void convert_RGBA_PM_to_RGB(QImageData *dest, const QImageData *src, Qt:: for (int i = 0; i < src->height; ++i) { const QRgb *end = src_data + src->width; while (src_data < end) { - *dest_data = 0xff000000 | INV_PREMUL(RGBA2ARGB(*src_data)); + *dest_data = 0xff000000 | qUnpremultiply(RGBA2ARGB(*src_data)); ++src_data; ++dest_data; } @@ -862,7 +862,7 @@ static QVector fix_color_table(const QVector &ctbl, QImage::Format f } else if (format == QImage::Format_ARGB32_Premultiplied) { // check if the color table has alpha for (int i = 0; i < colorTable.size(); ++i) - colorTable[i] = PREMUL(colorTable.at(i)); + colorTable[i] = qPremultiply(colorTable.at(i)); } return colorTable; } diff --git a/src/gui/image/qimage_sse2.cpp b/src/gui/image/qimage_sse2.cpp index 0d6eac4ea2..037846c9aa 100644 --- a/src/gui/image/qimage_sse2.cpp +++ b/src/gui/image/qimage_sse2.cpp @@ -94,7 +94,7 @@ bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionF if (*p < 0x00ffffff) *p = 0; else if (*p < 0xff000000) - *p = PREMUL(*p); + *p = qPremultiply(*p); } d = reinterpret_cast<__m128i*>(p+pad); diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index 4c1b30a6d8..839a7a709f 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -148,7 +148,7 @@ void QBlittablePlatformPixmap::fill(const QColor &color) m_alpha = true; } - uint pixel = PREMUL(color.rgba()); + uint pixel = qPremultiply(color.rgba()); const QPixelLayout *layout = &qPixelLayouts[blittable()->lock()->format()]; Q_ASSERT(layout->convertFromARGB32PM); layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0); diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 37259adcd2..1465fea8b9 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -208,7 +208,7 @@ void QRasterPlatformPixmap::fill(const QColor &color) } } } - pixel = PREMUL(color.rgba()); + pixel = qPremultiply(color.rgba()); const QPixelLayout *layout = &qPixelLayouts[image.format()]; layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0); } else { -- cgit v1.2.3