[gimp] plug-ins: port map-object to GEGL
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port map-object to GEGL
- Date: Tue, 9 Jul 2019 15:11:14 +0000 (UTC)
commit 75114b1c404805efb232f721b64947d0e89ec85a
Author: Michael Natterer <mitch gimp org>
Date: Tue Jul 9 17:10:45 2019 +0200
plug-ins: port map-object to GEGL
plug-ins/map-object/Makefile.am | 1 +
plug-ins/map-object/map-object-apply.c | 55 ++++++------
plug-ins/map-object/map-object-image.c | 152 +++++++++++----------------------
plug-ins/map-object/map-object-image.h | 45 +++++-----
plug-ins/map-object/map-object-main.c | 31 +++----
plug-ins/map-object/map-object-ui.c | 4 +-
plug-ins/map-object/map-object-ui.h | 2 +-
7 files changed, 113 insertions(+), 177 deletions(-)
---
diff --git a/plug-ins/map-object/Makefile.am b/plug-ins/map-object/Makefile.am
index f02568cbcf..b78b18b831 100644
--- a/plug-ins/map-object/Makefile.am
+++ b/plug-ins/map-object/Makefile.am
@@ -59,6 +59,7 @@ LDADD = \
$(libgimpmath) \
$(libgimpbase) \
$(GTK_LIBS) \
+ $(GEGL_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
$(map_object_RC)
diff --git a/plug-ins/map-object/map-object-apply.c b/plug-ins/map-object/map-object-apply.c
index abe886e546..0a2fb9baf6 100644
--- a/plug-ins/map-object/map-object-apply.c
+++ b/plug-ins/map-object/map-object-apply.c
@@ -133,13 +133,9 @@ init_compute (void)
for (i = 0; i < 6; i++)
{
- box_drawables[i] = gimp_drawable_get (mapvals.boxmap_id[i]);
+ box_drawable_ids[i] = mapvals.boxmap_id[i];
- gimp_pixel_rgn_init (&box_regions[i], box_drawables[i],
- 0, 0,
- box_drawables[i]->width,
- box_drawables[i]->height,
- FALSE, FALSE);
+ box_buffers[i] = gimp_drawable_get_buffer (box_drawable_ids[i]);
}
break;
@@ -174,16 +170,10 @@ init_compute (void)
for (i = 0; i < 2; i++)
{
- cylinder_drawables[i] =
- gimp_drawable_get (mapvals.cylindermap_id[i]);
-
- gimp_pixel_rgn_init (&cylinder_regions[i], cylinder_drawables[i],
- 0, 0,
- cylinder_drawables[i]->width,
- cylinder_drawables[i]->height,
- FALSE, FALSE);
- }
+ cylinder_drawable_ids[i] = mapvals.cylindermap_id[i];
+ cylinder_buffers[i] = gimp_drawable_get_buffer (cylinder_drawable_ids[i]);
+ }
break;
}
@@ -246,10 +236,13 @@ compute_image (void)
if (mapvals.create_new_image ||
mapvals.create_new_layer ||
(mapvals.transparent_background &&
- output_drawable->bpp != 4))
+ ! gimp_drawable_has_alpha (output_drawable_id)))
{
- gchar *layername[] = {_("Map to plane"), _("Map to sphere"), _("Map to box"),
- _("Map to cylinder"), _("Background")};
+ gchar *layername[] = {_("Map to plane"),
+ _("Map to sphere"),
+ _("Map to box"),
+ _("Map to cylinder"),
+ _("Background")};
new_layer_id = gimp_layer_new (new_image_id,
layername[mapvals.create_new_image ? 4 :
@@ -262,11 +255,10 @@ compute_image (void)
gimp_image_get_default_new_layer_mode (new_image_id));
insert_layer = TRUE;
- output_drawable = gimp_drawable_get (new_layer_id);
+ output_drawable_id = new_layer_id;
}
- gimp_pixel_rgn_init (&dest_region, output_drawable,
- 0, 0, width, height, TRUE, TRUE);
+ dest_buffer = gimp_drawable_get_shadow_buffer (output_drawable_id);
switch (mapvals.maptype)
{
@@ -284,7 +276,7 @@ compute_image (void)
break;
}
- if (mapvals.antialiasing == FALSE)
+ if (! mapvals.antialiasing)
{
for (ycount = 0; ycount < height; ycount++)
{
@@ -294,10 +286,11 @@ compute_image (void)
color = (* get_ray_color) (&p);
poke (xcount, ycount, &color, NULL);
- if ((progress_counter++ % width) == 0)
- gimp_progress_update ((gdouble) progress_counter /
- (gdouble) maxcounter);
+ progress_counter++;
}
+
+ gimp_progress_update ((gdouble) progress_counter /
+ (gdouble) maxcounter);
}
}
else
@@ -313,22 +306,22 @@ compute_image (void)
show_progress,
NULL);
}
+
gimp_progress_update (1.0);
- /* Update the region */
- /* ================= */
+ g_object_unref (source_buffer);
+ g_object_unref (dest_buffer);
- gimp_drawable_flush (output_drawable);
if (insert_layer)
gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0);
- gimp_drawable_merge_shadow (output_drawable->drawable_id, TRUE);
- gimp_drawable_update (output_drawable->drawable_id, 0, 0, width, height);
+
+ gimp_drawable_merge_shadow (output_drawable_id, TRUE);
+ gimp_drawable_update (output_drawable_id, 0, 0, width, height);
if (new_image_id != image_id)
{
gimp_display_new (new_image_id);
gimp_displays_flush ();
- gimp_drawable_detach (output_drawable);
}
gimp_image_undo_group_end (new_image_id);
diff --git a/plug-ins/map-object/map-object-image.c b/plug-ins/map-object/map-object-image.c
index e0d7edd056..1f16279909 100644
--- a/plug-ins/map-object/map-object-image.c
+++ b/plug-ins/map-object/map-object-image.c
@@ -23,23 +23,24 @@
#include "map-object-image.h"
-GimpDrawable *input_drawable, *output_drawable;
-GimpPixelRgn source_region,dest_region;
+gint32 input_drawable_id;
+gint32 output_drawable_id;
+GeglBuffer *source_buffer;
+GeglBuffer *dest_buffer;
-GimpDrawable *box_drawables[6];
-GimpPixelRgn box_regions[6];
+gint32 box_drawable_ids[6];
+GeglBuffer *box_buffers[6];
-GimpDrawable *cylinder_drawables[2];
-GimpPixelRgn cylinder_regions[2];
+gint32 cylinder_drawable_ids[2];
+GeglBuffer *cylinder_buffers[2];
guchar *preview_rgb_data = NULL;
gint preview_rgb_stride;
cairo_surface_t *preview_surface = NULL;
-glong maxcounter,old_depth,max_depth;
-gint imgtype,width,height,in_channels,out_channels,image_id;
+glong maxcounter, old_depth, max_depth;
+gint width, height, image_id;
GimpRGB background;
-gdouble oldthreshold;
gint border_x, border_y, border_w, border_h;
@@ -51,27 +52,14 @@ GimpRGB
peek (gint x,
gint y)
{
- static guchar data[4];
-
GimpRGB color;
- gimp_pixel_rgn_get_pixel (&source_region, data, x, y);
-
- color.r = (gdouble) (data[0]) / 255.0;
- color.g = (gdouble) (data[1]) / 255.0;
- color.b = (gdouble) (data[2]) / 255.0;
+ gegl_buffer_sample (source_buffer, x, y, NULL,
+ &color, babl_format ("R'G'B'A double"),
+ GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
- if (input_drawable->bpp == 4)
- {
- if (in_channels == 4)
- color.a = (gdouble) (data[3]) / 255.0;
- else
- color.a = 1.0;
- }
- else
- {
- color.a = 1.0;
- }
+ if (! babl_format_has_alpha (gegl_buffer_get_format (source_buffer)))
+ color.a = 1.0;
return color;
}
@@ -81,27 +69,14 @@ peek_box_image (gint image,
gint x,
gint y)
{
- static guchar data[4];
-
GimpRGB color;
- gimp_pixel_rgn_get_pixel (&box_regions[image], data, x, y);
-
- color.r = (gdouble) (data[0]) / 255.0;
- color.g = (gdouble) (data[1]) / 255.0;
- color.b = (gdouble) (data[2]) / 255.0;
+ gegl_buffer_sample (box_buffers[image], x, y, NULL,
+ &color, babl_format ("R'G'B'A double"),
+ GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
- if (box_drawables[image]->bpp == 4)
- {
- if (gimp_drawable_has_alpha (box_drawables[image]->drawable_id))
- color.a = (gdouble) (data[3]) / 255.0;
- else
- color.a = 1.0;
- }
- else
- {
- color.a = 1.0;
- }
+ if (! babl_format_has_alpha (gegl_buffer_get_format (box_buffers[image])))
+ color.a = 1.0;
return color;
}
@@ -111,27 +86,14 @@ peek_cylinder_image (gint image,
gint x,
gint y)
{
- static guchar data[4];
-
GimpRGB color;
- gimp_pixel_rgn_get_pixel (&cylinder_regions[image],data, x, y);
-
- color.r = (gdouble) (data[0]) / 255.0;
- color.g = (gdouble) (data[1]) / 255.0;
- color.b = (gdouble) (data[2]) / 255.0;
+ gegl_buffer_sample (cylinder_buffers[image], x, y, NULL,
+ &color, babl_format ("R'G'B'A double"),
+ GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
- if (cylinder_drawables[image]->bpp == 4)
- {
- if (gimp_drawable_has_alpha (cylinder_drawables[image]->drawable_id))
- color.a = (gdouble) (data[3]) / 255.0;
- else
- color.a = 1.0;
- }
- else
- {
- color.a = 1.0;
- }
+ if (! babl_format_has_alpha (gegl_buffer_get_format (cylinder_buffers[image])))
+ color.a = 1.0;
return color;
}
@@ -140,20 +102,21 @@ void
poke (gint x,
gint y,
GimpRGB *color,
- gpointer data)
+ gpointer user_data)
{
- static guchar col[4];
-
- gimp_rgba_get_uchar (color, &col[0], &col[1], &col[2], &col[3]);
-
- gimp_pixel_rgn_set_pixel (&dest_region, col, x, y);
+ gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (x, y, 1, 1), 0,
+ babl_format ("R'G'B'A double"), color,
+ GEGL_AUTO_ROWSTRIDE);
}
gint
checkbounds (gint x,
gint y)
{
- if (x < border_x || y < border_y || x >= border_x + border_w || y >= border_y + border_h)
+ if (x < border_x ||
+ y < border_y ||
+ x >= border_x + border_w ||
+ y >= border_y + border_h)
return FALSE;
else
return TRUE;
@@ -166,8 +129,8 @@ checkbounds_box_image (gint image,
{
gint w, h;
- w = box_drawables[image]->width;
- h = box_drawables[image]->height;
+ w = gegl_buffer_get_width (box_buffers[image]);
+ h = gegl_buffer_get_height (box_buffers[image]);
if (x < 0 || y < 0 || x >= w || y >= h)
return FALSE ;
@@ -182,8 +145,8 @@ checkbounds_cylinder_image (gint image,
{
gint w, h;
- w = cylinder_drawables[image]->width;
- h = cylinder_drawables[image]->height;
+ w = gegl_buffer_get_width (cylinder_buffers[image]);
+ h = gegl_buffer_get_height (cylinder_buffers[image]);
if (x < 0 || y < 0 || x >= w || y >= h)
return FALSE;
@@ -286,8 +249,8 @@ get_box_image_color (gint image,
gint x1, y1, x2, y2;
GimpRGB p[4];
- w = box_drawables[image]->width;
- h = box_drawables[image]->height;
+ w = gegl_buffer_get_width (box_buffers[image]);
+ h = gegl_buffer_get_height (box_buffers[image]);
x1 = (gint) ((u * (gdouble) w));
y1 = (gint) ((v * (gdouble) h));
@@ -318,8 +281,8 @@ get_cylinder_image_color (gint image,
gint x1, y1, x2, y2;
GimpRGB p[4];
- w = cylinder_drawables[image]->width;
- h = cylinder_drawables[image]->height;
+ w = gegl_buffer_get_width (cylinder_buffers[image]);
+ h = gegl_buffer_get_height (cylinder_buffers[image]);
x1 = (gint) ((u * (gdouble) w));
y1 = (gint) ((v * (gdouble) h));
@@ -346,30 +309,20 @@ get_cylinder_image_color (gint image,
/****************************************/
gint
-image_setup (GimpDrawable *drawable,
- gint interactive)
+image_setup (gint32 drawable_id,
+ gint interactive)
{
- /* Set the tile cache size */
- /* ======================= */
-
- gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) /
- gimp_tile_width ());
-
- /* Get some useful info on the input drawable */
- /* ========================================== */
+ input_drawable_id = drawable_id;
+ output_drawable_id = drawable_id;
- input_drawable = drawable;
- output_drawable = drawable;
-
- if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y,
+ if (! gimp_drawable_mask_intersect (drawable_id, &border_x, &border_y,
&border_w, &border_h))
return FALSE;
- width = input_drawable->width;
- height = input_drawable->height;
+ width = gimp_drawable_width (input_drawable_id);
+ height = gimp_drawable_height (input_drawable_id);
- gimp_pixel_rgn_init (&source_region, input_drawable,
- 0, 0, width, height, FALSE, FALSE);
+ source_buffer = gimp_drawable_get_buffer (input_drawable_id);
maxcounter = (glong) width * (glong) height;
@@ -383,13 +336,6 @@ image_setup (GimpDrawable *drawable,
gimp_rgb_set_alpha (&background, 1.0);
}
- /* Assume at least RGB */
- /* =================== */
-
- in_channels = 3;
- if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE)
- in_channels++;
-
if (interactive == TRUE)
{
preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24,
diff --git a/plug-ins/map-object/map-object-image.h b/plug-ins/map-object/map-object-image.h
index 4ce524c99a..189204b361 100644
--- a/plug-ins/map-object/map-object-image.h
+++ b/plug-ins/map-object/map-object-image.h
@@ -4,32 +4,31 @@
/* Externally visible variables */
/* ============================ */
-extern GimpDrawable *input_drawable, *output_drawable;
-extern GimpPixelRgn source_region,dest_region;
+extern gint32 input_drawable_id;
+extern gint32 output_drawable_id;
+extern GeglBuffer *source_buffer;
+extern GeglBuffer *dest_buffer;
-extern GimpDrawable *box_drawables[6];
-extern GimpPixelRgn box_regions[6];
+extern gint32 box_drawable_ids[6];
+extern GeglBuffer *box_buffers[6];
-extern GimpDrawable *cylinder_drawables[2];
-extern GimpPixelRgn cylinder_regions[2];
+extern gint32 cylinder_drawable_ids[2];
+extern GeglBuffer *cylinder_buffers[2];
extern guchar *preview_rgb_data;
extern gint preview_rgb_stride;
extern cairo_surface_t *preview_surface;
-extern glong maxcounter, old_depth, max_depth;
-extern gint imgtype, width,height, in_channels, out_channels, image_id;
+extern glong maxcounter, old_depth, max_depth;
+extern gint width, height, image_id;
extern GimpRGB background;
-extern gdouble oldthreshold;
extern gint border_x1, border_y1, border_x2, border_y2;
-extern GimpTile *current_in_tile, *current_out_tile;
-
/* Externally visible functions */
/* ============================ */
-extern gint image_setup (GimpDrawable *drawable,
+extern gint image_setup (gint32 drawable_id,
gint interactive);
extern glong in_xy_to_index (gint x,
gint y);
@@ -37,12 +36,12 @@ extern glong out_xy_to_index (gint x,
gint y);
extern gint checkbounds (gint x,
gint y);
-extern GimpRGB peek (gint x,
+extern GimpRGB peek (gint x,
gint y);
extern void poke (gint x,
gint y,
GimpRGB *color,
- gpointer data);
+ gpointer user_data);
extern GimpVector3 int_to_pos (gint x,
gint y);
extern void pos_to_int (gdouble x,
@@ -50,14 +49,14 @@ extern void pos_to_int (gdouble x,
gint *scr_x,
gint *scr_y);
-extern GimpRGB get_image_color (gdouble u,
- gdouble v,
- gint *inside);
-extern GimpRGB get_box_image_color (gint image,
- gdouble u,
- gdouble v);
-extern GimpRGB get_cylinder_image_color (gint image,
- gdouble u,
- gdouble v);
+extern GimpRGB get_image_color (gdouble u,
+ gdouble v,
+ gint *inside);
+extern GimpRGB get_box_image_color (gint image,
+ gdouble u,
+ gdouble v);
+extern GimpRGB get_cylinder_image_color (gint image,
+ gdouble u,
+ gdouble v);
#endif /* __MAPOBJECT_IMAGE_H__ */
diff --git a/plug-ins/map-object/map-object-main.c b/plug-ins/map-object/map-object-main.c
index 624f5fab7d..6bf3d94c6f 100644
--- a/plug-ins/map-object/map-object-main.c
+++ b/plug-ins/map-object/map-object-main.c
@@ -101,7 +101,7 @@ set_default_settings (void)
}
static void
-check_drawables (GimpDrawable *drawable)
+check_drawables (gint32 drawable_id)
{
gint i;
@@ -113,7 +113,7 @@ check_drawables (GimpDrawable *drawable)
if (mapvals.boxmap_id[i] == -1 ||
!gimp_item_is_valid (mapvals.boxmap_id[i]) ||
gimp_drawable_is_gray (mapvals.boxmap_id[i]))
- mapvals.boxmap_id[i] = drawable->drawable_id;
+ mapvals.boxmap_id[i] = drawable_id;
}
/* Check that cylindermap images are valid */
@@ -124,7 +124,7 @@ check_drawables (GimpDrawable *drawable)
if (mapvals.cylindermap_id[i] == -1 ||
!gimp_item_is_valid (mapvals.cylindermap_id[i]) ||
gimp_drawable_is_gray (mapvals.cylindermap_id[i]))
- mapvals.cylindermap_id[i] = drawable->drawable_id;
+ mapvals.cylindermap_id[i] = drawable_id;
}
}
@@ -207,13 +207,11 @@ run (const gchar *name,
GimpParam **return_vals)
{
static GimpParam values[1];
- GimpDrawable *drawable;
- GimpRunMode run_mode;
+ GimpRunMode run_mode;
+ gint32 drawable_id;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint i;
- run_mode = param[0].data.d_int32;
-
INIT_I18N ();
values[0].type = GIMP_PDB_STATUS;
@@ -230,8 +228,9 @@ run (const gchar *name,
/* Get the specified drawable */
/* ========================== */
- image_id = param[1].data.d_int32;
- drawable = gimp_drawable_get (param[2].data.d_drawable);
+ run_mode = param[0].data.d_int32;
+ image_id = param[1].data.d_int32;
+ drawable_id = param[2].data.d_int32;
switch (run_mode)
{
@@ -241,8 +240,8 @@ run (const gchar *name,
/* ====================== */
gimp_get_data (PLUG_IN_PROC, &mapvals);
- check_drawables (drawable);
- if (main_dialog (drawable))
+ check_drawables (drawable_id);
+ if (main_dialog (drawable_id))
{
compute_image ();
@@ -252,8 +251,8 @@ run (const gchar *name,
case GIMP_RUN_WITH_LAST_VALS:
gimp_get_data (PLUG_IN_PROC, &mapvals);
- check_drawables (drawable);
- if (image_setup (drawable, FALSE))
+ check_drawables (drawable_id);
+ if (image_setup (drawable_id, FALSE))
compute_image ();
break;
@@ -310,8 +309,8 @@ run (const gchar *name,
for (i = 0; i < 2; i++)
mapvals.cylindermap_id[i] = param[47+i].data.d_drawable;
- check_drawables (drawable);
- if (image_setup (drawable, FALSE))
+ check_drawables (drawable_id);
+ if (image_setup (drawable_id, FALSE))
compute_image ();
}
break;
@@ -321,8 +320,6 @@ run (const gchar *name,
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
-
- gimp_drawable_detach (drawable);
}
const GimpPlugInInfo PLUG_IN_INFO =
diff --git a/plug-ins/map-object/map-object-ui.c b/plug-ins/map-object/map-object-ui.c
index bdf1798f56..03221d3be8 100644
--- a/plug-ins/map-object/map-object-ui.c
+++ b/plug-ins/map-object/map-object-ui.c
@@ -1293,7 +1293,7 @@ create_main_notebook (GtkWidget *container)
/********************************/
gboolean
-main_dialog (GimpDrawable *drawable)
+main_dialog (gint32 drawable_id)
{
GtkWidget *main_hbox;
GtkWidget *vbox;
@@ -1424,7 +1424,7 @@ main_dialog (GimpDrawable *drawable)
g_object_unref (cursor);
}
- image_setup (drawable, TRUE);
+ image_setup (drawable_id, TRUE);
compute_preview_image ();
diff --git a/plug-ins/map-object/map-object-ui.h b/plug-ins/map-object/map-object-ui.h
index 2c619ac130..69f6065a1a 100644
--- a/plug-ins/map-object/map-object-ui.h
+++ b/plug-ins/map-object/map-object-ui.h
@@ -9,6 +9,6 @@ extern GtkWidget *previewarea;
/* Externally visible functions */
/* ============================ */
-gboolean main_dialog (GimpDrawable *drawable);
+gboolean main_dialog (gint32 drawable_id);
#endif /* __MAPOBJECT_UI_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]