
BaseJpegDeocde exampe program
Dependencies: BaseJpegDecode Terminal BaseUsbHost mbed mbed-rtos
Fork of BaseJpegDecode by
Diff: example3_c270.cpp
- Revision:
- 4:7d88de31c55a
- Parent:
- 3:2709bbf8baae
- Child:
- 5:033432f9baf3
--- a/example3_c270.cpp Thu Oct 25 11:02:17 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -#if 0 -// -// view webcam -// -#include "mbed.h" -#include "BaseJpegDecode.h" -#include "uvc.h" -#include "Terminal.h" - -// Logitech C270 -#define WIDTH 320 -#define HEIGHT 176 - -#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 JpegDecode : public BaseJpegDecode { -public: - int8_t m_buf[WIDTH/8*HEIGHT/8]; - virtual void outputDC(int mcu, int block, int value) { - if (mcu < (WIDTH/8*HEIGHT/8/2)) { - if (block <= 1) { // 0-1:Y 2:Cb 3:Cr - m_buf[mcu*2+block] = value; - } - } - } - virtual void outputAC(int mcu, int block, int scan, int value){}; - virtual void outputMARK(uint8_t c){}; -}; - -JpegDecode* 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); - term.printf("%s\n", __FILE__); - - decode = new JpegDecode; - ASSERT(decode); - uvc* cam = new uvc; - ASSERT(cam); - cam->SetImageSize(WIDTH, HEIGHT); - cam->SetFrameInterval(1000000); // 10.0fps - cam->setOnResult(callback_motion_jpeg); - ASSERT(cam->setup() >= 0); - term.cls(); - int n = 0; - while(1) { - int y; - for(y = 0; y < HEIGHT/8; y++) { - term.locate(0, y); - for(int x = 0; x < WIDTH/8; x++) { - if (decode->m_buf[y*WIDTH/8+x] > 0) { - term.printf("**"); - } else { - term.printf(".."); - } - cam->poll(); - } - } - term.locate(0, y); - term.printf("%d", n); - n++; - cam->wait_ms(5); - led2 = !led2; - } -} -#endif