| OLD | NEW |
| 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 "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
| 10 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 11 #include "SkStream.h" | 12 #include "SkStream.h" |
| 12 #include "SkSurface.h" | 13 #include "SkSurface.h" |
| 13 | 14 |
| 14 #include "seccomp_bpf.h" | 15 #include "seccomp_bpf.h" |
| 15 | 16 |
| 16 __SK_FORCE_IMAGE_DECODER_LINKING; | 17 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 17 | 18 |
| 18 DEFINE_string(out, "", "Filename of the PNG to write to."); | 19 DEFINE_string(out, "", "Filename of the PNG to write to."); |
| 20 DEFINE_string(source, "", "Filename of the source image."); |
| 21 |
| 22 // Defined in template.cpp. |
| 23 extern SkBitmap source; |
| 19 | 24 |
| 20 static bool install_syscall_filter() { | 25 static bool install_syscall_filter() { |
| 21 struct sock_filter filter[] = { | 26 struct sock_filter filter[] = { |
| 22 /* Grab the system call number. */ | 27 /* Grab the system call number. */ |
| 23 EXAMINE_SYSCALL, | 28 EXAMINE_SYSCALL, |
| 24 /* List allowed syscalls. */ | 29 /* List allowed syscalls. */ |
| 25 ALLOW_SYSCALL(exit_group), | 30 ALLOW_SYSCALL(exit_group), |
| 26 ALLOW_SYSCALL(exit), | 31 ALLOW_SYSCALL(exit), |
| 27 ALLOW_SYSCALL(fstat), | 32 ALLOW_SYSCALL(fstat), |
| 28 ALLOW_SYSCALL(read), | 33 ALLOW_SYSCALL(read), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 extern void draw(SkCanvas* canvas); | 87 extern void draw(SkCanvas* canvas); |
| 83 | 88 |
| 84 int main(int argc, char** argv) { | 89 int main(int argc, char** argv) { |
| 85 SkCommandLineFlags::Parse(argc, argv); | 90 SkCommandLineFlags::Parse(argc, argv); |
| 86 SkAutoGraphics init; | 91 SkAutoGraphics init; |
| 87 | 92 |
| 88 if (FLAGS_out.count() == 0) { | 93 if (FLAGS_out.count() == 0) { |
| 89 perror("The --out flag must have an argument."); | 94 perror("The --out flag must have an argument."); |
| 90 return 1; | 95 return 1; |
| 91 } | 96 } |
| 97 |
| 98 if (FLAGS_source.count() == 1) { |
| 99 if (!SkImageDecoder::DecodeFile(FLAGS_source[0], &source)) { |
| 100 perror("Unable to read the source image."); |
| 101 } |
| 102 } |
| 103 |
| 92 SkFILEWStream stream(FLAGS_out[0]); | 104 SkFILEWStream stream(FLAGS_out[0]); |
| 93 | 105 |
| 94 SkImageInfo info = SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType); | 106 SkImageInfo info = SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType); |
| 95 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 107 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 96 SkCanvas* canvas = surface->getCanvas(); | 108 SkCanvas* canvas = surface->getCanvas(); |
| 97 | 109 |
| 98 setLimits(); | 110 setLimits(); |
| 99 | 111 |
| 100 if (!install_syscall_filter()) { | 112 if (!install_syscall_filter()) { |
| 101 return 1; | 113 return 1; |
| 102 } | 114 } |
| 103 | 115 |
| 104 draw(canvas); | 116 draw(canvas); |
| 105 | 117 |
| 106 // Write out the image as a PNG. | 118 // Write out the image as a PNG. |
| 107 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 119 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 108 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); | 120 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); |
| 109 if (NULL == data.get()) { | 121 if (NULL == data.get()) { |
| 110 printf("Failed to encode\n"); | 122 printf("Failed to encode\n"); |
| 111 exit(1); | 123 exit(1); |
| 112 } | 124 } |
| 113 stream.write(data->data(), data->size()); | 125 stream.write(data->data(), data->size()); |
| 114 } | 126 } |
| OLD | NEW |