2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-04-11 15:53:35 +00:00
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
#include "gm_expectations.h"
|
2009-04-24 19:52:53 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-04-25 17:33:51 +00:00
|
|
|
#include "SkColorPriv.h"
|
2013-04-11 15:53:35 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2013-04-25 17:33:51 +00:00
|
|
|
#include "SkData.h"
|
2013-05-31 14:00:10 +00:00
|
|
|
#include "SkForceLinking.h"
|
2009-04-24 19:52:53 +00:00
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkImageEncoder.h"
|
2013-04-11 15:53:35 +00:00
|
|
|
#include "SkOSFile.h"
|
2013-05-03 20:14:28 +00:00
|
|
|
#include "SkRandom.h"
|
2009-04-24 19:52:53 +00:00
|
|
|
#include "SkStream.h"
|
2013-04-11 15:53:35 +00:00
|
|
|
#include "SkTArray.h"
|
2009-04-24 19:52:53 +00:00
|
|
|
#include "SkTemplates.h"
|
|
|
|
|
2013-05-31 14:00:10 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
2013-08-06 18:56:53 +00:00
|
|
|
DEFINE_string(config, "None", "Preferred config to decode into. [None|8888|565|A8]");
|
2013-05-08 19:14:23 +00:00
|
|
|
DEFINE_string(createExpectationsPath, "", "Path to write JSON expectations.");
|
2013-06-07 12:43:15 +00:00
|
|
|
DEFINE_string(mismatchPath, "", "Folder to write mismatched images to.");
|
2013-04-11 15:53:35 +00:00
|
|
|
DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.");
|
2013-05-08 19:14:23 +00:00
|
|
|
DEFINE_string(readExpectationsPath, "", "Path to read JSON expectations from.");
|
2013-04-25 17:33:51 +00:00
|
|
|
DEFINE_bool(reencode, true, "Reencode the images to test encoding.");
|
2013-10-08 19:40:18 +00:00
|
|
|
DEFINE_int32(sampleSize, 1, "Set the sampleSize for decoding.");
|
|
|
|
DEFINE_bool(skip, false, "Skip writing zeroes.");
|
2013-05-03 20:14:28 +00:00
|
|
|
DEFINE_bool(testSubsetDecoding, true, "Test decoding subsets of images.");
|
2013-06-07 12:43:15 +00:00
|
|
|
DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
|
2013-04-11 15:53:35 +00:00
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
struct Format {
|
|
|
|
SkImageEncoder::Type fType;
|
|
|
|
SkImageDecoder::Format fFormat;
|
|
|
|
const char* fSuffix;
|
|
|
|
};
|
2013-04-11 15:53:35 +00:00
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static const Format gFormats[] = {
|
|
|
|
{ SkImageEncoder::kBMP_Type, SkImageDecoder::kBMP_Format, ".bmp" },
|
|
|
|
{ SkImageEncoder::kGIF_Type, SkImageDecoder::kGIF_Format, ".gif" },
|
|
|
|
{ SkImageEncoder::kICO_Type, SkImageDecoder::kICO_Format, ".ico" },
|
|
|
|
{ SkImageEncoder::kJPEG_Type, SkImageDecoder::kJPEG_Format, ".jpg" },
|
|
|
|
{ SkImageEncoder::kPNG_Type, SkImageDecoder::kPNG_Format, ".png" },
|
|
|
|
{ SkImageEncoder::kWBMP_Type, SkImageDecoder::kWBMP_Format, ".wbmp" },
|
|
|
|
{ SkImageEncoder::kWEBP_Type, SkImageDecoder::kWEBP_Format, ".webp" }
|
|
|
|
};
|
2009-04-24 19:52:53 +00:00
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static SkImageEncoder::Type format_to_type(SkImageDecoder::Format format) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
|
|
|
|
if (gFormats[i].fFormat == format) {
|
|
|
|
return gFormats[i].fType;
|
|
|
|
}
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
2013-04-25 17:33:51 +00:00
|
|
|
return SkImageEncoder::kUnknown_Type;
|
|
|
|
}
|
2009-04-24 19:52:53 +00:00
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static const char* suffix_for_type(SkImageEncoder::Type type) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
|
|
|
|
if (gFormats[i].fType == type) {
|
|
|
|
return gFormats[i].fSuffix;
|
|
|
|
}
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
2013-04-25 17:33:51 +00:00
|
|
|
return "";
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
|
|
|
|
if (strcmp(suffix, gFormats[i].fSuffix) == 0) {
|
|
|
|
return gFormats[i].fFormat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SkImageDecoder::kUnknown_Format;
|
|
|
|
}
|
2009-04-24 19:52:53 +00:00
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static void make_outname(SkString* dst, const char outDir[], const char src[],
|
|
|
|
const char suffix[]) {
|
2013-05-28 16:45:07 +00:00
|
|
|
SkString basename = SkOSPath::SkBasename(src);
|
|
|
|
dst->set(SkOSPath::SkPathJoin(outDir, basename.c_str()));
|
2013-04-25 17:33:51 +00:00
|
|
|
if (!dst->endsWith(suffix)) {
|
2013-04-11 15:53:35 +00:00
|
|
|
const char* cstyleDst = dst->c_str();
|
|
|
|
const char* dot = strrchr(cstyleDst, '.');
|
|
|
|
if (dot != NULL) {
|
|
|
|
int32_t index = SkToS32(dot - cstyleDst);
|
|
|
|
dst->remove(index, dst->size() - index);
|
|
|
|
}
|
2013-04-25 17:33:51 +00:00
|
|
|
dst->append(suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the names of the filenames to report later which ones failed, succeeded, and were
|
|
|
|
// invalid.
|
|
|
|
static SkTArray<SkString, false> gInvalidStreams;
|
|
|
|
static SkTArray<SkString, false> gMissingCodecs;
|
|
|
|
static SkTArray<SkString, false> gDecodeFailures;
|
|
|
|
static SkTArray<SkString, false> gEncodeFailures;
|
|
|
|
static SkTArray<SkString, false> gSuccessfulDecodes;
|
2013-05-03 20:14:28 +00:00
|
|
|
static SkTArray<SkString, false> gSuccessfulSubsetDecodes;
|
|
|
|
static SkTArray<SkString, false> gFailedSubsetDecodes;
|
2013-08-06 18:51:30 +00:00
|
|
|
// Files/subsets that do not have expectations. Not reported as a failure of the test so
|
|
|
|
// the bots will not turn red with each new image test.
|
|
|
|
static SkTArray<SkString, false> gMissingExpectations;
|
|
|
|
static SkTArray<SkString, false> gMissingSubsetExpectations;
|
2013-04-25 17:33:51 +00:00
|
|
|
|
2013-08-06 18:56:53 +00:00
|
|
|
static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config);
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
// Expections read from a file specified by readExpectationsPath. The expectations must have been
|
|
|
|
// previously written using createExpectationsPath.
|
|
|
|
SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
|
|
|
|
|
2013-06-07 12:43:15 +00:00
|
|
|
static bool write_bitmap(const char outName[], const SkBitmap& bm) {
|
2013-10-07 16:56:01 +00:00
|
|
|
if (SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 100)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bm.config() == SkBitmap::kARGB_8888_Config) {
|
|
|
|
// First attempt at encoding failed, and the bitmap was already 8888. Making
|
|
|
|
// a copy is not going to help.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encoding failed. Copy to 8888 and try again.
|
2013-10-03 17:13:38 +00:00
|
|
|
SkBitmap bm8888;
|
2013-10-07 16:56:01 +00:00
|
|
|
if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
|
|
|
|
return false;
|
2013-10-03 17:13:38 +00:00
|
|
|
}
|
2013-10-07 16:56:01 +00:00
|
|
|
return SkImageEncoder::EncodeFile(outName, bm8888, SkImageEncoder::kPNG_Type, 100);
|
2013-04-25 17:33:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 20:14:28 +00:00
|
|
|
/**
|
|
|
|
* Return a random SkIRect inside the range specified.
|
|
|
|
* @param rand Random number generator.
|
|
|
|
* @param maxX Exclusive maximum x-coordinate. SkIRect's fLeft and fRight will be
|
|
|
|
* in the range [0, maxX)
|
|
|
|
* @param maxY Exclusive maximum y-coordinate. SkIRect's fTop and fBottom will be
|
|
|
|
* in the range [0, maxY)
|
|
|
|
* @return SkIRect Non-empty, non-degenerate rectangle.
|
|
|
|
*/
|
|
|
|
static SkIRect generate_random_rect(SkRandom* rand, int32_t maxX, int32_t maxY) {
|
|
|
|
SkASSERT(maxX > 1 && maxY > 1);
|
|
|
|
int32_t left = rand->nextULessThan(maxX);
|
|
|
|
int32_t right = rand->nextULessThan(maxX);
|
|
|
|
int32_t top = rand->nextULessThan(maxY);
|
|
|
|
int32_t bottom = rand->nextULessThan(maxY);
|
|
|
|
SkIRect rect = SkIRect::MakeLTRB(left, top, right, bottom);
|
|
|
|
rect.sort();
|
|
|
|
// Make sure rect is not empty.
|
|
|
|
if (rect.fLeft == rect.fRight) {
|
|
|
|
if (rect.fLeft > 0) {
|
|
|
|
rect.fLeft--;
|
|
|
|
} else {
|
|
|
|
rect.fRight++;
|
|
|
|
// This branch is only taken if 0 == rect.fRight, and
|
|
|
|
// maxX must be at least 2, so it must still be in
|
|
|
|
// range.
|
|
|
|
SkASSERT(rect.fRight < maxX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rect.fTop == rect.fBottom) {
|
|
|
|
if (rect.fTop > 0) {
|
|
|
|
rect.fTop--;
|
|
|
|
} else {
|
|
|
|
rect.fBottom++;
|
|
|
|
// Again, this must be in range.
|
|
|
|
SkASSERT(rect.fBottom < maxY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
// Stored expectations to be written to a file if createExpectationsPath is specified.
|
|
|
|
static Json::Value gExpectationsToWrite;
|
|
|
|
|
|
|
|
/**
|
2013-05-24 14:33:28 +00:00
|
|
|
* If expectations are to be recorded, record the bitmap expectations into global
|
2013-05-08 19:14:23 +00:00
|
|
|
* expectations array.
|
|
|
|
*/
|
|
|
|
static void write_expectations(const SkBitmap& bitmap, const char* filename) {
|
|
|
|
if (!FLAGS_createExpectationsPath.isEmpty()) {
|
|
|
|
// Creates an Expectations object, and add it to the list to write.
|
|
|
|
skiagm::Expectations expectation(bitmap);
|
|
|
|
Json::Value value = expectation.asJsonValue();
|
|
|
|
gExpectationsToWrite[filename] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 20:21:01 +00:00
|
|
|
/**
|
|
|
|
* Return true if this filename is a known failure, and therefore a failure
|
|
|
|
* to decode should be ignored.
|
|
|
|
*/
|
|
|
|
static bool expect_to_fail(const char* filename) {
|
|
|
|
if (NULL == gJsonExpectations.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
skiagm::Expectations jsExpectations = gJsonExpectations->get(filename);
|
|
|
|
return jsExpectations.ignoreFailure();
|
|
|
|
}
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
/**
|
|
|
|
* Compare against an expectation for this filename, if there is one.
|
2013-08-28 18:33:31 +00:00
|
|
|
* @param digest GmResultDigest, computed from the decoded bitmap, to compare to the
|
|
|
|
* expectation.
|
2013-05-08 19:14:23 +00:00
|
|
|
* @param filename String used to find the expected value.
|
2013-08-06 18:51:30 +00:00
|
|
|
* @param failureArray Array to add a failure message to on failure.
|
|
|
|
* @param missingArray Array to add missing expectation to on failure.
|
2013-05-14 17:30:17 +00:00
|
|
|
* @return bool True in any of these cases:
|
|
|
|
* - the bitmap matches the expectation.
|
|
|
|
* False in any of these cases:
|
2013-06-07 12:43:15 +00:00
|
|
|
* - there is no expectations file.
|
2013-05-14 17:30:17 +00:00
|
|
|
* - there is an expectations file, but no expectation for this bitmap.
|
|
|
|
* - there is an expectation for this bitmap, but it did not match.
|
|
|
|
* - expectation could not be computed from the bitmap.
|
2013-05-08 19:14:23 +00:00
|
|
|
*/
|
2013-08-28 18:33:31 +00:00
|
|
|
static bool compare_to_expectations_if_necessary(const skiagm::GmResultDigest& digest,
|
|
|
|
const char* filename,
|
2013-08-06 18:51:30 +00:00
|
|
|
SkTArray<SkString, false>* failureArray,
|
|
|
|
SkTArray<SkString, false>* missingArray) {
|
2013-08-28 18:33:31 +00:00
|
|
|
if (!digest.isValid()) {
|
2013-05-14 17:30:17 +00:00
|
|
|
if (failureArray != NULL) {
|
2013-06-07 12:43:15 +00:00
|
|
|
failureArray->push_back().printf("decoded %s, but could not create a GmResultDigest.",
|
2013-05-14 17:30:17 +00:00
|
|
|
filename);
|
|
|
|
}
|
|
|
|
return false;
|
2013-05-08 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 12:43:15 +00:00
|
|
|
if (NULL == gJsonExpectations.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
skiagm::Expectations jsExpectation = gJsonExpectations->get(filename);
|
|
|
|
if (jsExpectation.empty()) {
|
2013-08-06 18:51:30 +00:00
|
|
|
if (missingArray != NULL) {
|
|
|
|
missingArray->push_back().printf("decoded %s, but could not find expectation.",
|
2013-05-08 19:14:23 +00:00
|
|
|
filename);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:33:31 +00:00
|
|
|
if (jsExpectation.match(digest)) {
|
2013-05-08 19:14:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failureArray != NULL) {
|
|
|
|
failureArray->push_back().printf("decoded %s, but the result does not match "
|
|
|
|
"expectations.",
|
|
|
|
filename);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-15 18:14:36 +00:00
|
|
|
/**
|
|
|
|
* Helper function to write a bitmap subset to a file. Only called if subsets were created
|
|
|
|
* and a writePath was provided. Creates a subdirectory called 'subsets' and writes a PNG to
|
|
|
|
* that directory. Also creates a subdirectory called 'extracted' and writes a bitmap created
|
|
|
|
* using extractSubset to a PNG in that directory. Both files will represent the same
|
|
|
|
* subrectangle and have the same name for comparison.
|
|
|
|
* @param writePath Parent directory to hold the folders for the PNG files to write. Must
|
|
|
|
* not be NULL.
|
|
|
|
* @param filename Basename of the original file. Used to name the new files. Must not be
|
|
|
|
* NULL.
|
|
|
|
* @param subsetDim String representing the dimensions of the subset. Used to name the new
|
|
|
|
* files. Must not be NULL.
|
|
|
|
* @param bitmapFromDecodeSubset Pointer to SkBitmap created by SkImageDecoder::DecodeSubset,
|
|
|
|
* using rect as the area to decode.
|
|
|
|
* @param rect Rectangle of the area decoded into bitmapFromDecodeSubset. Used to call
|
|
|
|
* extractSubset on originalBitmap to create a bitmap with the same dimensions/pixels as
|
|
|
|
* bitmapFromDecodeSubset (assuming decodeSubset worked properly).
|
|
|
|
* @param originalBitmap SkBitmap decoded from the same stream as bitmapFromDecodeSubset,
|
|
|
|
* using SkImageDecoder::decode to get the entire image. Used to create a PNG file for
|
|
|
|
* comparison to the PNG created by bitmapFromDecodeSubset.
|
|
|
|
* @return bool Whether the function succeeded at drawing the decoded subset and the extracted
|
|
|
|
* subset to files.
|
|
|
|
*/
|
|
|
|
static bool write_subset(const char* writePath, const char* filename, const char* subsetDim,
|
|
|
|
SkBitmap* bitmapFromDecodeSubset, SkIRect rect,
|
|
|
|
const SkBitmap& originalBitmap) {
|
|
|
|
// All parameters must be valid.
|
|
|
|
SkASSERT(writePath != NULL);
|
|
|
|
SkASSERT(filename != NULL);
|
|
|
|
SkASSERT(subsetDim != NULL);
|
|
|
|
SkASSERT(bitmapFromDecodeSubset != NULL);
|
|
|
|
|
|
|
|
// Create a subdirectory to hold the results of decodeSubset.
|
2013-05-28 16:45:07 +00:00
|
|
|
SkString dir = SkOSPath::SkPathJoin(writePath, "subsets");
|
2013-05-15 18:14:36 +00:00
|
|
|
if (!sk_mkdir(dir.c_str())) {
|
|
|
|
gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s, but failed to "
|
|
|
|
"create a directory to write to.", subsetDim,
|
|
|
|
filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the subset to a file whose name includes the dimensions.
|
|
|
|
SkString suffix = SkStringPrintf("_%s.png", subsetDim);
|
|
|
|
SkString outPath;
|
|
|
|
make_outname(&outPath, dir.c_str(), filename, suffix.c_str());
|
2013-06-07 12:43:15 +00:00
|
|
|
SkAssertResult(write_bitmap(outPath.c_str(), *bitmapFromDecodeSubset));
|
2013-05-15 18:14:36 +00:00
|
|
|
gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str());
|
|
|
|
|
|
|
|
// Also use extractSubset from the original for visual comparison.
|
|
|
|
// Write the result to a file in a separate subdirectory.
|
|
|
|
SkBitmap extractedSubset;
|
|
|
|
if (!originalBitmap.extractSubset(&extractedSubset, rect)) {
|
|
|
|
gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s, but failed to "
|
|
|
|
"extract a similar subset for comparison.",
|
|
|
|
subsetDim, filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:45:07 +00:00
|
|
|
SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted");
|
2013-05-15 18:14:36 +00:00
|
|
|
if (!sk_mkdir(dirExtracted.c_str())) {
|
|
|
|
gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s, but failed to "
|
|
|
|
"create a directory for extractSubset comparison.",
|
|
|
|
subsetDim, filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str());
|
2013-06-07 12:43:15 +00:00
|
|
|
SkAssertResult(write_bitmap(outPath.c_str(), extractedSubset));
|
2013-05-15 18:14:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:33:31 +00:00
|
|
|
// FIXME: This test could be run on windows/mac once we remove their dependence on
|
|
|
|
// getLength. See https://code.google.com/p/skia/issues/detail?id=1570
|
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy class for testing to ensure that a stream without a length decodes the same
|
|
|
|
* as a stream with a length.
|
|
|
|
*/
|
|
|
|
class FILEStreamWithoutLength : public SkFILEStream {
|
|
|
|
public:
|
|
|
|
FILEStreamWithoutLength(const char path[])
|
|
|
|
: INHERITED(path) {}
|
|
|
|
|
|
|
|
virtual bool hasLength() const SK_OVERRIDE {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkFILEStream INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that decoding a stream which reports to not have a length still results in the
|
|
|
|
* same image as if it did report to have a length. Assumes that codec was used to
|
|
|
|
* successfully decode the file using SkFILEStream.
|
|
|
|
* @param srcPath The path to the file, for recreating the length-less stream.
|
|
|
|
* @param codec The SkImageDecoder originally used to decode srcPath, which will be used
|
|
|
|
* again to decode the length-less stream.
|
|
|
|
* @param digest GmResultDigest computed from decoding the stream the first time.
|
|
|
|
* Decoding the length-less stream is expected to result in a matching digest.
|
|
|
|
*/
|
|
|
|
static void test_stream_without_length(const char srcPath[], SkImageDecoder* codec,
|
|
|
|
const skiagm::GmResultDigest& digest) {
|
|
|
|
if (!digest.isValid()) {
|
|
|
|
// An error was already reported.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkASSERT(srcPath);
|
|
|
|
SkASSERT(codec);
|
|
|
|
FILEStreamWithoutLength stream(srcPath);
|
|
|
|
// This will only be called after a successful decode. Creating a stream from the same
|
|
|
|
// path should never fail.
|
|
|
|
SkASSERT(stream.isValid());
|
|
|
|
SkBitmap bm;
|
|
|
|
if (!codec->decode(&stream, &bm, gPrefConfig, SkImageDecoder::kDecodePixels_Mode)) {
|
|
|
|
gDecodeFailures.push_back().appendf("Without using getLength, %s failed to decode\n",
|
|
|
|
srcPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
skiagm::GmResultDigest lengthLessDigest(bm);
|
|
|
|
if (!lengthLessDigest.isValid()) {
|
|
|
|
gDecodeFailures.push_back().appendf("Without using getLength, %s failed to build "
|
|
|
|
"a digest\n", srcPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!lengthLessDigest.equals(digest)) {
|
|
|
|
gDecodeFailures.push_back().appendf("Without using getLength, %s did not match digest "
|
|
|
|
"that uses getLength\n", srcPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkFILEStream stream(srcPath);
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
gInvalidStreams.push_back().set(srcPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
|
|
|
|
if (NULL == codec) {
|
|
|
|
gMissingCodecs.push_back().set(srcPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkImageDecoder> ad(codec);
|
|
|
|
|
Add an option on SkImageDecoder to skip writing 0s.
Only implemented for PNG.
Add a getter and setter, and sets the default to false in the
constructor. Also copies the setting in copyFieldsToOther.
Fix an indpendent bug where fDitherImage was not being copied in
copyFieldsToOther.
In SkScaledBitmapSampler::begin, consolidate the settings passed in
by passing a const reference to the decoder. The decoder can be
referenced for its settings of dither, unpremultiplied, and now
skipping writing zeroes. Update callers to use the new API. In png
decoder, rather than passing around a pointer to an initial
read of getDitherImage, and potentially changing it, look at the
field on the decoder itself, and modify it directly. This is a
change in behavior - now if that same decoder is used to decode
a different image, the dither setting has changed. I think this is
okay because A) the typical use case is to use a new decoder for
each decode, B) we do not make any promises that a decode does not
change the decoder and C) it makes the code in SkScaledBitmapSampler
much cleaner.
In SkScaledBitmapScampler, add new row procs for skipping zeroes. Now
that choosing the row proc has five dimensions (src config, dst config,
dither, skip writing zeroes, unpremultiplied), use a new method: each
src/dst combination has a function for choosing the right proc depending
on the decoder.
SkScaledBitmapScampler::RowProc is now public for convenience.
Remove Sample_Gray_D8888_Unpremul, which is effectively no different
from Sample_Gray_D8888.
In cases where unpremultiplied was trivial, such as 565 and when
sampling from gray, decoding may now succeed.
Add a benchmark (currently disabled) for comparing the speed of skipping
writing zeroes versus not skipping. For this particular image, which is
mostly transparent pixels, normal decoding took about 3.6 milliseconds,
while skipping zeroes in the decode took only about 2.5 milliseconds
(this is on a Nexus 4). Presumably it would be slower on an image
with a small amount of transparency, but there will be no slowdown
for an image which reports that it has no transparency.
In SkImageRef_ashmem, always skip writing zeroes, since ashmem
memory is guaranteed to be initialized to 0.
Add a flag to skip writing zeroes in skimage.
Add a regression test for choosing the rowproc to ensure I did not
change any behavior accidentally.
BUG=skia:1661
R=reed@google.com
Review URL: https://codereview.chromium.org/24269006
git-svn-id: http://skia.googlecode.com/svn/trunk@11558 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-01 17:27:15 +00:00
|
|
|
codec->setSkipWritingZeroes(FLAGS_skip);
|
2013-10-08 19:40:18 +00:00
|
|
|
codec->setSampleSize(FLAGS_sampleSize);
|
2013-04-25 17:33:51 +00:00
|
|
|
stream.rewind();
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
// Create a string representing just the filename itself, for use in json expectations.
|
2013-05-28 16:45:07 +00:00
|
|
|
SkString basename = SkOSPath::SkBasename(srcPath);
|
|
|
|
const char* filename = basename.c_str();
|
2013-05-08 19:14:23 +00:00
|
|
|
|
2013-08-06 18:56:53 +00:00
|
|
|
if (!codec->decode(&stream, &bitmap, gPrefConfig,
|
2013-06-27 20:21:01 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode)) {
|
|
|
|
if (expect_to_fail(filename)) {
|
|
|
|
gSuccessfulDecodes.push_back().appendf(
|
|
|
|
"failed to decode %s, which is a known failure.", srcPath);
|
|
|
|
} else {
|
|
|
|
gDecodeFailures.push_back().set(srcPath);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-18 20:08:26 +00:00
|
|
|
// Test decoding just the bounds. The bounds should always match.
|
|
|
|
{
|
|
|
|
stream.rewind();
|
|
|
|
SkBitmap dim;
|
|
|
|
if (!codec->decode(&stream, &dim, SkImageDecoder::kDecodeBounds_Mode)) {
|
|
|
|
SkString failure = SkStringPrintf("failed to decode bounds for %s", srcPath);
|
|
|
|
gDecodeFailures.push_back() = failure;
|
|
|
|
} else {
|
|
|
|
// Now check that the bounds match:
|
|
|
|
if (dim.width() != bitmap.width() || dim.height() != bitmap.height()) {
|
|
|
|
SkString failure = SkStringPrintf("bounds do not match for %s", srcPath);
|
|
|
|
gDecodeFailures.push_back() = failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:33:31 +00:00
|
|
|
skiagm::GmResultDigest digest(bitmap);
|
|
|
|
if (compare_to_expectations_if_necessary(digest, filename,
|
2013-08-06 18:51:30 +00:00
|
|
|
&gDecodeFailures,
|
|
|
|
&gMissingExpectations)) {
|
2013-05-08 19:14:23 +00:00
|
|
|
gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.width(),
|
|
|
|
bitmap.height());
|
2013-06-07 12:43:15 +00:00
|
|
|
} else if (!FLAGS_mismatchPath.isEmpty()) {
|
|
|
|
SkString outPath;
|
|
|
|
make_outname(&outPath, FLAGS_mismatchPath[0], srcPath, ".png");
|
|
|
|
if (write_bitmap(outPath.c_str(), bitmap)) {
|
|
|
|
gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str());
|
|
|
|
} else {
|
|
|
|
gEncodeFailures.push_back().set(outPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:33:31 +00:00
|
|
|
// FIXME: This test could be run on windows/mac once we remove their dependence on
|
|
|
|
// getLength. See https://code.google.com/p/skia/issues/detail?id=1570
|
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
test_stream_without_length(srcPath, codec, digest);
|
|
|
|
#endif
|
|
|
|
|
2013-06-07 12:43:15 +00:00
|
|
|
if (writePath != NULL) {
|
|
|
|
SkString outPath;
|
|
|
|
make_outname(&outPath, writePath->c_str(), srcPath, ".png");
|
|
|
|
if (write_bitmap(outPath.c_str(), bitmap)) {
|
|
|
|
gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str());
|
|
|
|
} else {
|
|
|
|
gEncodeFailures.push_back().set(outPath);
|
|
|
|
}
|
2013-05-08 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
write_expectations(bitmap, filename);
|
2013-04-25 17:33:51 +00:00
|
|
|
|
2013-05-03 20:14:28 +00:00
|
|
|
if (FLAGS_testSubsetDecoding) {
|
2013-05-03 20:39:22 +00:00
|
|
|
SkDEBUGCODE(bool couldRewind =) stream.rewind();
|
2013-05-03 20:14:28 +00:00
|
|
|
SkASSERT(couldRewind);
|
|
|
|
int width, height;
|
|
|
|
// Build the tile index for decoding subsets. If the image is 1x1, skip subset
|
|
|
|
// decoding since there are no smaller subsets.
|
|
|
|
if (codec->buildTileIndex(&stream, &width, &height) && width > 1 && height > 1) {
|
|
|
|
SkASSERT(bitmap.width() == width && bitmap.height() == height);
|
|
|
|
// Call decodeSubset multiple times:
|
|
|
|
SkRandom rand(0);
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
SkBitmap bitmapFromDecodeSubset;
|
|
|
|
// FIXME: Come up with a more representative set of rectangles.
|
|
|
|
SkIRect rect = generate_random_rect(&rand, width, height);
|
|
|
|
SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop,
|
|
|
|
rect.fRight, rect.fBottom);
|
2013-08-06 18:56:53 +00:00
|
|
|
if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, gPrefConfig)) {
|
2013-05-08 19:14:23 +00:00
|
|
|
SkString subsetName = SkStringPrintf("%s_%s", filename, subsetDim.c_str());
|
2013-08-28 18:33:31 +00:00
|
|
|
skiagm::GmResultDigest subsetDigest(bitmapFromDecodeSubset);
|
|
|
|
if (compare_to_expectations_if_necessary(subsetDigest,
|
2013-05-08 19:14:23 +00:00
|
|
|
subsetName.c_str(),
|
2013-08-06 18:51:30 +00:00
|
|
|
&gFailedSubsetDecodes,
|
|
|
|
&gMissingSubsetExpectations)) {
|
2013-05-08 19:14:23 +00:00
|
|
|
gSuccessfulSubsetDecodes.push_back().printf("Decoded subset %s from %s",
|
|
|
|
subsetDim.c_str(), srcPath);
|
2013-06-07 12:43:15 +00:00
|
|
|
} else if (!FLAGS_mismatchPath.isEmpty()) {
|
|
|
|
write_subset(FLAGS_mismatchPath[0], filename, subsetDim.c_str(),
|
|
|
|
&bitmapFromDecodeSubset, rect, bitmap);
|
2013-05-08 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
write_expectations(bitmapFromDecodeSubset, subsetName.c_str());
|
2013-05-03 20:14:28 +00:00
|
|
|
if (writePath != NULL) {
|
2013-05-15 18:14:36 +00:00
|
|
|
write_subset(writePath->c_str(), filename, subsetDim.c_str(),
|
|
|
|
&bitmapFromDecodeSubset, rect, bitmap);
|
2013-05-03 20:14:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-05-15 18:14:36 +00:00
|
|
|
gFailedSubsetDecodes.push_back().printf("Failed to decode region %s from %s",
|
2013-05-03 20:14:28 +00:00
|
|
|
subsetDim.c_str(), srcPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 18:14:36 +00:00
|
|
|
|
2013-10-03 17:13:38 +00:00
|
|
|
// Do not attempt to re-encode A8, since our image encoders do not support encoding to A8.
|
|
|
|
if (FLAGS_reencode && bitmap.config() != SkBitmap::kA8_Config) {
|
2013-04-25 17:33:51 +00:00
|
|
|
// Encode to the format the file was originally in, or PNG if the encoder for the same
|
|
|
|
// format is unavailable.
|
|
|
|
SkImageDecoder::Format format = codec->getFormat();
|
|
|
|
if (SkImageDecoder::kUnknown_Format == format) {
|
|
|
|
if (stream.rewind()) {
|
|
|
|
format = SkImageDecoder::GetStreamFormat(&stream);
|
|
|
|
}
|
|
|
|
if (SkImageDecoder::kUnknown_Format == format) {
|
|
|
|
const char* dot = strrchr(srcPath, '.');
|
|
|
|
if (NULL != dot) {
|
|
|
|
format = guess_format_from_suffix(dot);
|
|
|
|
}
|
|
|
|
if (SkImageDecoder::kUnknown_Format == format) {
|
|
|
|
SkDebugf("Could not determine type for '%s'\n", srcPath);
|
|
|
|
format = SkImageDecoder::kPNG_Format;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SkASSERT(!stream.rewind() || SkImageDecoder::GetStreamFormat(&stream) == format);
|
|
|
|
}
|
|
|
|
SkImageEncoder::Type type = format_to_type(format);
|
|
|
|
// format should never be kUnknown_Format, so type should never be kUnknown_Type.
|
|
|
|
SkASSERT(type != SkImageEncoder::kUnknown_Type);
|
|
|
|
|
|
|
|
SkImageEncoder* encoder = SkImageEncoder::Create(type);
|
|
|
|
if (NULL == encoder) {
|
|
|
|
type = SkImageEncoder::kPNG_Type;
|
|
|
|
encoder = SkImageEncoder::Create(type);
|
|
|
|
SkASSERT(encoder);
|
|
|
|
}
|
|
|
|
SkAutoTDelete<SkImageEncoder> ade(encoder);
|
|
|
|
// Encode to a stream.
|
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
if (!encoder->encodeStream(&wStream, bitmap, 100)) {
|
|
|
|
gEncodeFailures.push_back().printf("Failed to reencode %s to type '%s'", srcPath,
|
|
|
|
suffix_for_type(type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTUnref<SkData> data(wStream.copyToData());
|
|
|
|
if (writePath != NULL && type != SkImageEncoder::kPNG_Type) {
|
2013-06-07 12:43:15 +00:00
|
|
|
// Write the encoded data to a file. Do not write to PNG, which was already written.
|
2013-04-25 17:33:51 +00:00
|
|
|
SkString outPath;
|
|
|
|
make_outname(&outPath, writePath->c_str(), srcPath, suffix_for_type(type));
|
|
|
|
SkFILEWStream file(outPath.c_str());
|
|
|
|
if(file.write(data->data(), data->size())) {
|
|
|
|
gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str());
|
|
|
|
} else {
|
|
|
|
gEncodeFailures.push_back().printf("Failed to write %s", outPath.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Ensure that the reencoded data can still be decoded.
|
|
|
|
SkMemoryStream memStream(data);
|
|
|
|
SkBitmap redecodedBitmap;
|
|
|
|
SkImageDecoder::Format formatOnSecondDecode;
|
2013-08-06 18:56:53 +00:00
|
|
|
if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, gPrefConfig,
|
2013-04-25 17:33:51 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode,
|
|
|
|
&formatOnSecondDecode)) {
|
|
|
|
SkASSERT(format_to_type(formatOnSecondDecode) == type);
|
|
|
|
} else {
|
|
|
|
gDecodeFailures.push_back().printf("Failed to redecode %s after reencoding to '%s'",
|
|
|
|
srcPath, suffix_for_type(type));
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 15:53:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-04-11 15:53:35 +00:00
|
|
|
// If strings is not empty, print title, followed by each string on its own line starting
|
|
|
|
// with a tab.
|
2013-04-25 17:33:51 +00:00
|
|
|
// @return bool True if strings had at least one entry.
|
|
|
|
static bool print_strings(const char* title, const SkTArray<SkString, false>& strings) {
|
2013-04-11 15:53:35 +00:00
|
|
|
if (strings.count() > 0) {
|
|
|
|
SkDebugf("%s:\n", title);
|
|
|
|
for (int i = 0; i < strings.count(); i++) {
|
|
|
|
SkDebugf("\t%s\n", strings[i].c_str());
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
2013-04-25 17:33:51 +00:00
|
|
|
return true;
|
2013-04-11 15:53:35 +00:00
|
|
|
}
|
2013-04-25 17:33:51 +00:00
|
|
|
return false;
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
/**
|
|
|
|
* If directory is non null and does not end with a path separator, append one.
|
|
|
|
* @param directory SkString representing the path to a directory. If the last character is not a
|
|
|
|
* path separator (specific to the current OS), append one.
|
|
|
|
*/
|
|
|
|
static void append_path_separator_if_necessary(SkString* directory) {
|
|
|
|
if (directory != NULL && directory->c_str()[directory->size() - 1] != SkPATH_SEPARATOR) {
|
|
|
|
directory->appendf("%c", SkPATH_SEPARATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-28 20:04:42 +00:00
|
|
|
/**
|
|
|
|
* Return true if the filename represents an image.
|
|
|
|
*/
|
|
|
|
static bool is_image_file(const char* filename) {
|
|
|
|
const char* gImageExtensions[] = {
|
|
|
|
".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".bmp", ".BMP",
|
|
|
|
".webp", ".WEBP", ".ico", ".ICO", ".wbmp", ".WBMP", ".gif", ".GIF"
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gImageExtensions); ++i) {
|
|
|
|
if (SkStrEndsWith(filename, gImageExtensions[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2013-04-11 15:53:35 +00:00
|
|
|
SkCommandLineFlags::SetUsage("Decode files, and optionally write the results to files.");
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
|
|
|
|
if (FLAGS_readPath.count() < 1) {
|
|
|
|
SkDebugf("Folder(s) or image(s) to decode are required.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 19:52:53 +00:00
|
|
|
SkAutoGraphics ag;
|
2013-04-11 15:53:35 +00:00
|
|
|
|
2013-06-19 19:12:53 +00:00
|
|
|
if (!FLAGS_readExpectationsPath.isEmpty() && sk_exists(FLAGS_readExpectationsPath[0])) {
|
2013-05-08 19:14:23 +00:00
|
|
|
gJsonExpectations.reset(SkNEW_ARGS(skiagm::JsonExpectationsSource,
|
|
|
|
(FLAGS_readExpectationsPath[0])));
|
|
|
|
}
|
|
|
|
|
2009-04-24 19:52:53 +00:00
|
|
|
SkString outDir;
|
2013-04-11 15:53:35 +00:00
|
|
|
SkString* outDirPtr;
|
2009-04-24 19:52:53 +00:00
|
|
|
|
2013-04-11 15:53:35 +00:00
|
|
|
if (FLAGS_writePath.count() == 1) {
|
|
|
|
outDir.set(FLAGS_writePath[0]);
|
2013-05-08 19:14:23 +00:00
|
|
|
append_path_separator_if_necessary(&outDir);
|
2013-04-11 15:53:35 +00:00
|
|
|
outDirPtr = &outDir;
|
|
|
|
} else {
|
|
|
|
outDirPtr = NULL;
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 18:56:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 15:53:35 +00:00
|
|
|
for (int i = 0; i < FLAGS_readPath.count(); i++) {
|
2013-06-21 19:12:47 +00:00
|
|
|
const char* readPath = FLAGS_readPath[i];
|
|
|
|
if (strlen(readPath) < 1) {
|
2013-04-11 15:53:35 +00:00
|
|
|
break;
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
2013-06-21 19:12:47 +00:00
|
|
|
if (sk_isdir(readPath)) {
|
|
|
|
const char* dir = readPath;
|
|
|
|
SkOSFile::Iter iter(dir);
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
2013-06-28 20:04:42 +00:00
|
|
|
if (!is_image_file(filename.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-21 19:12:47 +00:00
|
|
|
SkString fullname = SkOSPath::SkPathJoin(dir, filename.c_str());
|
2013-04-11 15:53:35 +00:00
|
|
|
decodeFileAndWrite(fullname.c_str(), outDirPtr);
|
2013-06-21 19:12:47 +00:00
|
|
|
}
|
2013-06-28 20:04:42 +00:00
|
|
|
} else if (sk_exists(readPath) && is_image_file(readPath)) {
|
2013-06-21 19:12:47 +00:00
|
|
|
decodeFileAndWrite(readPath, outDirPtr);
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 19:14:23 +00:00
|
|
|
if (!FLAGS_createExpectationsPath.isEmpty()) {
|
|
|
|
// Use an empty value for everything besides expectations, since the reader only cares
|
|
|
|
// about the expectations.
|
|
|
|
Json::Value nullValue;
|
|
|
|
Json::Value root = skiagm::CreateJsonTree(gExpectationsToWrite, nullValue, nullValue,
|
|
|
|
nullValue, nullValue);
|
|
|
|
std::string jsonStdString = root.toStyledString();
|
2013-06-07 12:43:15 +00:00
|
|
|
SkFILEWStream stream(FLAGS_createExpectationsPath[0]);
|
2013-05-08 19:14:23 +00:00
|
|
|
stream.write(jsonStdString.c_str(), jsonStdString.length());
|
|
|
|
}
|
2013-04-11 15:53:35 +00:00
|
|
|
// Add some space, since codecs may print warnings without newline.
|
|
|
|
SkDebugf("\n\n");
|
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
bool failed = print_strings("Invalid files", gInvalidStreams);
|
|
|
|
failed |= print_strings("Missing codec", gMissingCodecs);
|
|
|
|
failed |= print_strings("Failed to decode", gDecodeFailures);
|
|
|
|
failed |= print_strings("Failed to encode", gEncodeFailures);
|
|
|
|
print_strings("Decoded", gSuccessfulDecodes);
|
2013-08-06 18:51:30 +00:00
|
|
|
print_strings("Missing expectations", gMissingExpectations);
|
2013-04-11 15:53:35 +00:00
|
|
|
|
2013-05-03 20:14:28 +00:00
|
|
|
if (FLAGS_testSubsetDecoding) {
|
|
|
|
failed |= print_strings("Failed subset decodes", gFailedSubsetDecodes);
|
|
|
|
print_strings("Decoded subsets", gSuccessfulSubsetDecodes);
|
2013-08-06 18:51:30 +00:00
|
|
|
print_strings("Missing subset expectations", gMissingSubsetExpectations);
|
2013-05-03 20:14:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:33:51 +00:00
|
|
|
return failed ? -1 : 0;
|
2009-04-24 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|