Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Unified Diff: src/codec/SkJpegCodec.cpp

Issue 1267583002: Create a scanline decoder without creating a codec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bugs. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/codec/SkJpegCodec.cpp
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 5acc0b396c54d34abb922f80687104b54f85990a..9f0c7186a4b713ccac3b674d3f8f0b2554023354 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -382,11 +382,44 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
*/
class SkJpegScanlineDecoder : public SkScanlineDecoder {
public:
- SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec)
- : INHERITED(dstInfo)
+ SkJpegScanlineDecoder(const SkImageInfo& srcInfo, SkJpegCodec* codec)
+ : INHERITED(srcInfo)
, fCodec(codec)
{}
+ SkCodec::Result onReset(const SkImageInfo& dstInfo, const SkCodec::Options& options,
+ SkPMColor ctable[], int* ctableCount) override {
+
+ // Rewind the stream if needed
+ if (!fCodec->handleRewind()) {
+ return SkCodec::kCouldNotRewind;
+ }
+
+ // Set the jump location for libjpeg errors
+ if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
+ SkCodecPrintf("setjmp: Error from libjpeg\n");
+ return SkCodec::kInvalidInput;
+ }
+
+ // Check if we can decode to the requested destination and set the output color space
+ if (!fCodec->setOutputColorSpace(dstInfo)) {
+ return SkCodec::kInvalidConversion;
+ }
+
+ // Perform the necessary scaling
+ if (!fCodec->scaleToDimensions(dstInfo.width(), dstInfo.height())) {
+ return SkCodec::kInvalidScale;
+ }
+
+ // Now, given valid output dimensions, we can start the decompress
+ if (!turbo_jpeg_start_decompress(fCodec->fDecoderMgr->dinfo())) {
+ SkCodecPrintf("start decompress failed\n");
+ return SkCodec::kInvalidInput;
+ }
+
+ return SkCodec::kSuccess;
+ }
+
virtual ~SkJpegScanlineDecoder() {
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n");
@@ -456,48 +489,13 @@ private:
typedef SkScanlineDecoder INHERITED;
};
-SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
- const Options& options, SkPMColor ctable[], int* ctableCount) {
-
- // Rewind the stream if needed
- if (!this->handleRewind()) {
- SkCodecPrintf("Could not rewind\n");
- return NULL;
- }
-
- // Set the jump location for libjpeg errors
- if (setjmp(fDecoderMgr->getJmpBuf())) {
- SkCodecPrintf("setjmp: Error from libjpeg\n");
- return NULL;
- }
-
- SkStream* stream = this->stream()->duplicate();
- if (!stream) {
- return NULL;
- }
+SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) {
SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewFromStream(stream)));
if (!codec) {
return NULL;
}
- // Check if we can decode to the requested destination and set the output color space
- if (!codec->setOutputColorSpace(dstInfo)) {
- SkCodecPrintf("Cannot convert to output type\n");
- return NULL;
- }
-
- // Perform the necessary scaling
- if (!codec->scaleToDimensions(dstInfo.width(), dstInfo.height())) {
- SkCodecPrintf("Cannot scale to output dimensions\n");
- return NULL;
- }
-
- // Now, given valid output dimensions, we can start the decompress
- if (!turbo_jpeg_start_decompress(codec->fDecoderMgr->dinfo())) {
- SkCodecPrintf("start decompress failed\n");
- return NULL;
- }
-
+ const SkImageInfo& srcInfo = codec->getInfo();
// Return the new scanline decoder
- return SkNEW_ARGS(SkJpegScanlineDecoder, (dstInfo, codec.detach()));
+ return SkNEW_ARGS(SkJpegScanlineDecoder, (srcInfo, codec.detach()));
}

Powered by Google App Engine
This is Rietveld 408576698