Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: tools/render_pictures_main.cpp

Issue 273783004: add --readJsonSummaryPath to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make BitmapAndDigest lazily compute the bitmap Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "LazyDecodeBitmap.h" 8 #include "LazyDecodeBitmap.h"
9 #include "CopyTilesRenderer.h" 9 #include "CopyTilesRenderer.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 13 matching lines...) Expand all
24 #include "PictureRenderer.h" 24 #include "PictureRenderer.h"
25 #include "PictureRenderingFlags.h" 25 #include "PictureRenderingFlags.h"
26 #include "picture_utils.h" 26 #include "picture_utils.h"
27 27
28 // Flags used by this file, alphabetically: 28 // Flags used by this file, alphabetically:
29 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); 29 DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
30 DECLARE_bool(deferImageDecoding); 30 DECLARE_bool(deferImageDecoding);
31 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ " 31 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ "
32 "by more than this amount are considered errors, though all diffs a re reported. " 32 "by more than this amount are considered errors, though all diffs a re reported. "
33 "Requires --validate."); 33 "Requires --validate.");
34 DEFINE_string(readJsonSummaryPath, "", "JSON file to read image expectations fro m.");
34 DECLARE_string(readPath); 35 DECLARE_string(readPath);
35 DEFINE_bool(writeChecksumBasedFilenames, false, 36 DEFINE_bool(writeChecksumBasedFilenames, false,
36 "When writing out images, use checksum-based filenames."); 37 "When writing out images, use checksum-based filenames.");
37 DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded ima ge, write it to a " 38 DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded ima ge, write it to a "
38 "file rather than decoding it. Requires writePath to be set. Skips d rawing the full " 39 "file rather than decoding it. Requires writePath to be set. Skips d rawing the full "
39 "skp to a file. Not compatible with deferImageDecoding."); 40 "skp to a file. Not compatible with deferImageDecoding.");
40 DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image r esults to."); 41 DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image r esults to.");
41 DEFINE_string2(writePath, w, "", "Directory to write the rendered images into.") ; 42 DEFINE_string2(writePath, w, "", "Directory to write the rendered images into.") ;
42 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a " 43 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a "
43 "file, instead of an image for each tile."); 44 "file, instead of an image for each tile.");
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 /** 248 /**
248 * Render the SKP file(s) within inputPath, writing their bitmap images into out putDir. 249 * Render the SKP file(s) within inputPath, writing their bitmap images into out putDir.
249 * 250 *
250 * @param inputPath path to an individual SKP file, or a directory of SKP files 251 * @param inputPath path to an individual SKP file, or a directory of SKP files
251 * @param outputDir if not NULL, write the image(s) generated into this director y 252 * @param outputDir if not NULL, write the image(s) generated into this director y
252 * @param renderer PictureRenderer to use to render the SKPs 253 * @param renderer PictureRenderer to use to render the SKPs
253 * @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary 254 * @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary
254 */ 255 */
255 static bool render_picture(const SkString& inputPath, const SkString* outputDir, 256 static bool render_picture(const SkString& inputPath, const SkString* outputDir,
256 sk_tools::PictureRenderer& renderer, 257 sk_tools::PictureRenderer& renderer,
257 sk_tools::ImageResultsSummary *jsonSummaryPtr) { 258 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr ) {
258 int diffs[256] = {0}; 259 int diffs[256] = {0};
259 SkBitmap* bitmap = NULL; 260 SkBitmap* bitmap = NULL;
260 renderer.setJsonSummaryPtr(jsonSummaryPtr); 261 renderer.setJsonSummaryPtr(jsonSummaryPtr);
261 bool success = render_picture_internal(inputPath, 262 bool success = render_picture_internal(inputPath,
262 FLAGS_writeWholeImage ? NULL : outputDir, 263 FLAGS_writeWholeImage ? NULL : outputDir,
263 renderer, 264 renderer,
264 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); 265 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
265 266
266 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) { 267 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) {
267 SkDebugf("Failed to draw the picture.\n"); 268 SkDebugf("Failed to draw the picture.\n");
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 if (FLAGS_writeWholeImage) { 342 if (FLAGS_writeWholeImage) {
342 sk_tools::force_all_opaque(*bitmap); 343 sk_tools::force_all_opaque(*bitmap);
343 344
344 SkString inputFilename, outputPath; 345 SkString inputFilename, outputPath;
345 sk_tools::get_basename(&inputFilename, inputPath); 346 sk_tools::get_basename(&inputFilename, inputPath);
346 sk_tools::make_filepath(&outputPath, *outputDir, inputFilename); 347 sk_tools::make_filepath(&outputPath, *outputDir, inputFilename);
347 sk_tools::replace_char(&outputPath, '.', '_'); 348 sk_tools::replace_char(&outputPath, '.', '_');
348 outputPath.append(".png"); 349 outputPath.append(".png");
349 350
350 if (NULL != jsonSummaryPtr) { 351 if (NULL != jsonSummaryPtr) {
352 sk_tools::ImageDigest imageDigest(*bitmap);
351 SkString outputFileBasename; 353 SkString outputFileBasename;
352 sk_tools::get_basename(&outputFileBasename, outputPath); 354 sk_tools::get_basename(&outputFileBasename, outputPath);
353 jsonSummaryPtr->add(inputFilename.c_str(), outputFileBasename.c_str( ), *bitmap); 355 jsonSummaryPtr->add(inputFilename.c_str(), outputFileBasename.c_str( ), imageDigest);
354 } 356 }
355 357
356 if (NULL != outputDir) { 358 if (NULL != outputDir) {
357 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap, 359 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
358 SkImageEncoder::kPNG_Type, 100)) { 360 SkImageEncoder::kPNG_Type, 100)) {
359 SkDebugf("Failed to draw the picture.\n"); 361 SkDebugf("Failed to draw the picture.\n");
360 success = false; 362 success = false;
361 } 363 }
362 } 364 }
363 } 365 }
364 SkDELETE(bitmap); 366 SkDELETE(bitmap);
365 367
366 return success; 368 return success;
367 } 369 }
368 370
369 371
370 static int process_input(const char* input, const SkString* outputDir, 372 static int process_input(const char* input, const SkString* outputDir,
371 sk_tools::PictureRenderer& renderer, 373 sk_tools::PictureRenderer& renderer,
372 sk_tools::ImageResultsSummary *jsonSummaryPtr) { 374 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr) {
373 SkOSFile::Iter iter(input, "skp"); 375 SkOSFile::Iter iter(input, "skp");
374 SkString inputFilename; 376 SkString inputFilename;
375 int failures = 0; 377 int failures = 0;
376 SkDebugf("process_input, %s\n", input); 378 SkDebugf("process_input, %s\n", input);
377 if (iter.next(&inputFilename)) { 379 if (iter.next(&inputFilename)) {
378 do { 380 do {
379 SkString inputPath; 381 SkString inputPath;
380 SkString inputAsSkString(input); 382 SkString inputAsSkString(input);
381 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename); 383 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
382 if (!render_picture(inputPath, outputDir, renderer, jsonSummaryPtr)) { 384 if (!render_picture(inputPath, outputDir, renderer, jsonSummaryPtr)) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 if (renderer.get() == NULL) { 444 if (renderer.get() == NULL) {
443 exit(-1); 445 exit(-1);
444 } 446 }
445 447
446 SkAutoGraphics ag; 448 SkAutoGraphics ag;
447 449
448 SkString outputDir; 450 SkString outputDir;
449 if (FLAGS_writePath.count() == 1) { 451 if (FLAGS_writePath.count() == 1) {
450 outputDir.set(FLAGS_writePath[0]); 452 outputDir.set(FLAGS_writePath[0]);
451 } 453 }
452 sk_tools::ImageResultsSummary jsonSummary; 454 sk_tools::ImageResultsAndExpectations jsonSummary;
453 sk_tools::ImageResultsSummary* jsonSummaryPtr = NULL; 455 sk_tools::ImageResultsAndExpectations* jsonSummaryPtr = NULL;
454 if (FLAGS_writeJsonSummaryPath.count() == 1) { 456 if (FLAGS_writeJsonSummaryPath.count() == 1) {
455 jsonSummaryPtr = &jsonSummary; 457 jsonSummaryPtr = &jsonSummary;
458 if (FLAGS_readJsonSummaryPath.count() == 1) {
459 SkASSERT(jsonSummary.readExpectationsFile(FLAGS_readJsonSummaryPath[ 0]));
460 }
456 } 461 }
457 462
458 int failures = 0; 463 int failures = 0;
459 for (int i = 0; i < FLAGS_readPath.count(); i ++) { 464 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
460 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get() , jsonSummaryPtr); 465 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get() , jsonSummaryPtr);
461 } 466 }
462 if (failures != 0) { 467 if (failures != 0) {
463 SkDebugf("Failed to render %i pictures.\n", failures); 468 SkDebugf("Failed to render %i pictures.\n", failures);
464 return 1; 469 return 1;
465 } 470 }
(...skipping 12 matching lines...) Expand all
478 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); 483 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
479 } 484 }
480 return 0; 485 return 0;
481 } 486 }
482 487
483 #if !defined SK_BUILD_FOR_IOS 488 #if !defined SK_BUILD_FOR_IOS
484 int main(int argc, char * const argv[]) { 489 int main(int argc, char * const argv[]) {
485 return tool_main(argc, (char**) argv); 490 return tool_main(argc, (char**) argv);
486 } 491 }
487 #endif 492 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698