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

Side by Side Diff: tools/render_pictures_main.cpp

Issue 14637011: Add a new mode to render_pictures. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 "CopyTilesRenderer.h" 8 #include "CopyTilesRenderer.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 10 matching lines...) Expand all
21 #include "PictureRenderingFlags.h" 21 #include "PictureRenderingFlags.h"
22 #include "picture_utils.h" 22 #include "picture_utils.h"
23 23
24 // Flags used by this file, alphabetically: 24 // Flags used by this file, alphabetically:
25 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); 25 DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
26 DECLARE_bool(deferImageDecoding); 26 DECLARE_bool(deferImageDecoding);
27 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ " 27 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ "
28 "by more than this amount are considered errors, though all diffs a re reported. " 28 "by more than this amount are considered errors, though all diffs a re reported. "
29 "Requires --validate."); 29 "Requires --validate.");
30 DECLARE_string(readPath); 30 DECLARE_string(readPath);
31 DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded ima ge, write it to a "
32 "file rather than decoding it. Requires writePath to be set. Skips d rawing the full "
33 "skp to a file. Not compatible with deferImageDecoding.");
31 DEFINE_string2(writePath, w, "", "Directory to write the rendered images."); 34 DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
32 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a " 35 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a "
33 "file, instead of an image for each tile."); 36 "file, instead of an image for each tile.");
34 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as " 37 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as "
35 "the picture rendered in simple mode. When used in conjunction with --bbh, results " 38 "the picture rendered in simple mode. When used in conjunction with --bbh, results "
36 "are validated against the picture rendered in the same mode, but wi thout the bbh."); 39 "are validated against the picture rendered in the same mode, but wi thout the bbh.");
37 40
38 static void make_output_filepath(SkString* path, const SkString& dir, 41 static void make_output_filepath(SkString* path, const SkString& dir,
39 const SkString& name) { 42 const SkString& name) {
40 sk_tools::make_filepath(path, dir, name); 43 sk_tools::make_filepath(path, dir, name);
41 // Remove ".skp" 44 // Remove ".skp"
42 path->remove(path->size() - 4, 4); 45 path->remove(path->size() - 4, 4);
43 } 46 }
44 47
45 // Defined in PictureRenderingFlags.cpp 48 // Defined in PictureRenderingFlags.cpp
46 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap ); 49 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap );
47 50
51 //////////////////////////////////////////////////////////////////////////////// ////////////////////
52
53 /**
54 * Table for translating from format of data to a suffix.
55 */
56 struct Format {
57 SkImageDecoder::Format fFormat;
58 const char* fSuffix;
59 };
60 static const Format gFormats[] = {
61 { SkImageDecoder::kBMP_Format, ".bmp" },
62 { SkImageDecoder::kGIF_Format, ".gif" },
63 { SkImageDecoder::kICO_Format, ".ico" },
64 { SkImageDecoder::kJPEG_Format, ".jpg" },
65 { SkImageDecoder::kPNG_Format, ".png" },
66 { SkImageDecoder::kWBMP_Format, ".wbmp" },
67 { SkImageDecoder::kWEBP_Format, ".webp" },
68 { SkImageDecoder::kUnknown_Format, "" },
69 };
70
71 /**
72 * Get an appropriate suffix for an image format.
73 */
74 static const char* get_suffix_from_format(SkImageDecoder::Format format) {
75 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
76 if (gFormats[i].fFormat == format) {
77 return gFormats[i].fSuffix;
78 }
79 }
80 return "";
81 }
82
83 /**
84 * Base name for an image file created from the encoded data in an skp.
85 */
86 static SkString gInputFileName;
87
88 /**
89 * Number to be appended to the image file name so that it is unique.
90 */
91 static uint32_t gImageNo;
92
93 /**
94 * Set up the name for writing encoded data to a file.
95 * Sets gInputFileName to name, minus the last four characters, assuming that t he input looks like
96 * "*.skp".
97 * Sets gImageNo to 0, so images from file "X.skp" will look like "X_<gImageNo> .<suffix>",
98 * beginning with 0 for each new skp.
99 */
100 static void reset_image_file_base_name(const SkString& name) {
101 gImageNo = 0;
102 gInputFileName.set(name);
103 // Remove ".skp"
104 gInputFileName.remove(gInputFileName.size() - 4, 4);
borenet 2013/05/02 15:34:46 I'd feel more comfortable if we didn't assume the
scroggo 2013/05/03 20:43:07 Done.
105 }
106
107 /**
108 * Write the raw encoded bitmap data to a file.
109 */
110 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) {
111 SkASSERT(!FLAGS_writePath.isEmpty());
112 SkMemoryStream memStream(buffer, size);
113 SkString outPath;
114 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
115 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++ ,
116 get_suffix_from_format(format));
117 SkString dir(FLAGS_writePath[0]);
118 sk_tools::make_filepath(&outPath, dir, name);
119 SkFILEWStream fileStream(outPath.c_str());
120 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
121 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
122 }
123 // Put in a dummy bitmap.
124 return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config ,
125 SkImageDecoder::kDecodeBounds_Mode);
126 }
127
128 //////////////////////////////////////////////////////////////////////////////// ////////////////////
129
48 static bool render_picture(const SkString& inputPath, const SkString* outputDir, 130 static bool render_picture(const SkString& inputPath, const SkString* outputDir,
49 sk_tools::PictureRenderer& renderer, 131 sk_tools::PictureRenderer& renderer,
50 SkBitmap** out) { 132 SkBitmap** out) {
51 SkString inputFilename; 133 SkString inputFilename;
52 sk_tools::get_basename(&inputFilename, inputPath); 134 sk_tools::get_basename(&inputFilename, inputPath);
53 135
54 SkFILEStream inputStream; 136 SkFILEStream inputStream;
55 inputStream.setPath(inputPath.c_str()); 137 inputStream.setPath(inputPath.c_str());
56 if (!inputStream.isValid()) { 138 if (!inputStream.isValid()) {
57 SkDebugf("Could not open file %s\n", inputPath.c_str()); 139 SkDebugf("Could not open file %s\n", inputPath.c_str());
58 return false; 140 return false;
59 } 141 }
60 142
61 bool success = false; 143 bool success = false;
62 SkPicture* picture; 144 SkPicture* picture;
63 if (FLAGS_deferImageDecoding) { 145 if (FLAGS_deferImageDecoding) {
64 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi tmap)); 146 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi tmap));
147 } else if (FLAGS_writeEncodedImages) {
148 SkASSERT(!FLAGS_writePath.isEmpty());
149 reset_image_file_base_name(inputFilename);
150 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to _file));
65 } else { 151 } else {
66 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder ::DecodeMemory)); 152 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder ::DecodeMemory));
67 } 153 }
154
68 if (!success) { 155 if (!success) {
69 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); 156 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
70 return false; 157 return false;
71 } 158 }
72 159
73 for (int i = 0; i < FLAGS_clone; ++i) { 160 for (int i = 0; i < FLAGS_clone; ++i) {
74 SkPicture* clone = picture->clone(); 161 SkPicture* clone = picture->clone();
75 SkDELETE(picture); 162 SkDELETE(picture);
76 picture = clone; 163 picture = clone;
77 } 164 }
78 165
79 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), 166 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
80 inputPath.c_str()); 167 inputPath.c_str());
81 168
82 renderer.init(picture); 169 renderer.init(picture);
83 renderer.setup(); 170 renderer.setup();
84 171
85 SkString* outputPath = NULL; 172 SkString* outputPath = NULL;
86 if (NULL != outputDir && outputDir->size() > 0) { 173 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
87 outputPath = SkNEW(SkString); 174 outputPath = SkNEW(SkString);
88 make_output_filepath(outputPath, *outputDir, inputFilename); 175 make_output_filepath(outputPath, *outputDir, inputFilename);
89 } 176 }
90 177
91 success = renderer.render(outputPath, out); 178 success = renderer.render(outputPath, out);
92 if (outputPath) { 179 if (outputPath) {
93 if (!success) { 180 if (!success) {
94 SkDebugf("Could not write to file %s\n", outputPath->c_str()); 181 SkDebugf("Could not write to file %s\n", outputPath->c_str());
95 } 182 }
96 SkDELETE(outputPath); 183 SkDELETE(outputPath);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) { 377 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
291 SkDebugf("--maxComponentDiff requires --validate\n"); 378 SkDebugf("--maxComponentDiff requires --validate\n");
292 exit(-1); 379 exit(-1);
293 } 380 }
294 381
295 if (FLAGS_clone < 0) { 382 if (FLAGS_clone < 0) {
296 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone); 383 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
297 exit(-1); 384 exit(-1);
298 } 385 }
299 386
387 if (FLAGS_writeEncodedImages) {
388 if (FLAGS_writePath.isEmpty()) {
389 SkDebugf("--writeEncodedImages requires --writePath\n");
390 exit(-1);
391 }
392 if (FLAGS_deferImageDecoding) {
393 SkDebugf("--writeEncodedImages is not compatible with --deferImageDe coding\n");
394 exit(-1);
395 }
396 }
397
300 SkString errorString; 398 SkString errorString;
301 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, 399 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
302 kRender_Pictu reTool)); 400 kRender_Pictu reTool));
303 if (errorString.size() > 0) { 401 if (errorString.size() > 0) {
304 SkDebugf("%s\n", errorString.c_str()); 402 SkDebugf("%s\n", errorString.c_str());
305 } 403 }
306 404
307 if (renderer.get() == NULL) { 405 if (renderer.get() == NULL) {
308 exit(-1); 406 exit(-1);
309 } 407 }
(...skipping 23 matching lines...) Expand all
333 #endif 431 #endif
334 #endif 432 #endif
335 return 0; 433 return 0;
336 } 434 }
337 435
338 #if !defined SK_BUILD_FOR_IOS 436 #if !defined SK_BUILD_FOR_IOS
339 int main(int argc, char * const argv[]) { 437 int main(int argc, char * const argv[]) {
340 return tool_main(argc, (char**) argv); 438 return tool_main(argc, (char**) argv);
341 } 439 }
342 #endif 440 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698