supported GR-PEACH original: http://developer.mbed.org/users/va009039/code/USBHostC270_example/ The function of Isochronous has moved to USBHost_AddIso library.
Dependencies: USBHost_custom_Addiso
Fork of USBHostC270_example_GR-PEACH by
USBHostC270/decodeMJPEG/decodeMJPEG.cpp@15:ac8b6c6dfb3f, 2017-04-21 (annotated)
- Committer:
- Osamu Nakamura
- Date:
- Fri Apr 21 20:09:15 2017 +0900
- Revision:
- 15:ac8b6c6dfb3f
- Parent:
- 9:fecabade834a
Update main.cpp so that it can run on mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 9:fecabade834a | 1 | // decodeMJPEG.cpp 2012/12/8 |
va009039 | 9:fecabade834a | 2 | // decode motion-jpeg to jpeg |
va009039 | 9:fecabade834a | 3 | #include "mbed.h" |
va009039 | 9:fecabade834a | 4 | #include "decodeMJPEG.h" |
va009039 | 9:fecabade834a | 5 | |
va009039 | 9:fecabade834a | 6 | #define MARK_SOF0 0xc0 |
va009039 | 9:fecabade834a | 7 | #define MARK_DHT 0xc4 |
va009039 | 9:fecabade834a | 8 | #define MARK_RST0 0xd0 |
va009039 | 9:fecabade834a | 9 | #define MARK_RST7 0xd7 |
va009039 | 9:fecabade834a | 10 | #define MARK_SOI 0xd8 |
va009039 | 9:fecabade834a | 11 | #define MARK_EOI 0xd9 |
va009039 | 9:fecabade834a | 12 | #define MARK_SOS 0xda |
va009039 | 9:fecabade834a | 13 | #define MARK_DQT 0xdb |
va009039 | 9:fecabade834a | 14 | #define MARK_DRI 0xdd |
va009039 | 9:fecabade834a | 15 | #define MARK_APP 0xe0 |
va009039 | 9:fecabade834a | 16 | |
va009039 | 9:fecabade834a | 17 | #define SEQ_INIT 0 |
va009039 | 9:fecabade834a | 18 | #define SEQ_SOI 1 |
va009039 | 9:fecabade834a | 19 | #define SEQ_FRAME 2 |
va009039 | 9:fecabade834a | 20 | #define SEQ_MARK 3 |
va009039 | 9:fecabade834a | 21 | #define SEQ_SEG_LEN 4 |
va009039 | 9:fecabade834a | 22 | #define SEQ_SEG_LEN2 5 |
va009039 | 9:fecabade834a | 23 | #define SEQ_SEG_BODY 6 |
va009039 | 9:fecabade834a | 24 | #define SEQ_SOS 7 |
va009039 | 9:fecabade834a | 25 | #define SEQ_SOS2 8 |
va009039 | 9:fecabade834a | 26 | |
va009039 | 9:fecabade834a | 27 | static const uint8_t dht[] = { |
va009039 | 9:fecabade834a | 28 | 0xFF,0xC4,0x01,0xA2,0x00,0x00,0x01,0x05,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00, |
va009039 | 9:fecabade834a | 29 | 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A, |
va009039 | 9:fecabade834a | 30 | 0x0B,0x01,0x00,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00, |
va009039 | 9:fecabade834a | 31 | 0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x10,0x00, |
va009039 | 9:fecabade834a | 32 | 0x02,0x01,0x03,0x03,0x02,0x04,0x03,0x05,0x05,0x04,0x04,0x00,0x00,0x01,0x7D,0x01, |
va009039 | 9:fecabade834a | 33 | 0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22, |
va009039 | 9:fecabade834a | 34 | 0x71,0x14,0x32,0x81,0x91,0xA1,0x08,0x23,0x42,0xB1,0xC1,0x15,0x52,0xD1,0xF0,0x24, |
va009039 | 9:fecabade834a | 35 | 0x33,0x62,0x72,0x82,0x09,0x0A,0x16,0x17,0x18,0x19,0x1A,0x25,0x26,0x27,0x28,0x29, |
va009039 | 9:fecabade834a | 36 | 0x2A,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A, |
va009039 | 9:fecabade834a | 37 | 0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, |
va009039 | 9:fecabade834a | 38 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A, |
va009039 | 9:fecabade834a | 39 | 0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8, |
va009039 | 9:fecabade834a | 40 | 0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xC2,0xC3,0xC4,0xC5,0xC6, |
va009039 | 9:fecabade834a | 41 | 0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xE1,0xE2,0xE3, |
va009039 | 9:fecabade834a | 42 | 0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9, |
va009039 | 9:fecabade834a | 43 | 0xFA,0x11,0x00,0x02,0x01,0x02,0x04,0x04,0x03,0x04,0x07,0x05,0x04,0x04,0x00,0x01, |
va009039 | 9:fecabade834a | 44 | 0x02,0x77,0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07, |
va009039 | 9:fecabade834a | 45 | 0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,0xA1,0xB1,0xC1,0x09,0x23,0x33, |
va009039 | 9:fecabade834a | 46 | 0x52,0xF0,0x15,0x62,0x72,0xD1,0x0A,0x16,0x24,0x34,0xE1,0x25,0xF1,0x17,0x18,0x19, |
va009039 | 9:fecabade834a | 47 | 0x1A,0x26,0x27,0x28,0x29,0x2A,0x35,0x36,0x37,0x38,0x39,0x3A,0x43,0x44,0x45,0x46, |
va009039 | 9:fecabade834a | 48 | 0x47,0x48,0x49,0x4A,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x63,0x64,0x65,0x66, |
va009039 | 9:fecabade834a | 49 | 0x67,0x68,0x69,0x6A,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x82,0x83,0x84,0x85, |
va009039 | 9:fecabade834a | 50 | 0x86,0x87,0x88,0x89,0x8A,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0xA2,0xA3, |
va009039 | 9:fecabade834a | 51 | 0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA, |
va009039 | 9:fecabade834a | 52 | 0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8, |
va009039 | 9:fecabade834a | 53 | 0xD9,0xDA,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xF2,0xF3,0xF4,0xF5,0xF6, |
va009039 | 9:fecabade834a | 54 | 0xF7,0xF8,0xF9,0xFA, |
va009039 | 9:fecabade834a | 55 | }; |
va009039 | 9:fecabade834a | 56 | |
va009039 | 9:fecabade834a | 57 | decodeMJPEG::decodeMJPEG() |
va009039 | 9:fecabade834a | 58 | { |
va009039 | 9:fecabade834a | 59 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 60 | } |
va009039 | 9:fecabade834a | 61 | |
va009039 | 9:fecabade834a | 62 | void decodeMJPEG::inputPacket(const uint8_t* buf, int len) |
va009039 | 9:fecabade834a | 63 | { |
va009039 | 9:fecabade834a | 64 | for(int i = 12; i < len; i++) { |
va009039 | 9:fecabade834a | 65 | input(buf[i]); |
va009039 | 9:fecabade834a | 66 | } |
va009039 | 9:fecabade834a | 67 | } |
va009039 | 9:fecabade834a | 68 | |
va009039 | 9:fecabade834a | 69 | void decodeMJPEG::input(uint8_t c) |
va009039 | 9:fecabade834a | 70 | { |
va009039 | 9:fecabade834a | 71 | switch(m_seq) { |
va009039 | 9:fecabade834a | 72 | case SEQ_INIT: |
va009039 | 9:fecabade834a | 73 | if (c == 0xff) { |
va009039 | 9:fecabade834a | 74 | m_seq = SEQ_SOI; |
va009039 | 9:fecabade834a | 75 | } |
va009039 | 9:fecabade834a | 76 | break; |
va009039 | 9:fecabade834a | 77 | case SEQ_SOI: |
va009039 | 9:fecabade834a | 78 | if (c == MARK_SOI) { |
va009039 | 9:fecabade834a | 79 | outputJPEG(0xff, JPEG_START); // start |
va009039 | 9:fecabade834a | 80 | outputJPEG(c); |
va009039 | 9:fecabade834a | 81 | m_bDHT = false; |
va009039 | 9:fecabade834a | 82 | m_seq = SEQ_FRAME; |
va009039 | 9:fecabade834a | 83 | } else { |
va009039 | 9:fecabade834a | 84 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 85 | } |
va009039 | 9:fecabade834a | 86 | break; |
va009039 | 9:fecabade834a | 87 | case SEQ_FRAME: |
va009039 | 9:fecabade834a | 88 | if (c == 0xff) { |
va009039 | 9:fecabade834a | 89 | m_seq = SEQ_MARK; |
va009039 | 9:fecabade834a | 90 | } else { |
va009039 | 9:fecabade834a | 91 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 92 | } |
va009039 | 9:fecabade834a | 93 | break; |
va009039 | 9:fecabade834a | 94 | case SEQ_MARK: |
va009039 | 9:fecabade834a | 95 | if (c == MARK_SOI || c == MARK_EOI || c == 0x00) { |
va009039 | 9:fecabade834a | 96 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 97 | break; |
va009039 | 9:fecabade834a | 98 | } |
va009039 | 9:fecabade834a | 99 | m_mark = c; |
va009039 | 9:fecabade834a | 100 | m_seq = SEQ_SEG_LEN; |
va009039 | 9:fecabade834a | 101 | break; |
va009039 | 9:fecabade834a | 102 | case SEQ_SEG_LEN: |
va009039 | 9:fecabade834a | 103 | m_seg_len = c; |
va009039 | 9:fecabade834a | 104 | m_seq = SEQ_SEG_LEN2; |
va009039 | 9:fecabade834a | 105 | break; |
va009039 | 9:fecabade834a | 106 | case SEQ_SEG_LEN2: |
va009039 | 9:fecabade834a | 107 | m_seg_len <<= 8; |
va009039 | 9:fecabade834a | 108 | m_seg_len |= c; |
va009039 | 9:fecabade834a | 109 | m_seg_len -= 2; |
va009039 | 9:fecabade834a | 110 | m_seg_pos = 0; |
va009039 | 9:fecabade834a | 111 | m_seq = SEQ_SEG_BODY; |
va009039 | 9:fecabade834a | 112 | if (m_mark == MARK_SOS) { |
va009039 | 9:fecabade834a | 113 | if (m_bDHT == false) { |
va009039 | 9:fecabade834a | 114 | for(int i = 0; i < sizeof(dht); i++) { |
va009039 | 9:fecabade834a | 115 | outputJPEG(dht[i]); |
va009039 | 9:fecabade834a | 116 | } |
va009039 | 9:fecabade834a | 117 | } |
va009039 | 9:fecabade834a | 118 | m_output_desable = false; |
va009039 | 9:fecabade834a | 119 | } else if (m_mark == MARK_DHT) { |
va009039 | 9:fecabade834a | 120 | m_bDHT = true; |
va009039 | 9:fecabade834a | 121 | m_output_desable = false; |
va009039 | 9:fecabade834a | 122 | } else { |
va009039 | 9:fecabade834a | 123 | m_output_desable = false; |
va009039 | 9:fecabade834a | 124 | } |
va009039 | 9:fecabade834a | 125 | if (!m_output_desable) { |
va009039 | 9:fecabade834a | 126 | outputJPEG(0xff); |
va009039 | 9:fecabade834a | 127 | outputJPEG(m_mark); |
va009039 | 9:fecabade834a | 128 | outputJPEG((m_seg_len+2) >> 8); |
va009039 | 9:fecabade834a | 129 | outputJPEG((m_seg_len+2) & 0xff); |
va009039 | 9:fecabade834a | 130 | } |
va009039 | 9:fecabade834a | 131 | break; |
va009039 | 9:fecabade834a | 132 | case SEQ_SEG_BODY: |
va009039 | 9:fecabade834a | 133 | if (!m_output_desable) { |
va009039 | 9:fecabade834a | 134 | outputJPEG(c); |
va009039 | 9:fecabade834a | 135 | } |
va009039 | 9:fecabade834a | 136 | if (++m_seg_pos < m_seg_len) { |
va009039 | 9:fecabade834a | 137 | break; |
va009039 | 9:fecabade834a | 138 | } |
va009039 | 9:fecabade834a | 139 | if (m_mark == MARK_SOS) { |
va009039 | 9:fecabade834a | 140 | m_seq = SEQ_SOS; |
va009039 | 9:fecabade834a | 141 | break; |
va009039 | 9:fecabade834a | 142 | } |
va009039 | 9:fecabade834a | 143 | m_seq = SEQ_FRAME; |
va009039 | 9:fecabade834a | 144 | break; |
va009039 | 9:fecabade834a | 145 | case SEQ_SOS: |
va009039 | 9:fecabade834a | 146 | if (c == 0xff) { |
va009039 | 9:fecabade834a | 147 | m_seq = SEQ_SOS2; |
va009039 | 9:fecabade834a | 148 | break; |
va009039 | 9:fecabade834a | 149 | } |
va009039 | 9:fecabade834a | 150 | outputJPEG(c); |
va009039 | 9:fecabade834a | 151 | break; |
va009039 | 9:fecabade834a | 152 | case SEQ_SOS2: |
va009039 | 9:fecabade834a | 153 | if (c == 0x00) { |
va009039 | 9:fecabade834a | 154 | outputJPEG(0xff); |
va009039 | 9:fecabade834a | 155 | outputJPEG(0x00); |
va009039 | 9:fecabade834a | 156 | m_seq = SEQ_SOS; |
va009039 | 9:fecabade834a | 157 | break; |
va009039 | 9:fecabade834a | 158 | } else if (c >= MARK_RST0 && c <= MARK_RST7) { |
va009039 | 9:fecabade834a | 159 | outputJPEG(0xff); |
va009039 | 9:fecabade834a | 160 | outputJPEG(c); |
va009039 | 9:fecabade834a | 161 | m_seq = SEQ_SOS; |
va009039 | 9:fecabade834a | 162 | break; |
va009039 | 9:fecabade834a | 163 | } else if (c == MARK_EOI) { |
va009039 | 9:fecabade834a | 164 | outputJPEG(0xff); |
va009039 | 9:fecabade834a | 165 | outputJPEG(c, JPEG_END); |
va009039 | 9:fecabade834a | 166 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 167 | break; |
va009039 | 9:fecabade834a | 168 | } else if (c == MARK_SOI) { |
va009039 | 9:fecabade834a | 169 | outputJPEG(0xff); |
va009039 | 9:fecabade834a | 170 | outputJPEG(c); |
va009039 | 9:fecabade834a | 171 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 172 | break; |
va009039 | 9:fecabade834a | 173 | } |
va009039 | 9:fecabade834a | 174 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 175 | break; |
va009039 | 9:fecabade834a | 176 | default: |
va009039 | 9:fecabade834a | 177 | m_seq = SEQ_INIT; |
va009039 | 9:fecabade834a | 178 | break; |
va009039 | 9:fecabade834a | 179 | } |
va009039 | 9:fecabade834a | 180 | } |