[gimp/goat-invasion: 410/526] app: factor out GimpPlugIn's tile access emulation code to app/gegl/



commit 0b274fdbc7ee061934a2c02a5bc1413c721570a9
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 2 22:47:46 2012 +0200

    app: factor out GimpPlugIn's tile access emulation code to app/gegl/
    
    so it can be used to access a GeglBuffer's "tiles" in the XCF code.

 app/gegl/Makefile.am             |    2 +
 app/gegl/gimp-gegl-tile-compat.c |   70 ++++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-tile-compat.h |   32 +++++++++++++++++
 app/plug-in/gimpplugin-message.c |   56 ++++++------------------------
 4 files changed, 116 insertions(+), 44 deletions(-)
---
diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am
index f445f88..1f2c260 100644
--- a/app/gegl/Makefile.am
+++ b/app/gegl/Makefile.am
@@ -26,6 +26,8 @@ libappgegl_a_sources = \
 	gimp-gegl-loops.h			\
 	gimp-gegl-nodes.c			\
 	gimp-gegl-nodes.h			\
+	gimp-gegl-tile-compat.c			\
+	gimp-gegl-tile-compat.h			\
 	gimp-gegl-utils.c			\
 	gimp-gegl-utils.h			\
 	gimptilebackendtilemanager.c		\
diff --git a/app/gegl/gimp-gegl-tile-compat.c b/app/gegl/gimp-gegl-tile-compat.c
new file mode 100644
index 0000000..b9b08b8
--- /dev/null
+++ b/app/gegl/gimp-gegl-tile-compat.c
@@ -0,0 +1,70 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-gegl-tile-compat.h
+ * Copyright (C) 2012 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include "gimp-gegl-types.h"
+
+#include "gimp-gegl-tile-compat.h"
+
+
+gboolean
+gimp_gegl_buffer_get_tile_rect (GeglBuffer    *buffer,
+                                gint           tile_width,
+                                gint           tile_height,
+                                gint           tile_num,
+                                GeglRectangle *rect)
+{
+  gint n_tile_rows;
+  gint n_tile_columns;
+  gint tile_row;
+  gint tile_column;
+
+  n_tile_rows =
+    (gegl_buffer_get_height (buffer) + tile_height - 1) /
+    tile_height;
+
+  n_tile_columns =
+    (gegl_buffer_get_width (buffer) + tile_width - 1) /
+    tile_width;
+
+  if (tile_num > n_tile_rows * n_tile_columns - 1)
+    return FALSE;
+
+  tile_row    = tile_num / n_tile_columns;
+  tile_column = tile_num % n_tile_columns;
+
+  rect->x = tile_column * tile_width;
+  rect->y = tile_row    * tile_height;
+
+  if (tile_column == n_tile_columns - 1)
+    rect->width = gegl_buffer_get_width (buffer) - rect->x;
+  else
+    rect->width = tile_width;
+
+  if (tile_row == n_tile_rows - 1)
+    rect->height = gegl_buffer_get_height (buffer) - rect->y;
+  else
+    rect->height = tile_height;
+
+  return TRUE;
+}
diff --git a/app/gegl/gimp-gegl-tile-compat.h b/app/gegl/gimp-gegl-tile-compat.h
new file mode 100644
index 0000000..1d99852
--- /dev/null
+++ b/app/gegl/gimp-gegl-tile-compat.h
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-gegl-tile-compat.h
+ * Copyright (C) 2012 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_GEGL_TILE_COMPAT_H__
+#define __GIMP_GEGL_TILE_COMPAT_H__
+
+
+gboolean   gimp_gegl_buffer_get_tile_rect (GeglBuffer    *buffer,
+                                           gint           tile_width,
+                                           gint           tile_height,
+                                           gint           tile_num,
+                                           GeglRectangle *rect);
+
+
+#endif /* __GIMP_GEGL_TILE_COMPAT_H__ */
diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c
index 0e5e14a..8fd93ec 100644
--- a/app/plug-in/gimpplugin-message.c
+++ b/app/plug-in/gimpplugin-message.c
@@ -29,6 +29,8 @@
 
 #include "plug-in-types.h"
 
+#include "gegl/gimp-gegl-tile-compat.h"
+
 #include "core/gimp.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-shadow.h"
@@ -179,46 +181,6 @@ gimp_plug_in_handle_tile_request (GimpPlugIn *plug_in,
     gimp_plug_in_handle_tile_get (plug_in, request);
 }
 
-static gboolean
-gimp_plug_in_get_tile_rect (GeglBuffer    *buffer,
-                            gint           tile_num,
-                            GeglRectangle *rect)
-{
-  gint n_tile_rows;
-  gint n_tile_columns;
-  gint tile_row;
-  gint tile_column;
-
-  n_tile_rows =
-    (gegl_buffer_get_height (buffer) + GIMP_PLUG_IN_TILE_HEIGHT - 1) /
-    GIMP_PLUG_IN_TILE_HEIGHT;
-
-  n_tile_columns =
-    (gegl_buffer_get_width (buffer) + GIMP_PLUG_IN_TILE_WIDTH - 1) /
-    GIMP_PLUG_IN_TILE_WIDTH;
-
-  if (tile_num > n_tile_rows * n_tile_columns - 1)
-    return FALSE;
-
-  tile_row    = tile_num / n_tile_columns;
-  tile_column = tile_num % n_tile_columns;
-
-  rect->x = tile_column * GIMP_PLUG_IN_TILE_WIDTH;
-  rect->y = tile_row    * GIMP_PLUG_IN_TILE_HEIGHT;
-
-  if (tile_column == n_tile_columns - 1)
-    rect->width = gegl_buffer_get_width (buffer) - rect->x;
-  else
-    rect->width = GIMP_PLUG_IN_TILE_WIDTH;
-
-  if (tile_row == n_tile_rows - 1)
-    rect->height = gegl_buffer_get_height (buffer) - rect->y;
-  else
-    rect->height = GIMP_PLUG_IN_TILE_HEIGHT;
-
-  return TRUE;
-}
-
 static void
 gimp_plug_in_handle_tile_put (GimpPlugIn *plug_in,
                               GPTileReq  *request)
@@ -332,8 +294,11 @@ gimp_plug_in_handle_tile_put (GimpPlugIn *plug_in,
       buffer = gimp_drawable_get_buffer (drawable);
     }
 
-  if (! gimp_plug_in_get_tile_rect (buffer, tile_info->tile_num,
-                                    &tile_rect))
+  if (! gimp_gegl_buffer_get_tile_rect (buffer,
+                                        GIMP_PLUG_IN_TILE_WIDTH,
+                                        GIMP_PLUG_IN_TILE_HEIGHT,
+                                        tile_info->tile_num,
+                                        &tile_rect))
     {
       gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                     "Plug-In \"%s\"\n(%s)\n\n"
@@ -418,8 +383,11 @@ gimp_plug_in_handle_tile_get (GimpPlugIn *plug_in,
       buffer = gimp_drawable_get_buffer (drawable);
     }
 
-  if (! gimp_plug_in_get_tile_rect (buffer, request->tile_num,
-                                    &tile_rect))
+  if (! gimp_gegl_buffer_get_tile_rect (buffer,
+                                        GIMP_PLUG_IN_TILE_WIDTH,
+                                        GIMP_PLUG_IN_TILE_HEIGHT,
+                                        request->tile_num,
+                                        &tile_rect))
     {
       gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                     "Plug-In \"%s\"\n(%s)\n\n"



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