blob: 2041f7bbcc5a4991fc81791519b65f4de86ea068 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
scroggo@google.comb41ff952013-04-11 15:53:35 +00007
scroggo@google.com6843bdb2013-05-08 19:14:23 +00008#include "gm_expectations.h"
reed@android.comaf459792009-04-24 19:52:53 +00009#include "SkBitmap.h"
scroggo@google.com6843bdb2013-05-08 19:14:23 +000010#include "SkBitmapHasher.h"
scroggo@google.com39edf4c2013-04-25 17:33:51 +000011#include "SkColorPriv.h"
scroggo@google.comb41ff952013-04-11 15:53:35 +000012#include "SkCommandLineFlags.h"
scroggo@google.com39edf4c2013-04-25 17:33:51 +000013#include "SkData.h"
reed@android.comaf459792009-04-24 19:52:53 +000014#include "SkGraphics.h"
15#include "SkImageDecoder.h"
16#include "SkImageEncoder.h"
scroggo@google.comb41ff952013-04-11 15:53:35 +000017#include "SkOSFile.h"
scroggo@google.com7e6fcee2013-05-03 20:14:28 +000018#include "SkRandom.h"
reed@android.comaf459792009-04-24 19:52:53 +000019#include "SkStream.h"
scroggo@google.comb41ff952013-04-11 15:53:35 +000020#include "SkTArray.h"
reed@android.comaf459792009-04-24 19:52:53 +000021#include "SkTemplates.h"
22
scroggo@google.com6843bdb2013-05-08 19:14:23 +000023DEFINE_string(createExpectationsPath, "", "Path to write JSON expectations.");
scroggo@google.comb41ff952013-04-11 15:53:35 +000024DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.");
scroggo@google.com6843bdb2013-05-08 19:14:23 +000025DEFINE_string(readExpectationsPath, "", "Path to read JSON expectations from.");
scroggo@google.comb41ff952013-04-11 15:53:35 +000026DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com39edf4c2013-04-25 17:33:51 +000027DEFINE_bool(reencode, true, "Reencode the images to test encoding.");
scroggo@google.com7e6fcee2013-05-03 20:14:28 +000028DEFINE_bool(testSubsetDecoding, true, "Test decoding subsets of images.");
scroggo@google.comb41ff952013-04-11 15:53:35 +000029
scroggo@google.com39edf4c2013-04-25 17:33:51 +000030struct Format {
31 SkImageEncoder::Type fType;
32 SkImageDecoder::Format fFormat;
33 const char* fSuffix;
34};
scroggo@google.comb41ff952013-04-11 15:53:35 +000035
scroggo@google.com39edf4c2013-04-25 17:33:51 +000036static const Format gFormats[] = {
37 { SkImageEncoder::kBMP_Type, SkImageDecoder::kBMP_Format, ".bmp" },
38 { SkImageEncoder::kGIF_Type, SkImageDecoder::kGIF_Format, ".gif" },
39 { SkImageEncoder::kICO_Type, SkImageDecoder::kICO_Format, ".ico" },
40 { SkImageEncoder::kJPEG_Type, SkImageDecoder::kJPEG_Format, ".jpg" },
41 { SkImageEncoder::kPNG_Type, SkImageDecoder::kPNG_Format, ".png" },
42 { SkImageEncoder::kWBMP_Type, SkImageDecoder::kWBMP_Format, ".wbmp" },
43 { SkImageEncoder::kWEBP_Type, SkImageDecoder::kWEBP_Format, ".webp" }
44};
45
46static SkImageEncoder::Type format_to_type(SkImageDecoder::Format format) {
47 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
48 if (gFormats[i].fFormat == format) {
49 return gFormats[i].fType;
50 }
reed@android.comaf459792009-04-24 19:52:53 +000051 }
scroggo@google.com39edf4c2013-04-25 17:33:51 +000052 return SkImageEncoder::kUnknown_Type;
reed@android.comaf459792009-04-24 19:52:53 +000053}
54
scroggo@google.com39edf4c2013-04-25 17:33:51 +000055static const char* suffix_for_type(SkImageEncoder::Type type) {
56 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
57 if (gFormats[i].fType == type) {
58 return gFormats[i].fSuffix;
59 }
60 }
61 return "";
62}
reed@android.comaf459792009-04-24 19:52:53 +000063
scroggo@google.com39edf4c2013-04-25 17:33:51 +000064static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) {
65 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
66 if (strcmp(suffix, gFormats[i].fSuffix) == 0) {
67 return gFormats[i].fFormat;
68 }
69 }
70 return SkImageDecoder::kUnknown_Format;
71}
72
73static void make_outname(SkString* dst, const char outDir[], const char src[],
74 const char suffix[]) {
reed@android.comaf459792009-04-24 19:52:53 +000075 dst->set(outDir);
76 const char* start = strrchr(src, '/');
77 if (start) {
78 start += 1; // skip the actual last '/'
79 } else {
80 start = src;
81 }
82 dst->append(start);
scroggo@google.com39edf4c2013-04-25 17:33:51 +000083 if (!dst->endsWith(suffix)) {
scroggo@google.comb41ff952013-04-11 15:53:35 +000084 const char* cstyleDst = dst->c_str();
85 const char* dot = strrchr(cstyleDst, '.');
86 if (dot != NULL) {
87 int32_t index = SkToS32(dot - cstyleDst);
88 dst->remove(index, dst->size() - index);
89 }
scroggo@google.com39edf4c2013-04-25 17:33:51 +000090 dst->append(suffix);
scroggo@google.comb41ff952013-04-11 15:53:35 +000091 }
92}
93
scroggo@google.com39edf4c2013-04-25 17:33:51 +000094// Store the names of the filenames to report later which ones failed, succeeded, and were
95// invalid.
96static SkTArray<SkString, false> gInvalidStreams;
97static SkTArray<SkString, false> gMissingCodecs;
98static SkTArray<SkString, false> gDecodeFailures;
99static SkTArray<SkString, false> gEncodeFailures;
100static SkTArray<SkString, false> gSuccessfulDecodes;
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000101static SkTArray<SkString, false> gSuccessfulSubsetDecodes;
102static SkTArray<SkString, false> gFailedSubsetDecodes;
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000103
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000104// Expections read from a file specified by readExpectationsPath. The expectations must have been
105// previously written using createExpectationsPath.
106SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
107
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000108static bool write_bitmap(const char outName[], SkBitmap* bm) {
109 SkBitmap bitmap8888;
110 if (SkBitmap::kARGB_8888_Config != bm->config()) {
111 if (!bm->copyTo(&bitmap8888, SkBitmap::kARGB_8888_Config)) {
112 return false;
113 }
114 bm = &bitmap8888;
115 }
116 // FIXME: This forces all pixels to be opaque, like the many implementations
117 // of force_all_opaque. These should be unified if they cannot be eliminated.
118 SkAutoLockPixels lock(*bm);
119 for (int y = 0; y < bm->height(); y++) {
120 for (int x = 0; x < bm->width(); x++) {
121 *bm->getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
122 }
123 }
124 return SkImageEncoder::EncodeFile(outName, *bm, SkImageEncoder::kPNG_Type, 100);
125}
126
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000127/**
128 * Return a random SkIRect inside the range specified.
129 * @param rand Random number generator.
130 * @param maxX Exclusive maximum x-coordinate. SkIRect's fLeft and fRight will be
131 * in the range [0, maxX)
132 * @param maxY Exclusive maximum y-coordinate. SkIRect's fTop and fBottom will be
133 * in the range [0, maxY)
134 * @return SkIRect Non-empty, non-degenerate rectangle.
135 */
136static SkIRect generate_random_rect(SkRandom* rand, int32_t maxX, int32_t maxY) {
137 SkASSERT(maxX > 1 && maxY > 1);
138 int32_t left = rand->nextULessThan(maxX);
139 int32_t right = rand->nextULessThan(maxX);
140 int32_t top = rand->nextULessThan(maxY);
141 int32_t bottom = rand->nextULessThan(maxY);
142 SkIRect rect = SkIRect::MakeLTRB(left, top, right, bottom);
143 rect.sort();
144 // Make sure rect is not empty.
145 if (rect.fLeft == rect.fRight) {
146 if (rect.fLeft > 0) {
147 rect.fLeft--;
148 } else {
149 rect.fRight++;
150 // This branch is only taken if 0 == rect.fRight, and
151 // maxX must be at least 2, so it must still be in
152 // range.
153 SkASSERT(rect.fRight < maxX);
154 }
155 }
156 if (rect.fTop == rect.fBottom) {
157 if (rect.fTop > 0) {
158 rect.fTop--;
159 } else {
160 rect.fBottom++;
161 // Again, this must be in range.
162 SkASSERT(rect.fBottom < maxY);
163 }
164 }
165 return rect;
166}
167
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000168// Stored expectations to be written to a file if createExpectationsPath is specified.
169static Json::Value gExpectationsToWrite;
170
171/**
172 * If expectations are to be recorded, record the expected checksum of bitmap into global
173 * expectations array.
174 */
175static void write_expectations(const SkBitmap& bitmap, const char* filename) {
176 if (!FLAGS_createExpectationsPath.isEmpty()) {
177 // Creates an Expectations object, and add it to the list to write.
178 skiagm::Expectations expectation(bitmap);
179 Json::Value value = expectation.asJsonValue();
180 gExpectationsToWrite[filename] = value;
181 }
182}
183
184/**
185 * Return the name of the file, ignoring the directory structure.
186 * Does not create a new string.
187 * @param fullPath Full path to the file.
188 * @return string The basename of the file - anything beyond the final slash, or the full name
189 * if there is no slash.
190 * TODO: Might this be useful as a utility function in SkOSFile? Would it be more appropriate to
191 * create a new string?
192 */
193static const char* SkBasename(const char* fullPath) {
194 const char* filename = strrchr(fullPath, SkPATH_SEPARATOR);
195 if (NULL == filename || ++filename == '\0') {
196 filename = fullPath;
197 }
198 return filename;
199}
200
201/**
202 * Compare against an expectation for this filename, if there is one.
203 * @param bitmap SkBitmap to compare to the expected value.
204 * @param filename String used to find the expected value.
205 * @return bool True if the bitmap matched the expectation, or if there was no expectation. False
206 * if there was an expecation that the bitmap did not match, or if an expectation could not be
207 * computed from an expectation.
208 */
209static bool compare_to_expectations_if_necessary(const SkBitmap& bitmap, const char* filename,
210 SkTArray<SkString, false>* failureArray) {
211 if (NULL == gJsonExpectations.get()) {
212 return true;
213 }
214
215 skiagm::Expectations jsExpectation = gJsonExpectations->get(filename);
216 if (jsExpectation.empty()) {
217 return true;
218 }
219
220 SkHashDigest checksum;
221 if (!SkBitmapHasher::ComputeDigest(bitmap, &checksum)) {
222 if (failureArray != NULL) {
223 failureArray->push_back().printf("decoded %s, but could not create a checksum.",
224 filename);
225 }
226 return false;
227 }
228
229 if (jsExpectation.match(checksum)) {
230 return true;
231 }
232
233 if (failureArray != NULL) {
234 failureArray->push_back().printf("decoded %s, but the result does not match "
235 "expectations.",
236 filename);
237 }
238 return false;
239}
240
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000241static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) {
242 SkBitmap bitmap;
243 SkFILEStream stream(srcPath);
244 if (!stream.isValid()) {
245 gInvalidStreams.push_back().set(srcPath);
246 return;
247 }
248
249 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
250 if (NULL == codec) {
251 gMissingCodecs.push_back().set(srcPath);
252 return;
253 }
254
255 SkAutoTDelete<SkImageDecoder> ad(codec);
256
257 stream.rewind();
258 if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config,
259 SkImageDecoder::kDecodePixels_Mode)) {
260 gDecodeFailures.push_back().set(srcPath);
261 return;
262 }
263
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000264 // Create a string representing just the filename itself, for use in json expectations.
265 const char* filename = SkBasename(srcPath);
266
267 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures)) {
268 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.width(),
269 bitmap.height());
270 }
271
272 write_expectations(bitmap, filename);
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000273
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000274 if (FLAGS_testSubsetDecoding) {
scroggo@google.com0018f752013-05-03 20:39:22 +0000275 SkDEBUGCODE(bool couldRewind =) stream.rewind();
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000276 SkASSERT(couldRewind);
277 int width, height;
278 // Build the tile index for decoding subsets. If the image is 1x1, skip subset
279 // decoding since there are no smaller subsets.
280 if (codec->buildTileIndex(&stream, &width, &height) && width > 1 && height > 1) {
281 SkASSERT(bitmap.width() == width && bitmap.height() == height);
282 // Call decodeSubset multiple times:
283 SkRandom rand(0);
284 for (int i = 0; i < 5; i++) {
285 SkBitmap bitmapFromDecodeSubset;
286 // FIXME: Come up with a more representative set of rectangles.
287 SkIRect rect = generate_random_rect(&rand, width, height);
288 SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop,
289 rect.fRight, rect.fBottom);
290 if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, SkBitmap::kNo_Config)) {
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000291 SkString subsetName = SkStringPrintf("%s_%s", filename, subsetDim.c_str());
292 if (compare_to_expectations_if_necessary(bitmapFromDecodeSubset,
293 subsetName.c_str(),
294 &gFailedSubsetDecodes)) {
295 gSuccessfulSubsetDecodes.push_back().printf("Decoded subset %s from %s",
296 subsetDim.c_str(), srcPath);
297 }
298
299 write_expectations(bitmapFromDecodeSubset, subsetName.c_str());
300
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000301 if (writePath != NULL) {
302 // Write the region to a file whose name includes the dimensions.
303 SkString suffix = SkStringPrintf("_%s.png", subsetDim.c_str());
304 SkString outPath;
305 make_outname(&outPath, writePath->c_str(), srcPath, suffix.c_str());
scroggo@google.com8b5ff5c2013-05-03 20:21:17 +0000306 SkDEBUGCODE(bool success =)
307 write_bitmap(outPath.c_str(), &bitmapFromDecodeSubset);
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000308 SkASSERT(success);
309 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str());
310 // Also use extractSubset from the original for visual comparison.
311 SkBitmap extractedSubset;
312 if (bitmap.extractSubset(&extractedSubset, rect)) {
313 suffix.printf("_%s_extracted.png", subsetDim.c_str());
314 make_outname(&outPath, writePath->c_str(), srcPath, suffix.c_str());
scroggo@google.com0018f752013-05-03 20:39:22 +0000315 SkDEBUGCODE(success =) write_bitmap(outPath.c_str(), &extractedSubset);
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000316 SkASSERT(success);
317 }
318 }
319 } else {
320 gFailedSubsetDecodes.push_back().printf("Failed to decode region %s from %s\n",
321 subsetDim.c_str(), srcPath);
322 }
323 }
324 }
325 }
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000326 if (FLAGS_reencode) {
327 // Encode to the format the file was originally in, or PNG if the encoder for the same
328 // format is unavailable.
329 SkImageDecoder::Format format = codec->getFormat();
330 if (SkImageDecoder::kUnknown_Format == format) {
331 if (stream.rewind()) {
332 format = SkImageDecoder::GetStreamFormat(&stream);
333 }
334 if (SkImageDecoder::kUnknown_Format == format) {
335 const char* dot = strrchr(srcPath, '.');
336 if (NULL != dot) {
337 format = guess_format_from_suffix(dot);
338 }
339 if (SkImageDecoder::kUnknown_Format == format) {
340 SkDebugf("Could not determine type for '%s'\n", srcPath);
341 format = SkImageDecoder::kPNG_Format;
342 }
343
344 }
345 } else {
346 SkASSERT(!stream.rewind() || SkImageDecoder::GetStreamFormat(&stream) == format);
347 }
348 SkImageEncoder::Type type = format_to_type(format);
349 // format should never be kUnknown_Format, so type should never be kUnknown_Type.
350 SkASSERT(type != SkImageEncoder::kUnknown_Type);
351
352 SkImageEncoder* encoder = SkImageEncoder::Create(type);
353 if (NULL == encoder) {
354 type = SkImageEncoder::kPNG_Type;
355 encoder = SkImageEncoder::Create(type);
356 SkASSERT(encoder);
357 }
358 SkAutoTDelete<SkImageEncoder> ade(encoder);
359 // Encode to a stream.
360 SkDynamicMemoryWStream wStream;
361 if (!encoder->encodeStream(&wStream, bitmap, 100)) {
362 gEncodeFailures.push_back().printf("Failed to reencode %s to type '%s'", srcPath,
363 suffix_for_type(type));
364 return;
365 }
366
367 SkAutoTUnref<SkData> data(wStream.copyToData());
368 if (writePath != NULL && type != SkImageEncoder::kPNG_Type) {
369 // Write the encoded data to a file. Do not write to PNG, which will be written later,
370 // regardless of the input format.
371 SkString outPath;
372 make_outname(&outPath, writePath->c_str(), srcPath, suffix_for_type(type));
373 SkFILEWStream file(outPath.c_str());
374 if(file.write(data->data(), data->size())) {
375 gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str());
376 } else {
377 gEncodeFailures.push_back().printf("Failed to write %s", outPath.c_str());
378 }
379 }
380 // Ensure that the reencoded data can still be decoded.
381 SkMemoryStream memStream(data);
382 SkBitmap redecodedBitmap;
383 SkImageDecoder::Format formatOnSecondDecode;
384 if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, SkBitmap::kNo_Config,
385 SkImageDecoder::kDecodePixels_Mode,
386 &formatOnSecondDecode)) {
387 SkASSERT(format_to_type(formatOnSecondDecode) == type);
388 } else {
389 gDecodeFailures.push_back().printf("Failed to redecode %s after reencoding to '%s'",
390 srcPath, suffix_for_type(type));
391 }
392 }
393
394 if (writePath != NULL) {
395 SkString outPath;
396 make_outname(&outPath, writePath->c_str(), srcPath, ".png");
397 if (write_bitmap(outPath.c_str(), &bitmap)) {
398 gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str());
399 } else {
400 gEncodeFailures.push_back().set(outPath);
401 }
402 }
403}
404
405///////////////////////////////////////////////////////////////////////////////
406
scroggo@google.comb41ff952013-04-11 15:53:35 +0000407// If strings is not empty, print title, followed by each string on its own line starting
408// with a tab.
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000409// @return bool True if strings had at least one entry.
410static bool print_strings(const char* title, const SkTArray<SkString, false>& strings) {
scroggo@google.comb41ff952013-04-11 15:53:35 +0000411 if (strings.count() > 0) {
412 SkDebugf("%s:\n", title);
413 for (int i = 0; i < strings.count(); i++) {
414 SkDebugf("\t%s\n", strings[i].c_str());
415 }
416 SkDebugf("\n");
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000417 return true;
scroggo@google.comb41ff952013-04-11 15:53:35 +0000418 }
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000419 return false;
reed@android.comaf459792009-04-24 19:52:53 +0000420}
421
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000422/**
423 * If directory is non null and does not end with a path separator, append one.
424 * @param directory SkString representing the path to a directory. If the last character is not a
425 * path separator (specific to the current OS), append one.
426 */
427static void append_path_separator_if_necessary(SkString* directory) {
428 if (directory != NULL && directory->c_str()[directory->size() - 1] != SkPATH_SEPARATOR) {
429 directory->appendf("%c", SkPATH_SEPARATOR);
430 }
431}
432
caryclark@google.com5987f582012-10-02 18:33:14 +0000433int tool_main(int argc, char** argv);
434int tool_main(int argc, char** argv) {
scroggo@google.comb41ff952013-04-11 15:53:35 +0000435 SkCommandLineFlags::SetUsage("Decode files, and optionally write the results to files.");
436 SkCommandLineFlags::Parse(argc, argv);
437
438 if (FLAGS_readPath.count() < 1) {
439 SkDebugf("Folder(s) or image(s) to decode are required.\n");
440 return -1;
441 }
442
443
reed@android.comaf459792009-04-24 19:52:53 +0000444 SkAutoGraphics ag;
scroggo@google.comb41ff952013-04-11 15:53:35 +0000445
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000446 if (!FLAGS_readExpectationsPath.isEmpty()) {
447 gJsonExpectations.reset(SkNEW_ARGS(skiagm::JsonExpectationsSource,
448 (FLAGS_readExpectationsPath[0])));
449 }
450
reed@android.comaf459792009-04-24 19:52:53 +0000451 SkString outDir;
scroggo@google.comb41ff952013-04-11 15:53:35 +0000452 SkString* outDirPtr;
reed@android.comaf459792009-04-24 19:52:53 +0000453
scroggo@google.comb41ff952013-04-11 15:53:35 +0000454 if (FLAGS_writePath.count() == 1) {
455 outDir.set(FLAGS_writePath[0]);
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000456 append_path_separator_if_necessary(&outDir);
scroggo@google.comb41ff952013-04-11 15:53:35 +0000457 outDirPtr = &outDir;
458 } else {
459 outDirPtr = NULL;
460 }
461
462 for (int i = 0; i < FLAGS_readPath.count(); i++) {
463 if (strlen(FLAGS_readPath[i]) < 1) {
464 break;
465 }
466 SkOSFile::Iter iter(FLAGS_readPath[i]);
467 SkString filename;
468 if (iter.next(&filename)) {
469 SkString directory(FLAGS_readPath[i]);
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000470 append_path_separator_if_necessary(&directory);
scroggo@google.comb41ff952013-04-11 15:53:35 +0000471 do {
472 SkString fullname(directory);
473 fullname.append(filename);
474 decodeFileAndWrite(fullname.c_str(), outDirPtr);
475 } while (iter.next(&filename));
476 } else {
477 decodeFileAndWrite(FLAGS_readPath[i], outDirPtr);
reed@android.comaf459792009-04-24 19:52:53 +0000478 }
479 }
480
scroggo@google.com6843bdb2013-05-08 19:14:23 +0000481 if (!FLAGS_createExpectationsPath.isEmpty()) {
482 // Use an empty value for everything besides expectations, since the reader only cares
483 // about the expectations.
484 Json::Value nullValue;
485 Json::Value root = skiagm::CreateJsonTree(gExpectationsToWrite, nullValue, nullValue,
486 nullValue, nullValue);
487 std::string jsonStdString = root.toStyledString();
488 SkString path = SkStringPrintf("%s%cresults.json", FLAGS_createExpectationsPath[0],
489 SkPATH_SEPARATOR);
490 SkFILEWStream stream(path.c_str());
491 stream.write(jsonStdString.c_str(), jsonStdString.length());
492 }
scroggo@google.comb41ff952013-04-11 15:53:35 +0000493 // Add some space, since codecs may print warnings without newline.
494 SkDebugf("\n\n");
rmistry@google.comd6176b02012-08-23 18:14:13 +0000495
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000496 bool failed = print_strings("Invalid files", gInvalidStreams);
497 failed |= print_strings("Missing codec", gMissingCodecs);
498 failed |= print_strings("Failed to decode", gDecodeFailures);
499 failed |= print_strings("Failed to encode", gEncodeFailures);
500 print_strings("Decoded", gSuccessfulDecodes);
reed@android.comaf459792009-04-24 19:52:53 +0000501
scroggo@google.com7e6fcee2013-05-03 20:14:28 +0000502 if (FLAGS_testSubsetDecoding) {
503 failed |= print_strings("Failed subset decodes", gFailedSubsetDecodes);
504 print_strings("Decoded subsets", gSuccessfulSubsetDecodes);
505 }
506
scroggo@google.com39edf4c2013-04-25 17:33:51 +0000507 return failed ? -1 : 0;
reed@android.comaf459792009-04-24 19:52:53 +0000508}
509
caryclark@google.com5987f582012-10-02 18:33:14 +0000510#if !defined SK_BUILD_FOR_IOS
511int main(int argc, char * const argv[]) {
512 return tool_main(argc, (char**) argv);
513}
514#endif