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; |
} |