32 int RGB_2_JPEG(
unsigned char *buffer,
unsigned char **compressed,
long unsigned int *new_len,
int quality) {
33 struct jpeg_compress_struct cinfo = {0};
34 struct jpeg_error_mgr jerr;
41 cinfo.err = jpeg_std_error(&jerr);
42 jpeg_create_compress(&cinfo);
43 jpeg_mem_dest(&cinfo, compressed, new_len);
45 cinfo.image_width = 640;
46 cinfo.image_height = 480;
47 cinfo.input_components = 3;
48 cinfo.in_color_space = JCS_RGB;
50 jpeg_set_defaults(&cinfo);
51 jpeg_set_quality(&cinfo, quality,
TRUE);
52 jpeg_start_compress(&cinfo,
TRUE);
55 while (cinfo.next_scanline < cinfo.image_height) {
56 row_ptr[0] = &buffer[cinfo.next_scanline * row_stride];
57 jpeg_write_scanlines(&cinfo, row_ptr, 1);
60 jpeg_finish_compress(&cinfo);
61 jpeg_destroy_compress(&cinfo);
int RGB_2_JPEG(unsigned char *buffer, unsigned char **compressed, long unsigned int *new_len, int quality)