]> git.imager.perl.org - imager.git/blobdiff - jpeg.c
switch to Test::More in a few more test scripts, eliminate the
[imager.git] / jpeg.c
diff --git a/jpeg.c b/jpeg.c
index ab32e3df2c674e3cdeeff584d5780c9332cc8689..90573b7ae7716e642ccbf5b875111cdb71bd3d3c 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -427,11 +427,25 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
   channels = cinfo.output_components;
   switch (cinfo.out_color_space) {
   case JCS_GRAYSCALE:
+    if (cinfo.output_components != 1) {
+      mm_log((1, "i_readjpeg: grayscale image with %d channels\n", cinfo.output_components));
+      i_push_errorf(0, "grayscale image with invalid components %d", cinfo.output_components);
+      wiol_term_source(&cinfo);
+      jpeg_destroy_decompress(&cinfo);
+      return NULL;
+    }
     transfer_f = transfer_gray;
     break;
   
   case JCS_RGB:
     transfer_f = transfer_rgb;
+    if (cinfo.output_components != 3) {
+      mm_log((1, "i_readjpeg: RGB image with %d channels\n", cinfo.output_components));
+      i_push_errorf(0, "RGB image with invalid components %d", cinfo.output_components);
+      wiol_term_source(&cinfo);
+      jpeg_destroy_decompress(&cinfo);
+      return NULL;
+    }
     break;
 
   case JCS_CMYK:
@@ -489,7 +503,7 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
   markerp = cinfo.marker_list;
   while (markerp != NULL) {
     if (markerp->marker == JPEG_COM) {
-      i_tags_add(&im->tags, "jpeg_comment", 0, markerp->data,
+      i_tags_add(&im->tags, "jpeg_comment", 0, (const char *)markerp->data,
                 markerp->data_length, 0);
     }
 #ifdef IMEXIF_ENABLE
@@ -630,7 +644,8 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) {
   jpeg_start_compress(&cinfo, TRUE);
 
   if (i_tags_find(&im->tags, "jpeg_comment", 0, &comment_entry)) {
-    jpeg_write_marker(&cinfo, JPEG_COM, im->tags.tags[comment_entry].data,
+    jpeg_write_marker(&cinfo, JPEG_COM, 
+                      (const JOCTET *)im->tags.tags[comment_entry].data,
                      im->tags.tags[comment_entry].size);
   }