18 int JPEG_compress(JSAMPLE *image_buffer,
long width,
long height,
19 unsigned char *jpeg_image_buffer,
long size,
int quality)
21 struct jpeg_compress_struct cinfo;
22 struct jpeg_error_mgr jerr;
23 JSAMPROW row_pointer[1];
27 cinfo.err = jpeg_std_error(&jerr);
29 jpeg_create_compress(&cinfo);
37 cinfo.image_width = width;
38 cinfo.image_height = height;
39 cinfo.input_components = 3;
40 cinfo.in_color_space = JCS_RGB;
42 jpeg_set_defaults(&cinfo);
43 jpeg_set_quality(&cinfo, quality,
TRUE );
45 jpeg_start_compress(&cinfo,
TRUE);
47 row_stride = width * 3;
49 while (cinfo.next_scanline < cinfo.image_height) {
50 row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
51 (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
54 jpeg_finish_compress(&cinfo);
55 jpeg_destroy_compress(&cinfo);
62 struct jpeg_error_mgr
pub;
74 (*cinfo->err->output_message) (cinfo);
80 long *width,
long *height ,
long *components)
81 {
struct jpeg_decompress_struct cinfo;
85 cinfo.err = jpeg_std_error(&jerr.
pub);
89 jpeg_destroy_decompress(&cinfo);
92 jpeg_create_decompress(&cinfo);
96 (void) jpeg_read_header(&cinfo,
TRUE);
98 jpeg_calc_output_dimensions(&cinfo);
100 *width= cinfo.output_width;
101 *height= cinfo.output_height;
102 *components= cinfo.output_components;
103 total_size = cinfo.output_width * cinfo.output_height *
104 cinfo.output_components;
106 jpeg_destroy_decompress(&cinfo);
112 JOCTET *result_image,
113 long *width,
long *height)
116 struct jpeg_decompress_struct cinfo;
122 cinfo.err = jpeg_std_error(&jerr.
pub);
126 jpeg_destroy_decompress(&cinfo);
129 jpeg_create_decompress(&cinfo);
133 (void) jpeg_read_header(&cinfo,
TRUE);
135 jpeg_calc_output_dimensions(&cinfo);
137 *width= cinfo.output_width;
138 *height= cinfo.output_height;
140 row_stride = cinfo.output_width * cinfo.output_components;
141 total_size = row_stride * cinfo.output_height;
151 (void) jpeg_start_decompress(&cinfo);
153 while (cinfo.output_scanline < cinfo.output_height) {
154 jsampbuf= &result_image[cinfo.output_scanline * row_stride];
155 (void) jpeg_read_scanlines(&cinfo, &jsampbuf, 1);
158 (void) jpeg_finish_decompress(&cinfo);
160 jpeg_destroy_decompress(&cinfo);