Lines 23-29
Link Here
|
23 |
#include <config.h> |
23 |
#include <config.h> |
24 |
#endif /* HAVE_CONFIG_H */ |
24 |
#endif /* HAVE_CONFIG_H */ |
25 |
|
25 |
|
26 |
#ifdef HAVE_JPEGLIB |
26 |
#ifdef SIMAGE_JPEG_SUPPORT |
27 |
|
27 |
|
28 |
#include <stdio.h> |
28 |
#include <stdio.h> |
29 |
#include <setjmp.h> |
29 |
#include <setjmp.h> |
Lines 74-80
simage_jpeg_error(char * buffer, int buflen)
Link Here
|
74 |
strncpy(buffer, "JPEG saver: Error opening file", buflen); |
74 |
strncpy(buffer, "JPEG saver: Error opening file", buflen); |
75 |
break; |
75 |
break; |
76 |
case ERR_JPEGLIB_WRITE: |
76 |
case ERR_JPEGLIB_WRITE: |
77 |
strncpy(buffer, "JPEG saver: Internal libjpeg error", buflen); |
77 |
strncpy(buffer, "JPEG saver: Internal libjpeg error", buflen); |
78 |
break; |
78 |
break; |
79 |
} |
79 |
} |
80 |
return jpegerror; |
80 |
return jpegerror; |
Lines 89-95
struct my_error_mgr {
Link Here
|
89 |
|
89 |
|
90 |
typedef struct my_error_mgr * my_error_ptr; |
90 |
typedef struct my_error_mgr * my_error_ptr; |
91 |
|
91 |
|
92 |
static void |
92 |
static void |
93 |
my_error_exit (j_common_ptr cinfo) |
93 |
my_error_exit (j_common_ptr cinfo) |
94 |
{ |
94 |
{ |
95 |
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ |
95 |
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ |
Lines 105-111
my_error_exit (j_common_ptr cinfo)
Link Here
|
105 |
longjmp(myerr->setjmp_buffer, 1); |
105 |
longjmp(myerr->setjmp_buffer, 1); |
106 |
} |
106 |
} |
107 |
|
107 |
|
108 |
int |
108 |
int |
109 |
simage_jpeg_identify(const char * ptr, |
109 |
simage_jpeg_identify(const char * ptr, |
110 |
const unsigned char *header, |
110 |
const unsigned char *header, |
111 |
int headerlen) |
111 |
int headerlen) |
Lines 113-121
simage_jpeg_identify(const char * ptr,
Link Here
|
113 |
static unsigned char jpgcmp[] = {'J', 'F', 'I', 'F' }; |
113 |
static unsigned char jpgcmp[] = {'J', 'F', 'I', 'F' }; |
114 |
static unsigned char jpgcmp2[] = {'E', 'x', 'i', 'f' }; |
114 |
static unsigned char jpgcmp2[] = {'E', 'x', 'i', 'f' }; |
115 |
if (headerlen < 10) return 0; |
115 |
if (headerlen < 10) return 0; |
116 |
if (memcmp((const void*)&header[6], |
116 |
if (memcmp((const void*)&header[6], |
117 |
(const void*)jpgcmp, 4) == 0) return 1; |
117 |
(const void*)jpgcmp, 4) == 0) return 1; |
118 |
if (memcmp((const void*)&header[6], |
118 |
if (memcmp((const void*)&header[6], |
119 |
(const void*)jpgcmp2, 4) == 0) return 1; |
119 |
(const void*)jpgcmp2, 4) == 0) return 1; |
120 |
return 0; |
120 |
return 0; |
121 |
} |
121 |
} |
Lines 215-221
simage_jpeg_load(const char *filename,
Link Here
|
215 |
format = 3; |
215 |
format = 3; |
216 |
cinfo.out_color_space = JCS_RGB; |
216 |
cinfo.out_color_space = JCS_RGB; |
217 |
} |
217 |
} |
218 |
|
218 |
|
219 |
(void) jpeg_start_decompress(&cinfo); |
219 |
(void) jpeg_start_decompress(&cinfo); |
220 |
/* We can ignore the return value since suspension is not possible |
220 |
/* We can ignore the return value since suspension is not possible |
221 |
* with the stdio data source. |
221 |
* with the stdio data source. |
Lines 234-253
simage_jpeg_load(const char *filename,
Link Here
|
234 |
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); |
234 |
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); |
235 |
width = cinfo.output_width; |
235 |
width = cinfo.output_width; |
236 |
height = cinfo.output_height; |
236 |
height = cinfo.output_height; |
237 |
buffer = currPtr = (unsigned char*) |
237 |
buffer = currPtr = (unsigned char*) |
238 |
malloc(width*height*cinfo.output_components); |
238 |
malloc(width*height*cinfo.output_components); |
239 |
|
239 |
|
240 |
/* Step 6: while (scan lines remain to be read) */ |
240 |
/* Step 6: while (scan lines remain to be read) */ |
241 |
/* jpeg_read_scanlines(...); */ |
241 |
/* jpeg_read_scanlines(...); */ |
242 |
|
242 |
|
243 |
/* Here we use the library's state variable cinfo.output_scanline as the |
243 |
/* Here we use the library's state variable cinfo.output_scanline as the |
244 |
* loop counter, so that we don't have to keep track ourselves. |
244 |
* loop counter, so that we don't have to keep track ourselves. |
245 |
*/ |
245 |
*/ |
246 |
|
246 |
|
247 |
/* flip image upside down */ |
247 |
/* flip image upside down */ |
248 |
if (buffer) { |
248 |
if (buffer) { |
249 |
currPtr = buffer + row_stride * (cinfo.output_height-1); |
249 |
currPtr = buffer + row_stride * (cinfo.output_height-1); |
250 |
|
250 |
|
251 |
while (cinfo.output_scanline < cinfo.output_height) { |
251 |
while (cinfo.output_scanline < cinfo.output_height) { |
252 |
/* jpeg_read_scanlines expects an array of pointers to scanlines. |
252 |
/* jpeg_read_scanlines expects an array of pointers to scanlines. |
253 |
* Here the array is only one element long, but you could ask for |
253 |
* Here the array is only one element long, but you could ask for |
Lines 293-299
simage_jpeg_load(const char *filename,
Link Here
|
293 |
return buffer; |
293 |
return buffer; |
294 |
} |
294 |
} |
295 |
|
295 |
|
296 |
int |
296 |
int |
297 |
simage_jpeg_save(const char * filename, |
297 |
simage_jpeg_save(const char * filename, |
298 |
const unsigned char * bytes, |
298 |
const unsigned char * bytes, |
299 |
int width, |
299 |
int width, |
Lines 321-327
simage_jpeg_save(const char * filename,
Link Here
|
321 |
int quality; |
321 |
int quality; |
322 |
unsigned char * tmpbytes; |
322 |
unsigned char * tmpbytes; |
323 |
int bytesperrow; |
323 |
int bytesperrow; |
324 |
|
324 |
|
325 |
quality = 90; |
325 |
quality = 90; |
326 |
tmpbytes = NULL; |
326 |
tmpbytes = NULL; |
327 |
|
327 |
|
Lines 375-381
simage_jpeg_save(const char * filename,
Link Here
|
375 |
/* |
375 |
/* |
376 |
* alpha channel is not supported for jpeg. strip it. |
376 |
* alpha channel is not supported for jpeg. strip it. |
377 |
*/ |
377 |
*/ |
378 |
|
378 |
|
379 |
if (numcomponents == 4) { |
379 |
if (numcomponents == 4) { |
380 |
unsigned char * dst; |
380 |
unsigned char * dst; |
381 |
const unsigned char * src; |
381 |
const unsigned char * src; |
Lines 383-390
simage_jpeg_save(const char * filename,
Link Here
|
383 |
dst = tmpbytes = (unsigned char *) malloc(n*3); |
383 |
dst = tmpbytes = (unsigned char *) malloc(n*3); |
384 |
src = bytes; |
384 |
src = bytes; |
385 |
for (i = 0; i < n; i++) { |
385 |
for (i = 0; i < n; i++) { |
386 |
*dst++ = *src++; |
386 |
*dst++ = *src++; |
387 |
*dst++ = *src++; |
387 |
*dst++ = *src++; |
388 |
*dst++ = *src++; |
388 |
*dst++ = *src++; |
389 |
src++; |
389 |
src++; |
390 |
} |
390 |
} |
Lines 397-403
simage_jpeg_save(const char * filename,
Link Here
|
397 |
dst = tmpbytes = (unsigned char *) malloc(n*3); |
397 |
dst = tmpbytes = (unsigned char *) malloc(n*3); |
398 |
src = bytes; |
398 |
src = bytes; |
399 |
for (i = 0; i < n; i++) { |
399 |
for (i = 0; i < n; i++) { |
400 |
*dst++ = *src++; |
400 |
*dst++ = *src++; |
401 |
src++; |
401 |
src++; |
402 |
} |
402 |
} |
403 |
numcomponents = 1; |
403 |
numcomponents = 1; |
Lines 408-414
simage_jpeg_save(const char * filename,
Link Here
|
408 |
/* First we supply a description of the input image. |
408 |
/* First we supply a description of the input image. |
409 |
* Four fields of the cinfo struct must be filled in: |
409 |
* Four fields of the cinfo struct must be filled in: |
410 |
*/ |
410 |
*/ |
411 |
|
411 |
|
412 |
cinfo.image_width = width; /* image width and height, in pixels */ |
412 |
cinfo.image_width = width; /* image width and height, in pixels */ |
413 |
cinfo.image_height = height; |
413 |
cinfo.image_height = height; |
414 |
cinfo.input_components = numcomponents; /* # of color components per pixel */ |
414 |
cinfo.input_components = numcomponents; /* # of color components per pixel */ |
Lines 468-471
simage_jpeg_save(const char * filename,
Link Here
|
468 |
return 1; |
468 |
return 1; |
469 |
} |
469 |
} |
470 |
|
470 |
|
471 |
#endif /* HAVE_JPEGLIB */ |
471 |
#endif /* SIMAGE_JPEG_SUPPORT */ |