Changeset 328

Show
Ignore:
Timestamp:
01/14/07 20:26:38 (2 years ago)
Author:
goodea
Message:

save more RAM

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/cc3_ilp/cc3_jpg.c

    r302 r328  
    2424#include <jpeglib.h> 
    2525 
     26typedef struct { 
     27  struct jpeg_compress_struct cinfo; 
     28  struct jpeg_error_mgr jerr; 
     29} cc3_jpeg_t; 
    2630 
    27 static void destroy_jpeg(void); 
    28 static void init_jpeg(void);  
    29 static void capture_current_jpeg(FILE *f);  
     31 
     32static void destroy_jpeg(cc3_jpeg_t *cj); 
     33static cc3_jpeg_t *init_jpeg (void); 
     34static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f); 
    3035 
    3136void cc3_jpeg_send_simple(void) { 
     37  // init jpeg 
     38  cc3_jpeg_t *cj = init_jpeg(); 
    3239 
     40  capture_current_jpeg(cj, stdout); 
    3341 
    34   // init jpeg 
    35   init_jpeg(); 
    36  
    37   capture_current_jpeg(stdout); 
    38  
    39   destroy_jpeg(); 
     42  destroy_jpeg(cj); 
    4043} 
    4144 
    4245 
    43 static struct jpeg_compress_struct cinfo; 
    44 static struct jpeg_error_mgr jerr; 
    4546 
    46 //static cc3_pixel_t *row; 
    47 uint8_t *row; 
     47static cc3_jpeg_t *init_jpeg(void) { 
     48  cc3_jpeg_t *cj = malloc(sizeof(cc3_jpeg_t)); 
     49  if (cj == NULL) { 
     50    return NULL; 
     51  } 
    4852 
    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); 
    5258 
    5359  // 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 
    5663  //printf( "image width=%d image height=%d\n", cinfo.image_width, cinfo.image_height ); 
    57   cinfo.input_components = 3; 
     64  cj->cinfo.input_components = 3; 
    5865 // cinfo.in_color_space = JCS_YCbCr; 
    59   cinfo.in_color_space = JCS_RGB; 
     66  cj->cinfo.in_color_space = JCS_RGB; 
    6067 
    6168  // 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 
     76static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f) { 
     77  JSAMPROW row_pointer[1]; 
    6478 
    6579  // 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  } 
    7384 
    7485  // output is file 
    75   jpeg_stdio_dest(&cinfo, f); 
     86  jpeg_stdio_dest(&cj->cinfo, f); 
    7687 
    7788  // capture a frame to the FIFO 
     
    7990 
    8091  // read and compress 
    81   jpeg_start_compress(&cinfo, TRUE); 
    82   while (cinfo.next_scanline < cinfo.image_height) { 
    83     cc3_pixbuf_read_rows(row, 1); 
    84     jpeg_write_scanlines(&cinfo, 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); 
    8596  } 
    8697 
    8798  // finish 
    88   jpeg_finish_compress(&cinfo); 
     99  jpeg_finish_compress(&cj->cinfo); 
     100 
     101  free(row_pointer[0]); 
    89102} 
    90103 
    91104 
    92  
    93 static void destroy_jpeg(void) { 
    94   jpeg_destroy_compress(&cinfo); 
    95   free(row); 
     105static void destroy_jpeg(cc3_jpeg_t *cj) { 
     106  jpeg_destroy_compress(&cj->cinfo); 
     107  free(cj); 
    96108}