diff options
author | 2015-03-25 13:48:49 -0700 | |
---|---|---|
committer | 2015-03-25 13:48:49 -0700 | |
commit | 9c59ebc0db7cade1537591813430f7be47123e76 (patch) | |
tree | 9bf9c29f8408d66be2cdaabfcc4fc18f965372f9 /dm | |
parent | 59f9ec7e9c55e1ada77239bb60de87f31bf9c89a (diff) |
Test scanline decoding in DM.
BUG=skia:3475
Review URL: https://codereview.chromium.org/999173010
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DM.cpp | 8 | ||||
-rw-r--r-- | dm/DMSrcSink.cpp | 52 | ||||
-rw-r--r-- | dm/DMSrcSink.h | 7 |
3 files changed, 49 insertions, 18 deletions
@@ -25,7 +25,7 @@ #include "Test.h" #include "Timer.h" -DEFINE_string(src, "tests gm skp image subset codec", "Source types to test."); +DEFINE_string(src, "tests gm skp image subset codec scanline", "Source types to test."); DEFINE_bool(nameByHash, false, "If true, write to FLAGS_writePath[0]/<hash>.png instead of " "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); @@ -187,7 +187,8 @@ static void gather_srcs() { push_src("image", new ImageSrc(path)); // Decode entire image. push_src("subset", new ImageSrc(path, 2)); // Decode into 2 x 2 subsets if (codec_supported(exts[j])) { - push_src("codec", new CodecSrc(path)); // Decode with SkCodec. + push_src("codec", new CodecSrc(path, CodecSrc::kNormal_Mode)); + push_src("scanline", new CodecSrc(path, CodecSrc::kScanline_Mode)); } } } @@ -195,7 +196,8 @@ static void gather_srcs() { // assume that FLAGS_images[i] is a valid image if it is a file. push_src("image", new ImageSrc(flag)); // Decode entire image. push_src("subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets - push_src("codec", new CodecSrc(flag)); // Decode with SkCodec. + push_src("codec", new CodecSrc(flag, CodecSrc::kNormal_Mode)); + push_src("scanline", new CodecSrc(flag, CodecSrc::kScanline_Mode)); } } } diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 77131eb477..5242c95e83 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -19,6 +19,7 @@ #include "SkPictureData.h" #include "SkPictureRecorder.h" #include "SkRandom.h" +#include "SkScanlineDecoder.h" #include "SkSVGCanvas.h" #include "SkStream.h" #include "SkXMLWriter.h" @@ -51,7 +52,7 @@ Name GMSrc::name() const { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -CodecSrc::CodecSrc(Path path) : fPath(path) {} +CodecSrc::CodecSrc(Path path, Mode mode) : fPath(path), fMode(mode) {} Error CodecSrc::draw(SkCanvas* canvas) const { SkImageInfo canvasInfo; @@ -83,20 +84,43 @@ Error CodecSrc::draw(SkCanvas* canvas) const { decodeInfo.width(), decodeInfo.height()); } - SkAutoLockPixels alp(bitmap); - switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) { - case SkImageGenerator::kSuccess: - // We consider incomplete to be valid, since we should still decode what is - // available. - case SkImageGenerator::kIncompleteInput: - canvas->drawBitmap(bitmap, 0, 0); - return ""; - case SkImageGenerator::kInvalidConversion: - return Error::Nonfatal("Incompatible colortype conversion"); - default: - // Everything else is considered a failure. - return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); + switch (fMode) { + case kNormal_Mode: + switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) { + case SkImageGenerator::kSuccess: + // We consider incomplete to be valid, since we should still decode what is + // available. + case SkImageGenerator::kIncompleteInput: + break; + case SkImageGenerator::kInvalidConversion: + return Error::Nonfatal("Incompatible colortype conversion"); + default: + // Everything else is considered a failure. + return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); + } + break; + case kScanline_Mode: { + SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decodeInfo); + if (NULL == scanlineDecoder) { + return Error::Nonfatal("Cannot use scanline decoder for all images"); + } + for (int y = 0; y < decodeInfo.height(); ++y) { + const SkImageGenerator::Result result = scanlineDecoder->getScanlines( + bitmap.getAddr(0, y), 1, 0); + switch (result) { + case SkImageGenerator::kSuccess: + case SkImageGenerator::kIncompleteInput: + break; + default: + return SkStringPrintf("%s failed after %d scanlines with error message %d", + fPath.c_str(), y-1, (int) result); + } + } + break; + } } + canvas->drawBitmap(bitmap, 0, 0); + return ""; } SkISize CodecSrc::size() const { diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 1c56be7d5a..3a0eab020f 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -90,13 +90,18 @@ private: class CodecSrc : public Src { public: - explicit CodecSrc(Path path); + enum Mode { + kNormal_Mode, + kScanline_Mode, + }; + CodecSrc(Path, Mode); Error draw(SkCanvas*) const SK_OVERRIDE; SkISize size() const SK_OVERRIDE; Name name() const SK_OVERRIDE; private: Path fPath; + Mode fMode; }; |