[gimp/gimp-2-10] plug-ins: port imagemap to GEGL
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] plug-ins: port imagemap to GEGL
- Date: Fri, 19 Jul 2019 15:25:13 +0000 (UTC)
commit a5e1eb85d8bdbe9b6575e64c5873374949b0f4ff
Author: Michael Natterer <mitch gimp org>
Date: Fri Jul 19 17:20:58 2019 +0200
plug-ins: port imagemap to GEGL
(cherry picked from commit 3c73d42e979fa8c3f4d3914fd9106545447d4c9a)
plug-ins/imagemap/Makefile.am | 1 +
plug-ins/imagemap/imap_cmd_gimp_guides.c | 24 +--
plug-ins/imagemap/imap_commands.h | 2 +-
plug-ins/imagemap/imap_main.c | 31 ++--
plug-ins/imagemap/imap_preview.c | 243 +++++--------------------------
plug-ins/imagemap/imap_preview.h | 5 +-
6 files changed, 67 insertions(+), 239 deletions(-)
---
diff --git a/plug-ins/imagemap/Makefile.am b/plug-ins/imagemap/Makefile.am
index 99f07552ff..f24ddb12e2 100644
--- a/plug-ins/imagemap/Makefile.am
+++ b/plug-ins/imagemap/Makefile.am
@@ -147,6 +147,7 @@ LDADD = \
$(libgimpmath) \
$(libgimpbase) \
$(GTK_LIBS) \
+ $(GEGL_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
$(imagemap)
diff --git a/plug-ins/imagemap/imap_cmd_gimp_guides.c b/plug-ins/imagemap/imap_cmd_gimp_guides.c
index 894ea3ffd9..3f8fdd21df 100644
--- a/plug-ins/imagemap/imap_cmd_gimp_guides.c
+++ b/plug-ins/imagemap/imap_cmd_gimp_guides.c
@@ -41,7 +41,7 @@ typedef struct {
DefaultDialog_t *dialog;
ObjectList_t *list;
- GimpDrawable *drawable;
+ gint32 drawable_id;
GtkWidget *alternate;
GtkWidget *all;
@@ -67,7 +67,7 @@ gimp_guides_ok_cb(gpointer data)
GSList *vguides, *vg;
gboolean all;
const gchar *url;
- gint32 image_ID = gimp_item_get_image (param->drawable->drawable_id);
+ gint32 image_ID = gimp_item_get_image (param->drawable_id);
/* First get some dialog values */
@@ -208,21 +208,21 @@ make_gimp_guides_dialog(void)
static void
init_gimp_guides_dialog(GimpGuidesDialog_t *dialog, ObjectList_t *list,
- GimpDrawable *drawable)
+ gint32 drawable_id)
{
dialog->list = list;
- dialog->drawable = drawable;
+ dialog->drawable_id = drawable_id;
}
static void
-do_create_gimp_guides_dialog(ObjectList_t *list, GimpDrawable *drawable)
+do_create_gimp_guides_dialog(ObjectList_t *list, gint32 drawable_id)
{
static GimpGuidesDialog_t *dialog;
if (!dialog)
dialog = make_gimp_guides_dialog();
- init_gimp_guides_dialog(dialog, list, drawable);
+ init_gimp_guides_dialog(dialog, list, drawable_id);
default_dialog_show(dialog->dialog);
}
@@ -236,17 +236,17 @@ static CommandClass_t gimp_guides_command_class = {
};
typedef struct {
- Command_t parent;
- ObjectList_t *list;
- GimpDrawable *drawable;
+ Command_t parent;
+ ObjectList_t *list;
+ gint32 drawable_id;
} GimpGuidesCommand_t;
Command_t*
-gimp_guides_command_new(ObjectList_t *list, GimpDrawable *drawable)
+gimp_guides_command_new(ObjectList_t *list, gint32 drawable_id)
{
GimpGuidesCommand_t *command = g_new(GimpGuidesCommand_t, 1);
command->list = list;
- command->drawable = drawable;
+ command->drawable_id = drawable_id;
return command_init(&command->parent, _("Use Gimp Guides"),
&gimp_guides_command_class);
}
@@ -255,6 +255,6 @@ static CmdExecuteValue_t
gimp_guides_command_execute(Command_t *parent)
{
GimpGuidesCommand_t *command = (GimpGuidesCommand_t*) parent;
- do_create_gimp_guides_dialog(command->list, command->drawable);
+ do_create_gimp_guides_dialog(command->list, command->drawable_id);
return CMD_DESTRUCT;
}
diff --git a/plug-ins/imagemap/imap_commands.h b/plug-ins/imagemap/imap_commands.h
index cfc4d397c0..af8637bc9e 100644
--- a/plug-ins/imagemap/imap_commands.h
+++ b/plug-ins/imagemap/imap_commands.h
@@ -37,7 +37,7 @@ Command_t *delete_command_new(ObjectList_t *list, Object_t *obj);
Command_t *delete_point_command_new(Object_t *obj, GdkPoint *point);
Command_t *edit_object_command_new(Object_t *obj);
Command_t *gimp_guides_command_new(ObjectList_t *list,
- GimpDrawable *_drawable);
+ gint32 _drawable_id);
Command_t *guides_command_new(ObjectList_t *list);
Command_t *insert_point_command_new(Object_t *obj, gint x, gint y, gint edge);
Command_t *move_down_command_new(ObjectList_t *list);
diff --git a/plug-ins/imagemap/imap_main.c b/plug-ins/imagemap/imap_main.c
index f0bba4c09c..8254a878aa 100644
--- a/plug-ins/imagemap/imap_main.c
+++ b/plug-ins/imagemap/imap_main.c
@@ -70,7 +70,7 @@ static PreferencesData_t _preferences = {CSIM, TRUE, FALSE, TRUE, TRUE, FALSE,
FALSE, TRUE, DEFAULT_UNDO_LEVELS, DEFAULT_MRU_SIZE};
static MRU_t *_mru;
-static GimpDrawable *_drawable;
+static gint32 _drawable_id;
static GdkCursorType _cursor = GDK_TOP_LEFT_ARROW;
static gboolean _show_url = TRUE;
static gchar *_filename = NULL;
@@ -93,7 +93,7 @@ static void run (const gchar *name,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
-static gint dialog (GimpDrawable *drawable);
+static gint dialog (gint32 drawable_id);
const GimpPlugInInfo PLUG_IN_INFO = {
NULL, /* init_proc */
@@ -140,37 +140,33 @@ run (const gchar *name,
GimpParam **return_vals)
{
static GimpParam values[1];
- GimpDrawable *drawable;
GimpRunMode run_mode;
+ gint32 drawable_id;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
INIT_I18N ();
+ gegl_init (NULL, NULL);
*nreturn_vals = 1;
*return_vals = values;
- /* Get the specified drawable */
- drawable = gimp_drawable_get(param[2].data.d_drawable);
- _drawable = drawable;
+ run_mode = param[0].data.d_int32;
+ drawable_id = param[2].data.d_drawable;
+
+ _drawable_id = drawable_id;
_image_name = gimp_image_get_name(param[1].data.d_image);
_image_width = gimp_image_width(param[1].data.d_image);
_image_height = gimp_image_height(param[1].data.d_image);
- _map_info.color = gimp_drawable_is_rgb(drawable->drawable_id);
-
- run_mode = (GimpRunMode) param[0].data.d_int32;
+ _map_info.color = gimp_drawable_is_rgb(drawable_id);
if (run_mode == GIMP_RUN_INTERACTIVE) {
- if (!dialog(drawable)) {
+ if (!dialog(drawable_id)) {
/* The dialog was closed, or something similarly evil happened. */
status = GIMP_PDB_EXECUTION_ERROR;
}
}
- if (status == GIMP_PDB_SUCCESS) {
- gimp_drawable_detach(drawable);
- }
-
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
@@ -1189,7 +1185,7 @@ do_send_to_back(void)
void
do_use_gimp_guides_dialog(void)
{
- command_execute (gimp_guides_command_new (_shapes, _drawable));
+ command_execute (gimp_guides_command_new (_shapes, _drawable_id));
}
void
@@ -1211,7 +1207,7 @@ factory_move_down(void)
}
static gint
-dialog(GimpDrawable *drawable)
+dialog(gint32 drawable_id)
{
GtkWidget *dlg;
GtkWidget *hbox;
@@ -1266,7 +1262,8 @@ dialog(GimpDrawable *drawable)
/* selection_set_edit_command(tools, factory_edit); */
gtk_box_pack_start(GTK_BOX(hbox), tools, FALSE, FALSE, 0);
- _preview = make_preview(drawable);
+ _preview = make_preview(drawable_id);
+
g_signal_connect(_preview->preview, "motion-notify-event",
G_CALLBACK(preview_move), NULL);
g_signal_connect(_preview->preview, "enter-notify-event",
diff --git a/plug-ins/imagemap/imap_preview.c b/plug-ins/imagemap/imap_preview.c
index f042fcd4a2..160a88df72 100644
--- a/plug-ins/imagemap/imap_preview.c
+++ b/plug-ins/imagemap/imap_preview.c
@@ -94,211 +94,46 @@ render_background(Preview_t *preview_base)
}
static void
-render_gray_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
+render_rgb_image (Preview_t *preview_base,
+ gint32 drawable_id)
{
- guchar *src_row, *dest_buffer, *dest;
- gint row, col;
- gint bpp, dwidth, dheight, pwidth, pheight;
- gint *src_col;
- GtkWidget *preview = preview_base->preview;
-
- dwidth = srcrgn->w;
- dheight = srcrgn->h;
- pwidth = preview_base->widget_width;
- pheight = preview_base->widget_height;
- bpp = srcrgn->bpp;
-
- src_row = g_new(guchar, dwidth * bpp);
- dest_buffer = g_new(guchar, pwidth * pheight);
- src_col = g_new(gint, pwidth);
-
- for (col = 0; col < pwidth; col++)
- src_col[col] = (col * dwidth / pwidth) * bpp;
-
- dest = dest_buffer;
-
- for (row = 0; row < pheight; row++) {
- gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
- dwidth);
-
- for (col = 0; col < pwidth; col++) {
- guchar *src;
- src = &src_row[src_col[col]];
- *dest++ = *src;
- }
- }
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
- 0, 0, pwidth, pheight,
- GIMP_GRAY_IMAGE,
- dest_buffer,
- pwidth);
- g_free(src_col);
- g_free(src_row);
- g_free(dest_buffer);
+ GeglBuffer *buffer;
+ guchar *dest_buffer;
+ gint dwidth, dheight, pwidth, pheight;
+ GtkWidget *preview = preview_base->preview;
-}
+ dwidth = gimp_drawable_width (drawable_id);
+ dheight = gimp_drawable_height (drawable_id);
+ pwidth = preview_base->widget_width;
+ pheight = preview_base->widget_height;
-static void
-render_indexed_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
-{
- guchar *src_row, *dest_buffer, *src, *dest;
- gint row, col;
- gint dwidth, dheight, pwidth, pheight;
- gint *src_col;
- gint bpp, alpha, has_alpha;
- guchar *cmap, *color;
- gint ncols;
- gboolean gray = get_map_info()->show_gray;
- GtkWidget *preview = preview_base->preview;
-
- dwidth = srcrgn->w;
- dheight = srcrgn->h;
- pwidth = preview_base->widget_width;
- pheight = preview_base->widget_height;
- bpp = srcrgn->bpp;
- alpha = bpp;
- has_alpha = gimp_drawable_has_alpha(srcrgn->drawable->drawable_id);
- if (has_alpha)
- alpha--;
-
- cmap = gimp_image_get_colormap (gimp_item_get_image (srcrgn->drawable->drawable_id),
- &ncols);
-
- src_row = g_new(guchar, dwidth * bpp);
- dest_buffer = g_new(guchar, pwidth * pheight * 3);
- src_col = g_new(gint, pwidth);
-
- for (col = 0; col < pwidth; col++)
- src_col[col] = (col * dwidth / pwidth) * bpp;
-
- dest = dest_buffer;
- for (row = 0; row < pheight; row++) {
- gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
- dwidth);
-
- for (col = 0; col < pwidth; col++) {
- src = &src_row[src_col[col]];
- color = cmap + 3 * (int)(*src);
-
- if (gray) {
- guchar avg = (299 * color[0] + 587 * color[1] +
- 114 * color[2]) / 1000;
- *dest++ = avg;
- *dest++ = avg;
- *dest++ = avg;
- } else {
- *dest++ = color[0];
- *dest++ = color[1];
- *dest++ = color[2];
- }
- }
- }
- gimp_preview_area_draw(GIMP_PREVIEW_AREA(preview),
+ dest_buffer = g_new (guchar, pwidth * pheight * 4);
+
+ buffer = gimp_drawable_get_buffer (drawable_id);
+
+ gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, pwidth, pheight),
+ MIN ((gdouble) pwidth / (gdouble) dwidth,
+ (gdouble) pheight / (gdouble) dheight),
+ babl_format ("R'G'B'A u8"), dest_buffer,
+ GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+
+ g_object_unref (buffer);
+
+ gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, pwidth, pheight,
- GIMP_RGB_IMAGE,
+ GIMP_RGBA_IMAGE,
dest_buffer,
- pwidth * 3);
- g_free(src_col);
- g_free(src_row);
- g_free(dest_buffer);
-}
+ pwidth * 4);
-static void
-render_rgb_image(Preview_t *preview_base, GimpPixelRgn *srcrgn)
-{
- guchar *src_row, *dest_buffer, *src, *dest;
- gint row, col;
- gint dwidth, dheight, pwidth, pheight;
- gint *src_col;
- gint bpp, alpha, has_alpha, b;
- guchar check;
- gboolean gray = get_map_info()->show_gray;
- GtkWidget *preview = preview_base->preview;
-
- dwidth = srcrgn->w;
- dheight = srcrgn->h;
- pwidth = preview_base->widget_width;
- pheight = preview_base->widget_height;
- bpp = srcrgn->bpp;
- alpha = bpp;
- has_alpha = gimp_drawable_has_alpha(srcrgn->drawable->drawable_id);
- if (has_alpha)
- alpha--;
-
- src_row = g_new(guchar, dwidth * bpp);
- dest_buffer = g_new(guchar, pwidth * pheight * bpp);
- src_col = g_new(gint, pwidth);
-
- for (col = 0; col < pwidth; col++)
- src_col[col] = (col * dwidth / pwidth) * bpp;
-
- dest = dest_buffer;
- for (row = 0; row < pheight; row++) {
- gimp_pixel_rgn_get_row(srcrgn, src_row, 0, row * dheight / pheight,
- dwidth);
- for (col = 0; col < pwidth; col++) {
- src = &src_row[src_col[col]];
- if(!has_alpha || src[alpha] == OPAQUE) {
- /* no alpha channel or opaque -- simple way */
- for (b = 0; b < alpha; b++)
- dest[b] = src[b];
- } else {
- /* more or less transparent */
- if( ( col % (CHECKWIDTH*2) < CHECKWIDTH ) ^
- ( row % (CHECKWIDTH*2) < CHECKWIDTH ) )
- check = LIGHTCHECK;
- else
- check = DARKCHECK;
-
- if (src[alpha] == 0) {
- /* full transparent -- check */
- for (b = 0; b < alpha; b++)
- dest[b] = check;
- } else {
- /* middlemost transparent -- mix check and src */
- for (b = 0; b < alpha; b++)
- dest[b] = (src[b] * src[alpha] +
- check * (OPAQUE - src[alpha])) / OPAQUE;
- }
- }
- if (gray) {
- guchar avg;
- avg = (299 * dest[0] + 587 * dest[1] + 114 * dest[2]) / 1000;
- for (b = 0; b < alpha; b++)
- dest[b] = avg;
- }
- dest += alpha;
- }
- }
- gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
- 0, 0, pwidth, pheight,
- GIMP_RGB_IMAGE,
- dest_buffer,
- pwidth * 3);
- g_free(src_col);
- g_free(src_row);
- g_free(dest_buffer);
+ g_free (dest_buffer);
}
static void
-render_preview(Preview_t *preview_base, GimpPixelRgn *srcrgn)
+render_preview (Preview_t *preview_base,
+ gint32 drawable_id)
{
- render_background (preview_base);
-
- switch (gimp_drawable_type(srcrgn->drawable->drawable_id)) {
- case GIMP_RGB_IMAGE:
- case GIMP_RGBA_IMAGE:
- render_rgb_image(preview_base, srcrgn);
- break;
- case GIMP_GRAY_IMAGE:
- case GIMP_GRAYA_IMAGE:
- render_gray_image(preview_base, srcrgn);
- break;
- case GIMP_INDEXED_IMAGE:
- case GIMP_INDEXEDA_IMAGE:
- render_indexed_image(preview_base, srcrgn);
- break;
- }
+ render_background (preview_base);
+ render_rgb_image (preview_base, drawable_id);
}
static gboolean
@@ -358,7 +193,7 @@ preview_zoom(Preview_t *preview, gint zoom_factor)
gtk_widget_set_size_request (preview->preview, preview->widget_width,
preview->widget_height);
gtk_widget_queue_resize(preview->window);
- render_preview(preview, &preview->src_rgn);
+ render_preview(preview, preview->drawable_id);
preview_redraw();
}
@@ -417,7 +252,7 @@ preview_size_allocate (GtkWidget *widget,
{
Preview_t *preview = preview_void;
- render_preview (preview, &preview->src_rgn);
+ render_preview (preview, preview->drawable_id);
}
static void
@@ -432,7 +267,7 @@ scroll_adj_changed (GtkAdjustment *adj,
}
Preview_t *
-make_preview (GimpDrawable *drawable)
+make_preview (gint32 drawable_id)
{
Preview_t *data = g_new(Preview_t, 1);
GtkAdjustment *hadj;
@@ -446,7 +281,7 @@ make_preview (GimpDrawable *drawable)
GtkWidget *scrollbar;
gint width, height;
- data->drawable = drawable;
+ data->drawable_id = drawable_id;
data->preview = preview = gimp_preview_area_new ();
g_object_set_data (G_OBJECT (preview), "preview", data);
@@ -467,10 +302,8 @@ make_preview (GimpDrawable *drawable)
G_CALLBACK (handle_drop),
NULL);
- data->widget_width = data->width =
- gimp_drawable_width (drawable->drawable_id);
- data->widget_height = data->height =
- gimp_drawable_height (drawable->drawable_id);
+ data->widget_width = data->width = gimp_drawable_width (drawable_id);
+ data->widget_height = data->height = gimp_drawable_height (drawable_id);
gtk_widget_set_size_request (preview, data->widget_width,
data->widget_height);
@@ -561,9 +394,7 @@ make_preview (GimpDrawable *drawable)
gtk_widget_show (preview);
- gimp_pixel_rgn_init (&data->src_rgn, drawable, 0, 0, data->width,
- data->height, FALSE, FALSE);
- render_preview (data, &data->src_rgn);
+ render_preview (data, drawable_id);
gtk_widget_show (table);
diff --git a/plug-ins/imagemap/imap_preview.h b/plug-ins/imagemap/imap_preview.h
index 65d449a0b7..3fe01c4818 100644
--- a/plug-ins/imagemap/imap_preview.h
+++ b/plug-ins/imagemap/imap_preview.h
@@ -26,7 +26,7 @@
#include <libgimp/gimp.h>
typedef struct {
- GimpDrawable *drawable;
+ gint32 drawable_id;
GtkWidget *window;
GtkWidget *preview;
GtkWidget *hruler;
@@ -35,12 +35,11 @@ typedef struct {
gint height;
gint widget_width;
gint widget_height;
- GimpPixelRgn src_rgn;
GdkCursorType cursor;
} Preview_t;
-Preview_t *make_preview(GimpDrawable *drawable);
+Preview_t *make_preview(gint32 drawable_id);
void preview_redraw(void);
void preview_unset_tmp_obj (Object_t *obj);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]