]> git.imager.perl.org - imager.git/blobdiff - JPEG/imjpeg.c
correct an old bug link
[imager.git] / JPEG / imjpeg.c
index b1c97d208a788a4ae77c047a4ecdf6e14bb875cc..84d245037d1a31286130378245e6cfdb840c1e4f 100644 (file)
@@ -34,7 +34,6 @@ Reads and writes JPEG images
 #include "jerror.h"
 #include <errno.h>
 #include <stdlib.h>
-#include "imexif.h"
 
 #define JPEG_APP13       0xED    /* APP13 marker code */
 #define JPEG_APP1 (JPEG_APP0 + 1)
@@ -238,7 +237,7 @@ wiol_term_destination (j_compress_ptr cinfo) {
     ERREXIT(cinfo, JERR_FILE_WRITE);
   }
 
-  if (dest != NULL) myfree(dest->buffer);
+  myfree(dest->buffer);
 }
 
 
@@ -495,7 +494,11 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
                 markerp->data_length);
     }
     else if (markerp->marker == JPEG_APP1 && !seen_exif) {
-      seen_exif = i_int_decode_exif(im, markerp->data, markerp->data_length);
+      unsigned char *data = markerp->data;
+      size_t len = markerp->data_length;
+      if (len >= 6 && memcmp(data, "Exif\0\0", 6) == 0) {
+       seen_exif = im_decode_exif(im, data+6, len-6);
+      }
     }
     else if (markerp->marker == JPEG_APP13) {
       *iptc_itext = mymalloc(markerp->data_length);
@@ -566,6 +569,7 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
   int comment_entry;
   int want_channels = im->channels;
   int progressive = 0;
+  int optimize = 0;
 
   struct jpeg_compress_struct cinfo;
   struct my_error_mgr jerr;
@@ -627,6 +631,9 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
   if (progressive) {
     jpeg_simple_progression(&cinfo);
   }
+  if (!i_tags_get_int(&im->tags, "jpeg_optimize", 0, &optimize))
+    optimize = 0;
+  cinfo.optimize_coding = optimize;
 
   got_xres = i_tags_get_float(&im->tags, "i_xres", 0, &xres);
   got_yres = i_tags_get_float(&im->tags, "i_yres", 0, &yres);