#include <unistd.h>
#endif
#include <setjmp.h>
+#include <string.h>
#include "jpeglib.h"
#include "jerror.h"
#include <errno.h>
#include <stdlib.h>
-#include <stdio.h>
#include "imexif.h"
#define JPEG_APP13 0xED /* APP13 marker code */
#define JPEG_DIM_MAX JPEG_MAX_DIMENSION
-static unsigned char fake_eoi[]={(JOCTET) 0xFF,(JOCTET) JPEG_EOI};
-
-/* Bad design right here */
-
-static int tlength=0;
-static char **iptc_text=NULL;
+#define _STRINGIFY(x) #x
+#define STRINGIFY(x) _STRINGIFY(x)
+static unsigned char fake_eoi[]={(JOCTET) 0xFF,(JOCTET) JPEG_EOI};
/* Source and Destination managers */
-
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
io_glue *data;
typedef wiol_source_mgr *wiol_src_ptr;
typedef wiol_destination_mgr *wiol_dest_ptr;
-
/*
* Methods for io manager objects
*
mm_log((1,"wiol_fill_input_buffer(cinfo %p)\n", cinfo));
- nbytes = src->data->readcb(src->data, src->buffer, JPGS);
+ nbytes = i_io_read(src->data, src->buffer, JPGS);
if (nbytes <= 0) { /* Insert a fake EOI marker */
src->pub.next_input_byte = fake_eoi;
*/
mm_log((1,"wiol_empty_output_buffer(cinfo %p)\n", cinfo));
- rc = dest->data->writecb(dest->data, dest->buffer, JPGS);
+ rc = i_io_write(dest->data, dest->buffer, JPGS);
if (rc != JPGS) { /* XXX: Should raise some jpeg error */
myfree(dest->buffer);
- mm_log((1, "wiol_empty_output_buffer: Error: nbytes = %d != rc = %d\n", JPGS, rc));
+ mm_log((1, "wiol_empty_output_buffer: Error: nbytes = %d != rc = %d\n", JPGS, (int)rc));
ERREXIT(cinfo, JERR_FILE_WRITE);
}
dest->pub.free_in_buffer = JPGS;
/* yes, this needs to flush the buffer */
/* needs error handling */
- if (dest->data->writecb(dest->data, dest->buffer, nbytes) != nbytes) {
+ if (i_io_write(dest->data, dest->buffer, nbytes) != nbytes) {
myfree(dest->buffer);
ERREXIT(cinfo, JERR_FILE_WRITE);
}
-
+
if (dest != NULL) myfree(dest->buffer);
}
dest->pub.next_output_byte = dest->buffer;
}
-LOCAL(unsigned int)
-jpeg_getc (j_decompress_ptr cinfo)
-/* Read next byte */
-{
- struct jpeg_source_mgr * datasrc = cinfo->src;
-
- if (datasrc->bytes_in_buffer == 0) {
- if (! (*datasrc->fill_input_buffer) (cinfo))
- { fprintf(stderr,"Jpeglib: cant suspend.\n"); exit(3); }
- /* ERREXIT(cinfo, JERR_CANT_SUSPEND);*/
- }
- datasrc->bytes_in_buffer--;
- return GETJOCTET(*datasrc->next_input_byte++);
-}
-
-METHODDEF(boolean)
-APP13_handler (j_decompress_ptr cinfo) {
- INT32 length;
- unsigned int cnt=0;
-
- length = jpeg_getc(cinfo) << 8;
- length += jpeg_getc(cinfo);
- length -= 2; /* discount the length word itself */
-
- tlength=length;
-
- if ( ((*iptc_text)=mymalloc(length)) == NULL ) return FALSE;
- while (--length >= 0) (*iptc_text)[cnt++] = jpeg_getc(cinfo);
-
- return TRUE;
-}
-
METHODDEF(void)
my_output_message (j_common_ptr cinfo) {
char buffer[JMSG_LENGTH_MAX];
typedef void (*transfer_function_t)(i_color *out, JSAMPARRAY in, int width);
+static const char version_string[] =
+#ifdef LIBJPEG_TURBO_VERSION
+ "libjpeg-turbo " STRINGIFY(LIBJPEG_TURBO_VERSION) " api " STRINGIFY(JPEG_LIB_VERSION)
+#else
+ "libjpeg " STRINGIFY(JPEG_LIB_VERSION)
+#endif
+ ;
+
+/*
+=item i_libjpeg_version()
+
+=cut
+*/
+
+const char *
+i_libjpeg_version(void) {
+ return version_string;
+}
+
/*
=item i_readjpeg_wiol(data, length, iptc_itext, itlength)
i_clear_error();
- iptc_text = iptc_itext;
+ *iptc_itext = NULL;
+ *itlength = 0;
+
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
jerr.pub.output_message = my_output_message;
if (src_set)
wiol_term_source(&cinfo);
jpeg_destroy_decompress(&cinfo);
- *iptc_itext=NULL;
- *itlength=0;
if (line_buffer)
myfree(line_buffer);
if (im)
}
jpeg_create_decompress(&cinfo);
- jpeg_set_marker_processor(&cinfo, JPEG_APP13, APP13_handler);
+ jpeg_save_markers(&cinfo, JPEG_APP13, 0xFFFF);
jpeg_save_markers(&cinfo, JPEG_APP1, 0xFFFF);
jpeg_save_markers(&cinfo, JPEG_COM, 0xFFFF);
jpeg_wiol_src(&cinfo, data, length);
else if (markerp->marker == JPEG_APP1 && !seen_exif) {
seen_exif = i_int_decode_exif(im, markerp->data, markerp->data_length);
}
+ else if (markerp->marker == JPEG_APP13) {
+ *iptc_itext = mymalloc(markerp->data_length);
+ memcpy(*iptc_itext, markerp->data, markerp->data_length);
+ *itlength = markerp->data_length;
+ }
markerp = markerp->next;
}
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
- *itlength=tlength;
i_tags_set(&im->tags, "i_format", "jpeg", 4);
- mm_log((1,"i_readjpeg_wiol -> (0x%x)\n",im));
+ mm_log((1,"i_readjpeg_wiol -> (%p)\n",im));
return im;
}
jpeg_destroy_compress(&cinfo);
- ig->closecb(ig);
+ if (i_io_close(ig))
+ return 0;
return(1);
}