Changeset 328
- Timestamp:
- 01/14/07 20:26:38 (2 years ago)
- Files:
-
- trunk/lib/cc3_ilp/cc3_jpg.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/cc3_ilp/cc3_jpg.c
r302 r328 24 24 #include <jpeglib.h> 25 25 26 typedef struct { 27 struct jpeg_compress_struct cinfo; 28 struct jpeg_error_mgr jerr; 29 } cc3_jpeg_t; 26 30 27 static void destroy_jpeg(void); 28 static void init_jpeg(void); 29 static void capture_current_jpeg(FILE *f); 31 32 static void destroy_jpeg(cc3_jpeg_t *cj); 33 static cc3_jpeg_t *init_jpeg (void); 34 static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f); 30 35 31 36 void cc3_jpeg_send_simple(void) { 37 // init jpeg 38 cc3_jpeg_t *cj = init_jpeg(); 32 39 40 capture_current_jpeg(cj, stdout); 33 41 34 // init jpeg 35 init_jpeg(); 36 37 capture_current_jpeg(stdout); 38 39 destroy_jpeg(); 42 destroy_jpeg(cj); 40 43 } 41 44 42 45 43 static struct jpeg_compress_struct cinfo;44 static struct jpeg_error_mgr jerr;45 46 46 //static cc3_pixel_t *row; 47 uint8_t *row; 47 static cc3_jpeg_t *init_jpeg(void) { 48 cc3_jpeg_t *cj = malloc(sizeof(cc3_jpeg_t)); 49 if (cj == NULL) { 50 return NULL; 51 } 48 52 49 static void init_jpeg(void) { 50 cinfo.err = jpeg_std_error(&jerr); 51 jpeg_create_compress(&cinfo); 53 // init error structure 54 cj->cinfo.err = jpeg_std_error(&cj->jerr); 55 56 // init jpeg structure 57 jpeg_create_compress(&cj->cinfo); 52 58 53 59 // parameters for jpeg image 54 cinfo.image_width = cc3_g_current_frame.width; 55 cinfo.image_height = cc3_g_current_frame.height; 60 cj->cinfo.image_width = cc3_g_current_frame.width; 61 cj->cinfo.image_height = cc3_g_current_frame.height; 62 56 63 //printf( "image width=%d image height=%d\n", cinfo.image_width, cinfo.image_height ); 57 c info.input_components = 3;64 cj->cinfo.input_components = 3; 58 65 // cinfo.in_color_space = JCS_YCbCr; 59 c info.in_color_space = JCS_RGB;66 cj->cinfo.in_color_space = JCS_RGB; 60 67 61 68 // set image quality, etc. 62 jpeg_set_defaults(&cinfo); 63 jpeg_set_quality(&cinfo, 85, true); 69 jpeg_set_defaults(&cj->cinfo); 70 jpeg_set_quality(&cj->cinfo, 85, true); 71 72 // return 73 return cj; 74 } 75 76 static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f) { 77 JSAMPROW row_pointer[1]; 64 78 65 79 // allocate memory for 1 row 66 row = cc3_malloc_rows(1); 67 if(row==NULL) printf( "FUCK, out of memory!\n" ); 68 } 69 70 static void capture_current_jpeg(FILE *f) { 71 JSAMPROW row_pointer[1]; 72 row_pointer[0] = row; 80 row_pointer[0] = cc3_malloc_rows(1); 81 if (row_pointer[0] == NULL) { 82 return; 83 } 73 84 74 85 // output is file 75 jpeg_stdio_dest(&c info, f);86 jpeg_stdio_dest(&cj->cinfo, f); 76 87 77 88 // capture a frame to the FIFO … … 79 90 80 91 // read and compress 81 jpeg_start_compress(&c info, TRUE);82 while (c info.next_scanline <cinfo.image_height) {83 cc3_pixbuf_read_rows(row , 1);84 jpeg_write_scanlines(&c info, row_pointer, 1);92 jpeg_start_compress(&cj->cinfo, TRUE); 93 while (cj->cinfo.next_scanline < cj->cinfo.image_height) { 94 cc3_pixbuf_read_rows(row_pointer[0], 1); 95 jpeg_write_scanlines(&cj->cinfo, row_pointer, 1); 85 96 } 86 97 87 98 // finish 88 jpeg_finish_compress(&cinfo); 99 jpeg_finish_compress(&cj->cinfo); 100 101 free(row_pointer[0]); 89 102 } 90 103 91 104 92 93 static void destroy_jpeg(void) { 94 jpeg_destroy_compress(&cinfo); 95 free(row); 105 static void destroy_jpeg(cc3_jpeg_t *cj) { 106 jpeg_destroy_compress(&cj->cinfo); 107 free(cj); 96 108 }
