From 04db5e3722c9f3e32f2a0a03962abc9456139883 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Thu, 22 Jul 2010 12:54:57 +0200 Subject: Avoid qMin() for each pixel when converting indexed colors in-place Instead of checking if the value is in boundary for each pixel, we can fill the color table with 256 value and convert the colors directly. This optimization is an idea of Kim Kalland. Reviewed-by: Kim Reviewed-by: Olivier Goffart --- src/gui/image/qimage.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index e8c01c7..dc70dcb 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2346,8 +2346,12 @@ static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConve } else { for (int i = 0; i < data->colortable.size(); ++i) data->colortable[i] = PREMUL(data->colortable.at(i)); + + // Fill the rest of the table in case src_data > colortable.size() + const int oldSize = data->colortable.size(); + const QRgb lastColor = data->colortable.at(oldSize - 1); + data->colortable.insert(oldSize, 256 - oldSize, lastColor); } - const int tableSize = data->colortable.size() - 1; for (int i = 0; i < data->height; ++i) { src_data -= src_pad; @@ -2355,7 +2359,7 @@ static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConve for (int pixI = 0; pixI < width; ++pixI) { --src_data; --dest_data; - *dest_data = data->colortable[qMin(tableSize, *src_data)]; + *dest_data = data->colortable.at(*src_data); } } @@ -2391,8 +2395,12 @@ static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversio data->colortable.resize(256); for (int i = 0; i < 256; ++i) data->colortable[i] = qRgb(i, i, i); + } else { + // Fill the rest of the table in case src_data > colortable.size() + const int oldSize = data->colortable.size(); + const QRgb lastColor = data->colortable.at(oldSize - 1); + data->colortable.insert(oldSize, 256 - oldSize, lastColor); } - const int tableSize = data->colortable.size() - 1; for (int i = 0; i < data->height; ++i) { src_data -= src_pad; @@ -2400,7 +2408,7 @@ static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversio for (int pixI = 0; pixI < width; ++pixI) { --src_data; --dest_data; - *dest_data = (quint32) data->colortable[qMin(tableSize, *src_data)]; + *dest_data = (quint32) data->colortable.at(*src_data); } } -- cgit v0.12