
BaseJpegDeocde exampe program
Dependencies: BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos
Fork of BaseJpegDecode by
example2_c270.cpp
- Committer:
- va009039
- Date:
- 2012-10-25
- Revision:
- 3:2709bbf8baae
- Parent:
- 2:697ebeb8336f
File content as of revision 3:2709bbf8baae:
#if 0 // // dump YCrCb // [Y0, Y1], // (Cr, Cb), // #include "mbed.h" #include "BaseJpegDecode.h" #include "uvc.h" #include "Terminal.h" // Logitech C270 #define WIDTH 160 #define HEIGHT 120 #define ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); Terminal term(USBTX, USBRX); class Decode1 : public BaseJpegDecode { public: int16_t m_y0[WIDTH/16*HEIGHT/8]; int16_t m_y1[WIDTH/16*HEIGHT/8]; int16_t m_cb[WIDTH/16*HEIGHT/8]; int16_t m_cr[WIDTH/16*HEIGHT/8]; virtual void outputDC(int mcu, int block, int value) { if (mcu >= (WIDTH/16*HEIGHT/8)) { return; } switch(block) { // 0-1:Y 2:Cb 3:Cr case 0: m_y0[mcu] = value * qt[0][0]; break; case 1: m_y1[mcu] = value * qt[0][0]; break; case 2: m_cb[mcu] = value * qt[1][0]; break; case 3: m_cr[mcu] = value * qt[1][0]; break; } } virtual void outputAC(int mcu, int block, int scan, int value){}; virtual void outputMARK(uint8_t c){ if (c == 0xd9) { // EOI led2 = !led2; } }; }; Decode1* decode = NULL; void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len) { if (decode) { decode->input(buf+12, len-12); } led1 = buf[1]&1; // FID } int main() { term.baud(921600); printf("%s\n", __FILE__); decode = new Decode1; ASSERT(decode); uvc* cam = new uvc; ASSERT(cam); cam->SetImageSize(WIDTH, HEIGHT); cam->SetFrameInterval(2000000); // 5.0fps cam->setOnResult(callback_motion_jpeg); ASSERT(cam->setup() >= 0); term.cls(); while(1) { int column = 0; for(int y = 0; y < HEIGHT/8; y++) { term.locate(0, column++); for(int x = 0; x < WIDTH/16; x++) { int mcu = y*WIDTH/16+x; term.printf("%+4d,%+4d,", decode->m_y0[mcu], decode->m_y1[mcu]); cam->poll(); } term.locate(0, column++); for(int x = 0; x < WIDTH/16; x++) { int mcu = y*WIDTH/16+x; term.printf("%+4d,%+4d,", decode->m_cb[mcu], decode->m_cr[mcu]); cam->poll(); } } cam->wait_ms(500); led3 = !led3; } } #endif