Norimasa Okamoto / Mbed 2 deprecated SimpleJpegDecode_example

Dependencies:   BaseJpegDecode BaseUsbHost FATFileSystem mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // SimpleJpegDecode_example/main.cpp 2013/2/2
00002 // convert jpeg to bmp
00003 //
00004 #include "mbed.h"
00005 #include "rtos.h"
00006 #include "BaseUsbHost.h"
00007 #include "SimpleJpegDecode.h"
00008 #include "UsbFlashDrive.h"
00009 #include "bmp24.h"
00010 
00011 #define INPUT_FILE  "/usb/input.jpg"
00012 #define OUTPUT_FILE "/usb/output.bmp"
00013 
00014 Serial pc(USBTX, USBRX);
00015 
00016 SimpleJpegDecode decode;
00017 bmp24 bmp;
00018 
00019 void callbackRGB(int x, int y, uint8_t* rgb)
00020 {
00021     bmp.point(x, y, rgb);
00022 }
00023 
00024 int main() {
00025     pc.baud(921600);
00026     printf("%s\n", __FILE__);
00027 
00028     BaseUsbHost* usbHost = new BaseUsbHost();
00029     ControlEp* ctlEp = new ControlEp; // root hub
00030     if (UsbHub::check(ctlEp)) {
00031         UsbHub* hub = new UsbHub(ctlEp);
00032         ctlEp = hub->search<UsbFlashDrive>();
00033     }
00034     if (!UsbFlashDrive::check(ctlEp)) {
00035         error("USB flash drive is not connected.\n");
00036     }
00037     UsbFlashDrive* drive = new UsbFlashDrive("usb", ctlEp);
00038 
00039     bmp.clear();
00040     decode.setOnResult(callbackRGB);
00041     decode.clear();
00042     printf("input: %s\n", INPUT_FILE);
00043     FILE* fp = fopen(INPUT_FILE, "rb");
00044     if (fp == NULL) {
00045          error("open error\n");
00046     }
00047     while(!feof(fp)) {
00048         int c = fgetc(fp);
00049         decode.input(c);
00050     }
00051     fclose(fp);
00052     printf("output: %s\n", OUTPUT_FILE);
00053     if (!bmp.writeFile(OUTPUT_FILE)) {
00054         error("write error\n");
00055     }
00056     exit(1);     
00057 }