Chromium Code Reviews| Index: src/codec/SkJpegCodec.cpp |
| diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp |
| index 30c1a39f06f5f647755d2b2b4404c11b21703a79..c0c503863a5033759a62a412823497c6ee477855 100644 |
| --- a/src/codec/SkJpegCodec.cpp |
| +++ b/src/codec/SkJpegCodec.cpp |
| @@ -325,7 +325,8 @@ bool SkJpegCodec::onDimensionsSupported(const SkISize& size) { |
| */ |
| SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
| void* dst, size_t dstRowBytes, |
| - const Options& options, SkPMColor*, int*) { |
| + const Options& options, SkPMColor*, int*, |
| + int* rowsDecoded) { |
| if (options.fSubset) { |
| // Subsets are not supported. |
| return kUnimplemented; |
| @@ -343,6 +344,7 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
| if (!this->setOutputColorSpace(dstInfo)) { |
| return fDecoderMgr->returnFailure("conversion_possible", kInvalidConversion); |
| } |
| + fDstInfo = dstInfo; |
| // Now, given valid output dimensions, we can start the decompress |
| if (!jpeg_start_decompress(dinfo)) { |
| @@ -358,20 +360,11 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
| JSAMPLE* dstRow = (JSAMPLE*) dst; |
| for (uint32_t y = 0; y < dstHeight; y++) { |
| // Read rows of the image |
| - uint32_t rowsDecoded = jpeg_read_scanlines(dinfo, &dstRow, 1); |
| + uint32_t lines = jpeg_read_scanlines(dinfo, &dstRow, 1); |
| // If we cannot read enough rows, assume the input is incomplete |
| - if (rowsDecoded != 1) { |
| - // Fill the remainder of the image with black. This error handling |
| - // behavior is unspecified but SkCodec consistently uses black as |
| - // the fill color for opaque images. If the destination is kGray, |
| - // the low 8 bits of SK_ColorBLACK will be used. Conveniently, |
| - // these are zeros, which is the representation for black in kGray. |
| - // If the destination is kRGB_565, the low 16 bits of SK_ColorBLACK |
| - // will be used. Conveniently, these are zeros, which is the |
| - // representation for black in kRGB_565. |
| - SkSwizzler::Fill(dstRow, dstInfo, dstRowBytes, dstHeight - y, |
| - SK_ColorBLACK, nullptr, options.fZeroInitialized); |
| + if (lines != 1) { |
| + *rowsDecoded = y; |
| return fDecoderMgr->returnFailure("Incomplete image data", kIncompleteInput); |
| } |
| @@ -394,9 +387,8 @@ SkSampler* SkJpegCodec::getSampler() { |
| return fSwizzler; |
| } |
| - const SkImageInfo& info = this->dstInfo(); |
| SkSwizzler::SrcConfig srcConfig; |
| - switch (info.colorType()) { |
| + switch (fDstInfo.colorType()) { |
| case kGray_8_SkColorType: |
| srcConfig = SkSwizzler::kGray; |
| break; |
| @@ -414,7 +406,7 @@ SkSampler* SkJpegCodec::getSampler() { |
| SkASSERT(false); |
| } |
| - fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, info, |
| + fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, fDstInfo, |
|
scroggo
2015/10/07 16:04:24
After SkScaledCodec calls this, it will modify the
msarett
2015/10/07 17:40:41
That's correct.
The point of fDstInfo was to ensu
|
| this->options().fZeroInitialized)); |
| if (!fSwizzler) { |
| return nullptr; |
| @@ -442,6 +434,7 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| fSwizzler.reset(nullptr); |
| fSrcRow = nullptr; |
| fStorage.free(); |
| + fDstInfo = dstInfo; |
| // Now, given valid output dimensions, we can start the decompress |
| if (!jpeg_start_decompress(fDecoderMgr->dinfo())) { |
| @@ -452,7 +445,7 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| return kSuccess; |
| } |
| -SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
| +int SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
| // Set the jump location for libjpeg errors |
| if (setjmp(fDecoderMgr->getJmpBuf())) { |
| return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
| @@ -471,10 +464,8 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte |
| // Read row of the image |
| uint32_t rowsDecoded = jpeg_read_scanlines(fDecoderMgr->dinfo(), &dstRow, 1); |
| if (rowsDecoded != 1) { |
| - SkSwizzler::Fill(dstRow, this->dstInfo(), rowBytes, count - y, |
| - SK_ColorBLACK, nullptr, this->options().fZeroInitialized); |
| fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height(); |
| - return kIncompleteInput; |
| + return y; |
| } |
| // Convert to RGBA if necessary |
| @@ -490,7 +481,7 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte |
| dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
| } |
| } |
| - return kSuccess; |
| + return count; |
| } |
| #ifndef TURBO_HAS_SKIP |
| @@ -504,14 +495,11 @@ SkCodec::Result SkJpegCodec::onGetScanlines(void* dst, int count, size_t rowByte |
| } |
| #endif |
| -SkCodec::Result SkJpegCodec::onSkipScanlines(int count) { |
| +bool SkJpegCodec::onSkipScanlines(int count) { |
| // Set the jump location for libjpeg errors |
| if (setjmp(fDecoderMgr->getJmpBuf())) { |
| return fDecoderMgr->returnFailure("setjmp", kInvalidInput); |
| } |
| - jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
| - |
| - return kSuccess; |
| + return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
| } |
| - |