plug-ins: port grid to GEGL, stupid 8-bit port only

This commit is contained in:
Michael Natterer 2019-07-10 12:43:27 +02:00
parent eaed92e7a0
commit 0326a3e79a
3 changed files with 104 additions and 76 deletions

View File

@ -1398,6 +1398,7 @@ grid_LDADD = \
$(libgimpcolor) \ $(libgimpcolor) \
$(libgimpbase) \ $(libgimpbase) \
$(GTK_LIBS) \ $(GTK_LIBS) \
$(GEGL_LIBS) \
$(RT_LIBS) \ $(RT_LIBS) \
$(INTLLIBS) \ $(INTLLIBS) \
$(grid_RC) $(grid_RC)

View File

@ -65,10 +65,10 @@ static guchar best_cmap_match (const guchar *cmap,
gint ncolors, gint ncolors,
const GimpRGB *color); const GimpRGB *color);
static void grid (gint32 image_ID, static void grid (gint32 image_ID,
GimpDrawable *drawable, gint32 drawable_ID,
GimpPreview *preview); GimpPreview *preview);
static gint dialog (gint32 image_ID, static gint dialog (gint32 image_ID,
GimpDrawable *drawable); gint32 drawable_ID);
const GimpPlugInInfo PLUG_IN_INFO = const GimpPlugInInfo PLUG_IN_INFO =
{ {
@ -162,19 +162,20 @@ run (const gchar *name,
GimpParam **return_vals) GimpParam **return_vals)
{ {
static GimpParam values[1]; static GimpParam values[1];
GimpDrawable *drawable;
gint32 image_ID; gint32 image_ID;
gint32 drawable_ID;
GimpRunMode run_mode; GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N ();
gegl_init (NULL, NULL);
*nreturn_vals = 1; *nreturn_vals = 1;
*return_vals = values; *return_vals = values;
INIT_I18N (); run_mode = param[0].data.d_int32;
image_ID = param[1].data.d_int32;
run_mode = param[0].data.d_int32; drawable_ID = param[2].data.d_drawable;
image_ID = param[1].data.d_int32;
drawable = gimp_drawable_get (param[2].data.d_drawable);
if (run_mode == GIMP_RUN_NONINTERACTIVE) if (run_mode == GIMP_RUN_NONINTERACTIVE)
{ {
@ -224,7 +225,7 @@ run (const gchar *name,
if (run_mode == GIMP_RUN_INTERACTIVE) if (run_mode == GIMP_RUN_INTERACTIVE)
{ {
if (!dialog (image_ID, drawable)) if (! dialog (image_ID, drawable_ID))
{ {
/* The dialog was closed, or something similarly evil happened. */ /* The dialog was closed, or something similarly evil happened. */
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
@ -239,20 +240,17 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
gimp_progress_init (_("Drawing grid")); gimp_progress_init (_("Drawing grid"));
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
grid (image_ID, drawable, NULL); grid (image_ID, drawable_ID, NULL);
if (run_mode != GIMP_RUN_NONINTERACTIVE) if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush (); gimp_displays_flush ();
if (run_mode == GIMP_RUN_INTERACTIVE) if (run_mode == GIMP_RUN_INTERACTIVE)
gimp_set_data (PLUG_IN_PROC, &grid_cfg, sizeof (grid_cfg)); gimp_set_data (PLUG_IN_PROC, &grid_cfg, sizeof (grid_cfg));
gimp_drawable_detach (drawable);
} }
values[0].type = GIMP_PDB_STATUS; values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status; values[0].data.d_status = status;
} }
@ -325,22 +323,26 @@ pix_composite (guchar *p1,
} }
static void static void
grid (gint32 image_ID, grid (gint32 image_ID,
GimpDrawable *drawable, gint32 drawable_ID,
GimpPreview *preview) GimpPreview *preview)
{ {
GimpPixelRgn srcPR, destPR; GeglBuffer *src_buffer;
gint bytes; GeglBuffer *dest_buffer;
gint x_offset, y_offset; const Babl *format;
guchar *dest, *buffer = NULL; gint bytes;
gint x, y; gint x_offset;
gboolean alpha; gint y_offset;
gboolean blend; guchar *dest;
guchar hcolor[4]; guchar *buffer = NULL;
guchar vcolor[4]; gint x, y;
guchar icolor[4]; gboolean alpha;
guchar *cmap; gboolean blend;
gint ncolors; guchar hcolor[4];
guchar vcolor[4];
guchar icolor[4];
guchar *cmap;
gint ncolors;
gimp_rgba_get_uchar (&grid_cfg.hcolor, gimp_rgba_get_uchar (&grid_cfg.hcolor,
hcolor, hcolor + 1, hcolor + 2, hcolor + 3); hcolor, hcolor + 1, hcolor + 2, hcolor + 3);
@ -349,10 +351,17 @@ grid (gint32 image_ID,
gimp_rgba_get_uchar (&grid_cfg.icolor, gimp_rgba_get_uchar (&grid_cfg.icolor,
icolor, icolor + 1, icolor + 2, icolor + 3); icolor, icolor + 1, icolor + 2, icolor + 3);
alpha = gimp_drawable_has_alpha (drawable_ID);
switch (gimp_image_base_type (image_ID)) switch (gimp_image_base_type (image_ID))
{ {
case GIMP_RGB: case GIMP_RGB:
blend = TRUE; blend = TRUE;
if (alpha)
format = babl_format ("R'G'B'A u8");
else
format = babl_format ("R'G'B' u8");
break; break;
case GIMP_GRAY: case GIMP_GRAY:
@ -360,6 +369,11 @@ grid (gint32 image_ID,
vcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.vcolor); vcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.vcolor);
icolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.icolor); icolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.icolor);
blend = TRUE; blend = TRUE;
if (alpha)
format = babl_format ("Y'A u8");
else
format = babl_format ("Y' u8");
break; break;
case GIMP_INDEXED: case GIMP_INDEXED:
@ -371,6 +385,8 @@ grid (gint32 image_ID,
g_free (cmap); g_free (cmap);
blend = FALSE; blend = FALSE;
format = gimp_drawable_get_format (drawable_ID);
break; break;
default: default:
@ -378,8 +394,7 @@ grid (gint32 image_ID,
blend = FALSE; blend = FALSE;
} }
bytes = drawable->bpp; bytes = babl_format_get_bytes_per_pixel (format);
alpha = gimp_drawable_has_alpha (drawable->drawable_id);
if (preview) if (preview)
{ {
@ -395,24 +410,25 @@ grid (gint32 image_ID,
{ {
gint w, h; gint w, h;
if (! gimp_drawable_mask_intersect (drawable->drawable_id, if (! gimp_drawable_mask_intersect (drawable_ID,
&sx1, &sy1, &w, &h)) &sx1, &sy1, &w, &h))
return; return;
sx2 = sx1 + w; sx2 = sx1 + w;
sy2 = sy1 + h; sy2 = sy1 + h;
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, w, h, TRUE, TRUE); dest_buffer = gimp_drawable_get_shadow_buffer (drawable_ID);
} }
gimp_pixel_rgn_init (&srcPR, src_buffer = gimp_drawable_get_buffer (drawable_ID);
drawable, 0, 0, sx2 - sx1, sy2 - sy1, FALSE, FALSE);
dest = g_new (guchar, (sx2 - sx1) * bytes); dest = g_new (guchar, (sx2 - sx1) * bytes);
for (y = sy1; y < sy2; y++) for (y = sy1; y < sy2; y++)
{ {
gimp_pixel_rgn_get_row (&srcPR, dest, sx1, y, (sx2 - sx1)); gegl_buffer_get (src_buffer, GEGL_RECTANGLE (sx1, y, sx2 - sx1, 1), 1.0,
format, dest,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
y_offset = y - grid_cfg.hoffset; y_offset = y - grid_cfg.hoffset;
while (y_offset < 0) while (y_offset < 0)
@ -492,7 +508,10 @@ grid (gint32 image_ID,
} }
else else
{ {
gimp_pixel_rgn_set_row (&destPR, dest, sx1, y, (sx2 - sx1)); gegl_buffer_set (dest_buffer,
GEGL_RECTANGLE (sx1, y, sx2 - sx1, 1), 0,
format, dest,
GEGL_AUTO_ROWSTRIDE);
if (y % 16 == 0) if (y % 16 == 0)
gimp_progress_update ((gdouble) y / (gdouble) (sy2 - sy1)); gimp_progress_update ((gdouble) y / (gdouble) (sy2 - sy1));
@ -501,6 +520,8 @@ grid (gint32 image_ID,
g_free (dest); g_free (dest);
g_object_unref (src_buffer);
if (preview) if (preview)
{ {
gimp_preview_draw_buffer (preview, buffer, bytes * (sx2 - sx1)); gimp_preview_draw_buffer (preview, buffer, bytes * (sx2 - sx1));
@ -509,9 +530,11 @@ grid (gint32 image_ID,
else else
{ {
gimp_progress_update (1.0); gimp_progress_update (1.0);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); g_object_unref (dest_buffer);
gimp_drawable_update (drawable->drawable_id,
gimp_drawable_merge_shadow (drawable_ID, TRUE);
gimp_drawable_update (drawable_ID,
sx1, sy1, sx2 - sx1, sy2 - sy1); sx1, sy1, sx2 - sx1, sy2 - sy1);
} }
} }
@ -557,11 +580,13 @@ update_values (void)
static void static void
update_preview (GimpPreview *preview, update_preview (GimpPreview *preview,
GimpDrawable *drawable) gpointer drawable_ID)
{ {
update_values (); update_values ();
grid (gimp_item_get_image (drawable->drawable_id), drawable, preview); grid (gimp_item_get_image (GPOINTER_TO_INT (drawable_ID)),
GPOINTER_TO_INT (drawable_ID),
preview);
} }
static void static void
@ -615,8 +640,8 @@ color_callback (GtkWidget *widget,
static gint static gint
dialog (gint32 image_ID, dialog (gint32 image_ID,
GimpDrawable *drawable) gint32 drawable_ID)
{ {
GimpColorConfig *config; GimpColorConfig *config;
GtkWidget *dlg; GtkWidget *dlg;
@ -626,19 +651,24 @@ dialog (gint32 image_ID,
GtkWidget *label; GtkWidget *label;
GtkWidget *preview; GtkWidget *preview;
GtkWidget *button; GtkWidget *button;
GtkWidget *width; GtkWidget *width;
GtkWidget *space; GtkWidget *space;
GtkWidget *offset; GtkWidget *offset;
GtkWidget *chain_button; GtkWidget *chain_button;
GimpUnit unit; GimpUnit unit;
gdouble xres; gint d_width;
gdouble yres; gint d_height;
gboolean run; gdouble xres;
gdouble yres;
gboolean run;
g_return_val_if_fail (main_dialog == NULL, FALSE); g_return_val_if_fail (main_dialog == NULL, FALSE);
gimp_ui_init (PLUG_IN_BINARY, TRUE); gimp_ui_init (PLUG_IN_BINARY, TRUE);
d_width = gimp_drawable_width (drawable_ID);
d_height = gimp_drawable_height (drawable_ID);
main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE, main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE,
NULL, 0, NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC, gimp_standard_help_func, PLUG_IN_PROC,
@ -665,13 +695,13 @@ dialog (gint32 image_ID,
main_vbox, TRUE, TRUE, 0); main_vbox, TRUE, TRUE, 0);
gtk_widget_show (main_vbox); gtk_widget_show (main_vbox);
preview = gimp_drawable_preview_new_from_drawable_id (drawable->drawable_id); preview = gimp_drawable_preview_new_from_drawable_id (drawable_ID);
gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
gtk_widget_show (preview); gtk_widget_show (preview);
g_signal_connect (preview, "invalidated", g_signal_connect (preview, "invalidated",
G_CALLBACK (update_preview), G_CALLBACK (update_preview),
drawable); GINT_TO_POINTER (drawable_ID));
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
@ -700,18 +730,17 @@ dialog (gint32 image_ID,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 2, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 2, xres, TRUE);
/* set the size (in pixels) that will be treated as 0% and 100% */ /* set the size (in pixels) that will be treated as 0% and 100% */
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 0, 0.0, d_height);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 1, 0.0, d_width);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 2, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 2, 0.0, d_width);
/* set upper and lower limits (in pixels) */ /* set upper and lower limits (in pixels) */
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 0, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 0, 0.0,
drawable->height); d_height);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 1, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 1, 0.0,
drawable->width); d_width);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 2, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 2, 0.0,
MAX (drawable->width, MAX (d_width, d_height));
drawable->height));
gtk_grid_set_column_spacing (GTK_GRID (width), 6); gtk_grid_set_column_spacing (GTK_GRID (width), 6);
/* initialize the values */ /* initialize the values */
@ -772,18 +801,17 @@ dialog (gint32 image_ID,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 2, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 2, xres, TRUE);
/* set the size (in pixels) that will be treated as 0% and 100% */ /* set the size (in pixels) that will be treated as 0% and 100% */
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 0, 0.0, d_height);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 1, 0.0, d_width);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 2, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 2, 0.0, d_width);
/* set upper and lower limits (in pixels) */ /* set upper and lower limits (in pixels) */
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 0, 1.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 0, 1.0,
drawable->height); d_height);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 1, 1.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 1, 1.0,
drawable->width); d_width);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 2, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 2, 0.0,
MAX (drawable->width, MAX (d_width, d_height));
drawable->height));
gtk_grid_set_column_spacing (GTK_GRID (space), 6); gtk_grid_set_column_spacing (GTK_GRID (space), 6);
/* initialize the values */ /* initialize the values */
@ -838,18 +866,17 @@ dialog (gint32 image_ID,
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 2, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 2, xres, TRUE);
/* set the size (in pixels) that will be treated as 0% and 100% */ /* set the size (in pixels) that will be treated as 0% and 100% */
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 0, 0.0, d_height);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 1, 0.0, d_width);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 2, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 2, 0.0, d_width);
/* set upper and lower limits (in pixels) */ /* set upper and lower limits (in pixels) */
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 0, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 0, 0.0,
drawable->height); d_height);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 1, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 1, 0.0,
drawable->width); d_width);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 2, 0.0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 2, 0.0,
MAX (drawable->width, MAX (d_width, d_height));
drawable->height));
gtk_grid_set_column_spacing (GTK_GRID (offset), 6); gtk_grid_set_column_spacing (GTK_GRID (offset), 6);
/* initialize the values */ /* initialize the values */

View File

@ -63,7 +63,7 @@
'filter-pack' => { ui => 1 }, 'filter-pack' => { ui => 1 },
'goat-exercise' => { gegl => 1 }, 'goat-exercise' => { gegl => 1 },
'gradient-map' => { gegl => 1 }, 'gradient-map' => { gegl => 1 },
'grid' => { ui => 1 }, 'grid' => { ui => 1, gegl => 1 },
'guillotine' => {}, 'guillotine' => {},
'hot' => { ui => 1 }, 'hot' => { ui => 1 },
'jigsaw' => { ui => 1, gegl => 1 }, 'jigsaw' => { ui => 1, gegl => 1 },