Test scanline decoding in DM.
BUG=skia:3475 Review URL: https://codereview.chromium.org/999173010
This commit is contained in:
parent
59f9ec7e9c
commit
9c59ebc0db
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user