Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 * Common code for setting the error manager. | 376 * Common code for setting the error manager. |
| 377 */ | 377 */ |
| 378 static void set_error_mgr(jpeg_decompress_struct* cinfo, skjpeg_error_mgr* error Manager) { | 378 static void set_error_mgr(jpeg_decompress_struct* cinfo, skjpeg_error_mgr* error Manager) { |
| 379 SkASSERT(cinfo != nullptr); | 379 SkASSERT(cinfo != nullptr); |
| 380 SkASSERT(errorManager != nullptr); | 380 SkASSERT(errorManager != nullptr); |
| 381 cinfo->err = jpeg_std_error(errorManager); | 381 cinfo->err = jpeg_std_error(errorManager); |
| 382 errorManager->error_exit = skjpeg_error_exit; | 382 errorManager->error_exit = skjpeg_error_exit; |
| 383 } | 383 } |
| 384 | 384 |
| 385 /** | 385 /** |
| 386 * Common code for turning off upsampling and smoothing. Turning these | |
| 387 * off helps performance without showing noticable differences in the | |
| 388 * resulting bitmap. | |
| 389 */ | |
| 390 static void turn_off_visual_optimizations(jpeg_decompress_struct* cinfo) { | |
| 391 SkASSERT(cinfo != nullptr); | |
| 392 /* this gives about 30% performance improvement. In theory it may | |
| 393 reduce the visual quality, in practice I'm not seeing a difference | |
| 394 */ | |
| 395 cinfo->do_fancy_upsampling = 0; | |
| 396 | |
| 397 /* this gives another few percents */ | |
| 398 cinfo->do_block_smoothing = 0; | |
|
msarett
2015/11/06 00:28:02
This setting is ignored by libjpeg/libjpeg-turbo u
| |
| 399 } | |
| 400 | |
| 401 /** | |
| 402 * Common code for setting the dct method. | 386 * Common code for setting the dct method. |
| 403 */ | 387 */ |
| 404 static void set_dct_method(const SkImageDecoder& decoder, jpeg_decompress_struct * cinfo) { | 388 static void set_dct_method(const SkImageDecoder& decoder, jpeg_decompress_struct * cinfo) { |
| 405 SkASSERT(cinfo != nullptr); | 389 SkASSERT(cinfo != nullptr); |
| 406 #ifdef DCT_IFAST_SUPPORTED | |
| 407 if (decoder.getPreferQualityOverSpeed()) { | |
| 408 cinfo->dct_method = JDCT_ISLOW; | |
| 409 } else { | |
| 410 cinfo->dct_method = JDCT_IFAST; | |
| 411 } | |
| 412 #else | |
| 413 cinfo->dct_method = JDCT_ISLOW; | 390 cinfo->dct_method = JDCT_ISLOW; |
| 414 #endif | |
| 415 } | 391 } |
| 416 | 392 |
| 417 SkColorType SkJPEGImageDecoder::getBitmapColorType(jpeg_decompress_struct* cinfo ) { | 393 SkColorType SkJPEGImageDecoder::getBitmapColorType(jpeg_decompress_struct* cinfo ) { |
| 418 SkASSERT(cinfo != nullptr); | 394 SkASSERT(cinfo != nullptr); |
| 419 | 395 |
| 420 SrcDepth srcDepth = k32Bit_SrcDepth; | 396 SrcDepth srcDepth = k32Bit_SrcDepth; |
| 421 if (JCS_GRAYSCALE == cinfo->jpeg_color_space) { | 397 if (JCS_GRAYSCALE == cinfo->jpeg_color_space) { |
| 422 srcDepth = k8BitGray_SrcDepth; | 398 srcDepth = k8BitGray_SrcDepth; |
| 423 } | 399 } |
| 424 | 400 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 can) much faster that we, just use their num/denom api to approximate | 549 can) much faster that we, just use their num/denom api to approximate |
| 574 the size. | 550 the size. |
| 575 */ | 551 */ |
| 576 int sampleSize = this->getSampleSize(); | 552 int sampleSize = this->getSampleSize(); |
| 577 | 553 |
| 578 set_dct_method(*this, &cinfo); | 554 set_dct_method(*this, &cinfo); |
| 579 | 555 |
| 580 SkASSERT(1 == cinfo.scale_num); | 556 SkASSERT(1 == cinfo.scale_num); |
| 581 cinfo.scale_denom = sampleSize; | 557 cinfo.scale_denom = sampleSize; |
| 582 | 558 |
| 583 turn_off_visual_optimizations(&cinfo); | |
| 584 | |
| 585 const SkColorType colorType = this->getBitmapColorType(&cinfo); | 559 const SkColorType colorType = this->getBitmapColorType(&cinfo); |
| 586 const SkAlphaType alphaType = kAlpha_8_SkColorType == colorType ? | 560 const SkAlphaType alphaType = kAlpha_8_SkColorType == colorType ? |
| 587 kPremul_SkAlphaType : kOpaque_SkAlphaType; | 561 kPremul_SkAlphaType : kOpaque_SkAlphaType; |
| 588 | 562 |
| 589 adjust_out_color_space_and_dither(&cinfo, colorType, *this); | 563 adjust_out_color_space_and_dither(&cinfo, colorType, *this); |
| 590 | 564 |
| 591 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { | 565 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 592 // Assume an A8 bitmap is not opaque to avoid the check of each | 566 // Assume an A8 bitmap is not opaque to avoid the check of each |
| 593 // individual pixel. It is very unlikely to be opaque, since | 567 // individual pixel. It is very unlikely to be opaque, since |
| 594 // an opaque A8 bitmap would not be very interesting. | 568 // an opaque A8 bitmap would not be very interesting. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly | 874 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly |
| 901 update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_ SizeType); | 875 update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_ SizeType); |
| 902 return true; | 876 return true; |
| 903 } | 877 } |
| 904 | 878 |
| 905 set_dct_method(*this, &cinfo); | 879 set_dct_method(*this, &cinfo); |
| 906 | 880 |
| 907 SkASSERT(1 == cinfo.scale_num); | 881 SkASSERT(1 == cinfo.scale_num); |
| 908 cinfo.scale_denom = 1; | 882 cinfo.scale_denom = 1; |
| 909 | 883 |
| 910 turn_off_visual_optimizations(&cinfo); | |
| 911 | |
| 912 #ifdef ANDROID_RGB | 884 #ifdef ANDROID_RGB |
| 913 cinfo.dither_mode = JDITHER_NONE; | 885 cinfo.dither_mode = JDITHER_NONE; |
| 914 #endif | 886 #endif |
| 915 | 887 |
| 916 /* image_width and image_height are the original dimensions, available | 888 /* image_width and image_height are the original dimensions, available |
| 917 after jpeg_read_header(). To see the scaled dimensions, we have to call | 889 after jpeg_read_header(). To see the scaled dimensions, we have to call |
| 918 jpeg_start_decompress(), and then read output_width and output_height. | 890 jpeg_start_decompress(), and then read output_width and output_height. |
| 919 */ | 891 */ |
| 920 if (!jpeg_start_decompress(&cinfo)) { | 892 if (!jpeg_start_decompress(&cinfo)) { |
| 921 return return_false(cinfo, "start_decompress YUV8"); | 893 return return_false(cinfo, "start_decompress YUV8"); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 jpeg_decompress_struct* cinfo = imageIndex->cinfo(); | 948 jpeg_decompress_struct* cinfo = imageIndex->cinfo(); |
| 977 // We have a new cinfo, so set the error mgr again. | 949 // We have a new cinfo, so set the error mgr again. |
| 978 set_error_mgr(cinfo, &sk_err); | 950 set_error_mgr(cinfo, &sk_err); |
| 979 | 951 |
| 980 // FIXME: This sets cinfo->out_color_space, which we may change later | 952 // FIXME: This sets cinfo->out_color_space, which we may change later |
| 981 // based on the config in onDecodeSubset. This should be fine, since | 953 // based on the config in onDecodeSubset. This should be fine, since |
| 982 // jpeg_init_read_tile_scanline will check out_color_space again after | 954 // jpeg_init_read_tile_scanline will check out_color_space again after |
| 983 // that change (when it calls jinit_color_deconverter). | 955 // that change (when it calls jinit_color_deconverter). |
| 984 (void) this->getBitmapColorType(cinfo); | 956 (void) this->getBitmapColorType(cinfo); |
| 985 | 957 |
| 986 turn_off_visual_optimizations(cinfo); | |
| 987 | |
| 988 // instead of jpeg_start_decompress() we start a tiled decompress | 958 // instead of jpeg_start_decompress() we start a tiled decompress |
| 989 if (!imageIndex->startTileDecompress()) { | 959 if (!imageIndex->startTileDecompress()) { |
| 990 return false; | 960 return false; |
| 991 } | 961 } |
| 992 | 962 |
| 993 SkASSERT(1 == cinfo->scale_num); | 963 SkASSERT(1 == cinfo->scale_num); |
| 994 fImageWidth = cinfo->output_width; | 964 fImageWidth = cinfo->output_width; |
| 995 fImageHeight = cinfo->output_height; | 965 fImageHeight = cinfo->output_height; |
| 996 | 966 |
| 997 if (width) { | 967 if (width) { |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1450 return SkImageDecoder::kUnknown_Format; | 1420 return SkImageDecoder::kUnknown_Format; |
| 1451 } | 1421 } |
| 1452 | 1422 |
| 1453 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1423 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1454 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr; | 1424 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr; |
| 1455 } | 1425 } |
| 1456 | 1426 |
| 1457 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1427 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
| 1458 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1428 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
| 1459 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1429 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
| OLD | NEW |