Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Unified Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 18083026: Allow decoding JPEG into A8. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Naming improvements, remove obsolete, add a test. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/images/SkImageDecoder_libjpeg.cpp
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index bea1e98641f65725d1087576f9b191c820ec9f3f..e4d7ace0d48295d32c98ba4805909a2204e69afc 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -289,21 +289,33 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
/* this gives another few percents */
cinfo.do_block_smoothing = 0;
+ SrcDepth srcDepth = k32Bit_SrcDepth;
/* default format is RGB */
if (cinfo.jpeg_color_space == JCS_CMYK) {
// libjpeg cannot convert from CMYK to RGB - here we set up
// so libjpeg will give us CMYK samples back and we will
// later manually convert them to RGB
cinfo.out_color_space = JCS_CMYK;
+ } else if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
+ cinfo.out_color_space = JCS_GRAYSCALE;
+ srcDepth = k8BitGray_SrcDepth;
} else {
cinfo.out_color_space = JCS_RGB;
}
- SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false);
+ SkBitmap::Config config = this->getPrefConfig(srcDepth, false);
// only these make sense for jpegs
- if (config != SkBitmap::kARGB_8888_Config &&
- config != SkBitmap::kARGB_4444_Config &&
- config != SkBitmap::kRGB_565_Config) {
+ if (SkBitmap::kA8_Config == config) {
+ if (cinfo.jpeg_color_space != JCS_GRAYSCALE) {
+ // Converting from a non grayscale image to A8 is
+ // not currently supported.
+ config = SkBitmap::kARGB_8888_Config;
+ // Change the output from jpeg back to RGB.
+ cinfo.out_color_space = JCS_RGB;
+ }
+ } else if (config != SkBitmap::kARGB_8888_Config &&
+ config != SkBitmap::kARGB_4444_Config &&
+ config != SkBitmap::kRGB_565_Config) {
config = SkBitmap::kARGB_8888_Config;
}

Powered by Google App Engine
This is Rietveld 408576698