add cmd-line args
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 7 Jan 2009 11:47:57 +0000 (11:47 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 7 Jan 2009 11:47:57 +0000 (11:47 +0000)
respect canvas size from each bench obj, rather than hardcode 640x480

git-svn-id: http://skia.googlecode.com/svn/trunk@57 2bbb7eff-a529-9590-31e7-b0007b416f81

bench/BenchTool/main.cpp

index ae0dc58..34a2b88 100644 (file)
@@ -1,6 +1,6 @@
 //#include <iostream>
 #include "SkCanvas.h"
-#include "SkImageDecoder.h"
+#include "SkImageEncoder.h"
 #include "SkString.h"
 
 #include "SkBenchmark.h"
@@ -43,27 +43,53 @@ static void make_filename(const char name[], SkString* path) {
 }
 
 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;