RSS/Atom feed Twitter
Site is read-only, email is disabled

problem creating simple plugin

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

2 of 2 messages available
Toggle history

Please log in to manage your subscriptions.

problem creating simple plugin lode leroy 27 Jul 11:51
  problem creating simple plugin Sven Neumann 27 Jul 12:21
lode leroy
2005-07-27 11:51:36 UTC (over 18 years ago)

problem creating simple plugin

Hello,

I have a problem creating a cery simple gimp plugin..

The idea is to select a part of an image, and the plugin should create a new image with the size of the selection, and put (processed) pixels in that new image (a bit like "Copy && Past As New").

The plugin compiles, runs without crashing, the progress bar is ok, but I do not see the new image anywhere. I must be doing something *obvious* wrong somewhere...

void render (gint32 image_ID, GimpDrawable *src_drawable,
PlugInVals *vals,
PlugInImageVals *image_vals,
PlugInDrawableVals *drawable_vals)
{
gint progress, max_progress;
gint x1, y1, x2, y2;
gint x, y, width, height;
GimpPixelRgn src_rgn, msk_rgn, dst_rgn; gint rgn_stride, msk_stride, dst_stride; gint rgn_bpp, msk_bpp, dst_bpp; guchar *rgn_buf, *msk_buf, *dst_buf; guchar **src, **msk, **dst;

gint32 selection_ID; GimpDrawable* msk_drawable;

gint32 dst_image; gint32 dst_layer;
GimpDrawable* dst_drawable;

/* Get selection */ selection_ID = gimp_image_get_selection (image_ID);

/* Get selection area */ gimp_drawable_mask_bounds (src_drawable->drawable_id, &x1, &y1, &x2, &y2); rgn_bpp = gimp_drawable_bpp (src_drawable->drawable_id);

width = (x2 - x1); height = (y2 - y1);

/* Get selection mask */ msk_drawable = gimp_drawable_get (selection_ID); msk_bpp = gimp_drawable_bpp (msk_drawable->drawable_id);

/* create new image */ dst_image = gimp_image_new(width, height, GIMP_RGB); gimp_image_undo_disable(dst_image); dst_layer = gimp_layer_new(dst_image, "Histogram", width, height, GIMP_RGB_IMAGE, 100, GIMP_NORMAL_MODE);
gimp_image_add_layer(dst_image, dst_layer, 0); dst_drawable = gimp_drawable_get(dst_layer); dst_bpp = gimp_drawable_bpp (dst_drawable->drawable_id);

/* Initialize progress */ progress = 0;
max_progress = width * height;

/* substitute pixel vales */ gimp_pixel_rgn_init (&src_rgn, src_drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&msk_rgn, msk_drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&dst_rgn, dst_drawable, 0, 0, width, height, FALSE, FALSE);

rgn_buf = g_new0 (guchar, width * height * rgn_bpp); msk_buf = g_new0 (guchar, width * height * msk_bpp); dst_buf = g_new0 (guchar, width * height * dst_bpp);

gimp_progress_init (_("Histogram"));

gimp_pixel_rgn_get_rect(&src_rgn, rgn_buf, x1, y1, width, height); gimp_pixel_rgn_get_rect(&msk_rgn, msk_buf, x1, y1, width, height); gimp_pixel_rgn_get_rect(&dst_rgn, dst_buf, 0, 0, width, height);

rgn_stride = width * rgn_bpp; msk_stride = width * msk_bpp;
dst_stride = width * dst_bpp;

src = g_new (guchar*, height); dst = g_new (guchar*, height);
msk = g_new (guchar*, height);

for(y = 0; y < height; y++) { src[y] = &rgn_buf[y * rgn_stride]; dst[y] = &dst_buf[y * dst_stride]; msk[y] = &msk_buf[y * msk_stride]; }

/* here goes the processing */ for (y = 1; y < height-1; y++)
{
for (x = 0; x < width-1; x++)
{
if (msk[y][x]!=0) {
dst[y][x] = src[y][x];
}
}

/* Update progress */
progress += width;

gimp_progress_update ((double) progress / (double) max_progress); }

gimp_progress_update (1.0);

/* update the region */ gimp_drawable_flush (dst_drawable); gimp_drawable_detach(dst_drawable);

//gimp_pixel_rgn_set_rect(&dst_rgn, dst_buf, 0, 0, width, height);

g_free(src); g_free(dst);
g_free(msk);

g_free(rgn_buf); g_free(dst_buf);
g_free(msk_buf);
}

Sven Neumann
2005-07-27 12:21:34 UTC (over 18 years ago)

problem creating simple plugin

Hi,

"lode leroy" writes:

The plugin compiles, runs without crashing, the progress bar is ok, but I do not see the new image anywhere. I must be doing something *obvious* wrong somewhere...

You aren't creating a display for your new image. So obviously there isn't anything to see.

Sven