00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <stdbool.h> 00004 00005 #include <png.h> 00006 00007 #include <cc3.h> 00008 00009 static void capture_2serial(void); 00010 00011 int main(void) { 00012 00013 cc3_uart_init (0, 00014 CC3_UART_RATE_115200, 00015 CC3_UART_MODE_8N1, 00016 CC3_UART_BINMODE_BINARY); 00017 00018 cc3_camera_init (); 00019 00020 // use MMC 00021 cc3_filesystem_init(); 00022 00023 cc3_camera_set_resolution(CC3_CAMERA_RESOLUTION_LOW); 00024 cc3_timer_wait_ms(1000); 00025 00026 // init 00027 while(true) { 00028 00029 while(!cc3_button_get_state()); 00030 00031 cc3_led_set_state(0, false); 00032 00033 capture_2serial(); 00034 00035 } 00036 00037 return 0; 00038 } 00039 00040 00041 void capture_2serial(void) 00042 { 00043 uint32_t x, y; 00044 uint32_t size_x, size_y; 00045 00046 uint32_t time, time2; 00047 int write_time; 00048 00049 cc3_pixbuf_load(); 00050 00051 uint8_t *row = cc3_malloc_rows(1); 00052 uint8_t num_channels = cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL ? 3 : 1; 00053 00054 size_x = cc3_g_pixbuf_frame.width; 00055 size_y = cc3_g_pixbuf_frame.height; 00056 00057 time = cc3_timer_get_current_ms(); 00058 00059 putchar(1); 00060 putchar(size_x>>2); 00061 putchar(size_y>>2); 00062 putchar(num_channels); 00063 00064 for (y = 0; y < size_y; y++) { 00065 00066 if (y % 4 == 0) 00067 cc3_led_set_state (0, true); 00068 else 00069 cc3_led_set_state (0, false); 00070 00071 cc3_pixbuf_read_rows(row, 1); 00072 00073 //if(sw_color_space==HSV_COLOR && num_channels==CC3_CHANNEL_ALL ) 00074 // cc3_rgb2hsv_row(row,size_x); 00075 00076 for (x = 0; x < size_x * num_channels; x++) { 00077 uint8_t p = row[x]; 00078 00079 // avoid confusion from FIFO corruptions 00080 //if (p < 16) { 00081 // p = 16; 00082 //} 00083 //else if (p > 240) { 00084 // p = 240; 00085 //} 00086 putchar (p); 00087 } 00088 00089 00090 } 00091 00092 time2 = cc3_timer_get_current_ms(); 00093 write_time = time2 - time; 00094 00095 free(row); 00096 00097 fprintf(stderr, "write_time %10d\n", 00098 write_time); 00099 cc3_led_set_state (0, false); 00100 00101 }