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

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 interlaced Created 5 years, 4 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
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkScanlineDecoder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkJpegCodec.cpp
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 84e90d444249142d69a68cd52cab59cebb37c30a..e160f0c4e29a124aa09b03fcb6fd8dea37f57b0e 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -389,13 +389,47 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
*/
class SkJpegScanlineDecoder : public SkScanlineDecoder {
public:
- SkJpegScanlineDecoder(const SkImageInfo& dstInfo, SkJpegCodec* codec,
- const SkCodec::Options& opts)
- : INHERITED(dstInfo)
+ SkJpegScanlineDecoder(const SkImageInfo& srcInfo, SkJpegCodec* codec)
+ : INHERITED(srcInfo)
, fCodec(codec)
- , fOpts(opts)
+ , fOpts()
{}
+ SkCodec::Result onStart(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;
+ }
+
+ fOpts = options;
+
+ return SkCodec::kSuccess;
+ }
+
virtual ~SkJpegScanlineDecoder() {
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
SkCodecPrintf("setjmp: Error in libjpeg finish_decompress\n");
@@ -464,53 +498,18 @@ public:
private:
SkAutoTDelete<SkJpegCodec> fCodec;
- const SkCodec::Options& fOpts;
+ SkCodec::Options fOpts;
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(), options));
+ return SkNEW_ARGS(SkJpegScanlineDecoder, (srcInfo, codec.detach()));
}
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkScanlineDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698