[gimp] file-jpeg: GEGL convert load functions



commit 51680fb987904de9fca8bae8f7ed5e8b20ef7028
Author: Mukund Sivaraman <muks banu com>
Date:   Mon May 13 11:39:45 2013 +0530

    file-jpeg: GEGL convert load functions
    
    drawable_global doesn't seem to be used anywhere. This commit removes
    it.

 plug-ins/file-jpeg/jpeg-load.c |   55 +++++++++++++++++++++-------------------
 plug-ins/file-jpeg/jpeg-save.c |    6 ----
 plug-ins/file-jpeg/jpeg.c      |    1 +
 plug-ins/file-jpeg/jpeg.h      |    1 -
 4 files changed, 30 insertions(+), 33 deletions(-)
---
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index 5a7d5f0..581e071 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -66,20 +66,15 @@ static void      jpeg_load_cmyk_to_rgb      (guchar   *buf,
                                              glong     pixels,
                                              gpointer  transform);
 
-
-GimpDrawable    *drawable_global;
 gint32 volatile  preview_image_ID;
 gint32           preview_layer_ID;
 
-
 gint32
 load_image (const gchar  *filename,
             GimpRunMode   runmode,
             gboolean      preview,
             GError      **error)
 {
-  GimpPixelRgn     pixel_rgn;
-  GimpDrawable    *drawable;
   gint32 volatile  image_ID;
   gint32           layer_ID;
   struct jpeg_decompress_struct cinfo;
@@ -88,8 +83,9 @@ load_image (const gchar  *filename,
   FILE            *infile;
   guchar          *buf;
   guchar         **rowbuf;
-  gint             image_type;
-  gint             layer_type;
+  GimpImageBaseType image_type;
+  GimpImageType    layer_type;
+  GeglBuffer      *buffer;
   gint             tile_height;
   gint             scanlines;
   gint             i, start, end;
@@ -258,10 +254,6 @@ load_image (const gchar  *filename,
                                  layer_type, 100, GIMP_NORMAL_MODE);
     }
 
-  drawable_global = drawable = gimp_drawable_get (layer_ID);
-  gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
-                       drawable->width, drawable->height, TRUE, FALSE);
-
   if (! preview)
     {
       GString  *comment_buffer = NULL;
@@ -417,6 +409,9 @@ load_image (const gchar  *filename,
   /* Here we use the library's state variable cinfo.output_scanline as the
    * loop counter, so that we don't have to keep track ourselves.
    */
+
+  buffer = gimp_drawable_get_buffer (layer_ID);
+
   while (cinfo.output_scanline < cinfo.output_height)
     {
       start = cinfo.output_scanline;
@@ -429,11 +424,15 @@ load_image (const gchar  *filename,
         jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &rowbuf[i], 1);
 
       if (cinfo.out_color_space == JCS_CMYK)
-        jpeg_load_cmyk_to_rgb (buf, drawable->width * scanlines,
+        jpeg_load_cmyk_to_rgb (buf, cinfo.output_width * scanlines,
                                cmyk_transform);
 
-      gimp_pixel_rgn_set_rect (&pixel_rgn, buf,
-                               0, start, drawable->width, scanlines);
+      gegl_buffer_set (buffer,
+                       GEGL_RECTANGLE (0, start, cinfo.output_width, scanlines),
+                       0,
+                       NULL,
+                       buf,
+                       GEGL_AUTO_ROWSTRIDE);
 
       if (! preview && (cinfo.output_scanline % 32) == 0)
         gimp_progress_update ((gdouble) cinfo.output_scanline /
@@ -457,6 +456,8 @@ load_image (const gchar  *filename,
   /* This is an important step since it will release a good deal of memory. */
   jpeg_destroy_decompress (&cinfo);
 
+  g_object_unref (buffer);
+
   /* free up the temporary buffers */
   g_free (rowbuf);
   g_free (buf);
@@ -477,7 +478,6 @@ load_image (const gchar  *filename,
   if (! preview)
     {
       gimp_progress_update (1.0);
-      gimp_drawable_detach (drawable);
     }
 
   gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
@@ -661,15 +661,14 @@ load_thumbnail_image (const gchar   *filename,
 {
   gint32 volatile  image_ID;
   ExifData        *exif_data;
-  GimpPixelRgn     pixel_rgn;
-  GimpDrawable    *drawable;
   gint32           layer_ID;
   struct jpeg_decompress_struct cinfo;
   struct my_error_mgr           jerr;
   guchar          *buf;
   guchar         **rowbuf;
-  gint             image_type;
-  gint             layer_type;
+  GimpImageBaseType image_type;
+  GimpImageType    layer_type;
+  GeglBuffer      *buffer;
   gint             tile_height;
   gint             scanlines;
   gint             i, start, end;
@@ -822,16 +821,14 @@ load_thumbnail_image (const gchar   *filename,
                              cinfo.output_height,
                              layer_type, 100, GIMP_NORMAL_MODE);
 
-  drawable_global = drawable = gimp_drawable_get (layer_ID);
-  gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
-                       drawable->width, drawable->height, TRUE, FALSE);
-
   /* Step 6: while (scan lines remain to be read) */
   /*           jpeg_read_scanlines(...); */
 
   /* Here we use the library's state variable cinfo.output_scanline as the
    * loop counter, so that we don't have to keep track ourselves.
    */
+  buffer = gimp_drawable_get_buffer (layer_ID);
+
   while (cinfo.output_scanline < cinfo.output_height)
     {
       start = cinfo.output_scanline;
@@ -843,10 +840,14 @@ load_thumbnail_image (const gchar   *filename,
         jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &rowbuf[i], 1);
 
       if (cinfo.out_color_space == JCS_CMYK)
-        jpeg_load_cmyk_to_rgb (buf, drawable->width * scanlines, NULL);
+        jpeg_load_cmyk_to_rgb (buf, cinfo.output_width * scanlines, NULL);
 
-      gimp_pixel_rgn_set_rect (&pixel_rgn, buf,
-                               0, start, drawable->width, scanlines);
+      gegl_buffer_set (buffer,
+                       GEGL_RECTANGLE (0, start, cinfo.output_width, scanlines),
+                       0,
+                       NULL,
+                       buf,
+                       GEGL_AUTO_ROWSTRIDE);
 
       gimp_progress_update ((gdouble) cinfo.output_scanline /
                             (gdouble) cinfo.output_height);
@@ -866,6 +867,8 @@ load_thumbnail_image (const gchar   *filename,
    */
   jpeg_destroy_decompress (&cinfo);
 
+  g_object_unref (buffer);
+
   /* free up the temporary buffers */
   g_free (rowbuf);
   g_free (buf);
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index 1c38561..21c3ba9 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -796,12 +796,6 @@ destroy_preview (void)
       g_source_remove (id);
     }
 
-  if (drawable_global)
-    {
-      gimp_drawable_detach (drawable_global);
-      drawable_global = NULL;
-    }
-
   if (gimp_image_is_valid (preview_image_ID) &&
       gimp_item_is_valid (preview_layer_ID))
     {
diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c
index 8afe283..bdfb70a 100644
--- a/plug-ins/file-jpeg/jpeg.c
+++ b/plug-ins/file-jpeg/jpeg.c
@@ -204,6 +204,7 @@ run (const gchar      *name,
   run_mode = param[0].data.d_int32;
 
   INIT_I18N ();
+  gegl_init (NULL, NULL);
 
   *nreturn_vals = 1;
   *return_vals  = values;
diff --git a/plug-ins/file-jpeg/jpeg.h b/plug-ins/file-jpeg/jpeg.h
index ed7c136..5cc0651 100644
--- a/plug-ins/file-jpeg/jpeg.h
+++ b/plug-ins/file-jpeg/jpeg.h
@@ -53,7 +53,6 @@ typedef enum
 
 extern gint32 volatile  preview_image_ID;
 extern gint32           preview_layer_ID;
-extern GimpDrawable    *drawable_global;
 extern gboolean         undo_touched;
 extern gboolean         load_interactive;
 extern gint32           display_ID;


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