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

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: Respond to comments 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 any extension ".*"
96 * Sets gImageNo to 0, so images from file "X.skp" will
97 * look like "X_<gImageNo>.<suffix>", beginning with 0
98 * for each new skp.
99 */
100 static void reset_image_file_base_name(const SkString& name) {
101 gImageNo = 0;
102 // Remove ".skp"
103 const char* cName = name.c_str();
104 const char* dot = strrchr(cName, '.');
105 if (dot != NULL) {
106 gInputFileName.set(cName, dot - cName);
107 } else {
108 gInputFileName.set(name);
109 }
110 }
111
112 /**
113 * Write the raw encoded bitmap data to a file.
114 */
115 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) {
116 SkASSERT(!FLAGS_writePath.isEmpty());
117 SkMemoryStream memStream(buffer, size);
118 SkString outPath;
119 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
120 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++ ,
121 get_suffix_from_format(format));
122 SkString dir(FLAGS_writePath[0]);
123 sk_tools::make_filepath(&outPath, dir, name);
124 SkFILEWStream fileStream(outPath.c_str());
125 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
126 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
127 }
128 // Put in a dummy bitmap.
129 return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config ,
130 SkImageDecoder::kDecodeBounds_Mode);
131 }
132
133 //////////////////////////////////////////////////////////////////////////////// ////////////////////
134
48 static bool render_picture(const SkString& inputPath, const SkString* outputDir, 135 static bool render_picture(const SkString& inputPath, const SkString* outputDir,
49 sk_tools::PictureRenderer& renderer, 136 sk_tools::PictureRenderer& renderer,
50 SkBitmap** out) { 137 SkBitmap** out) {
51 SkString inputFilename; 138 SkString inputFilename;
52 sk_tools::get_basename(&inputFilename, inputPath); 139 sk_tools::get_basename(&inputFilename, inputPath);
53 140
54 SkFILEStream inputStream; 141 SkFILEStream inputStream;
55 inputStream.setPath(inputPath.c_str()); 142 inputStream.setPath(inputPath.c_str());
56 if (!inputStream.isValid()) { 143 if (!inputStream.isValid()) {
57 SkDebugf("Could not open file %s\n", inputPath.c_str()); 144 SkDebugf("Could not open file %s\n", inputPath.c_str());
58 return false; 145 return false;
59 } 146 }
60 147
61 bool success = false; 148 bool success = false;
62 SkPicture* picture; 149 SkPicture* picture;
63 if (FLAGS_deferImageDecoding) { 150 if (FLAGS_deferImageDecoding) {
64 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi tmap)); 151 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi tmap));
152 } else if (FLAGS_writeEncodedImages) {
153 SkASSERT(!FLAGS_writePath.isEmpty());
154 reset_image_file_base_name(inputFilename);
155 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to _file));
65 } else { 156 } else {
66 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder ::DecodeMemory)); 157 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder ::DecodeMemory));
67 } 158 }
159
68 if (!success) { 160 if (!success) {
69 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); 161 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
70 return false; 162 return false;
71 } 163 }
72 164
73 for (int i = 0; i < FLAGS_clone; ++i) { 165 for (int i = 0; i < FLAGS_clone; ++i) {
74 SkPicture* clone = picture->clone(); 166 SkPicture* clone = picture->clone();
75 SkDELETE(picture); 167 SkDELETE(picture);
76 picture = clone; 168 picture = clone;
77 } 169 }
78 170
79 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), 171 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
80 inputPath.c_str()); 172 inputPath.c_str());
81 173
82 renderer.init(picture); 174 renderer.init(picture);
83 renderer.setup(); 175 renderer.setup();
84 176
85 SkString* outputPath = NULL; 177 SkString* outputPath = NULL;
86 if (NULL != outputDir && outputDir->size() > 0) { 178 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
87 outputPath = SkNEW(SkString); 179 outputPath = SkNEW(SkString);
88 make_output_filepath(outputPath, *outputDir, inputFilename); 180 make_output_filepath(outputPath, *outputDir, inputFilename);
89 } 181 }
90 182
91 success = renderer.render(outputPath, out); 183 success = renderer.render(outputPath, out);
92 if (outputPath) { 184 if (outputPath) {
93 if (!success) { 185 if (!success) {
94 SkDebugf("Could not write to file %s\n", outputPath->c_str()); 186 SkDebugf("Could not write to file %s\n", outputPath->c_str());
95 } 187 }
96 SkDELETE(outputPath); 188 SkDELETE(outputPath);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) { 382 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
291 SkDebugf("--maxComponentDiff requires --validate\n"); 383 SkDebugf("--maxComponentDiff requires --validate\n");
292 exit(-1); 384 exit(-1);
293 } 385 }
294 386
295 if (FLAGS_clone < 0) { 387 if (FLAGS_clone < 0) {
296 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone); 388 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
297 exit(-1); 389 exit(-1);
298 } 390 }
299 391
392 if (FLAGS_writeEncodedImages) {
393 if (FLAGS_writePath.isEmpty()) {
394 SkDebugf("--writeEncodedImages requires --writePath\n");
395 exit(-1);
396 }
397 if (FLAGS_deferImageDecoding) {
398 SkDebugf("--writeEncodedImages is not compatible with --deferImageDe coding\n");
399 exit(-1);
400 }
401 }
402
300 SkString errorString; 403 SkString errorString;
301 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, 404 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
302 kRender_Pictu reTool)); 405 kRender_Pictu reTool));
303 if (errorString.size() > 0) { 406 if (errorString.size() > 0) {
304 SkDebugf("%s\n", errorString.c_str()); 407 SkDebugf("%s\n", errorString.c_str());
305 } 408 }
306 409
307 if (renderer.get() == NULL) { 410 if (renderer.get() == NULL) {
308 exit(-1); 411 exit(-1);
309 } 412 }
(...skipping 23 matching lines...) Expand all
333 #endif 436 #endif
334 #endif 437 #endif
335 return 0; 438 return 0;
336 } 439 }
337 440
338 #if !defined SK_BUILD_FOR_IOS 441 #if !defined SK_BUILD_FOR_IOS
339 int main(int argc, char * const argv[]) { 442 int main(int argc, char * const argv[]) {
340 return tool_main(argc, (char**) argv); 443 return tool_main(argc, (char**) argv);
341 } 444 }
342 #endif 445 #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