| OLD | NEW |
| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } 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) { |
| 327 cinfo.out_color_space = JCS_RGB_565; | 327 cinfo.out_color_space = JCS_RGB_565; |
| 328 if (this->getDitherImage()) { | 328 if (this->getDitherImage()) { |
| 329 cinfo.dither_mode = JDITHER_ORDERED; | 329 cinfo.dither_mode = JDITHER_ORDERED; |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 #endif | 332 #endif |
| 333 | 333 |
| 334 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { | 334 if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 335 bm->setConfig(config, cinfo.image_width, cinfo.image_height); | 335 bm->setConfig(config, cinfo.image_width, cinfo.image_height); |
| 336 bm->setIsOpaque(true); | 336 bm->setIsOpaque(config != SkBitmap::kA8_Config); |
| 337 return true; | 337 return true; |
| 338 } | 338 } |
| 339 | 339 |
| 340 /* image_width and image_height are the original dimensions, available | 340 /* image_width and image_height are the original dimensions, available |
| 341 after jpeg_read_header(). To see the scaled dimensions, we have to call | 341 after jpeg_read_header(). To see the scaled dimensions, we have to call |
| 342 jpeg_start_decompress(), and then read output_width and output_height. | 342 jpeg_start_decompress(), and then read output_width and output_height. |
| 343 */ | 343 */ |
| 344 if (!jpeg_start_decompress(&cinfo)) { | 344 if (!jpeg_start_decompress(&cinfo)) { |
| 345 /* If we failed here, we may still have enough information to return | 345 /* If we failed here, we may still have enough information to return |
| 346 to the caller if they just wanted (subsampled bounds). If sampleSize | 346 to the caller if they just wanted (subsampled bounds). If sampleSize |
| 347 was 1, then we would have already returned. Thus we just check if | 347 was 1, then we would have already returned. Thus we just check if |
| 348 we're in kDecodeBounds_Mode, and that we have valid output sizes. | 348 we're in kDecodeBounds_Mode, and that we have valid output sizes. |
| 349 | 349 |
| 350 One reason to fail here is that we have insufficient stream data | 350 One reason to fail here is that we have insufficient stream data |
| 351 to complete the setup. However, output dimensions seem to get | 351 to complete the setup. However, output dimensions seem to get |
| 352 computed very early, which is why this special check can pay off. | 352 computed very early, which is why this special check can pay off. |
| 353 */ | 353 */ |
| 354 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { | 354 if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimension
s(cinfo)) { |
| 355 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, | 355 SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, |
| 356 recompute_sampleSize(sampleSize, cinfo)); | 356 recompute_sampleSize(sampleSize, cinfo)); |
| 357 bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()); | 357 bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()); |
| 358 bm->setIsOpaque(true); | 358 bm->setIsOpaque(config != SkBitmap::kA8_Config); |
| 359 return true; | 359 return true; |
| 360 } else { | 360 } else { |
| 361 return return_false(cinfo, *bm, "start_decompress"); | 361 return return_false(cinfo, *bm, "start_decompress"); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 sampleSize = recompute_sampleSize(sampleSize, cinfo); | 364 sampleSize = recompute_sampleSize(sampleSize, cinfo); |
| 365 | 365 |
| 366 // should we allow the Chooser (if present) to pick a config for us??? | 366 // should we allow the Chooser (if present) to pick a config for us??? |
| 367 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { | 367 if (!this->chooseFromOneChoice(config, cinfo.output_width, cinfo.output_heig
ht)) { |
| 368 return return_false(cinfo, *bm, "chooseFromOneChoice"); | 368 return return_false(cinfo, *bm, "chooseFromOneChoice"); |
| 369 } | 369 } |
| 370 | 370 |
| 371 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); | 371 SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampl
eSize); |
| 372 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 372 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); |
| 373 bm->setIsOpaque(true); | 373 bm->setIsOpaque(config != SkBitmap::kA8_Config); |
| 374 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 374 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 375 return true; | 375 return true; |
| 376 } | 376 } |
| 377 if (!this->allocPixelRef(bm, NULL)) { | 377 if (!this->allocPixelRef(bm, NULL)) { |
| 378 return return_false(cinfo, *bm, "allocPixelRef"); | 378 return return_false(cinfo, *bm, "allocPixelRef"); |
| 379 } | 379 } |
| 380 | 380 |
| 381 SkAutoLockPixels alp(*bm); | 381 SkAutoLockPixels alp(*bm); |
| 382 | 382 |
| 383 #ifdef ANDROID_RGB | 383 #ifdef ANDROID_RGB |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1023 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1024 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1024 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 | 1027 |
| 1028 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); | 1028 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libjpeg_dfactory); |
| 1029 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg
); | 1029 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_jpeg
); |
| 1030 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact
ory); | 1030 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libjpeg_efact
ory); |
| OLD | NEW |