[gegl] jpg-load: Add support for grayscale JPEGs



commit 4e18f6d216c28745e8d9d16ada111e3aa2d9c94d
Author: Mukund Sivaraman <muks banu com>
Date:   Thu Sep 8 11:25:56 2011 +0530

    jpg-load: Add support for grayscale JPEGs

 operations/external/jpg-load.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/operations/external/jpg-load.c b/operations/external/jpg-load.c
index b98bf86..90d7286 100644
--- a/operations/external/jpg-load.c
+++ b/operations/external/jpg-load.c
@@ -91,9 +91,11 @@ gegl_jpg_load_buffer_import_jpg (GeglBuffer  *gegl_buffer,
   (void) jpeg_read_header (&cinfo, TRUE);
   (void) jpeg_start_decompress (&cinfo);
 
-  if (cinfo.output_components != 3)
+  if ((cinfo.output_components != 1) &&
+      (cinfo.output_components != 3))
     {
-      g_warning ("attempted to load non RGB JPEG");
+      g_warning ("attempted to load unsupported JPEG (components=%d)",
+                 cinfo.output_components);
       jpeg_destroy_decompress (&cinfo);
       return -1;
     }
@@ -117,8 +119,20 @@ gegl_jpg_load_buffer_import_jpg (GeglBuffer  *gegl_buffer,
       rect.height = 1;
 
       jpeg_read_scanlines (&cinfo, buffer, 1);
-      gegl_buffer_set (gegl_buffer, &rect, babl_format ("R'G'B' u8"), buffer[0],
-                       GEGL_AUTO_ROWSTRIDE);
+
+      switch (cinfo.output_components)
+        {
+        case 1:
+          gegl_buffer_set (gegl_buffer, &rect,
+                           babl_format ("Y' u8"), buffer[0],
+                           GEGL_AUTO_ROWSTRIDE);
+          break;
+        case 3:
+        default:
+          gegl_buffer_set (gegl_buffer, &rect,
+                           babl_format ("R'G'B' u8"), buffer[0],
+                           GEGL_AUTO_ROWSTRIDE);
+	}
     }
   jpeg_destroy_decompress (&cinfo);
   fclose (infile);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]