//#include <iostream>
#include "SkCanvas.h"
-#include "SkImageDecoder.h"
+#include "SkImageEncoder.h"
#include "SkString.h"
#include "SkBenchmark.h"
}
int main (int argc, char * const argv[]) {
- const int w = 640;
- const int h = 480;
+ SkString outDir;
+ SkBitmap::Config outConfig = SkBitmap::kARGB_8888_Config;
+
+ char* const* stop = argv + argc;
+ for (++argv; argv < stop; ++argv) {
+ if (strcmp(*argv, "-o") == 0) {
+ argv++;
+ if (argv < stop && **argv) {
+ outDir.set(*argv);
+ if (outDir.c_str()[outDir.size() - 1] != '/') {
+ outDir.append("/");
+ }
+ }
+ } else if (strcmp(*argv, "-8888") == 0) {
+ outConfig = SkBitmap::kARGB_8888_Config;
+ } else if (strcmp(*argv, "-565") == 0) {
+ outConfig = SkBitmap::kRGB_565_Config;
+ } else if (strcmp(*argv, "-4444") == 0) {
+ outConfig = SkBitmap::kARGB_4444_Config;
+ } else if (strcmp(*argv, "-a8") == 0) {
+ outConfig = SkBitmap::kA8_Config;
+ }
+ }
- SkBitmap bm;
- bm.setConfig(SkBitmap::kARGB_8888_Config, w, h);
- bm.allocPixels();
-
- SkCanvas canvas(bm);
-
Iter iter;
SkBenchmark* bench;
while ((bench = iter.next()) != NULL) {
+ SkIPoint dim = bench->getSize();
+ if (dim.fX <= 0 || dim.fY <= 0) {
+ continue;
+ }
+
+ SkBitmap bm;
+ bm.setConfig(outConfig, dim.fX, dim.fY);
+ bm.allocPixels();
+
+ SkCanvas canvas(bm);
canvas.drawColor(SK_ColorWHITE);
bench->draw(&canvas);
SkString str;
make_filename(bench->getName(), &str);
- str.prepend("/skimages/");
+ str.prepend(outDir);
str.append(".png");
::remove(str.c_str());
- SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type);
+ SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type,
+ 100);
}
return 0;