convert JPEG stream data to bitmap, BaseJpegDecode example program
Dependencies: BaseJpegDecode BaseUsbHost FATFileSystem mbed-rtos mbed
JPEGデコードのサンプルプログラムです。
JPEGのMCU単位で逐次デコード出力していますので少ないRAMメモリで動かすことが出来ます。
#include "USBHostMSD.h" #include "SimpleJpegDecode.h" #include "bmp24.h" const char* INPUT_FILE = "/usb/input.jpg"; const char* OUTPUT_FILE = "/usb/output.bmp"; bmp24 bmp; RawSerial pc(USBTX, USBRX); void callbackRGB(int x, int y, uint8_t* rgb) { bmp.point(x, y, rgb); pc.printf("x=%d, y=%d, RGB=(0x%02x,0x%02x,0x%02x)\n", x, y, rgb[0], rgb[1], rgb[2]); } int main() { pc.baud(115200); USBHostMSD* msd = new USBHostMSD("usb"); if (!msd->connect()) { error("USB Flash drive not found.\n"); } SimpleJpegDecode* decode = new SimpleJpegDecode(RGB24); decode->setOnResult(callbackRGB); decode->clear(); pc.printf("input: %s\n", INPUT_FILE); FILE* fp = fopen(INPUT_FILE, "rb"); if (fp == NULL) { error("open error\n"); } while(1) { int c = fgetc(fp); if (c == EOF) { break; } decode->input(c); } fclose(fp); pc.printf("output: %s\n", OUTPUT_FILE); if (!bmp.writeFile(OUTPUT_FILE)) { error("write error\n"); } exit(1); }
main.cpp
- Committer:
- va009039
- Date:
- 2013-02-02
- Revision:
- 0:98f918e1d528
File content as of revision 0:98f918e1d528:
// SimpleJpegDecode_example/main.cpp 2013/2/2 // convert jpeg to bmp // #include "mbed.h" #include "rtos.h" #include "BaseUsbHost.h" #include "SimpleJpegDecode.h" #include "UsbFlashDrive.h" #include "bmp24.h" #define INPUT_FILE "/usb/input.jpg" #define OUTPUT_FILE "/usb/output.bmp" Serial pc(USBTX, USBRX); SimpleJpegDecode decode; bmp24 bmp; void callbackRGB(int x, int y, uint8_t* rgb) { bmp.point(x, y, rgb); } int main() { pc.baud(921600); printf("%s\n", __FILE__); BaseUsbHost* usbHost = new BaseUsbHost(); ControlEp* ctlEp = new ControlEp; // root hub if (UsbHub::check(ctlEp)) { UsbHub* hub = new UsbHub(ctlEp); ctlEp = hub->search<UsbFlashDrive>(); } if (!UsbFlashDrive::check(ctlEp)) { error("USB flash drive is not connected.\n"); } UsbFlashDrive* drive = new UsbFlashDrive("usb", ctlEp); bmp.clear(); decode.setOnResult(callbackRGB); decode.clear(); printf("input: %s\n", INPUT_FILE); FILE* fp = fopen(INPUT_FILE, "rb"); if (fp == NULL) { error("open error\n"); } while(!feof(fp)) { int c = fgetc(fp); decode.input(c); } fclose(fp); printf("output: %s\n", OUTPUT_FILE); if (!bmp.writeFile(OUTPUT_FILE)) { error("write error\n"); } exit(1); }