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

Side by Side Diff: tools/render_pictures_main.cpp

Issue 202983003: add --writeChecksumBasedFilenames flag to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pass SkString pointers to init Created 6 years, 9 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
« no previous file with comments | « tools/bbh_shootout.cpp ('k') | tools/tests/render_pictures_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 #include "PictureRenderingFlags.h" 22 #include "PictureRenderingFlags.h"
23 #include "picture_utils.h" 23 #include "picture_utils.h"
24 24
25 // Flags used by this file, alphabetically: 25 // Flags used by this file, alphabetically:
26 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); 26 DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
27 DECLARE_bool(deferImageDecoding); 27 DECLARE_bool(deferImageDecoding);
28 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ " 28 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ "
29 "by more than this amount are considered errors, though all diffs a re reported. " 29 "by more than this amount are considered errors, though all diffs a re reported. "
30 "Requires --validate."); 30 "Requires --validate.");
31 DECLARE_string(readPath); 31 DECLARE_string(readPath);
32 DEFINE_bool(writeChecksumBasedFilenames, false,
33 "When writing out images, use checksum-based filenames.");
32 DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded ima ge, write it to a " 34 DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded ima ge, write it to a "
33 "file rather than decoding it. Requires writePath to be set. Skips d rawing the full " 35 "file rather than decoding it. Requires writePath to be set. Skips d rawing the full "
34 "skp to a file. Not compatible with deferImageDecoding."); 36 "skp to a file. Not compatible with deferImageDecoding.");
35 DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image r esults to. " 37 DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image r esults to. "
36 "TODO(epoger): Currently, this only works if --writePath is also s pecified. " 38 "TODO(epoger): Currently, this only works if --writePath is also s pecified. "
37 "See https://code.google.com/p/skia/issues/detail?id=2043 ."); 39 "See https://code.google.com/p/skia/issues/detail?id=2043 .");
38 DEFINE_string2(writePath, w, "", "Directory to write the rendered images."); 40 DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
39 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a " 41 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a "
40 "file, instead of an image for each tile."); 42 "file, instead of an image for each tile.");
41 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as " 43 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as "
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 //////////////////////////////////////////////////////////////////////////////// //////////////////// 140 //////////////////////////////////////////////////////////////////////////////// ////////////////////
139 141
140 /** 142 /**
141 * Called only by render_picture(). 143 * Called only by render_picture().
142 */ 144 */
143 static bool render_picture_internal(const SkString& inputPath, const SkString* o utputDir, 145 static bool render_picture_internal(const SkString& inputPath, const SkString* o utputDir,
144 sk_tools::PictureRenderer& renderer, 146 sk_tools::PictureRenderer& renderer,
145 SkBitmap** out) { 147 SkBitmap** out) {
146 SkString inputFilename; 148 SkString inputFilename;
147 sk_tools::get_basename(&inputFilename, inputPath); 149 sk_tools::get_basename(&inputFilename, inputPath);
150 SkString outputDirString;
151 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
152 outputDirString.set(*outputDir);
153 }
148 154
149 SkFILEStream inputStream; 155 SkFILEStream inputStream;
150 inputStream.setPath(inputPath.c_str()); 156 inputStream.setPath(inputPath.c_str());
151 if (!inputStream.isValid()) { 157 if (!inputStream.isValid()) {
152 SkDebugf("Could not open file %s\n", inputPath.c_str()); 158 SkDebugf("Could not open file %s\n", inputPath.c_str());
153 return false; 159 return false;
154 } 160 }
155 161
156 SkPicture::InstallPixelRefProc proc; 162 SkPicture::InstallPixelRefProc proc;
157 if (FLAGS_deferImageDecoding) { 163 if (FLAGS_deferImageDecoding) {
(...skipping 24 matching lines...) Expand all
182 188
183 for (int i = 0; i < FLAGS_clone; ++i) { 189 for (int i = 0; i < FLAGS_clone; ++i) {
184 SkPicture* clone = picture->clone(); 190 SkPicture* clone = picture->clone();
185 SkDELETE(picture); 191 SkDELETE(picture);
186 picture = clone; 192 picture = clone;
187 } 193 }
188 194
189 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), 195 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
190 inputPath.c_str()); 196 inputPath.c_str());
191 197
192 renderer.init(picture); 198 renderer.init(picture, &outputDirString, &inputFilename, FLAGS_writeChecksum BasedFilenames);
193 199
194 if (FLAGS_preprocess) { 200 if (FLAGS_preprocess) {
195 if (NULL != renderer.getCanvas()) { 201 if (NULL != renderer.getCanvas()) {
196 renderer.getCanvas()->EXPERIMENTAL_optimize(picture); 202 renderer.getCanvas()->EXPERIMENTAL_optimize(picture);
197 } 203 }
198 } 204 }
199 205
200 renderer.setup(); 206 renderer.setup();
201 207
202 SkString* outputPath = NULL; 208 bool success = renderer.render(out);
203 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) { 209 if (!success) {
204 outputPath = SkNEW(SkString); 210 SkDebugf("Failed to render %s\n", inputFilename.c_str());
205 make_output_filepath(outputPath, *outputDir, inputFilename);
206 }
207
208 bool success = renderer.render(outputPath, out);
209 if (outputPath) {
210 if (!success) {
211 SkDebugf("Could not write to file %s\n", outputPath->c_str());
212 }
213 SkDELETE(outputPath);
214 } 211 }
215 212
216 renderer.end(); 213 renderer.end();
217 214
218 SkDELETE(picture); 215 SkDELETE(picture);
219 return success; 216 return success;
220 } 217 }
221 218
222 static inline int getByte(uint32_t value, int index) { 219 static inline int getByte(uint32_t value, int index) {
223 SkASSERT(0 <= index && index < 4); 220 SkASSERT(0 <= index && index < 4);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if(diffs[i] > 0) { 342 if(diffs[i] > 0) {
346 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diff s[i]); 343 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diff s[i]);
347 } 344 }
348 } 345 }
349 } 346 }
350 347
351 if (FLAGS_writeWholeImage) { 348 if (FLAGS_writeWholeImage) {
352 sk_tools::force_all_opaque(*bitmap); 349 sk_tools::force_all_opaque(*bitmap);
353 350
354 if (NULL != jsonSummaryPtr) { 351 if (NULL != jsonSummaryPtr) {
355 // EPOGER: This is a hacky way of constructing the filename associat ed with the 352 // TODO(epoger): This is a hacky way of constructing the filename as sociated with the
356 // image checksum; we basically are repeating the logic of make_outp ut_filepath() 353 // image checksum; we basically are repeating the logic of make_outp ut_filepath()
357 // and code below here, within here. 354 // and code below here, within here.
358 // It would be better for the filename (without outputDir) to be pas sed in here, 355 // It would be better for the filename (without outputDir) to be pas sed in here,
359 // and used both for the checksum file and writing into outputDir. 356 // and used both for the checksum file and writing into outputDir.
360 // 357 //
361 // EPOGER: what about including the config type within hashFilename? That way, 358 // TODO(epoger): what about including the config type within hashFil ename? That way,
362 // we could combine results of different config types without confli cting filenames. 359 // we could combine results of different config types without confli cting filenames.
363 SkString hashFilename; 360 SkString hashFilename;
364 sk_tools::get_basename(&hashFilename, inputPath); 361 sk_tools::get_basename(&hashFilename, inputPath);
365 hashFilename.remove(hashFilename.size() - 4, 4); // Remove ".skp" 362 hashFilename.remove(hashFilename.size() - 4, 4); // Remove ".skp"
366 hashFilename.append(".png"); 363 hashFilename.append(".png");
367 jsonSummaryPtr->add(hashFilename.c_str(), *bitmap); 364 jsonSummaryPtr->add(hashFilename.c_str(), *bitmap);
368 } 365 }
369 366
370 if (NULL != outputDir) { 367 if (NULL != outputDir) {
371 SkString inputFilename; 368 SkString inputFilename;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); 494 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
498 } 495 }
499 return 0; 496 return 0;
500 } 497 }
501 498
502 #if !defined SK_BUILD_FOR_IOS 499 #if !defined SK_BUILD_FOR_IOS
503 int main(int argc, char * const argv[]) { 500 int main(int argc, char * const argv[]) {
504 return tool_main(argc, (char**) argv); 501 return tool_main(argc, (char**) argv);
505 } 502 }
506 #endif 503 #endif
OLDNEW
« no previous file with comments | « tools/bbh_shootout.cpp ('k') | tools/tests/render_pictures_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698