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

Side by Side Diff: experimental/webtry/main.cpp

Issue 656463002: add support for skfiddle width/height options (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add new db creation commands to the design documnt Created 6 years, 2 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
« no previous file with comments | « experimental/webtry/DESIGN.md ('k') | experimental/webtry/res/js/webtry.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <sys/time.h> 1 #include <sys/time.h>
2 #include <sys/resource.h> 2 #include <sys/resource.h>
3 3
4 #include "SkCanvas.h" 4 #include "SkCanvas.h"
5 #include "SkCommandLineFlags.h" 5 #include "SkCommandLineFlags.h"
6 #include "SkData.h" 6 #include "SkData.h"
7 #include "SkForceLinking.h" 7 #include "SkForceLinking.h"
8 #include "SkGraphics.h" 8 #include "SkGraphics.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
11 #include "SkImageInfo.h" 11 #include "SkImageInfo.h"
12 #include "SkOSFile.h"
12 #include "SkStream.h" 13 #include "SkStream.h"
13 #include "SkSurface.h" 14 #include "SkSurface.h"
14 15
15 #include "seccomp_bpf.h" 16 #include "seccomp_bpf.h"
16 17
17 __SK_FORCE_IMAGE_DECODER_LINKING; 18 __SK_FORCE_IMAGE_DECODER_LINKING;
18 19
19 DEFINE_string(out, "", "Filename of the PNG to write to."); 20 DEFINE_string(out, "", "Filename of the PNG to write to.");
20 DEFINE_string(source, "", "Filename of the source image."); 21 DEFINE_string(source, "", "Filename of the source image.");
22 DEFINE_int32(width, 256, "Width of output image.");
23 DEFINE_int32(height, 256, "Height of output image.");
21 24
22 // Defined in template.cpp. 25 // Defined in template.cpp.
23 extern SkBitmap source; 26 extern SkBitmap source;
24 27
25 static bool install_syscall_filter() { 28 static bool install_syscall_filter() {
26 29
27 #ifndef SK_UNSAFE_BUILD_DESKTOP_ONLY 30 #ifndef SK_UNSAFE_BUILD_DESKTOP_ONLY
28 struct sock_filter filter[] = { 31 struct sock_filter filter[] = {
29 /* Grab the system call number. */ 32 /* Grab the system call number. */
30 EXAMINE_SYSCALL, 33 EXAMINE_SYSCALL,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 int main(int argc, char** argv) { 98 int main(int argc, char** argv) {
96 SkCommandLineFlags::Parse(argc, argv); 99 SkCommandLineFlags::Parse(argc, argv);
97 SkAutoGraphics init; 100 SkAutoGraphics init;
98 101
99 if (FLAGS_out.count() == 0) { 102 if (FLAGS_out.count() == 0) {
100 perror("The --out flag must have an argument."); 103 perror("The --out flag must have an argument.");
101 return 1; 104 return 1;
102 } 105 }
103 106
104 if (FLAGS_source.count() == 1) { 107 if (FLAGS_source.count() == 1) {
105 if (!SkImageDecoder::DecodeFile(FLAGS_source[0], &source)) { 108 const char *sourceDir = getenv("WEBTRY_INOUT");
106 perror("Unable to read the source image."); 109 if (NULL == sourceDir) {
107 } 110 sourceDir = "/skia_build/inout";
111 }
112
113 SkString sourcePath = SkOSPath::Join(sourceDir, FLAGS_source[0]);
114 if (!SkImageDecoder::DecodeFile(sourcePath.c_str(), &source)) {
115 perror("Unable to read the source image.");
116 }
108 } 117 }
109 118
110 SkFILEWStream stream(FLAGS_out[0]); 119 SkFILEWStream stream(FLAGS_out[0]);
111 120
112 SkImageInfo info = SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType); 121 SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_S kAlphaType);
113 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 122 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
114 SkCanvas* canvas = surface->getCanvas(); 123 SkCanvas* canvas = surface->getCanvas();
115 124
116 setLimits(); 125 setLimits();
117 126
118 if (!install_syscall_filter()) { 127 if (!install_syscall_filter()) {
119 return 1; 128 return 1;
120 } 129 }
121 130
122 draw(canvas); 131 draw(canvas);
123 132
124 // Write out the image as a PNG. 133 // Write out the image as a PNG.
125 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 134 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
126 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); 135 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
127 if (NULL == data.get()) { 136 if (NULL == data.get()) {
128 printf("Failed to encode\n"); 137 printf("Failed to encode\n");
129 exit(1); 138 exit(1);
130 } 139 }
131 stream.write(data->data(), data->size()); 140 stream.write(data->data(), data->size());
132 } 141 }
OLDNEW
« no previous file with comments | « experimental/webtry/DESIGN.md ('k') | experimental/webtry/res/js/webtry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698