2014-01-02 19:42:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*
|
|
|
|
* Simple tool to generate SKP files for testing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2014-01-02 19:42:15 +00:00
|
|
|
#include "SkScalar.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2015-08-26 12:15:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-01-02 19:42:15 +00:00
|
|
|
// Flags used by this file, alphabetically:
|
|
|
|
DEFINE_int32(blue, 128, "Value of blue color channel in image, 0-255.");
|
2014-01-15 16:33:31 +00:00
|
|
|
DEFINE_int32(border, 4, "Width of the black border around the image.");
|
2014-01-02 19:42:15 +00:00
|
|
|
DEFINE_int32(green, 128, "Value of green color channel in image, 0-255.");
|
|
|
|
DEFINE_int32(height, 200, "Height of canvas to create.");
|
|
|
|
DEFINE_int32(red, 128, "Value of red color channel in image, 0-255.");
|
|
|
|
DEFINE_int32(width, 300, "Width of canvas to create.");
|
|
|
|
DEFINE_string(writePath, "", "Filepath to write the SKP into.");
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
// Create a 'width' by 'height' skp with a 'border'-wide black border around
|
|
|
|
// a 'color' rectangle.
|
|
|
|
static void make_skp(SkScalar width, SkScalar height, SkScalar border, SkColor color,
|
2014-01-02 19:42:15 +00:00
|
|
|
const char *writePath) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2015-08-27 14:41:13 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0);
|
2014-01-02 19:42:15 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
2014-01-15 16:33:31 +00:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
2014-08-29 15:03:56 +00:00
|
|
|
SkRect r = SkRect::MakeWH(width, height);
|
|
|
|
canvas->drawRect(r, paint);
|
2014-01-15 16:33:31 +00:00
|
|
|
paint.setColor(color);
|
2014-08-29 15:03:56 +00:00
|
|
|
r.inset(border, border);
|
|
|
|
canvas->drawRect(r, paint);
|
2014-01-02 19:42:15 +00:00
|
|
|
SkFILEWStream stream(writePath);
|
2016-03-18 14:25:55 +00:00
|
|
|
recorder.finishRecordingAsPicture()->serialize(&stream);
|
2014-01-02 19:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::SetUsage("Creates a simple .skp file for testing.");
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
|
|
|
|
// Validate flags.
|
|
|
|
if ((FLAGS_blue < 0) || (FLAGS_blue > 255)) {
|
|
|
|
SkDebugf("--blue must be within range [0,255]\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if ((FLAGS_green < 0) || (FLAGS_green > 255)) {
|
|
|
|
SkDebugf("--green must be within range [0,255]\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (FLAGS_height <= 0) {
|
|
|
|
SkDebugf("--height must be >0\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if ((FLAGS_red < 0) || (FLAGS_red > 255)) {
|
|
|
|
SkDebugf("--red must be within range [0,255]\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (FLAGS_width <= 0) {
|
|
|
|
SkDebugf("--width must be >0\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (FLAGS_writePath.isEmpty()) {
|
|
|
|
SkDebugf("--writePath must be nonempty\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue);
|
2016-03-29 16:03:52 +00:00
|
|
|
make_skp(SkIntToScalar(FLAGS_width),
|
|
|
|
SkIntToScalar(FLAGS_height),
|
|
|
|
SkIntToScalar(FLAGS_border),
|
2014-08-29 15:03:56 +00:00
|
|
|
color, FLAGS_writePath[0]);
|
2014-01-02 19:42:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|