Index: src/codec/SkJpegCodec.cpp |
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp |
index 2eaff1a9a67f47be24d70c6e7dddba21fd056350..9c9bd77c13515ff17f32e2cf33bede895e7463f7 100644 |
--- a/src/codec/SkJpegCodec.cpp |
+++ b/src/codec/SkJpegCodec.cpp |
@@ -297,9 +297,15 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
void* dst, size_t dstRowBytes, |
const Options& options, SkPMColor*, int*) { |
+ // Do not allow a regular decode if the caller has asked for a scanline decoder |
+ if (NULL != this->scanlineDecoder()) { |
+ return fDecoderMgr->returnFailure("cannot getPixels() if a scanline decoder has been" |
+ "created", kInvalidParameters); |
+ } |
+ |
// Rewind the stream if needed |
if (!this->handleRewind()) { |
- fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind); |
+ return fDecoderMgr->returnFailure("could not rewind stream", kCouldNotRewind); |
} |
// Get a pointer to the decompress info since we will use it quite frequently |
@@ -388,6 +394,25 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo, |
} |
/* |
+ * We override the destructor to ensure that the scanline decoder is left in a |
+ * finished state before destroying the decode manager. |
+ */ |
+SkJpegCodec::~SkJpegCodec() { |
+ SkAutoTDelete<SkScanlineDecoder> decoder(this->detachScanlineDecoder()); |
+ if (NULL != decoder) { |
+ if (setjmp(fDecoderMgr->getJmpBuf())) { |
+ SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); |
scroggo
2015/06/30 20:59:58
Do we need this error message? I guess it could be
msarett
2015/06/30 21:33:00
I would lean towards keeping it. It doesn't print
|
+ return; |
+ } |
+ |
+ // We may not have decoded the entire image. Prevent libjpeg-turbo from failing on a |
+ // partial decode. |
+ fDecoderMgr->dinfo()->output_scanline = this->getInfo().height(); |
+ jpeg_finish_decompress(fDecoderMgr->dinfo()); |
+ } |
+} |
+ |
+/* |
* Enable scanline decoding for jpegs |
*/ |
class SkJpegScanlineDecoder : public SkScanlineDecoder { |
@@ -443,15 +468,6 @@ public: |
return SkImageGenerator::kSuccess; |
} |
- void onFinish() override { |
- if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
- SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n"); |
- return; |
- } |
- |
- jpeg_finish_decompress(fCodec->fDecoderMgr->dinfo()); |
- } |
- |
private: |
SkJpegCodec* fCodec; // unowned |
SkAutoMalloc fStorage; |