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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 cinfo.scale_denom = sampleSize; 282 cinfo.scale_denom = sampleSize;
283 283
284 /* this gives about 30% performance improvement. In theory it may 284 /* this gives about 30% performance improvement. In theory it may
285 reduce the visual quality, in practice I'm not seeing a difference 285 reduce the visual quality, in practice I'm not seeing a difference
286 */ 286 */
287 cinfo.do_fancy_upsampling = 0; 287 cinfo.do_fancy_upsampling = 0;
288 288
289 /* this gives another few percents */ 289 /* this gives another few percents */
290 cinfo.do_block_smoothing = 0; 290 cinfo.do_block_smoothing = 0;
291 291
292 SrcDepth srcDepth = k32Bit_SrcDepth;
292 /* default format is RGB */ 293 /* default format is RGB */
293 if (cinfo.jpeg_color_space == JCS_CMYK) { 294 if (cinfo.jpeg_color_space == JCS_CMYK) {
294 // libjpeg cannot convert from CMYK to RGB - here we set up 295 // libjpeg cannot convert from CMYK to RGB - here we set up
295 // so libjpeg will give us CMYK samples back and we will 296 // so libjpeg will give us CMYK samples back and we will
296 // later manually convert them to RGB 297 // later manually convert them to RGB
297 cinfo.out_color_space = JCS_CMYK; 298 cinfo.out_color_space = JCS_CMYK;
299 } else if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
300 cinfo.out_color_space = JCS_GRAYSCALE;
301 srcDepth = k8BitGray_SrcDepth;
298 } else { 302 } else {
299 cinfo.out_color_space = JCS_RGB; 303 cinfo.out_color_space = JCS_RGB;
300 } 304 }
301 305
302 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false); 306 SkBitmap::Config config = this->getPrefConfig(srcDepth, false);
303 // only these make sense for jpegs 307 // only these make sense for jpegs
304 if (config != SkBitmap::kARGB_8888_Config && 308 if (SkBitmap::kA8_Config == config) {
305 config != SkBitmap::kARGB_4444_Config && 309 if (cinfo.jpeg_color_space != JCS_GRAYSCALE) {
306 config != SkBitmap::kRGB_565_Config) { 310 // Converting from a non grayscale image to A8 is
311 // not currently supported.
312 config = SkBitmap::kARGB_8888_Config;
313 // Change the output from jpeg back to RGB.
314 cinfo.out_color_space = JCS_RGB;
315 }
316 } else if (config != SkBitmap::kARGB_8888_Config &&
317 config != SkBitmap::kARGB_4444_Config &&
318 config != SkBitmap::kRGB_565_Config) {
307 config = SkBitmap::kARGB_8888_Config; 319 config = SkBitmap::kARGB_8888_Config;
308 } 320 }
309 321
310 #ifdef ANDROID_RGB 322 #ifdef ANDROID_RGB
311 cinfo.dither_mode = JDITHER_NONE; 323 cinfo.dither_mode = JDITHER_NONE;
312 if (SkBitmap::kARGB_8888_Config == config && JCS_CMYK != cinfo.out_color_spa ce) { 324 if (SkBitmap::kARGB_8888_Config == config && JCS_CMYK != cinfo.out_color_spa ce) {
313 cinfo.out_color_space = JCS_RGBA_8888; 325 cinfo.out_color_space = JCS_RGBA_8888;
314 } else if (SkBitmap::kRGB_565_Config == config && JCS_CMYK != cinfo.out_colo r_space) { 326 } else if (SkBitmap::kRGB_565_Config == config && JCS_CMYK != cinfo.out_colo r_space) {
315 cinfo.out_color_space = JCS_RGB_565; 327 cinfo.out_color_space = JCS_RGB_565;
316 if (this->getDitherImage()) { 328 if (this->getDitherImage()) {
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 } 1021 }
1010 1022
1011 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1023 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1012 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1024 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1013 } 1025 }
1014 1026
1015 1027
1016 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); 1028 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory);
1017 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg ); 1029 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg );
1018 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact ory); 1030 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact ory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698