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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 536 |
537 turn_off_visual_optimizations(&cinfo); | 537 turn_off_visual_optimizations(&cinfo); |
538 | 538 |
539 const SkBitmap::Config config = this->getBitmapConfig(&cinfo); | 539 const SkBitmap::Config config = this->getBitmapConfig(&cinfo); |
540 | 540 |
541 #ifdef ANDROID_RGB | 541 #ifdef ANDROID_RGB |
542 adjust_out_color_space_and_dither(&cinfo, config, *this); | 542 adjust_out_color_space_and_dither(&cinfo, config, *this); |
543 #endif | 543 #endif |
544 | 544 |
545 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { | 545 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { |
546 bm->setConfig(config, cinfo.image_width, cinfo.image_height); | 546 return bm->setConfig(config, cinfo.image_width, cinfo.image_height, 0, |
547 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 547 SkBitmap::kA8_Config == config ? |
548 return true; | 548 kPremul_SkAlphaType : kOpaque_SkAlphaType); |
549 } | 549 } |
550 | 550 |
551 /* image_width and image_height are the original dimensions, available | 551 /* image_width and image_height are the original dimensions, available |
552 after jpeg_read_header(). To see the scaled dimensions, we have to call | 552 after jpeg_read_header(). To see the scaled dimensions, we have to call |
553 jpeg_start_decompress(), and then read output_width and output_height. | 553 jpeg_start_decompress(), and then read output_width and output_height. |
554 */ | 554 */ |
555 if (!jpeg_start_decompress(&cinfo)) { | 555 if (!jpeg_start_decompress(&cinfo)) { |
556 /* If we failed here, we may still have enough information to return | 556 /* If we failed here, we may still have enough information to return |
557 to the caller if they just wanted (subsampled bounds). If sampleSize | 557 to the caller if they just wanted (subsampled bounds). If sampleSize |
558 was 1, then we would have already returned. Thus we just check if | 558 was 1, then we would have already returned. Thus we just check if |
559 we're in kDecodeBounds_Mode, and that we have valid output sizes. | 559 we're in kDecodeBounds_Mode, and that we have valid output sizes. |
560 | 560 |
561 One reason to fail here is that we have insufficient stream data | 561 One reason to fail here is that we have insufficient stream data |
562 to complete the setup. However, output dimensions seem to get | 562 to complete the setup. However, output dimensions seem to get |
563 computed very early, which is why this special check can pay off. | 563 computed very early, which is why this special check can pay off. |
564 */ | 564 */ |
565 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { | 565 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { |
566 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, | 566 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, |
567 recompute_sampleSize(sampleSize, cinfo)); | 567 recompute_sampleSize(sampleSize, cinfo)); |
568 bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()); | 568 return bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()
, |
569 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 569 0, SkBitmap::kA8_Config == config ? |
570 return true; | 570 kPremul_SkAlphaType : kOpaque_SkAlphaType); |
571 } else { | 571 } else { |
572 return return_false(cinfo, *bm, "start_decompress"); | 572 return return_false(cinfo, *bm, "start_decompress"); |
573 } | 573 } |
574 } | 574 } |
575 sampleSize = recompute_sampleSize(sampleSize, cinfo); | 575 sampleSize = recompute_sampleSize(sampleSize, cinfo); |
576 | 576 |
577 // should we allow the Chooser (if present) to pick a config for us??? | 577 // should we allow the Chooser (if present) to pick a config for us??? |
578 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { | 578 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { |
579 return return_false(cinfo, *bm, "chooseFromOneChoice"); | 579 return return_false(cinfo, *bm, "chooseFromOneChoice"); |
580 } | 580 } |
581 | 581 |
582 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); | 582 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); |
583 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 583 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, |
584 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 584 SkBitmap::kA8_Config != config ? kOpaque_SkAlphaType : kPremul
_SkAlphaType); |
585 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 585 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
586 return true; | 586 return true; |
587 } | 587 } |
588 if (!this->allocPixelRef(bm, NULL)) { | 588 if (!this->allocPixelRef(bm, NULL)) { |
589 return return_false(cinfo, *bm, "allocPixelRef"); | 589 return return_false(cinfo, *bm, "allocPixelRef"); |
590 } | 590 } |
591 | 591 |
592 SkAutoLockPixels alp(*bm); | 592 SkAutoLockPixels alp(*bm); |
593 | 593 |
594 #ifdef ANDROID_RGB | 594 #ifdef ANDROID_RGB |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 int height = rect.height(); | 794 int height = rect.height(); |
795 | 795 |
796 jpeg_init_read_tile_scanline(cinfo, fImageIndex->huffmanIndex(), | 796 jpeg_init_read_tile_scanline(cinfo, fImageIndex->huffmanIndex(), |
797 &startX, &startY, &width, &height); | 797 &startX, &startY, &width, &height); |
798 int skiaSampleSize = recompute_sampleSize(requestedSampleSize, *cinfo); | 798 int skiaSampleSize = recompute_sampleSize(requestedSampleSize, *cinfo); |
799 int actualSampleSize = skiaSampleSize * (DCTSIZE / cinfo->min_DCT_scaled_siz
e); | 799 int actualSampleSize = skiaSampleSize * (DCTSIZE / cinfo->min_DCT_scaled_siz
e); |
800 | 800 |
801 SkScaledBitmapSampler sampler(width, height, skiaSampleSize); | 801 SkScaledBitmapSampler sampler(width, height, skiaSampleSize); |
802 | 802 |
803 SkBitmap bitmap; | 803 SkBitmap bitmap; |
804 bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 804 bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, |
805 bitmap.setIsOpaque(true); | 805 kOpaque_SkAlphaType); |
806 | 806 |
807 // Check ahead of time if the swap(dest, src) is possible or not. | 807 // Check ahead of time if the swap(dest, src) is possible or not. |
808 // If yes, then we will stick to AllocPixelRef since it's cheaper with the | 808 // If yes, then we will stick to AllocPixelRef since it's cheaper with the |
809 // swap happening. If no, then we will use alloc to allocate pixels to | 809 // swap happening. If no, then we will use alloc to allocate pixels to |
810 // prevent garbage collection. | 810 // prevent garbage collection. |
811 int w = rect.width() / actualSampleSize; | 811 int w = rect.width() / actualSampleSize; |
812 int h = rect.height() / actualSampleSize; | 812 int h = rect.height() / actualSampleSize; |
813 bool swapOnly = (rect == region) && bm->isNull() && | 813 bool swapOnly = (rect == region) && bm->isNull() && |
814 (w == bitmap.width()) && (h == bitmap.height()) && | 814 (w == bitmap.width()) && (h == bitmap.height()) && |
815 ((startX - rect.x()) / actualSampleSize == 0) && | 815 ((startX - rect.x()) / actualSampleSize == 0) && |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 return SkImageDecoder::kUnknown_Format; | 1215 return SkImageDecoder::kUnknown_Format; |
1216 } | 1216 } |
1217 | 1217 |
1218 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1218 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
1219 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1219 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
1220 } | 1220 } |
1221 | 1221 |
1222 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1222 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
1223 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1223 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
1224 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1224 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
OLD | NEW |