Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 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 #include "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkJpegCodec.h" | 9 #include "SkJpegCodec.h" |
| 10 #include "SkJpegDecoderMgr.h" | 10 #include "SkJpegDecoderMgr.h" |
| 11 #include "SkJpegUtility_codec.h" | 11 #include "SkJpegUtility_codec.h" |
| 12 #include "SkCodecPriv.h" | 12 #include "SkCodecPriv.h" |
| 13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 14 #include "SkScaledCodec.h" | |
| 14 #include "SkScanlineDecoder.h" | 15 #include "SkScanlineDecoder.h" |
| 15 #include "SkStream.h" | 16 #include "SkStream.h" |
| 16 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
| 17 #include "SkTypes.h" | 18 #include "SkTypes.h" |
| 18 | 19 |
| 19 // stdio is needed for libjpeg-turbo | 20 // stdio is needed for libjpeg-turbo |
| 20 #include <stdio.h> | 21 #include <stdio.h> |
| 21 | 22 |
| 22 extern "C" { | 23 extern "C" { |
| 23 #include "jpeglibmangler.h" | 24 #include "jpeglibmangler.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 streamDeleter.detach(); | 140 streamDeleter.detach(); |
| 140 return codec; | 141 return codec; |
| 141 } | 142 } |
| 142 return NULL; | 143 return NULL; |
| 143 } | 144 } |
| 144 | 145 |
| 145 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, | 146 SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, |
| 146 JpegDecoderMgr* decoderMgr) | 147 JpegDecoderMgr* decoderMgr) |
| 147 : INHERITED(srcInfo, stream) | 148 : INHERITED(srcInfo, stream) |
| 148 , fDecoderMgr(decoderMgr) | 149 , fDecoderMgr(decoderMgr) |
| 150 , fPartialNum(1) | |
| 151 , fPartialDenom(1) | |
| 149 {} | 152 {} |
| 150 | 153 |
| 151 /* | 154 /* |
| 152 * Return a valid set of output dimensions for this decoder, given an input scal e | 155 * Return a valid set of output dimensions for this decoder, given an input scal e |
| 153 */ | 156 */ |
| 154 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { | 157 SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { |
| 155 // libjpeg-turbo supports scaling by 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1, so we will | 158 // libjpeg-turbo supports scaling by 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1, so we will |
| 156 // support these as well | 159 // support these as well |
| 157 long num; | 160 long num; |
| 158 long denom = 8; | 161 long denom = 8; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 182 dinfo.global_state = DSTATE_READY; | 185 dinfo.global_state = DSTATE_READY; |
| 183 dinfo.num_components = 0; | 186 dinfo.num_components = 0; |
| 184 dinfo.scale_num = num; | 187 dinfo.scale_num = num; |
| 185 dinfo.scale_denom = denom; | 188 dinfo.scale_denom = denom; |
| 186 turbo_jpeg_calc_output_dimensions(&dinfo); | 189 turbo_jpeg_calc_output_dimensions(&dinfo); |
| 187 | 190 |
| 188 // Return the calculated output dimensions for the given scale | 191 // Return the calculated output dimensions for the given scale |
| 189 return SkISize::Make(dinfo.output_width, dinfo.output_height); | 192 return SkISize::Make(dinfo.output_width, dinfo.output_height); |
| 190 } | 193 } |
| 191 | 194 |
| 195 // The swizzler is only used for sampling in the x direction | |
| 196 // when sampling a scanlineDecoder is used. The swizzler is not used in onGetPix els | |
| 197 SkCodec::Result SkJpegCodec::initializeSwizzler(const SkImageInfo& requestedInfo , | |
| 198 void* dst, size_t rowBytes, | |
|
scroggo
2015/08/05 15:36:00
It looks like these parameters are not needed? I t
emmaleer
2015/08/05 18:41:52
Acknowledged.
| |
| 199 const Options& options, | |
| 200 SkPMColor ctable[], | |
| 201 int* ctableCount) { | |
| 202 | |
| 203 const SkColorType srcColorType = requestedInfo.colorType(); | |
|
scroggo
2015/08/05 15:36:00
It seems weird that the requestedInfo yields the s
emmaleer
2015/08/05 18:41:52
Yes, the destination and source colorTypes are the
| |
| 204 SkSwizzler::SrcConfig srcConfig; | |
| 205 switch (srcColorType) { | |
| 206 case kGray_8_SkColorType: | |
| 207 srcConfig = SkSwizzler::kGray; | |
| 208 break; | |
| 209 case kRGBA_8888_SkColorType: | |
| 210 srcConfig = SkSwizzler::kRGBX; | |
| 211 break; | |
| 212 case kBGRA_8888_SkColorType: | |
| 213 srcConfig = SkSwizzler::kBGRX; | |
| 214 break; | |
| 215 case kRGB_565_SkColorType: | |
| 216 srcConfig = SkSwizzler::kRGB_565; | |
| 217 break; | |
| 218 default: | |
| 219 //would have exited before now if the colorType was supported by jpe g | |
| 220 SkASSERT(false); | |
| 221 } | |
| 222 | |
| 223 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, NULL, requestedInfo, | |
|
scroggo
2015/08/05 15:36:00
Sorry, I've gone back and forth on this. If the sw
emmaleer
2015/08/05 18:41:52
Yes, that makes sense. Now that the creation funct
scroggo
2015/08/05 19:10:04
sounds good
emmaleer
2015/08/06 13:45:46
Swizzler is now in the ScanlineDecoder.
| |
| 224 options.fZeroInitialized, this->g etInfo().width())); | |
| 225 if (!fSwizzler) { | |
| 226 // FIXME: CreateSwizzler could fail for another reason. | |
| 227 return kUnimplemented; | |
| 228 } | |
| 229 return kSuccess; | |
| 230 } | |
| 231 | |
| 192 /* | 232 /* |
| 193 * Handles rewinding the input stream if it is necessary | 233 * Handles rewinding the input stream if it is necessary |
| 194 */ | 234 */ |
| 195 bool SkJpegCodec::handleRewind() { | 235 bool SkJpegCodec::handleRewind() { |
| 196 switch(this->rewindIfNeeded()) { | 236 switch(this->rewindIfNeeded()) { |
| 197 case kCouldNotRewind_RewindState: | 237 case kCouldNotRewind_RewindState: |
| 198 return fDecoderMgr->returnFalse("could not rewind"); | 238 return fDecoderMgr->returnFalse("could not rewind"); |
| 199 case kRewound_RewindState: { | 239 case kRewound_RewindState: { |
| 200 JpegDecoderMgr* decoderMgr = NULL; | 240 JpegDecoderMgr* decoderMgr = NULL; |
| 201 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { | 241 if (!ReadHeader(this->stream(), NULL, &decoderMgr)) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 // much faster than decoding to color and then converting | 305 // much faster than decoding to color and then converting |
| 266 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; | 306 fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE; |
| 267 } | 307 } |
| 268 return true; | 308 return true; |
| 269 default: | 309 default: |
| 270 return false; | 310 return false; |
| 271 } | 311 } |
| 272 } | 312 } |
| 273 | 313 |
| 274 /* | 314 /* |
| 275 * Checks if we can scale to the requested dimensions and scales the dimensions | 315 * Checks if we can natively scale to the requested dimensions and natively scal es the |
| 276 * if possible | 316 * dimensions if possible |
| 277 */ | 317 */ |
| 278 bool SkJpegCodec::scaleToDimensions(uint32_t dstWidth, uint32_t dstHeight) { | 318 bool SkJpegCodec::nativelyScaleToDimensions(uint32_t dstWidth, uint32_t dstHeigh t) { |
| 279 // libjpeg-turbo can scale to 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1 | 319 // libjpeg-turbo can scale to 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, and 1/1 |
| 280 fDecoderMgr->dinfo()->scale_denom = 8; | 320 fDecoderMgr->dinfo()->scale_denom = 8; |
| 281 fDecoderMgr->dinfo()->scale_num = 8; | 321 fDecoderMgr->dinfo()->scale_num = 8; |
| 282 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); | 322 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); |
| 283 while (fDecoderMgr->dinfo()->output_width != dstWidth || | 323 while (fDecoderMgr->dinfo()->output_width != dstWidth || |
| 284 fDecoderMgr->dinfo()->output_height != dstHeight) { | 324 fDecoderMgr->dinfo()->output_height != dstHeight) { |
| 285 | 325 |
| 286 // Return a failure if we have tried all of the possible scales | 326 // Return a failure if we have tried all of the possible scales |
| 287 if (1 == fDecoderMgr->dinfo()->scale_num || | 327 if (1 == fDecoderMgr->dinfo()->scale_num || |
| 288 dstWidth > fDecoderMgr->dinfo()->output_width || | 328 dstWidth > fDecoderMgr->dinfo()->output_width || |
| 289 dstHeight > fDecoderMgr->dinfo()->output_height) { | 329 dstHeight > fDecoderMgr->dinfo()->output_height) { |
| 290 return fDecoderMgr->returnFalse("could not scale to requested dimens ions"); | 330 // reset native scale settings on failure because this may be suppor ted by the swizzler |
| 331 this->fDecoderMgr->dinfo()->scale_num = 8; | |
| 332 turbo_jpeg_calc_output_dimensions(this->fDecoderMgr->dinfo()); | |
| 333 return false; | |
| 291 } | 334 } |
| 292 | 335 |
| 293 // Try the next scale | 336 // Try the next scale |
| 294 fDecoderMgr->dinfo()->scale_num -= 1; | 337 fDecoderMgr->dinfo()->scale_num -= 1; |
| 295 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); | 338 turbo_jpeg_calc_output_dimensions(fDecoderMgr->dinfo()); |
| 296 } | 339 } |
| 297 return true; | 340 return true; |
| 298 } | 341 } |
| 299 | 342 |
| 300 /* | 343 /* |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 320 if (setjmp(fDecoderMgr->getJmpBuf())) { | 363 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 321 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 364 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
| 322 } | 365 } |
| 323 | 366 |
| 324 // Check if we can decode to the requested destination and set the output co lor space | 367 // Check if we can decode to the requested destination and set the output co lor space |
| 325 if (!this->setOutputColorSpace(dstInfo)) { | 368 if (!this->setOutputColorSpace(dstInfo)) { |
| 326 return fDecoderMgr->returnFailure("conversion_possible", kInvalidConvers ion); | 369 return fDecoderMgr->returnFailure("conversion_possible", kInvalidConvers ion); |
| 327 } | 370 } |
| 328 | 371 |
| 329 // Perform the necessary scaling | 372 // Perform the necessary scaling |
| 330 if (!this->scaleToDimensions(dstInfo.width(), dstInfo.height())) { | 373 if (!this->nativelyScaleToDimensions(dstInfo.width(), dstInfo.height())) { |
| 331 return fDecoderMgr->returnFailure("cannot scale to requested dims", kInv alidScale); | 374 return fDecoderMgr->returnFailure("cannot scale to requested dims", kInv alidScale); |
| 332 } | 375 } |
| 333 | 376 |
| 334 // Now, given valid output dimensions, we can start the decompress | 377 // Now, given valid output dimensions, we can start the decompress |
| 335 if (!turbo_jpeg_start_decompress(dinfo)) { | 378 if (!turbo_jpeg_start_decompress(dinfo)) { |
| 336 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); | 379 return fDecoderMgr->returnFailure("startDecompress", kInvalidInput); |
| 337 } | 380 } |
| 338 | 381 |
| 339 // The recommended output buffer height should always be 1 in high quality m odes. | 382 // The recommended output buffer height should always be 1 in high quality m odes. |
| 340 // If it's not, we want to know because it means our strategy is not optimal . | 383 // If it's not, we want to know because it means our strategy is not optimal . |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 /* | 430 /* |
| 388 * Enable scanline decoding for jpegs | 431 * Enable scanline decoding for jpegs |
| 389 */ | 432 */ |
| 390 class SkJpegScanlineDecoder : public SkScanlineDecoder { | 433 class SkJpegScanlineDecoder : public SkScanlineDecoder { |
| 391 public: | 434 public: |
| 392 SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec, | 435 SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec, |
| 393 const SkCodec::Options& opts) | 436 const SkCodec::Options& opts) |
| 394 : INHERITED(dstInfo) | 437 : INHERITED(dstInfo) |
| 395 , fCodec(codec) | 438 , fCodec(codec) |
| 396 , fOpts(opts) | 439 , fOpts(opts) |
| 397 {} | 440 { |
| 441 if(fCodec->fSwizzler) { | |
| 442 int colorBytes = (codec->fDecoderMgr->dinfo()->out_color_space == JC S_RGB565) ? 2 : | |
|
scroggo
2015/08/05 15:36:00
Maybe make this a static function that takes a din
msarett
2015/08/05 15:54:56
Sorry for making a suggestion that led to code dup
emmaleer
2015/08/05 18:41:52
Acknowledged.
| |
| 443 codec->fDecoderMgr->dinfo()->out_color_components; | |
| 444 fStorage.reset(codec->fDecoderMgr->dinfo()->output_width * colorByte s); | |
| 445 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | |
| 446 } else { | |
| 447 fSrcRow = NULL; | |
| 448 } | |
| 449 } | |
| 398 | 450 |
| 399 virtual ~SkJpegScanlineDecoder() { | 451 virtual ~SkJpegScanlineDecoder() { |
| 400 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 452 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
| 401 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); | 453 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); |
| 402 return; | 454 return; |
| 403 } | 455 } |
| 404 | 456 |
| 405 // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a | 457 // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a |
| 406 // partial decode. | 458 // partial decode. |
| 407 fCodec->fDecoderMgr->dinfo()->output_scanline = fCodec->getInfo().height (); | 459 fCodec->fDecoderMgr->dinfo()->output_scanline = fCodec->getInfo().height (); |
| 408 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); | 460 turbo_jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); |
| 409 } | 461 } |
| 410 | 462 |
| 411 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de { | 463 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de { |
| 412 // Set the jump location for libjpeg errors | 464 // Set the jump location for libjpeg errors |
| 413 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 465 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
| 414 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); | 466 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); |
| 415 } | 467 } |
| 468 // Read rows one at a time | |
| 469 JSAMPLE* dstRow; | |
| 470 if (fCodec->fSwizzler) { | |
| 471 // write data to storage row, then sample using swizzler | |
| 472 dstRow = fSrcRow; | |
| 473 } else { | |
| 474 // write data directly to dst | |
| 475 dstRow = (JSAMPLE*) dst; | |
| 476 } | |
| 416 | 477 |
| 417 // Read rows one at a time | |
| 418 JSAMPLE* dstRow = (JSAMPLE*) dst; | |
| 419 for (int y = 0; y < count; y++) { | 478 for (int y = 0; y < count; y++) { |
| 420 // Read row of the image | 479 // Read row of the image |
| 421 uint32_t rowsDecoded = | 480 uint32_t rowsDecoded = |
| 422 turbo_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dst Row, 1); | 481 turbo_jpeg_read_scanlines(fCodec->fDecoderMgr->dinfo(), &dst Row, 1); |
| 423 if (rowsDecoded != 1) { | 482 if (rowsDecoded != 1) { |
| 424 if (SkCodec::kNo_ZeroInitialized == fOpts.fZeroInitialized || | 483 if (SkCodec::kNo_ZeroInitialized == fOpts.fZeroInitialized || |
| 425 kN32_SkColorType == this->dstInfo().colorType()) { | 484 kN32_SkColorType == this->dstInfo().colorType()) { |
| 426 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, | 485 SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, |
| 427 count - y, SK_ColorBLACK, NULL); | 486 count - y, SK_ColorBLACK, NULL); |
| 428 } | 487 } |
| 429 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo(). height(); | 488 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo(). height(); |
| 430 return SkCodec::kIncompleteInput; | 489 return SkCodec::kIncompleteInput; |
| 431 } | 490 } |
| 432 | 491 |
| 433 // Convert to RGBA if necessary | 492 // Convert to RGBA if necessary |
| 434 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { | 493 if (JCS_CMYK == fCodec->fDecoderMgr->dinfo()->out_color_space) { |
| 435 convert_CMYK_to_RGBA(dstRow, this->dstInfo().width()); | 494 convert_CMYK_to_RGBA(dstRow, fCodec->fDecoderMgr->dinfo()->outpu t_width); |
| 436 } | 495 } |
| 437 | 496 |
| 438 // Move to the next row | 497 if(fCodec->fSwizzler) { |
| 439 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | 498 // use swizzler to sample row |
| 499 fCodec->fSwizzler->swizzle(dst, dstRow); | |
| 500 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); | |
| 501 } else { | |
| 502 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | |
| 503 } | |
| 440 } | 504 } |
| 441 | |
| 442 return SkCodec::kSuccess; | 505 return SkCodec::kSuccess; |
| 443 } | 506 } |
| 444 | 507 |
| 445 #ifndef TURBO_HAS_SKIP | 508 #ifndef TURBO_HAS_SKIP |
| 446 #define turbo_jpeg_skip_scanlines(dinfo, count) \ | 509 #define turbo_jpeg_skip_scanlines(dinfo, count) \ |
| 447 SkAutoMalloc storage(dinfo->output_width * dinfo->out_color_components); \ | 510 int colorBytes = (codec->fDecoderMgr->dinfo()->out_color_space == JCS_RGB565 ) ? 2 : \ |
|
scroggo
2015/08/05 15:36:00
colorBytes is unused - I assume you want to change
emmaleer
2015/08/05 18:41:52
Acknowledged.
| |
| 448 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \ | 511 codec->fDecoderMgr->dinfo()->out_color_components; \ |
| 449 for (int y = 0; y < count; y++) { \ | 512 SkAutoMalloc storage(dinfo->output_width * dinfo->out_color_components); \ |
| 450 turbo_jpeg_read_scanlines(dinfo, &storagePtr, 1); \ | 513 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \ |
| 514 for (int y = 0; y < count; y++) { \ | |
| 515 turbo_jpeg_read_scanlines(dinfo, &storagePtr, 1); \ | |
| 451 } | 516 } |
| 452 #endif | 517 #endif |
| 453 | 518 |
| 454 SkCodec::Result onSkipScanlines(int count) override { | 519 SkCodec::Result onSkipScanlines(int count) override { |
| 455 // Set the jump location for libjpeg errors | 520 // Set the jump location for libjpeg errors |
| 456 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 521 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
| 457 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); | 522 return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvali dInput); |
| 458 } | 523 } |
| 459 | 524 |
| 460 turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count); | 525 turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count); |
| 461 | 526 |
| 462 return SkCodec::kSuccess; | 527 return SkCodec::kSuccess; |
| 463 } | 528 } |
| 464 | 529 |
| 465 private: | 530 private: |
| 466 SkAutoTDelete<SkJpegCodec> fCodec; | 531 SkAutoTDelete<SkJpegCodec> fCodec; |
| 532 SkAutoMalloc fStorage; // Only used if sampling is needed | |
| 533 uint8_t* fSrcRow; // Only used if sampling is needed | |
| 467 const SkCodec::Options& fOpts; | 534 const SkCodec::Options& fOpts; |
| 468 | 535 |
| 469 typedef SkScanlineDecoder INHERITED; | 536 typedef SkScanlineDecoder INHERITED; |
| 470 }; | 537 }; |
| 471 | 538 |
| 472 SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, | 539 SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, |
| 473 const Options& options, SkPMColor ctable[], int* ctableCount) { | 540 const Options& options, SkPMColor ctable[], int* ctableCount) { |
| 474 | 541 |
| 475 // Rewind the stream if needed | 542 // Rewind the stream if needed |
| 476 if (!this->handleRewind()) { | 543 if (!this->handleRewind()) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 492 if (!codec) { | 559 if (!codec) { |
| 493 return NULL; | 560 return NULL; |
| 494 } | 561 } |
| 495 | 562 |
| 496 // Check if we can decode to the requested destination and set the output co lor space | 563 // Check if we can decode to the requested destination and set the output co lor space |
| 497 if (!codec->setOutputColorSpace(dstInfo)) { | 564 if (!codec->setOutputColorSpace(dstInfo)) { |
| 498 SkCodecPrintf("Cannot convert to output type\n"); | 565 SkCodecPrintf("Cannot convert to output type\n"); |
| 499 return NULL; | 566 return NULL; |
| 500 } | 567 } |
| 501 | 568 |
| 569 SkImageInfo scaledInfo = dstInfo; | |
| 570 | |
| 502 // Perform the necessary scaling | 571 // Perform the necessary scaling |
| 503 if (!codec->scaleToDimensions(dstInfo.width(), dstInfo.height())) { | 572 if (!codec->nativelyScaleToDimensions(dstInfo.width(), dstInfo.height())) { |
| 504 SkCodecPrintf("Cannot scale to output dimensions\n"); | 573 // full native scaling to dstInfo dimensions not supported |
| 505 return NULL; | 574 |
| 575 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI nfo)) { | |
| 576 return NULL; | |
| 577 } | |
| 578 // create swizzler for sampling | |
| 579 if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opti ons, ctable, | |
| 580 ctableCount) | |
| 581 != kSuccess) { | |
| 582 SkCodecPrintf("failed to initialize the swizzler.\n"); | |
| 583 return NULL; | |
| 584 } | |
| 506 } | 585 } |
| 507 | 586 |
| 508 // Now, given valid output dimensions, we can start the decompress | 587 // Now, given valid output dimensions, we can start the decompress |
| 509 if (!turbo_jpeg_start_decompress(codec->fDecoderMgr->dinfo())) { | 588 if (!turbo_jpeg_start_decompress(codec->fDecoderMgr->dinfo())) { |
| 510 SkCodecPrintf("start decompress failed\n"); | 589 SkCodecPrintf("start decompress failed\n"); |
| 511 return NULL; | 590 return NULL; |
| 512 } | 591 } |
| 513 | 592 |
| 514 // Return the new scanline decoder | 593 // Return the new scanline decoder |
| 515 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, codec.detach(), options)) ; | 594 return SkNEW_ARGS(SkJpegScanlineDecoder, (scaledInfo, codec.detach(), option s)); |
| 516 } | 595 } |
| OLD | NEW |