summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qjpeghandler.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-02-14 10:39:30 +0100
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-09-17 14:48:48 +0200
commitd84a6eab5129ba29951a7ba6d82820b21cc9872e (patch)
tree1d794ecd3f37363a286f3eeda8e571c36ec4006c /src/gui/image/qjpeghandler.cpp
parentbce19cb9063003af5924c643f6fc1416146b4242 (diff)
Add Grayscale8 and Alpha8 formats to QImage and drawing
Extend the QImage format with two 8-bit grayscale and alpha formats. These formats have the advantage over Indexed8 that they have simpler conversion and can be rendered to by the raster engine. [ChangeLog][QtGui][QImage] Added support grayscale and alpha 8-bit formats which can also be rendered to. Change-Id: I4343c80a92a3dda196aa38d0c3ea251b094fc274 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui/image/qjpeghandler.cpp')
-rw-r--r--src/gui/image/qjpeghandler.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/gui/image/qjpeghandler.cpp b/src/gui/image/qjpeghandler.cpp
index c1d3ff9a85..72ea24c4f8 100644
--- a/src/gui/image/qjpeghandler.cpp
+++ b/src/gui/image/qjpeghandler.cpp
@@ -228,7 +228,7 @@ inline static bool read_jpeg_format(QImage::Format &format, j_decompress_ptr cin
bool result = true;
switch (cinfo->output_components) {
case 1:
- format = QImage::Format_Indexed8;
+ format = QImage::Format_Grayscale8;
break;
case 3:
case 4:
@@ -248,7 +248,7 @@ static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info,
QImage::Format format;
switch (info->output_components) {
case 1:
- format = QImage::Format_Indexed8;
+ format = QImage::Format_Grayscale8;
break;
case 3:
case 4:
@@ -258,16 +258,9 @@ static bool ensureValidImage(QImage *dest, struct jpeg_decompress_struct *info,
return false; // unsupported format
}
- if (dest->size() != size || dest->format() != format) {
+ if (dest->size() != size || dest->format() != format)
*dest = QImage(size, format);
- if (format == QImage::Format_Indexed8) {
- dest->setColorCount(256);
- for (int i = 0; i < 256; i++)
- dest->setColor(i, qRgb(i,i,i));
- }
- }
-
return !dest->isNull();
}
@@ -558,6 +551,9 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in
bool success = false;
const QVector<QRgb> cmap = image.colorTable();
+ if (image.format() == QImage::Format_Invalid || image.format() == QImage::Format_Alpha8)
+ return false;
+
struct jpeg_compress_struct cinfo;
JSAMPROW row_pointer[1];
row_pointer[0] = 0;
@@ -581,19 +577,23 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in
cinfo.image_width = image.width();
cinfo.image_height = image.height();
- bool gray=false;
+ bool gray = false;
switch (image.format()) {
case QImage::Format_Mono:
case QImage::Format_MonoLSB:
case QImage::Format_Indexed8:
gray = true;
- for (int i = image.colorCount(); gray && i--;) {
- gray = gray & (qRed(cmap[i]) == qGreen(cmap[i]) &&
- qRed(cmap[i]) == qBlue(cmap[i]));
+ for (int i = image.colorCount(); gray && i; i--) {
+ gray = gray & qIsGray(cmap[i-1]);
}
cinfo.input_components = gray ? 1 : 3;
cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB;
break;
+ case QImage::Format_Grayscale8:
+ gray = true;
+ cinfo.input_components = 1;
+ cinfo.in_color_space = JCS_GRAYSCALE;
+ break;
default:
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
@@ -678,6 +678,9 @@ static bool write_jpeg_image(const QImage &image, QIODevice *device, volatile in
}
}
break;
+ case QImage::Format_Grayscale8:
+ memcpy(row, image.constScanLine(cinfo.next_scanline), w);
+ break;
case QImage::Format_RGB888:
memcpy(row, image.constScanLine(cinfo.next_scanline), w * 3);
break;