]> git.imager.perl.org - imager.git/blobdiff - JPEG/imjpeg.c
add write failure diagnostics for 250-draw/010-draw.t
[imager.git] / JPEG / imjpeg.c
index c9787bd5ba51cead5df37cf16caebbfc4258b7bb..dcb0ed639c3683cf78315376c2d6e14f9b330f03 100644 (file)
@@ -42,6 +42,9 @@ Reads and writes JPEG images
 
 #define JPEG_DIM_MAX JPEG_MAX_DIMENSION
 
 
 #define JPEG_DIM_MAX JPEG_MAX_DIMENSION
 
+#define _STRINGIFY(x) #x
+#define STRINGIFY(x) _STRINGIFY(x)
+
 static unsigned char fake_eoi[]={(JOCTET) 0xFF,(JOCTET) JPEG_EOI};
 
 /* Source and Destination managers */
 static unsigned char fake_eoi[]={(JOCTET) 0xFF,(JOCTET) JPEG_EOI};
 
 /* Source and Destination managers */
@@ -215,7 +218,7 @@ wiol_empty_output_buffer(j_compress_ptr cinfo) {
 
   if (rc != JPGS) { /* XXX: Should raise some jpeg error */
     myfree(dest->buffer);
 
   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;
     ERREXIT(cinfo, JERR_FILE_WRITE);
   }
   dest->pub.free_in_buffer = JPGS;
@@ -337,6 +340,25 @@ transfer_gray(i_color *out, JSAMPARRAY in, int width) {
 
 typedef void (*transfer_function_t)(i_color *out, JSAMPARRAY in, int width);
 
 
 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)
 
 /*
 =item i_readjpeg_wiol(data, length, iptc_itext, itlength)
 
@@ -525,7 +547,7 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
 
   i_tags_set(&im->tags, "i_format", "jpeg", 4);
 
 
   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;
 }
 
   return im;
 }
 
@@ -544,6 +566,7 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
   int comment_entry;
   int want_channels = im->channels;
   int progressive = 0;
   int comment_entry;
   int want_channels = im->channels;
   int progressive = 0;
+  int optimize = 0;
 
   struct jpeg_compress_struct cinfo;
   struct my_error_mgr jerr;
 
   struct jpeg_compress_struct cinfo;
   struct my_error_mgr jerr;
@@ -605,6 +628,9 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
   if (progressive) {
     jpeg_simple_progression(&cinfo);
   }
   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);
 
   got_xres = i_tags_get_float(&im->tags, "i_xres", 0, &xres);
   got_yres = i_tags_get_float(&im->tags, "i_yres", 0, &yres);