blob: 00082075c72ab33535980dc82ff106c8e9c48594 [file] [log] [blame]
commit-bot@chromium.orgc7355982014-01-02 19:42:15 +00001/*
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:
19DEFINE_int32(blue, 128, "Value of blue color channel in image, 0-255.");
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000020DEFINE_int32(border, 4, "Width of the black border around the image.");
commit-bot@chromium.orgc7355982014-01-02 19:42:15 +000021DEFINE_int32(green, 128, "Value of green color channel in image, 0-255.");
22DEFINE_int32(height, 200, "Height of canvas to create.");
23DEFINE_int32(red, 128, "Value of red color channel in image, 0-255.");
24DEFINE_int32(width, 300, "Width of canvas to create.");
25DEFINE_string(writePath, "", "Filepath to write the SKP into.");
26
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000027static void skpmaker(int width, int height, int border, SkColor color,
commit-bot@chromium.orgc7355982014-01-02 19:42:15 +000028 const char *writePath) {
29 SkPicture pict;
30 SkCanvas* canvas = pict.beginRecording(width, height);
31 SkPaint paint;
32 paint.setStyle(SkPaint::kFill_Style);
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000033 paint.setColor(SK_ColorBLACK);
commit-bot@chromium.org7e1a31d2014-01-15 16:04:45 +000034 canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), paint);
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000035 paint.setColor(color);
36 canvas->drawRectCoords(SkIntToScalar(border), SkIntToScalar(border),
37 SkIntToScalar(width - border*2), SkIntToScalar(height - border*2),
38 paint);
commit-bot@chromium.orgc7355982014-01-02 19:42:15 +000039 pict.endRecording();
40 SkFILEWStream stream(writePath);
41 pict.serialize(&stream);
42}
43
44int tool_main(int argc, char** argv);
45int tool_main(int argc, char** argv) {
46 SkCommandLineFlags::SetUsage("Creates a simple .skp file for testing.");
47 SkCommandLineFlags::Parse(argc, argv);
48
49 // Validate flags.
50 if ((FLAGS_blue < 0) || (FLAGS_blue > 255)) {
51 SkDebugf("--blue must be within range [0,255]\n");
52 exit(-1);
53 }
54 if ((FLAGS_green < 0) || (FLAGS_green > 255)) {
55 SkDebugf("--green must be within range [0,255]\n");
56 exit(-1);
57 }
58 if (FLAGS_height <= 0) {
59 SkDebugf("--height must be >0\n");
60 exit(-1);
61 }
62 if ((FLAGS_red < 0) || (FLAGS_red > 255)) {
63 SkDebugf("--red must be within range [0,255]\n");
64 exit(-1);
65 }
66 if (FLAGS_width <= 0) {
67 SkDebugf("--width must be >0\n");
68 exit(-1);
69 }
70 if (FLAGS_writePath.isEmpty()) {
71 SkDebugf("--writePath must be nonempty\n");
72 exit(-1);
73 }
74
75 SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue);
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000076 skpmaker(FLAGS_width, FLAGS_height, FLAGS_border, color, FLAGS_writePath[0]);
commit-bot@chromium.orgc7355982014-01-02 19:42:15 +000077 return 0;
78}
79
80#if !defined SK_BUILD_FOR_IOS
81int main(int argc, char * const argv[]) {
82 return tool_main(argc, (char**) argv);
83}
84#endif