| 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" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 fSrcRowBytes = SkSwizzler::BytesPerPixel(srcConfig) * dstInfo.width(); | 290 fSrcRowBytes = SkSwizzler::BytesPerPixel(srcConfig) * dstInfo.width(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 /* | 293 /* |
| 294 * Performs the jpeg decode | 294 * Performs the jpeg decode |
| 295 */ | 295 */ |
| 296 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, | 296 SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
| 297 void* dst, size_t dstRowBytes, | 297 void* dst, size_t dstRowBytes, |
| 298 const Options& options, SkPMColor*, int
*) { | 298 const Options& options, SkPMColor*, int
*) { |
| 299 | 299 |
| 300 // Do not allow a regular decode if the caller has asked for a scanline deco
der |
| 301 if (NULL != this->scanlineDecoder()) { |
| 302 return fDecoderMgr->returnFailure("cannot getPixels() if a scanline deco
der has been" |
| 303 "created", kInvalidInput); |
| 304 } |
| 305 |
| 300 // Rewind the stream if needed | 306 // Rewind the stream if needed |
| 301 if (!this->handleRewind()) { | 307 if (!this->handleRewind()) { |
| 302 fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind); | 308 return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRe
wind); |
| 303 } | 309 } |
| 304 | 310 |
| 305 // Get a pointer to the decompress info since we will use it quite frequentl
y | 311 // Get a pointer to the decompress info since we will use it quite frequentl
y |
| 306 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); | 312 jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo(); |
| 307 | 313 |
| 308 // Set the jump location for libjpeg errors | 314 // Set the jump location for libjpeg errors |
| 309 if (setjmp(fDecoderMgr->getJmpBuf())) { | 315 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 310 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); | 316 return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
| 311 } | 317 } |
| 312 | 318 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 448 |
| 443 return SkImageGenerator::kSuccess; | 449 return SkImageGenerator::kSuccess; |
| 444 } | 450 } |
| 445 | 451 |
| 446 void onFinish() override { | 452 void onFinish() override { |
| 447 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { | 453 if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
| 448 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); | 454 SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); |
| 449 return; | 455 return; |
| 450 } | 456 } |
| 451 | 457 |
| 458 // We may not have decoded the entire image. Prevent libjpeg-turbo from
failing on a |
| 459 // partial decode. |
| 460 fCodec->fDecoderMgr->dinfo()->output_scanline = dstInfo().height(); |
| 452 jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); | 461 jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); |
| 453 } | 462 } |
| 454 | 463 |
| 455 private: | 464 private: |
| 456 SkJpegCodec* fCodec; // unowned | 465 SkJpegCodec* fCodec; // unowned |
| 457 SkAutoMalloc fStorage; | 466 SkAutoMalloc fStorage; |
| 458 uint8_t* fSrcRow; // ptr into fStorage | 467 uint8_t* fSrcRow; // ptr into fStorage |
| 459 | 468 |
| 460 typedef SkScanlineDecoder INHERITED; | 469 typedef SkScanlineDecoder INHERITED; |
| 461 }; | 470 }; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 // Create the swizzler | 505 // Create the swizzler |
| 497 this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options); | 506 this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options); |
| 498 if (NULL == fSwizzler) { | 507 if (NULL == fSwizzler) { |
| 499 SkCodecPrintf("Could not create swizzler\n"); | 508 SkCodecPrintf("Could not create swizzler\n"); |
| 500 return NULL; | 509 return NULL; |
| 501 } | 510 } |
| 502 | 511 |
| 503 // Return the new scanline decoder | 512 // Return the new scanline decoder |
| 504 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, this)); | 513 return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, this)); |
| 505 } | 514 } |
| OLD | NEW |