| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 483 |
| 484 turn_off_visual_optimizations(&cinfo); | 484 turn_off_visual_optimizations(&cinfo); |
| 485 | 485 |
| 486 const SkBitmap::Config config = this->getBitmapConfig(&cinfo); | 486 const SkBitmap::Config config = this->getBitmapConfig(&cinfo); |
| 487 | 487 |
| 488 #ifdef ANDROID_RGB | 488 #ifdef ANDROID_RGB |
| 489 adjust_out_color_space_and_dither(&cinfo, config, *this); | 489 adjust_out_color_space_and_dither(&cinfo, config, *this); |
| 490 #endif | 490 #endif |
| 491 | 491 |
| 492 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { | 492 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 493 bm->setConfig(config, cinfo.image_width, cinfo.image_height); | 493 return bm->setConfig(config, cinfo.image_width, cinfo.image_height, 0, |
| 494 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 494 SkBitmap::kA8_Config == config ? |
| 495 return true; | 495 kPremul_SkAlphaType : kOpaque_SkAlphaType); |
| 496 } | 496 } |
| 497 | 497 |
| 498 /* image_width and image_height are the original dimensions, available | 498 /* image_width and image_height are the original dimensions, available |
| 499 after jpeg_read_header(). To see the scaled dimensions, we have to call | 499 after jpeg_read_header(). To see the scaled dimensions, we have to call |
| 500 jpeg_start_decompress(), and then read output_width and output_height. | 500 jpeg_start_decompress(), and then read output_width and output_height. |
| 501 */ | 501 */ |
| 502 if (!jpeg_start_decompress(&cinfo)) { | 502 if (!jpeg_start_decompress(&cinfo)) { |
| 503 /* If we failed here, we may still have enough information to return | 503 /* If we failed here, we may still have enough information to return |
| 504 to the caller if they just wanted (subsampled bounds). If sampleSize | 504 to the caller if they just wanted (subsampled bounds). If sampleSize |
| 505 was 1, then we would have already returned. Thus we just check if | 505 was 1, then we would have already returned. Thus we just check if |
| 506 we're in kDecodeBounds_Mode, and that we have valid output sizes. | 506 we're in kDecodeBounds_Mode, and that we have valid output sizes. |
| 507 | 507 |
| 508 One reason to fail here is that we have insufficient stream data | 508 One reason to fail here is that we have insufficient stream data |
| 509 to complete the setup. However, output dimensions seem to get | 509 to complete the setup. However, output dimensions seem to get |
| 510 computed very early, which is why this special check can pay off. | 510 computed very early, which is why this special check can pay off. |
| 511 */ | 511 */ |
| 512 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { | 512 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { |
| 513 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, | 513 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, |
| 514 recompute_sampleSize(sampleSize, cinfo)); | 514 recompute_sampleSize(sampleSize, cinfo)); |
| 515 bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()); | 515 return bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()
, |
| 516 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 516 0, SkBitmap::kA8_Config == config ? |
| 517 return true; | 517 kPremul_SkAlphaType : kOpaque_SkAlphaType); |
| 518 } else { | 518 } else { |
| 519 return return_false(cinfo, *bm, "start_decompress"); | 519 return return_false(cinfo, *bm, "start_decompress"); |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 sampleSize = recompute_sampleSize(sampleSize, cinfo); | 522 sampleSize = recompute_sampleSize(sampleSize, cinfo); |
| 523 | 523 |
| 524 // should we allow the Chooser (if present) to pick a config for us??? | 524 // should we allow the Chooser (if present) to pick a config for us??? |
| 525 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { | 525 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { |
| 526 return return_false(cinfo, *bm, "chooseFromOneChoice"); | 526 return return_false(cinfo, *bm, "chooseFromOneChoice"); |
| 527 } | 527 } |
| 528 | 528 |
| 529 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); | 529 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); |
| 530 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 530 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, |
| 531 bm->setIsOpaque(config != SkBitmap::kA8_Config); | 531 SkBitmap::kA8_Config != config ? kOpaque_SkAlphaType : kPremul
_SkAlphaType); |
| 532 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 532 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 533 return true; | 533 return true; |
| 534 } | 534 } |
| 535 if (!this->allocPixelRef(bm, NULL)) { | 535 if (!this->allocPixelRef(bm, NULL)) { |
| 536 return return_false(cinfo, *bm, "allocPixelRef"); | 536 return return_false(cinfo, *bm, "allocPixelRef"); |
| 537 } | 537 } |
| 538 | 538 |
| 539 SkAutoLockPixels alp(*bm); | 539 SkAutoLockPixels alp(*bm); |
| 540 | 540 |
| 541 #ifdef ANDROID_RGB | 541 #ifdef ANDROID_RGB |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 int height = rect.height(); | 735 int height = rect.height(); |
| 736 | 736 |
| 737 jpeg_init_read_tile_scanline(cinfo, fImageIndex->huffmanIndex(), | 737 jpeg_init_read_tile_scanline(cinfo, fImageIndex->huffmanIndex(), |
| 738 &startX, &startY, &width, &height); | 738 &startX, &startY, &width, &height); |
| 739 int skiaSampleSize = recompute_sampleSize(requestedSampleSize, *cinfo); | 739 int skiaSampleSize = recompute_sampleSize(requestedSampleSize, *cinfo); |
| 740 int actualSampleSize = skiaSampleSize * (DCTSIZE / cinfo->min_DCT_scaled_siz
e); | 740 int actualSampleSize = skiaSampleSize * (DCTSIZE / cinfo->min_DCT_scaled_siz
e); |
| 741 | 741 |
| 742 SkScaledBitmapSampler sampler(width, height, skiaSampleSize); | 742 SkScaledBitmapSampler sampler(width, height, skiaSampleSize); |
| 743 | 743 |
| 744 SkBitmap bitmap; | 744 SkBitmap bitmap; |
| 745 bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 745 bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, |
| 746 bitmap.setIsOpaque(true); | 746 kOpaque_SkAlphaType); |
| 747 | 747 |
| 748 // Check ahead of time if the swap(dest, src) is possible or not. | 748 // Check ahead of time if the swap(dest, src) is possible or not. |
| 749 // If yes, then we will stick to AllocPixelRef since it's cheaper with the | 749 // If yes, then we will stick to AllocPixelRef since it's cheaper with the |
| 750 // swap happening. If no, then we will use alloc to allocate pixels to | 750 // swap happening. If no, then we will use alloc to allocate pixels to |
| 751 // prevent garbage collection. | 751 // prevent garbage collection. |
| 752 int w = rect.width() / actualSampleSize; | 752 int w = rect.width() / actualSampleSize; |
| 753 int h = rect.height() / actualSampleSize; | 753 int h = rect.height() / actualSampleSize; |
| 754 bool swapOnly = (rect == region) && bm->isNull() && | 754 bool swapOnly = (rect == region) && bm->isNull() && |
| 755 (w == bitmap.width()) && (h == bitmap.height()) && | 755 (w == bitmap.width()) && (h == bitmap.height()) && |
| 756 ((startX - rect.x()) / actualSampleSize == 0) && | 756 ((startX - rect.x()) / actualSampleSize == 0) && |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 return SkImageDecoder::kUnknown_Format; | 1152 return SkImageDecoder::kUnknown_Format; |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1155 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1156 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1156 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1159 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
| 1160 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1160 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
| 1161 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1161 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
| OLD | NEW |