fUseMPDs.push_back() = false;
// Prepare the images for decoding
- if (!CollectImages(&fImages)) {
+ if (!CollectImages(FLAGS_images, &fImages)) {
exit(1);
}
}
SkTArray<SkString> images;
- if (!CollectImages(&images)) {
+ if (!CollectImages(FLAGS_images, &images)) {
return false;
}
}
}
+ 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;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+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) {}
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);
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"
"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[] = {
#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;
DECLARE_bool(dryRun);
DECLARE_bool(gpu);
DECLARE_string(images);
+DECLARE_string(colorImages);
DECLARE_string(match);
DECLARE_bool(quiet);
DECLARE_bool(resetGpuContext);
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