diff options
author | msarett <msarett@google.com> | 2016-04-29 09:38:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-29 09:38:40 -0700 |
commit | 69deca8d1e57daec540f8a7f10d9c660b640b9a9 (patch) | |
tree | dbf8b6d316f6d0f49373870692ca6e442630b74e | |
parent | 1b5dd884546d35ff0909168cbfeafd7f53225a97 (diff) |
Add ColorCodecSrc for testing/comparison on color corrected decodes
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1933753002
Review-Url: https://codereview.chromium.org/1933753002
-rw-r--r-- | bench/nanobench.cpp | 2 | ||||
-rw-r--r-- | dm/DM.cpp | 12 | ||||
-rw-r--r-- | dm/DMSrcSink.cpp | 65 | ||||
-rw-r--r-- | dm/DMSrcSink.h | 18 | ||||
-rw-r--r-- | tools/flags/SkCommonFlags.cpp | 9 | ||||
-rw-r--r-- | tools/flags/SkCommonFlags.h | 16 |
6 files changed, 109 insertions, 13 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 5e26b48395..7999ad5c61 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -606,7 +606,7 @@ public: fUseMPDs.push_back() = false; // Prepare the images for decoding - if (!CollectImages(&fImages)) { + if (!CollectImages(FLAGS_images, &fImages)) { exit(1); } @@ -779,7 +779,7 @@ static bool gather_srcs() { } SkTArray<SkString> images; - if (!CollectImages(&images)) { + if (!CollectImages(FLAGS_images, &images)) { return false; } @@ -795,6 +795,16 @@ static bool gather_srcs() { } } + SkTArray<SkString> colorImages; + if (!CollectImages(FLAGS_colorImages, &colorImages)) { + return false; + } + + for (auto colorImage : colorImages) { + ColorCodecSrc* src = new ColorCodecSrc(colorImage, ColorCodecSrc::kBaseline_Mode); + push_src("image", "color_codec_baseline", src); + } + return true; } diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index e8018297b7..f99afe4859 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -932,6 +932,71 @@ Name ImageGenSrc::name() const { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +ColorCodecSrc::ColorCodecSrc(Path path, Mode mode) + : fPath(path) + , fMode(mode) +{} + +bool ColorCodecSrc::veto(SinkFlags flags) const { + // Test to direct raster backends (8888 and 565). + return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect; +} + +Error ColorCodecSrc::draw(SkCanvas* canvas) const { + if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { + return Error::Nonfatal("No need to test color correction to 565 backend."); + } + + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); + if (!encoded) { + return SkStringPrintf("Couldn't read %s.", fPath.c_str()); + } + + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); + if (nullptr == codec.get()) { + return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); + } + + SkImageInfo decodeInfo = codec->getInfo().makeColorType(kN32_SkColorType); + SkBitmap bitmap; + if (!bitmap.tryAllocPixels(decodeInfo)) { + return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), + decodeInfo.width(), decodeInfo.height()); + } + + switch (fMode) { + case kBaseline_Mode: + switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) { + case SkCodec::kSuccess: + break; + default: + // Everything else is considered a failure. + return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); + } + canvas->drawBitmap(bitmap, 0, 0); + break; + default: + SkASSERT(false); + return "Invalid fMode"; + } + return ""; +} + +SkISize ColorCodecSrc::size() const { + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); + if (nullptr == codec) { + return SkISize::Make(0, 0); + } + return SkISize::Make(codec->getInfo().width(), codec->getInfo().height()); +} + +Name ColorCodecSrc::name() const { + return SkOSPath::Basename(fPath.c_str()); +} + +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + static const SkRect kSKPViewport = {0,0, 1000,1000}; SKPSrc::SKPSrc(Path path) : fPath(path) {} diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 5f60dc59fd..5a734a6f3c 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -208,6 +208,24 @@ private: bool fRunSerially; }; +class ColorCodecSrc : public Src { +public: + enum Mode { + // Mimic legacy behavior and apply no color correction. + kBaseline_Mode, + }; + + ColorCodecSrc(Path, Mode); + + Error draw(SkCanvas*) const override; + SkISize size() const override; + Name name() const override; + bool veto(SinkFlags) const override; +private: + Path fPath; + Mode fMode; +}; + class SKPSrc : public Src { public: explicit SKPSrc(Path path); diff --git a/tools/flags/SkCommonFlags.cpp b/tools/flags/SkCommonFlags.cpp index eb2075c58a..1caffd54d6 100644 --- a/tools/flags/SkCommonFlags.cpp +++ b/tools/flags/SkCommonFlags.cpp @@ -18,6 +18,9 @@ DEFINE_bool(gpu, true, "master switch for running GPU-bound work."); DEFINE_string(images, "", "List of images and/or directories to decode. A directory with no images" " is treated as a fatal error."); +DEFINE_string(colorImages, "", "List of images and/or directories to decode with color correction. " + "A directory with no images is treated as a fatal error."); + DEFINE_string2(match, m, nullptr, "[~][^]substring[$] [...] of GM name to run.\n" "Multiple matches may be separated by spaces.\n" @@ -55,7 +58,7 @@ DEFINE_string(properties, "", "Space-separated key/value pairs to add to JSON identifying this run."); DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading"); -bool CollectImages(SkTArray<SkString>* output) { +bool CollectImages(SkCommandLineFlags::StringArray images, SkTArray<SkString>* output) { SkASSERT(output); static const char* const exts[] = { @@ -67,8 +70,8 @@ bool CollectImages(SkTArray<SkString>* output) { #endif }; - for (int i = 0; i < FLAGS_images.count(); ++i) { - const char* flag = FLAGS_images[i]; + for (int i = 0; i < images.count(); ++i) { + const char* flag = images[i]; if (!sk_exists(flag)) { SkDebugf("%s does not exist!\n", flag); return false; diff --git a/tools/flags/SkCommonFlags.h b/tools/flags/SkCommonFlags.h index c6cbde45ca..ddd0fc89e0 100644 --- a/tools/flags/SkCommonFlags.h +++ b/tools/flags/SkCommonFlags.h @@ -16,6 +16,7 @@ DECLARE_bool(cpu); DECLARE_bool(dryRun); DECLARE_bool(gpu); DECLARE_string(images); +DECLARE_string(colorImages); DECLARE_string(match); DECLARE_bool(quiet); DECLARE_bool(resetGpuContext); @@ -34,17 +35,16 @@ DECLARE_string(key); DECLARE_string(properties); /** - * Helper to assist in collecting image paths from --images. + * Helper to assist in collecting image paths from |dir| specified through a command line flag. * - * Populates an array of strings with paths to images to test. + * Populates |output|, an array of strings with paths to images to test. * - * Returns true if each argument to --images is meaningful: + * Returns true if each argument to the images flag is meaningful: * - If the file/directory does not exist, return false. - * - If a directory passed to --images does not have any supported images (based on file - * type), return false. - * - If a file is passed to --images, assume the user is deliberately testing this image, - * regardless of file type. + * - If |dir| does not have any supported images (based on file type), return false. + * - If |dir| is a single file, assume the user is deliberately testing this image, + * regardless of file type. */ -bool CollectImages(SkTArray<SkString>*); +bool CollectImages(SkCommandLineFlags::StringArray dir, SkTArray<SkString>* output); #endif |