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
This commit is contained in:
parent
1b5dd88454
commit
69deca8d1e
@ -606,7 +606,7 @@ public:
|
||||
fUseMPDs.push_back() = false;
|
||||
|
||||
// Prepare the images for decoding
|
||||
if (!CollectImages(&fImages)) {
|
||||
if (!CollectImages(FLAGS_images, &fImages)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
12
dm/DM.cpp
12
dm/DM.cpp
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user