From c4bea746a3a94e8484b88a3a337e17591ce1d3c8 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Thu, 22 Jul 2010 13:53:54 +0200 Subject: Improve the conversion from indexted to RGB16 Instead of converting each color, we create a color table with the RGB16 colors. The conversion can be done for each pixel directly with the table. Reviewed-by: Kim Reviewed-by: Olivier Goffart --- src/gui/image/qimage.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index dc70dcb..713e765 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2440,12 +2440,23 @@ static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConvers const int width = data->width; const int src_pad = data->bytes_per_line - width; const int dest_pad = (dst_bytes_per_line >> 1) - width; - if (data->colortable.size() == 0) { - data->colortable.resize(256); + + quint16 colorTableRGB16[256]; + if (data->colortable.isEmpty()) { for (int i = 0; i < 256; ++i) - data->colortable[i] = qRgb(i, i, i); + colorTableRGB16[i] = qt_colorConvert(qRgb(i, i, i), 0); + } else { + // 1) convert the existing colors to RGB16 + const int tableSize = data->colortable.size(); + for (int i = 0; i < tableSize; ++i) + colorTableRGB16[i] = qt_colorConvert(data->colortable.at(i), 0); + data->colortable = QVector(); + + // 2) fill the rest of the table in case src_data > colortable.size() + const quint16 lastColor = colorTableRGB16[tableSize - 1]; + for (int i = tableSize; i < 256; ++i) + colorTableRGB16[i] = lastColor; } - const int tableSize = data->colortable.size() - 1; for (int i = 0; i < data->height; ++i) { src_data -= src_pad; @@ -2453,12 +2464,10 @@ static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConvers for (int pixI = 0; pixI < width; ++pixI) { --src_data; --dest_data; - const uint pixel = data->colortable[qMin(tableSize, *src_data)]; - *dest_data = qt_colorConvert(pixel, 0); + *dest_data = colorTableRGB16[*src_data]; } } - data->colortable = QVector(); data->format = QImage::Format_RGB16; data->bytes_per_line = dst_bytes_per_line; data->depth = depth; -- cgit v0.12