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

Side by Side Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 1412803009: Change quality settings on SkImageDecoder_libjpeg (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Adding suppressions (and rebase) Created 5 years, 1 month 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
« no previous file with comments | « no previous file | tools/valgrind.supp » ('j') | tools/valgrind.supp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 * Common code for setting the error manager. 372 * Common code for setting the error manager.
373 */ 373 */
374 static void set_error_mgr(jpeg_decompress_struct* cinfo, skjpeg_error_mgr* error Manager) { 374 static void set_error_mgr(jpeg_decompress_struct* cinfo, skjpeg_error_mgr* error Manager) {
375 SkASSERT(cinfo != nullptr); 375 SkASSERT(cinfo != nullptr);
376 SkASSERT(errorManager != nullptr); 376 SkASSERT(errorManager != nullptr);
377 cinfo->err = jpeg_std_error(errorManager); 377 cinfo->err = jpeg_std_error(errorManager);
378 errorManager->error_exit = skjpeg_error_exit; 378 errorManager->error_exit = skjpeg_error_exit;
379 } 379 }
380 380
381 /** 381 /**
382 * Common code for turning off upsampling and smoothing. Turning these
383 * off helps performance without showing noticable differences in the
384 * resulting bitmap.
385 */
386 static void turn_off_visual_optimizations(jpeg_decompress_struct* cinfo) {
387 SkASSERT(cinfo != nullptr);
388 /* this gives about 30% performance improvement. In theory it may
389 reduce the visual quality, in practice I'm not seeing a difference
390 */
391 cinfo->do_fancy_upsampling = 0;
392
393 /* this gives another few percents */
394 cinfo->do_block_smoothing = 0;
395 }
396
397 /**
398 * Common code for setting the dct method. 382 * Common code for setting the dct method.
399 */ 383 */
400 static void set_dct_method(const SkImageDecoder& decoder, jpeg_decompress_struct * cinfo) { 384 static void set_dct_method(const SkImageDecoder& decoder, jpeg_decompress_struct * cinfo) {
401 SkASSERT(cinfo != nullptr); 385 SkASSERT(cinfo != nullptr);
402 #ifdef DCT_IFAST_SUPPORTED
403 if (decoder.getPreferQualityOverSpeed()) {
404 cinfo->dct_method = JDCT_ISLOW;
405 } else {
406 cinfo->dct_method = JDCT_IFAST;
407 }
408 #else
409 cinfo->dct_method = JDCT_ISLOW; 386 cinfo->dct_method = JDCT_ISLOW;
410 #endif
411 } 387 }
412 388
413 SkColorType SkJPEGImageDecoder::getBitmapColorType(jpeg_decompress_struct* cinfo ) { 389 SkColorType SkJPEGImageDecoder::getBitmapColorType(jpeg_decompress_struct* cinfo ) {
414 SkASSERT(cinfo != nullptr); 390 SkASSERT(cinfo != nullptr);
415 391
416 SrcDepth srcDepth = k32Bit_SrcDepth; 392 SrcDepth srcDepth = k32Bit_SrcDepth;
417 if (JCS_GRAYSCALE == cinfo->jpeg_color_space) { 393 if (JCS_GRAYSCALE == cinfo->jpeg_color_space) {
418 srcDepth = k8BitGray_SrcDepth; 394 srcDepth = k8BitGray_SrcDepth;
419 } 395 }
420 396
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 can) much faster that we, just use their num/denom api to approximate 545 can) much faster that we, just use their num/denom api to approximate
570 the size. 546 the size.
571 */ 547 */
572 int sampleSize = this->getSampleSize(); 548 int sampleSize = this->getSampleSize();
573 549
574 set_dct_method(*this, &cinfo); 550 set_dct_method(*this, &cinfo);
575 551
576 SkASSERT(1 == cinfo.scale_num); 552 SkASSERT(1 == cinfo.scale_num);
577 cinfo.scale_denom = sampleSize; 553 cinfo.scale_denom = sampleSize;
578 554
579 turn_off_visual_optimizations(&cinfo);
580
581 const SkColorType colorType = this->getBitmapColorType(&cinfo); 555 const SkColorType colorType = this->getBitmapColorType(&cinfo);
582 const SkAlphaType alphaType = kAlpha_8_SkColorType == colorType ? 556 const SkAlphaType alphaType = kAlpha_8_SkColorType == colorType ?
583 kPremul_SkAlphaType : kOpaque_SkAlphaType; 557 kPremul_SkAlphaType : kOpaque_SkAlphaType;
584 558
585 adjust_out_color_space_and_dither(&cinfo, colorType, *this); 559 adjust_out_color_space_and_dither(&cinfo, colorType, *this);
586 560
587 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { 561 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) {
588 // Assume an A8 bitmap is not opaque to avoid the check of each 562 // Assume an A8 bitmap is not opaque to avoid the check of each
589 // individual pixel. It is very unlikely to be opaque, since 563 // individual pixel. It is very unlikely to be opaque, since
590 // an opaque A8 bitmap would not be very interesting. 564 // an opaque A8 bitmap would not be very interesting.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly 870 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly
897 update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_ SizeType); 871 update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_ SizeType);
898 return true; 872 return true;
899 } 873 }
900 874
901 set_dct_method(*this, &cinfo); 875 set_dct_method(*this, &cinfo);
902 876
903 SkASSERT(1 == cinfo.scale_num); 877 SkASSERT(1 == cinfo.scale_num);
904 cinfo.scale_denom = 1; 878 cinfo.scale_denom = 1;
905 879
906 turn_off_visual_optimizations(&cinfo);
907
908 #ifdef ANDROID_RGB 880 #ifdef ANDROID_RGB
909 cinfo.dither_mode = JDITHER_NONE; 881 cinfo.dither_mode = JDITHER_NONE;
910 #endif 882 #endif
911 883
912 /* image_width and image_height are the original dimensions, available 884 /* image_width and image_height are the original dimensions, available
913 after jpeg_read_header(). To see the scaled dimensions, we have to call 885 after jpeg_read_header(). To see the scaled dimensions, we have to call
914 jpeg_start_decompress(), and then read output_width and output_height. 886 jpeg_start_decompress(), and then read output_width and output_height.
915 */ 887 */
916 if (!jpeg_start_decompress(&cinfo)) { 888 if (!jpeg_start_decompress(&cinfo)) {
917 return return_false(cinfo, "start_decompress YUV8"); 889 return return_false(cinfo, "start_decompress YUV8");
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 jpeg_decompress_struct* cinfo = imageIndex->cinfo(); 944 jpeg_decompress_struct* cinfo = imageIndex->cinfo();
973 // We have a new cinfo, so set the error mgr again. 945 // We have a new cinfo, so set the error mgr again.
974 set_error_mgr(cinfo, &sk_err); 946 set_error_mgr(cinfo, &sk_err);
975 947
976 // FIXME: This sets cinfo->out_color_space, which we may change later 948 // FIXME: This sets cinfo->out_color_space, which we may change later
977 // based on the config in onDecodeSubset. This should be fine, since 949 // based on the config in onDecodeSubset. This should be fine, since
978 // jpeg_init_read_tile_scanline will check out_color_space again after 950 // jpeg_init_read_tile_scanline will check out_color_space again after
979 // that change (when it calls jinit_color_deconverter). 951 // that change (when it calls jinit_color_deconverter).
980 (void) this->getBitmapColorType(cinfo); 952 (void) this->getBitmapColorType(cinfo);
981 953
982 turn_off_visual_optimizations(cinfo);
983
984 // instead of jpeg_start_decompress() we start a tiled decompress 954 // instead of jpeg_start_decompress() we start a tiled decompress
985 if (!imageIndex->startTileDecompress()) { 955 if (!imageIndex->startTileDecompress()) {
986 return false; 956 return false;
987 } 957 }
988 958
989 SkASSERT(1 == cinfo->scale_num); 959 SkASSERT(1 == cinfo->scale_num);
990 fImageWidth = cinfo->output_width; 960 fImageWidth = cinfo->output_width;
991 fImageHeight = cinfo->output_height; 961 fImageHeight = cinfo->output_height;
992 962
993 if (width) { 963 if (width) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 return SkImageDecoder::kUnknown_Format; 1416 return SkImageDecoder::kUnknown_Format;
1447 } 1417 }
1448 1418
1449 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1419 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1450 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr; 1420 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr;
1451 } 1421 }
1452 1422
1453 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); 1423 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1454 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); 1424 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1455 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); 1425 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind.supp » ('j') | tools/valgrind.supp » ('J')

Powered by Google App Engine
This is Rietveld 408576698