17 unsigned char *jpeg_image_buffer,
long size,
int quality)
19 struct jpeg_compress_struct cinfo;
20 struct jpeg_error_mgr jerr;
21 JSAMPROW row_pointer[1];
25 cinfo.err = jpeg_std_error(&jerr);
27 jpeg_create_compress(&cinfo);
35 cinfo.image_width = width;
36 cinfo.image_height = height;
37 cinfo.input_components = 3;
38 cinfo.in_color_space = JCS_RGB;
40 jpeg_set_defaults(&cinfo);
41 jpeg_set_quality(&cinfo, quality,
TRUE );
43 jpeg_start_compress(&cinfo,
TRUE);
45 row_stride = width * 3;
47 while (cinfo.next_scanline < cinfo.image_height) {
48 row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
49 (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
52 jpeg_finish_compress(&cinfo);
53 jpeg_destroy_compress(&cinfo);
60 struct jpeg_error_mgr
pub;
72 (*cinfo->err->output_message) (cinfo);
78 long *width,
long *height ,
long *components)
79 {
struct jpeg_decompress_struct cinfo;
83 cinfo.err = jpeg_std_error(&jerr.
pub);
87 jpeg_destroy_decompress(&cinfo);
90 jpeg_create_decompress(&cinfo);
94 (void) jpeg_read_header(&cinfo,
TRUE);
96 jpeg_calc_output_dimensions(&cinfo);
98 *width= cinfo.output_width;
99 *height= cinfo.output_height;
100 *components= cinfo.output_components;
101 total_size = cinfo.output_width * cinfo.output_height *
102 cinfo.output_components;
104 jpeg_destroy_decompress(&cinfo);
110 JOCTET *result_image,
111 long *width,
long *height)
114 struct jpeg_decompress_struct cinfo;
120 cinfo.err = jpeg_std_error(&jerr.
pub);
124 jpeg_destroy_decompress(&cinfo);
127 jpeg_create_decompress(&cinfo);
131 (void) jpeg_read_header(&cinfo,
TRUE);
133 jpeg_calc_output_dimensions(&cinfo);
135 *width= cinfo.output_width;
136 *height= cinfo.output_height;
138 row_stride = cinfo.output_width * cinfo.output_components;
139 total_size = row_stride * cinfo.output_height;
149 (void) jpeg_start_decompress(&cinfo);
151 while (cinfo.output_scanline < cinfo.output_height) {
152 jsampbuf= &result_image[cinfo.output_scanline * row_stride];
153 (void) jpeg_read_scanlines(&cinfo, &jsampbuf, 1);
156 (void) jpeg_finish_decompress(&cinfo);
158 jpeg_destroy_decompress(&cinfo);
static void my_error_exit(j_common_ptr cinfo)
int JPEG_compress(JSAMPLE *image_buffer, long width, long height, unsigned char *jpeg_image_buffer, long size, int quality)
jpeg_memio_dest(j_compress_ptr cinfo, JOCTET *jpegimgbuf, long *size)
int JPEG_header(JOCTET *jpeg_image, long jpeg_size, long *width, long *height, long *components)
struct jpeg_error_mgr pub
jpeg_memio_src(j_decompress_ptr cinfo, JOCTET *buf, long size)
struct my_error_mgr * my_error_ptr
int JPEG_decompress(JOCTET *jpeg_image, long jpeg_size, JOCTET *result_image, long *width, long *height)