BaseJpegDeocde exampe program

Dependencies:   BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos

Fork of BaseJpegDecode by Norimasa Okamoto

Revision:
3:2709bbf8baae
Parent:
1:58dfd5386a92
--- a/benchmark_BaseJpegDecode.cpp	Mon Oct 22 14:10:04 2012 +0000
+++ b/benchmark_BaseJpegDecode.cpp	Thu Oct 25 11:02:17 2012 +0000
@@ -1,13 +1,11 @@
 #if 0
 #include "mbed.h"
 #include "BaseJpegDecode.h"
-#include <vector>
+#include "Benchmark_data.h"
 
 #define DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);} while(0);
 #define ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
 
-LocalFileSystem local("local");
-DigitalOut myled(LED1);
 Serial pc(USBTX, USBRX);
 
 class JpegDecode : public BaseJpegDecode {
@@ -40,43 +38,56 @@
 {
 }
 
+JpegDecode* decode;
+
+void benchmark(uint8_t* image, int size)
+{
+    decode->DC_count = 0;
+    decode->AC_count = 0;
+#ifdef JPEG_USE_REPORT_CODE
+    decode->report_scan_count = 0;
+    decode->report_scan_dc_count = 0;
+    decode->report_scan_ac_count = 0;
+#endif
+    Timer t;
+    t.reset();
+    t.start();
+    decode->clear();    
+    for(int i = 0; i < size; i++) {
+        decode->input(image[i]);
+    }
+    t.stop();
+    
+    printf("%p %d bytes\n", image, size);
+    for(int tq = 0; tq < 2; tq++) {
+        printf("DQT(%d):", tq);
+        for(int i = 0; i < 64; i++) {
+            printf(" %d", decode->qt[tq][i]);
+        }
+        printf("\n");
+    }
+    printf("SOF0: width: %d height: %d yblocks: %d\n", decode->width, decode->height, decode->m_yblocks);
+    printf("Scan: DC: %d AC: %d\n", decode->DC_count, decode->AC_count);
+#ifdef JPEG_USE_REPORT_CODE
+    printf("report: scan_count: %d\n", decode->report_scan_count);
+    printf("report: scan_dc_count: %d\n", decode->report_scan_dc_count);
+    printf("report: scan_ac_count: %d\n", decode->report_scan_ac_count);
+#endif
+    printf("benchmark: %d ms\n", t.read_ms());
+}
+
 int main() {
     pc.baud(921600);
     printf("%s\n", __FILE__);
 
-    JpegDecode* decode = new JpegDecode;
+    decode = new JpegDecode;
     ASSERT(decode);
-    while(1) {
-        char path[128];
-        printf("JPEG file: ");
-        gets(path);
-        FILE* fp = fopen(path, "rb");
-        if (fp == NULL) {
-            printf("file open error %s\n", path);
-            continue;
-        }
-        vector<uint8_t> image;
-        while(1) {
-            int c = fgetc(fp);
-            if (c == EOF) {
-                break;
-            }
-            image.push_back(c);
-        }
-        fclose(fp);
-        printf("%s %d bytes\n", path, image.size());
-        decode->DC_count = 0;
-        decode->AC_count = 0;
-        Timer t;
-        t.reset();
-        t.start();
-        decode->clear();    
-        for(int i = 0; i < image.size(); i++) {
-            decode->input(image[i]);
-        }
-        t.stop();
-        printf("DC: %d AC: %d benchmark: %d ms\n", decode->DC_count, decode->AC_count, t.read_ms());
-    }     
+
+    benchmark(c270_cam0001_jpg, sizeof(c270_cam0001_jpg));
+    benchmark(vx700_cam0001_jpg, sizeof(vx700_cam0001_jpg));
+ 
+    printf("----\n");
+    exit(1);     
 }
 
-#endif
\ No newline at end of file
+#endif