BaseJpegDeocde exampe program

Dependencies:   BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos

Fork of BaseJpegDecode by Norimasa Okamoto

Revision:
5:033432f9baf3
Parent:
4:7d88de31c55a
--- a/example_SimpleJpegDecode.cpp	Tue Oct 30 15:35:36 2012 +0000
+++ b/example_SimpleJpegDecode.cpp	Thu Nov 15 10:20:38 2012 +0000
@@ -1,4 +1,4 @@
-#if 1
+#if 0
 //
 // split jpeg to bmp files
 //
@@ -18,32 +18,11 @@
 
 int offset_x = 0;
 int offset_y = 0;
-void callback(int x, int y, uint8_t* yuv)
+
+void callbackRGB(int x, int y, uint8_t* rgb)
 {
     led1 = !led1;
     if (bmp) {
-        uint8_t rgb[3];
-        int r = yuv[0] + (yuv[2]-128) * 1.4020;
-        if (r < 0) {
-            r = 0;
-        } else if (r > 255) {
-            r = 255;
-        }
-        rgb[0] = r;
-        int g = yuv[0] - (yuv[1]-128) * 0.3441 - (yuv[2]-128) * 0.7139;
-        if (g < 0) {
-            g = 0;
-        } else if (g > 255) {
-            g = 255;
-        }
-        rgb[1] = g;
-        int b = yuv[0] + (yuv[1]-128) * 1.7718 - (yuv[2]-128) * 0.0012;
-        if (b < 0) {
-            b = 0;
-        } else if (b > 255) {
-            b = 255;
-        }
-        rgb[2] = b;
         bmp->point(x - offset_x, y - offset_y, rgb);
     }
 }
@@ -59,34 +38,67 @@
     bmp = new bmp24;
     ASSERT(bmp);
 
-    decode = new SimpleJpegDecode;
+    decode = new SimpleJpegDecode();
     ASSERT(decode);
-    decode->setOnResult(callback);
 
     const char* input_file = "/usb/input.jpg";
-    printf("input: %s\n", input_file);
+
+    FILE *fp = fopen(input_file, "rb");
+    ASSERT(fp != NULL);
+    Timer benchmark_t;
+    benchmark_t.reset();
+    benchmark_t.start();
+    while(!feof(fp)) {
+        int c = fgetc(fp);
+        led2 = !led2;
+    }
+    benchmark_t.stop();
+    fclose(fp);
+    printf("input: %s, %d ms\n", input_file, benchmark_t.read_ms());
+    
+    decode->clear();
+    fp = fopen(input_file, "rb");
+    ASSERT(fp != NULL);
+    benchmark_t.reset();
+    benchmark_t.start();
+    while(!feof(fp)) {
+        int c = fgetc(fp);
+        decode->input(c);
+        led2 = !led2;
+    }
+    benchmark_t.stop();
+    fclose(fp);
+    printf("width: %d, height: %d, yblock: %d, %d ms\n", decode->width, decode->height, 
+                                                         decode->yblock, benchmark_t.read_ms());
+
+    decode->setOnResult(callbackRGB);
     int n = 0;
-    for(offset_y = 0; offset_y < 240; offset_y += 48) {
-        for(offset_x = 0; offset_x < 320; offset_x += 64) {
+    for(offset_y = 0; offset_y < decode->height; offset_y += bmp->height) {
+        for(offset_x = 0; offset_x < decode->width; offset_x += bmp->width) {
             bmp->clear();
             decode->clear();
-            FILE *fp = fopen(input_file, "rb");
+            fp = fopen(input_file, "rb");
             ASSERT(fp != NULL);
+            benchmark_t.reset();
+            benchmark_t.start();
             while(!feof(fp)) {
                 int c = fgetc(fp);
                 decode->input(c);
                 led2 = !led2;
             }
+            benchmark_t.stop();
             fclose(fp);
             char path[32];
             sprintf(path, "/usb/output%02d.bmp", n++);
-            printf("offset: (%3d,%3d) %s\n", offset_x, offset_y, path);
+            printf("offset: (%3d,%3d), size:(%3d,%3d), %s %d ms\n", 
+                offset_x, offset_y, bmp->width, bmp->height, 
+                path, benchmark_t.read_ms());
             bmp->writeFile(path);
             led3 = !led3;
         }
         led4 = !led4;
     }
-    printf("width: %d, height: %d, yblock: %d\n", decode->width, decode->height, decode->m_yblocks);
+    printf("done\n");
     exit(1);     
 }
 #endif