OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 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 * | |
7 * Simple tool to generate SKP files for testing. | |
8 */ | |
9 | |
10 #include "SkCanvas.h" | |
11 #include "SkColor.h" | |
12 #include "SkCommandLineFlags.h" | |
13 #include "SkPaint.h" | |
14 #include "SkPicture.h" | |
15 #include "SkScalar.h" | |
16 #include "SkStream.h" | |
17 | |
18 // Flags used by this file, alphabetically: | |
19 DEFINE_int32(blue, 128, "Value of blue color channel in image, 0-255."); | |
20 DEFINE_int32(green, 128, "Value of green color channel in image, 0-255."); | |
21 DEFINE_int32(height, 200, "Height of canvas to create."); | |
22 DEFINE_int32(red, 128, "Value of red color channel in image, 0-255."); | |
23 DEFINE_int32(width, 300, "Width of canvas to create."); | |
24 DEFINE_string(writePath, "", "Filepath to write the SKP into."); | |
25 | |
26 static void skpmaker(SkScalar width, SkScalar height, SkColor color, | |
27 const char *writePath) { | |
28 SkPicture pict; | |
29 SkCanvas* canvas = pict.beginRecording(width, height); | |
30 SkPaint paint; | |
31 paint.setStyle(SkPaint::kFill_Style); | |
32 paint.setColor(color); | |
33 canvas->drawRectCoords(0, 0, width, height, paint); | |
34 pict.endRecording(); | |
35 SkFILEWStream stream(writePath); | |
36 pict.serialize(&stream); | |
37 } | |
38 | |
39 int tool_main(int argc, char** argv); | |
40 int tool_main(int argc, char** argv) { | |
41 SkCommandLineFlags::SetUsage("Creates a simple .skp file for testing."); | |
42 SkCommandLineFlags::Parse(argc, argv); | |
43 | |
44 // Validate flags. | |
45 if ((FLAGS_blue < 0) || (FLAGS_blue > 255)) { | |
46 SkDebugf("--blue must be within range [0,255]\n"); | |
47 exit(-1); | |
48 } | |
49 if ((FLAGS_green < 0) || (FLAGS_green > 255)) { | |
50 SkDebugf("--green must be within range [0,255]\n"); | |
51 exit(-1); | |
52 } | |
53 if (FLAGS_height <= 0) { | |
54 SkDebugf("--height must be >0\n"); | |
55 exit(-1); | |
56 } | |
57 if ((FLAGS_red < 0) || (FLAGS_red > 255)) { | |
58 SkDebugf("--red must be within range [0,255]\n"); | |
59 exit(-1); | |
60 } | |
61 if (FLAGS_width <= 0) { | |
62 SkDebugf("--width must be >0\n"); | |
63 exit(-1); | |
64 } | |
65 if (FLAGS_writePath.isEmpty()) { | |
66 SkDebugf("--writePath must be nonempty\n"); | |
67 exit(-1); | |
68 } | |
69 | |
70 SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue); | |
71 skpmaker(SkIntToScalar(FLAGS_width), SkIntToScalar(FLAGS_height), color, FLA
GS_writePath[0]); | |
72 return 0; | |
73 } | |
74 | |
75 #if !defined SK_BUILD_FOR_IOS | |
76 int main(int argc, char * const argv[]) { | |
77 return tool_main(argc, (char**) argv); | |
78 } | |
79 #endif | |
OLD | NEW |