diff options
author | Sergey Borovkov <serge.borovkov@gmail.com> | 2012-10-27 18:17:05 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-09 00:37:42 +0100 |
commit | b009ed0cc87a3b16e5c4554f07875177366d1dba (patch) | |
tree | 98a380a4ddd7ca57b0b7227014b2f2fb51f94e64 /src/gui/image/qpnghandler.cpp | |
parent | 0d519164f29eb04208eac8bb7dd85443e2b282e1 (diff) |
Save grayscale palleted images to grayscale png
While Qt does not support grayscale images explicitly it makes sense to
save palleted images to grayscale png when possible for better
compression and compatibility as opening and saving grayscale images now
converts them to palleted
Change-Id: Iab7c5a5a9d24b9352f5a7bafe04824a97d2463d9
Reviewed-by: aavit <eirik.aavitsland@digia.com>
Diffstat (limited to 'src/gui/image/qpnghandler.cpp')
-rw-r--r-- | src/gui/image/qpnghandler.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 8434282178..bedf881a9a 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -102,7 +102,6 @@ QT_BEGIN_NAMESPACE All PNG files load to the minimal QImage equivalent. All QImage formats output to reasonably efficient PNG equivalents. - Never to grayscale. */ class QPngHandlerPrivate @@ -834,8 +833,12 @@ bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image, vo int color_type = 0; - if (image.colorCount()) - color_type = PNG_COLOR_TYPE_PALETTE; + if (image.colorCount()) { + if (image.isGrayscale()) + color_type = PNG_COLOR_TYPE_GRAY; + else + color_type = PNG_COLOR_TYPE_PALETTE; + } else if (image.hasAlphaChannel()) color_type = PNG_COLOR_TYPE_RGB_ALPHA; else @@ -852,7 +855,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image, vo if (image.format() == QImage::Format_MonoLSB) png_set_packswap(png_ptr); - if (image.colorCount()) { + if (color_type == PNG_COLOR_TYPE_PALETTE) { // Paletted int num_palette = qMin(256, image.colorCount()); png_color palette[256]; |