diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-07-22 10:54:57 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-07-22 12:03:20 (GMT) |
commit | 04db5e3722c9f3e32f2a0a03962abc9456139883 (patch) | |
tree | 30ab8ad6dcd33fe21e4b3a0d99abdb9196867781 | |
parent | bf15a487e4e0b5d4edca232258526e0d3cf471a0 (diff) | |
download | Qt-04db5e3722c9f3e32f2a0a03962abc9456139883.zip Qt-04db5e3722c9f3e32f2a0a03962abc9456139883.tar.gz Qt-04db5e3722c9f3e32f2a0a03962abc9456139883.tar.bz2 |
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
-rw-r--r-- | src/gui/image/qimage.cpp | 16 |
1 files 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<int>(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<int>(tableSize, *src_data)]; + *dest_data = (quint32) data->colortable.at(*src_data); } } |