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); }
UsbFlashDrive/UsbFlashDrive.h@0:98f918e1d528, 2013-02-02 (annotated)
- Committer:
- va009039
- Date:
- Sat Feb 02 01:25:25 2013 +0000
- Revision:
- 0:98f918e1d528
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:98f918e1d528 | 1 | // usbFlashDrive.h 2013/1/8 |
va009039 | 0:98f918e1d528 | 2 | #pragma once |
va009039 | 0:98f918e1d528 | 3 | |
va009039 | 0:98f918e1d528 | 4 | #include "FATFileSystem.h" |
va009039 | 0:98f918e1d528 | 5 | |
va009039 | 0:98f918e1d528 | 6 | #define SCSI_CMD_REQUEST_SENSE 0x03 |
va009039 | 0:98f918e1d528 | 7 | #define SCSI_CMD_TEST_UNIT_READY 0x00 |
va009039 | 0:98f918e1d528 | 8 | #define SCSI_CMD_INQUIRY 0x12 |
va009039 | 0:98f918e1d528 | 9 | #define SCSI_CMD_READ_10 0x28 |
va009039 | 0:98f918e1d528 | 10 | #define SCSI_CMD_READ_CAPACITY 0x25 |
va009039 | 0:98f918e1d528 | 11 | #define SCSI_CMD_WRITE_10 0x2A |
va009039 | 0:98f918e1d528 | 12 | |
va009039 | 0:98f918e1d528 | 13 | #pragma pack(push,1) |
va009039 | 0:98f918e1d528 | 14 | struct CBW { |
va009039 | 0:98f918e1d528 | 15 | uint32_t dCBWSignature; |
va009039 | 0:98f918e1d528 | 16 | uint32_t dCBWTag; |
va009039 | 0:98f918e1d528 | 17 | uint32_t dCBWDataTraansferLength; |
va009039 | 0:98f918e1d528 | 18 | uint8_t bmCBWFlags; |
va009039 | 0:98f918e1d528 | 19 | uint8_t bCBWLUN; |
va009039 | 0:98f918e1d528 | 20 | uint8_t bCBWCBLength; |
va009039 | 0:98f918e1d528 | 21 | uint8_t CBWCB[16]; |
va009039 | 0:98f918e1d528 | 22 | }; |
va009039 | 0:98f918e1d528 | 23 | |
va009039 | 0:98f918e1d528 | 24 | struct CSW { |
va009039 | 0:98f918e1d528 | 25 | uint32_t dCSWSignature; |
va009039 | 0:98f918e1d528 | 26 | uint32_t dCSWTag; |
va009039 | 0:98f918e1d528 | 27 | uint32_t dCSWDataResidue; |
va009039 | 0:98f918e1d528 | 28 | uint8_t bCSWStatus; |
va009039 | 0:98f918e1d528 | 29 | }; |
va009039 | 0:98f918e1d528 | 30 | #pragma pack(pop) |
va009039 | 0:98f918e1d528 | 31 | |
va009039 | 0:98f918e1d528 | 32 | class UsbFlashDrive : public FATFileSystem { |
va009039 | 0:98f918e1d528 | 33 | public: |
va009039 | 0:98f918e1d528 | 34 | UsbFlashDrive(const char* name, ControlEp* ctlEp = NULL); |
va009039 | 0:98f918e1d528 | 35 | static bool check(ControlEp* ctlEp); |
va009039 | 0:98f918e1d528 | 36 | virtual int disk_initialize(); |
va009039 | 0:98f918e1d528 | 37 | virtual int disk_write(const uint8_t* buffer, uint64_t sector); |
va009039 | 0:98f918e1d528 | 38 | virtual int disk_read(uint8_t* buffer, uint64_t sector); |
va009039 | 0:98f918e1d528 | 39 | virtual int disk_status(); |
va009039 | 0:98f918e1d528 | 40 | virtual int disk_sync(); |
va009039 | 0:98f918e1d528 | 41 | virtual uint64_t disk_sectors(); |
va009039 | 0:98f918e1d528 | 42 | private: |
va009039 | 0:98f918e1d528 | 43 | int setup(ControlEp* ctlEp, int timeout = 9000); |
va009039 | 0:98f918e1d528 | 44 | int ParseConfiguration(ControlEp* ctlEp); |
va009039 | 0:98f918e1d528 | 45 | int BulkOnlyMassStorageReset(ControlEp* ctlEp); |
va009039 | 0:98f918e1d528 | 46 | int GetMaxLUN(ControlEp* ctlEp); |
va009039 | 0:98f918e1d528 | 47 | int ReadCapacity(); |
va009039 | 0:98f918e1d528 | 48 | int GetSenseInfo(); |
va009039 | 0:98f918e1d528 | 49 | int TestUnitReady(); |
va009039 | 0:98f918e1d528 | 50 | int Inquire(); |
va009039 | 0:98f918e1d528 | 51 | int MS_BulkRecv(uint32_t block_number, int num_blocks, uint8_t* user_buffer); |
va009039 | 0:98f918e1d528 | 52 | int MS_BulkSend(uint32_t block_number, int num_blocks, const uint8_t* user_buffer); |
va009039 | 0:98f918e1d528 | 53 | int CommandTransport(const uint8_t* cdb, int size); |
va009039 | 0:98f918e1d528 | 54 | int StatusTransport(); |
va009039 | 0:98f918e1d528 | 55 | int _bulkRecv(uint8_t* buf, int size); |
va009039 | 0:98f918e1d528 | 56 | int _bulkSend(const uint8_t* buf, int size); |
va009039 | 0:98f918e1d528 | 57 | const char* m_name; |
va009039 | 0:98f918e1d528 | 58 | int m_drive; |
va009039 | 0:98f918e1d528 | 59 | uint32_t m_numBlocks; |
va009039 | 0:98f918e1d528 | 60 | int m_BlockSize; |
va009039 | 0:98f918e1d528 | 61 | int m_lun; |
va009039 | 0:98f918e1d528 | 62 | int m_MaxLUN; |
va009039 | 0:98f918e1d528 | 63 | int m_interface; |
va009039 | 0:98f918e1d528 | 64 | uint32_t m_tag; |
va009039 | 0:98f918e1d528 | 65 | CBW m_CBW; |
va009039 | 0:98f918e1d528 | 66 | CSW m_CSW; |
va009039 | 0:98f918e1d528 | 67 | // endpoint |
va009039 | 0:98f918e1d528 | 68 | BulkEp* m_pEpBulkIn; |
va009039 | 0:98f918e1d528 | 69 | BulkEp* m_pEpBulkOut; |
va009039 | 0:98f918e1d528 | 70 | // report |
va009039 | 0:98f918e1d528 | 71 | uint32_t m_report_disk_write; |
va009039 | 0:98f918e1d528 | 72 | uint32_t m_report_disk_read; |
va009039 | 0:98f918e1d528 | 73 | uint32_t m_report_disk_status; |
va009039 | 0:98f918e1d528 | 74 | uint32_t m_report_disk_sync; |
va009039 | 0:98f918e1d528 | 75 | }; |