Add config option to skimage.

Allows testing 565 and A8, in addition to 8888.

Also makes the preference consistent for each test (in one run).

BUG=skia:1465
R=djsollen@google.com

Review URL: https://codereview.chromium.org/22297007

git-svn-id: http://skia.googlecode.com/svn/trunk@10579 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-08-06 18:56:53 +00:00
parent e339eb054b
commit 6d99de11c4

View File

@ -22,6 +22,7 @@
__SK_FORCE_IMAGE_DECODER_LINKING;
DEFINE_string(config, "None", "Preferred config to decode into. [None|8888|565|A8]");
DEFINE_string(createExpectationsPath, "", "Path to write JSON expectations.");
DEFINE_string(mismatchPath, "", "Folder to write mismatched images to.");
DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.");
@ -102,6 +103,8 @@ static SkTArray<SkString, false> gFailedSubsetDecodes;
static SkTArray<SkString, false> gMissingExpectations;
static SkTArray<SkString, false> gMissingSubsetExpectations;
static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config);
// Expections read from a file specified by readExpectationsPath. The expectations must have been
// previously written using createExpectationsPath.
SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
@ -323,7 +326,7 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
SkString basename = SkOSPath::SkBasename(srcPath);
const char* filename = basename.c_str();
if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config,
if (!codec->decode(&stream, &bitmap, gPrefConfig,
SkImageDecoder::kDecodePixels_Mode)) {
if (expect_to_fail(filename)) {
gSuccessfulDecodes.push_back().appendf(
@ -393,7 +396,7 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
SkIRect rect = generate_random_rect(&rand, width, height);
SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop,
rect.fRight, rect.fBottom);
if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, SkBitmap::kNo_Config)) {
if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, gPrefConfig)) {
SkString subsetName = SkStringPrintf("%s_%s", filename, subsetDim.c_str());
if (compare_to_expectations_if_necessary(bitmapFromDecodeSubset,
subsetName.c_str(),
@ -476,7 +479,7 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
SkMemoryStream memStream(data);
SkBitmap redecodedBitmap;
SkImageDecoder::Format formatOnSecondDecode;
if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, SkBitmap::kNo_Config,
if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, gPrefConfig,
SkImageDecoder::kDecodePixels_Mode,
&formatOnSecondDecode)) {
SkASSERT(format_to_type(formatOnSecondDecode) == type);
@ -560,6 +563,21 @@ int tool_main(int argc, char** argv) {
outDirPtr = NULL;
}
if (FLAGS_config.count() == 1) {
// Only consider the first config specified on the command line.
const char* config = FLAGS_config[0];
if (0 == strcmp(config, "8888")) {
gPrefConfig = SkBitmap::kARGB_8888_Config;
} else if (0 == strcmp(config, "565")) {
gPrefConfig = SkBitmap::kRGB_565_Config;
} else if (0 == strcmp(config, "A8")) {
gPrefConfig = SkBitmap::kA8_Config;
} else if (0 != strcmp(config, "None")) {
SkDebugf("Invalid preferred config\n");
return -1;
}
}
for (int i = 0; i < FLAGS_readPath.count(); i++) {
const char* readPath = FLAGS_readPath[i];
if (strlen(readPath) < 1) {