diff options
author | aavit <qt-info@nokia.com> | 2010-03-05 10:00:49 (GMT) |
---|---|---|
committer | aavit <qt-info@nokia.com> | 2010-03-05 10:00:49 (GMT) |
commit | 512593cb8db6242eda631b8c71d22e2d154abc98 (patch) | |
tree | 8fe918051d51338b9257ad0a6ff6a8acbfca9e4c /src/plugins/imageformats | |
parent | 7b923d14c0e8d8f84c71e8d636a0632f4566f00a (diff) | |
download | Qt-512593cb8db6242eda631b8c71d22e2d154abc98.zip Qt-512593cb8db6242eda631b8c71d22e2d154abc98.tar.gz Qt-512593cb8db6242eda631b8c71d22e2d154abc98.tar.bz2 |
Fixed failure to store certain image formats as jpeg
In contrast to other image format handlers, the jpeg handler would not
convert a QImage of an "unusual" format to a format it could handle
when asked to write it. Now it does.
Task-number: QTBUG-7780
Reviewed-by: Trond
Diffstat (limited to 'src/plugins/imageformats')
-rw-r--r-- | src/plugins/imageformats/jpeg/qjpeghandler.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 3555b21..6eed824 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -562,11 +562,29 @@ inline my_jpeg_destination_mgr::my_jpeg_destination_mgr(QIODevice *device) free_in_buffer = max_buf; } +static bool can_write_format(QImage::Format fmt) +{ + switch (fmt) { + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + case QImage::Format_Indexed8: + case QImage::Format_RGB888: + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + case QImage::Format_ARGB32_Premultiplied: + return true; + break; + default: + break; + } + return false; +} static bool write_jpeg_image(const QImage &sourceImage, QIODevice *device, int sourceQuality) { bool success = false; - const QImage image = sourceImage; + const QImage image = can_write_format(sourceImage.format()) ? + sourceImage : sourceImage.convertToFormat(QImage::Format_RGB888); const QVector<QRgb> cmap = image.colorTable(); struct jpeg_compress_struct cinfo; |