BaseJpegDeocde exampe program

Dependencies:   BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos

Fork of BaseJpegDecode by Norimasa Okamoto

Committer:
va009039
Date:
Wed Dec 05 12:41:25 2012 +0000
Revision:
6:95be1cd2bc14
Parent:
5:033432f9baf3
update FATFileASystem and BaseJpegDecode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 5:033432f9baf3 1 #if 0
va009039 4:7d88de31c55a 2 //
va009039 4:7d88de31c55a 3 // split jpeg to bmp files
va009039 4:7d88de31c55a 4 //
va009039 4:7d88de31c55a 5 #include "mbed.h"
va009039 4:7d88de31c55a 6 #include "SimpleJpegDecode.h"
va009039 4:7d88de31c55a 7 #include "bmp24.h"
va009039 4:7d88de31c55a 8 #include "uvc.h"
va009039 4:7d88de31c55a 9 #include "msc.h"
va009039 4:7d88de31c55a 10
va009039 4:7d88de31c55a 11 #define ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
va009039 4:7d88de31c55a 12
va009039 4:7d88de31c55a 13 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
va009039 4:7d88de31c55a 14 Serial pc(USBTX, USBRX);
va009039 4:7d88de31c55a 15
va009039 4:7d88de31c55a 16 SimpleJpegDecode* decode = NULL;
va009039 4:7d88de31c55a 17 bmp24* bmp = NULL;
va009039 4:7d88de31c55a 18
va009039 4:7d88de31c55a 19 int offset_x = 0;
va009039 4:7d88de31c55a 20 int offset_y = 0;
va009039 5:033432f9baf3 21
va009039 5:033432f9baf3 22 void callbackRGB(int x, int y, uint8_t* rgb)
va009039 4:7d88de31c55a 23 {
va009039 4:7d88de31c55a 24 led1 = !led1;
va009039 4:7d88de31c55a 25 if (bmp) {
va009039 4:7d88de31c55a 26 bmp->point(x - offset_x, y - offset_y, rgb);
va009039 4:7d88de31c55a 27 }
va009039 4:7d88de31c55a 28 }
va009039 4:7d88de31c55a 29
va009039 4:7d88de31c55a 30 int main() {
va009039 4:7d88de31c55a 31 pc.baud(921600);
va009039 4:7d88de31c55a 32 printf("%s\n", __FILE__);
va009039 4:7d88de31c55a 33
va009039 4:7d88de31c55a 34 msc* usb = new msc("usb");
va009039 4:7d88de31c55a 35 int r = usb->setup();
va009039 4:7d88de31c55a 36 ASSERT(r == 0);
va009039 4:7d88de31c55a 37
va009039 4:7d88de31c55a 38 bmp = new bmp24;
va009039 4:7d88de31c55a 39 ASSERT(bmp);
va009039 4:7d88de31c55a 40
va009039 5:033432f9baf3 41 decode = new SimpleJpegDecode();
va009039 4:7d88de31c55a 42 ASSERT(decode);
va009039 4:7d88de31c55a 43
va009039 4:7d88de31c55a 44 const char* input_file = "/usb/input.jpg";
va009039 5:033432f9baf3 45
va009039 5:033432f9baf3 46 FILE *fp = fopen(input_file, "rb");
va009039 5:033432f9baf3 47 ASSERT(fp != NULL);
va009039 5:033432f9baf3 48 Timer benchmark_t;
va009039 5:033432f9baf3 49 benchmark_t.reset();
va009039 5:033432f9baf3 50 benchmark_t.start();
va009039 5:033432f9baf3 51 while(!feof(fp)) {
va009039 5:033432f9baf3 52 int c = fgetc(fp);
va009039 5:033432f9baf3 53 led2 = !led2;
va009039 5:033432f9baf3 54 }
va009039 5:033432f9baf3 55 benchmark_t.stop();
va009039 5:033432f9baf3 56 fclose(fp);
va009039 5:033432f9baf3 57 printf("input: %s, %d ms\n", input_file, benchmark_t.read_ms());
va009039 5:033432f9baf3 58
va009039 5:033432f9baf3 59 decode->clear();
va009039 5:033432f9baf3 60 fp = fopen(input_file, "rb");
va009039 5:033432f9baf3 61 ASSERT(fp != NULL);
va009039 5:033432f9baf3 62 benchmark_t.reset();
va009039 5:033432f9baf3 63 benchmark_t.start();
va009039 5:033432f9baf3 64 while(!feof(fp)) {
va009039 5:033432f9baf3 65 int c = fgetc(fp);
va009039 5:033432f9baf3 66 decode->input(c);
va009039 5:033432f9baf3 67 led2 = !led2;
va009039 5:033432f9baf3 68 }
va009039 5:033432f9baf3 69 benchmark_t.stop();
va009039 5:033432f9baf3 70 fclose(fp);
va009039 5:033432f9baf3 71 printf("width: %d, height: %d, yblock: %d, %d ms\n", decode->width, decode->height,
va009039 5:033432f9baf3 72 decode->yblock, benchmark_t.read_ms());
va009039 5:033432f9baf3 73
va009039 5:033432f9baf3 74 decode->setOnResult(callbackRGB);
va009039 4:7d88de31c55a 75 int n = 0;
va009039 5:033432f9baf3 76 for(offset_y = 0; offset_y < decode->height; offset_y += bmp->height) {
va009039 5:033432f9baf3 77 for(offset_x = 0; offset_x < decode->width; offset_x += bmp->width) {
va009039 4:7d88de31c55a 78 bmp->clear();
va009039 4:7d88de31c55a 79 decode->clear();
va009039 5:033432f9baf3 80 fp = fopen(input_file, "rb");
va009039 4:7d88de31c55a 81 ASSERT(fp != NULL);
va009039 5:033432f9baf3 82 benchmark_t.reset();
va009039 5:033432f9baf3 83 benchmark_t.start();
va009039 4:7d88de31c55a 84 while(!feof(fp)) {
va009039 4:7d88de31c55a 85 int c = fgetc(fp);
va009039 4:7d88de31c55a 86 decode->input(c);
va009039 4:7d88de31c55a 87 led2 = !led2;
va009039 4:7d88de31c55a 88 }
va009039 5:033432f9baf3 89 benchmark_t.stop();
va009039 4:7d88de31c55a 90 fclose(fp);
va009039 4:7d88de31c55a 91 char path[32];
va009039 4:7d88de31c55a 92 sprintf(path, "/usb/output%02d.bmp", n++);
va009039 5:033432f9baf3 93 printf("offset: (%3d,%3d), size:(%3d,%3d), %s %d ms\n",
va009039 5:033432f9baf3 94 offset_x, offset_y, bmp->width, bmp->height,
va009039 5:033432f9baf3 95 path, benchmark_t.read_ms());
va009039 4:7d88de31c55a 96 bmp->writeFile(path);
va009039 4:7d88de31c55a 97 led3 = !led3;
va009039 4:7d88de31c55a 98 }
va009039 4:7d88de31c55a 99 led4 = !led4;
va009039 4:7d88de31c55a 100 }
va009039 5:033432f9baf3 101 printf("done\n");
va009039 4:7d88de31c55a 102 exit(1);
va009039 4:7d88de31c55a 103 }
va009039 4:7d88de31c55a 104 #endif