Commit bfa352ba authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

libgimp/gimpdrawablepreview.[ch] renamed gimp_drawable_preview_draw() to

2004-09-15  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpdrawablepreview.[ch]
	* libgimp/gimpui.def: renamed gimp_drawable_preview_draw() to
	gimp_drawable_preview_draw_buffer() and added a rowstride
	parameter. Added new functions gimp_drawable_preview_get_drawable()
	and gimp_drawable_preview_draw_region().

	* plug-ins/common/mblur.c: added a preview that uses the
	shadow tiles as the preview buffer and draws using the new
	gimp_drawable_preview_draw_region() API.

	* plug-ins/common/photocopy.c
	* plug-ins/common/softglow.c: use gimp_drawable_preview_draw_region().

	* plug-ins/common/cartoon.c
	* plug-ins/common/despeckle.c
	* plug-ins/common/edge.c
	* plug-ins/common/gauss.c
	* plug-ins/common/grid.c
	* plug-ins/common/neon.c
	* plug-ins/common/noisify.c
	* plug-ins/common/sel_gauss.c
	* plug-ins/common/sharpen.c
	* plug-ins/common/sobel.c
	* plug-ins/common/spread.c
	* plug-ins/common/struc.c
	* plug-ins/common/unsharp.c
	* plug-ins/common/wind.c: use gimp_drawable_preview_draw_buffer().
parent 186b5908
2004-09-15 Sven Neumann <sven@gimp.org>
* libgimp/gimpdrawablepreview.[ch]
* libgimp/gimpui.def: renamed gimp_drawable_preview_draw() to
gimp_drawable_preview_draw_buffer() and added a rowstride
parameter. Added new functions gimp_drawable_preview_get_drawable()
and gimp_drawable_preview_draw_region().
* plug-ins/common/mblur.c: added a preview that uses the
shadow tiles as the preview buffer and draws using the new
gimp_drawable_preview_draw_region() API.
* plug-ins/common/photocopy.c
* plug-ins/common/softglow.c: use gimp_drawable_preview_draw_region().
* plug-ins/common/cartoon.c
* plug-ins/common/despeckle.c
* plug-ins/common/edge.c
* plug-ins/common/gauss.c
* plug-ins/common/grid.c
* plug-ins/common/neon.c
* plug-ins/common/noisify.c
* plug-ins/common/sel_gauss.c
* plug-ins/common/sharpen.c
* plug-ins/common/sobel.c
* plug-ins/common/spread.c
* plug-ins/common/struc.c
* plug-ins/common/unsharp.c
* plug-ins/common/wind.c: use gimp_drawable_preview_draw_buffer().
2004-09-15 Michael Natterer <mitch@gimp.org>
* app/widgets/gimphelp-ids.h: added help IDs for the drawable- and
......
......@@ -690,7 +690,9 @@ gimp_drawable_get_thumbnail
<TITLE>GimpDrawablePreview</TITLE>
GimpDrawablePreview
gimp_drawable_preview_new
gimp_drawable_preview_draw
gimp_drawable_preview_get_drawable
gimp_drawable_preview_draw_buffer
gimp_drawable_preview_draw_region
<SUBSECTION Standard>
GimpDrawablePreviewClass
GIMP_DRAWABLE_PREVIEW
......
......@@ -30,12 +30,31 @@ GimpDrawablePreview
@Returns:
<!-- ##### FUNCTION gimp_drawable_preview_draw ##### -->
<!-- ##### FUNCTION gimp_drawable_preview_get_drawable ##### -->
<para>
</para>
@preview:
@buf:
@Returns:
<!-- ##### FUNCTION gimp_drawable_preview_draw_buffer ##### -->
<para>
</para>
@preview:
@buffer:
@rowstride:
<!-- ##### FUNCTION gimp_drawable_preview_draw_region ##### -->
<para>
</para>
@preview:
@region:
......@@ -205,6 +205,69 @@ gimp_drawable_preview_draw_thumb (GimpPreview *preview,
}
}
static void
gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
gint x,
gint y,
gint width,
gint height,
const guchar *buf,
gint rowstride)
{
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
GimpDrawable *drawable = preview->drawable;
gint32 image_id;
image_id = gimp_drawable_get_image (drawable->drawable_id);
if (gimp_selection_is_empty (image_id))
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview->area),
x - gimp_preview->xoff - gimp_preview->xmin,
y - gimp_preview->yoff - gimp_preview->ymin,
width,
height,
gimp_drawable_type (drawable->drawable_id),
buf, rowstride);
}
else
{
GimpPixelRgn selection_rgn;
GimpPixelRgn drawable_rgn;
guchar *sel;
guchar *src;
gint selection_id;
selection_id = gimp_image_get_selection (image_id);
gimp_pixel_rgn_init (&drawable_rgn, drawable,
x, y, width, height,
FALSE, FALSE);
gimp_pixel_rgn_init (&selection_rgn, gimp_drawable_get (selection_id),
x, y, width, height,
FALSE, FALSE);
sel = g_new (guchar, width * height);
src = g_new (guchar, width * height * drawable->bpp);
gimp_pixel_rgn_get_rect (&drawable_rgn, src, x, y, width, height);
gimp_pixel_rgn_get_rect (&selection_rgn, sel, x, y, width, height);
gimp_preview_area_mask (GIMP_PREVIEW_AREA (gimp_preview->area),
x - gimp_preview->xoff - gimp_preview->xmin,
y - gimp_preview->yoff - gimp_preview->ymin,
width,
height,
gimp_drawable_type (drawable->drawable_id),
src, width * drawable->bpp,
buf, rowstride,
sel, width);
g_free (sel);
g_free (src);
}
}
static void
gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview,
GimpDrawable *drawable)
......@@ -288,78 +351,95 @@ gimp_drawable_preview_new (GimpDrawable *drawable,
}
/**
* gimp_drawable_preview_draw:
* @preview: a #GimpDrawablePreview widget
* @buf:
* gimp_drawable_preview_get_drawable:
* @preview: a #GimpDrawablePreview widget
*
* Return value: the #GimpDrawable that has been passed to
* gimp_drawable_preview_new().
*
* Since: GIMP 2.2
**/
GimpDrawable *
gimp_drawable_preview_get_drawable (GimpDrawablePreview *preview)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview), NULL);
return preview->drawable;
}
/**
* gimp_drawable_preview_draw_buffer:
* @preview: a #GimpDrawablePreview widget
* @buffer:
* @rowstride:
*
* Since: GIMP 2.2
**/
void
gimp_drawable_preview_draw (GimpDrawablePreview *preview,
const guchar *buf)
gimp_drawable_preview_draw_buffer (GimpDrawablePreview *preview,
const guchar *buffer,
gint rowstride)
{
GimpPreview *gimp_preview;
GimpDrawable *drawable;
gint32 image_id;
gint width, height;
gint bytes;
GimpPreview *gimp_preview;
g_return_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview));
g_return_if_fail (preview->drawable != NULL);
g_return_if_fail (buf != NULL);
g_return_if_fail (buffer != NULL);
gimp_preview = GIMP_PREVIEW (preview);
drawable = preview->drawable;
width = gimp_preview->width;
height = gimp_preview->height;
bytes = drawable->bpp;
gimp_drawable_preview_draw_area (preview,
gimp_preview->xmin + gimp_preview->xoff,
gimp_preview->ymin + gimp_preview->yoff,
gimp_preview->width,
gimp_preview->height,
buffer, rowstride);
}
image_id = gimp_drawable_get_image (drawable->drawable_id);
/**
* gimp_drawable_preview_draw_region:
* @preview: a #GimpDrawablePreview widget
* @region: a #GimpPixelRgn
*
* Since: GIMP 2.2
**/
void
gimp_drawable_preview_draw_region (GimpDrawablePreview *preview,
const GimpPixelRgn *region)
{
g_return_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview));
g_return_if_fail (preview->drawable != NULL);
g_return_if_fail (region != NULL);
if (gimp_selection_is_empty (image_id))
/* If the data field is initialized, this region is currently being
* processed and we can access it directly.
*/
if (region->data)
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview->area),
0, 0, width, height,
gimp_drawable_type (drawable->drawable_id),
buf,
width * bytes);
gimp_drawable_preview_draw_area (preview,
region->x,
region->y,
region->w,
region->h,
region->data,
region->rowstride);
}
else
{
GimpPixelRgn selection_rgn;
GimpPixelRgn drawable_rgn;
guchar *sel;
guchar *src;
gint selection_id;
gint x1, y1;
selection_id = gimp_image_get_selection (image_id);
x1 = gimp_preview->xoff + gimp_preview->xmin;
y1 = gimp_preview->yoff + gimp_preview->ymin;
gimp_pixel_rgn_init (&drawable_rgn, drawable,
x1, y1, width, height,
FALSE, FALSE);
gimp_pixel_rgn_init (&selection_rgn, gimp_drawable_get (selection_id),
x1, y1, width, height,
FALSE, FALSE);
sel = g_new (guchar, width * height);
src = g_new (guchar, width * height * bytes);
gimp_pixel_rgn_get_rect (&drawable_rgn, src, x1, y1, width, height);
gimp_pixel_rgn_get_rect (&selection_rgn, sel, x1, y1, width, height);
GimpPixelRgn src = *region;
gpointer iter;
gimp_preview_area_mask (GIMP_PREVIEW_AREA (gimp_preview->area),
0, 0, width, height,
gimp_drawable_type (drawable->drawable_id),
src, width * bytes,
buf, width * bytes,
sel, width);
g_free (sel);
g_free (src);
for (iter = gimp_pixel_rgns_register (1, &src);
iter != NULL;
iter = gimp_pixel_rgns_process (iter))
{
gimp_drawable_preview_draw_area (preview,
src.x,
src.y,
src.w,
src.h,
src.data,
src.rowstride);
}
}
}
......@@ -53,13 +53,17 @@ struct _GimpDrawablePreviewClass
};
GType gimp_drawable_preview_get_type (void) G_GNUC_CONST;
GType gimp_drawable_preview_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_drawable_preview_new (GimpDrawable *drawable,
gboolean *toggle);
GtkWidget * gimp_drawable_preview_new (GimpDrawable *drawable,
gboolean *toggle);
GimpDrawable * gimp_drawable_preview_get_drawable (GimpDrawablePreview *preview);
void gimp_drawable_preview_draw (GimpDrawablePreview *preview,
const guchar *buf);
void gimp_drawable_preview_draw_buffer (GimpDrawablePreview *preview,
const guchar *buffer,
gint rowstride);
void gimp_drawable_preview_draw_region (GimpDrawablePreview *preview,
const GimpPixelRgn *region);
G_END_DECLS
......
......@@ -7,7 +7,9 @@ EXPORTS
gimp_drawable_combo_box_new
gimp_drawable_get_thumbnail
gimp_drawable_menu_new
gimp_drawable_preview_draw
gimp_drawable_preview_draw_buffer
gimp_drawable_preview_draw_region
gimp_drawable_preview_get_drawable
gimp_drawable_preview_get_type
gimp_drawable_preview_new
gimp_export_image
......
......@@ -586,7 +586,8 @@ cartoon (GimpDrawable *drawable,
if (preview)
{
gimp_drawable_preview_draw (preview, preview_buffer);
gimp_drawable_preview_draw_buffer (preview,
preview_buffer, width * bytes);
g_free (preview_buffer);
}
else
......
......@@ -855,7 +855,8 @@ preview_update (GtkWidget *widget)
* Update the screen...
*/
gimp_drawable_preview_draw (GIMP_DRAWABLE_PREVIEW (preview), rgba);
gimp_drawable_preview_draw_buffer (GIMP_DRAWABLE_PREVIEW (preview),
rgba, preview->width * img_bpp);
g_free (rgba);
g_free (preview_src);
......
......@@ -843,7 +843,7 @@ edge_preview_update (GimpDrawablePreview *preview)
/*
* Draw the preview image on the screen...
*/
gimp_drawable_preview_draw (preview, render_buffer);
gimp_drawable_preview_draw_buffer (preview, render_buffer, width * bytes);
g_free (render_buffer);
g_free (src);
......
......@@ -294,7 +294,7 @@ run (const gchar *name,
{
bvals.horizontal = param[3].data.d_float;
bvals.vertical = param[4].data.d_float;
bvals.method = param[5].data.d_int32;
bvals.method = param[5].data.d_int32;
}
if (status == GIMP_PDB_SUCCESS &&
(bvals.horizontal <= 0.0 && bvals.vertical <= 0.0))
......@@ -1043,8 +1043,8 @@ gauss (GimpDrawable *drawable,
if (preview)
{
gimp_drawable_preview_draw (GIMP_DRAWABLE_PREVIEW (preview),
preview_buffer2);
gimp_drawable_preview_draw_buffer (GIMP_DRAWABLE_PREVIEW (preview),
preview_buffer2, width * bytes);
g_free (preview_buffer1);
g_free (preview_buffer2);
}
......
......@@ -482,7 +482,8 @@ grid (gint32 image_ID,
if (preview)
{
gimp_drawable_preview_draw (GIMP_DRAWABLE_PREVIEW (preview), buffer);
gimp_drawable_preview_draw_buffer (GIMP_DRAWABLE_PREVIEW (preview),
buffer, bytes * (sx2 - sx1));
g_free (buffer);
}
else
......
......@@ -76,11 +76,12 @@ typedef enum
typedef struct
{
gint32 mblur_type;
gint32 length;
gint32 angle;
gdouble center_x;
gdouble center_y;
gint32 mblur_type;
gint32 length;
gint32 angle;
gdouble center_x;
gdouble center_y;
gboolean preview;
} mblur_vals_t;
/***** Prototypes *****/
......@@ -92,12 +93,29 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static void mblur (GimpDrawable *drawable);
static void mblur_linear (GimpDrawable *drawable);
static void mblur_radial (GimpDrawable *drawable);
static void mblur_zoom (GimpDrawable *drawable);
static gboolean mblur_dialog (gint32 image_ID);
static void mblur (GimpDrawable *drawable,
GimpPreview *preview);
static void mblur_linear (GimpDrawable *drawable,
GimpPreview *preview,
gint x1,
gint y1,
gint width,
gint height);
static void mblur_radial (GimpDrawable *drawable,
GimpPreview *preview,
gint x1,
gint y1,
gint width,
gint height);
static void mblur_zoom (GimpDrawable *drawable,
GimpPreview *preview,
gint x1,
gint y1,
gint width,
gint height);
static gboolean mblur_dialog (gint32 image_ID,
GimpDrawable *drawable);
/***** Variables *****/
......@@ -115,17 +133,18 @@ static mblur_vals_t mbvals =
5, /* length */
45, /* radius */
100000.0, /* center_x */
100000.0 /* center_y */
100000.0, /* center_y */
FALSE /* preview */
};
static GtkObject *length = NULL;
static GtkObject *angle = NULL;
static GtkWidget *center = NULL;
static gint img_width, img_height, img_bpp;
static gint sel_x1, sel_y1, sel_x2, sel_y2;
static gint sel_width, sel_height;
static gint has_alpha;
static GtkObject *length = NULL;
static GtkObject *angle = NULL;
static GtkWidget *center = NULL;
static GtkWidget *preview = NULL;
static gint img_width, img_height, img_bpp;
static gboolean has_alpha;
/***** Functions *****/
......@@ -175,6 +194,8 @@ run (const gchar *name,
GimpRunMode run_mode;
GimpPDBStatusType status;
GimpDrawable *drawable;
gint x1, y1, x2, y2;
INIT_I18N ();
status = GIMP_PDB_SUCCESS;
......@@ -194,16 +215,10 @@ run (const gchar *name,
img_height = gimp_drawable_height (drawable->drawable_id);
img_bpp = gimp_drawable_bpp (drawable->drawable_id);
gimp_drawable_mask_bounds (drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
/* Calculate scaling parameters */
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
mbvals.center_x = (gdouble) (sel_x1 + sel_x2 - 1) / 2.0;
mbvals.center_y = (gdouble) (sel_y1 + sel_y2 - 1) / 2.0;
mbvals.center_x = (gdouble) (x1 + x2 - 1) / 2.0;
mbvals.center_y = (gdouble) (y1 + y2 - 1) / 2.0;
switch (run_mode)
{
......@@ -212,7 +227,7 @@ run (const gchar *name,
gimp_get_data (PLUG_IN_NAME, &mbvals);
/* Get information from the dialog */
if (!mblur_dialog (param[1].data.d_image))
if (! mblur_dialog (param[1].data.d_image, drawable))
return;
break;
......@@ -258,7 +273,7 @@ run (const gchar *name,
/* Run! */
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
mblur (drawable);
mblur (drawable, NULL);
/* If run mode is interactive, flush displays */
if (run_mode != GIMP_RUN_NONINTERACTIVE)
......@@ -277,7 +292,12 @@ run (const gchar *name,
}
static void
mblur_linear (GimpDrawable *drawable)
mblur_linear (GimpDrawable *drawable,
GimpPreview *preview,
gint x1,
gint y1,
gint width,
gint height)
{
GimpPixelRgn dest_rgn;
GimpPixelFetcher *pft;
......@@ -294,7 +314,7 @@ mblur_linear (GimpDrawable *drawable)
gint dx, dy, px, py, swapdir, err, e, s1, s2;
gimp_pixel_rgn_init (&dest_rgn, drawable,
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
x1, y1, width, height, (preview == NULL), TRUE);
pft = gimp_pixel_fetcher_new (drawable, FALSE);
......@@ -302,7 +322,7 @@ mblur_linear (GimpDrawable *drawable)
gimp_pixel_fetcher_set_bg_color (pft, &background);
progress = 0;
max_progress = sel_width * sel_height;
max_progress = width * height;
n = mbvals.length;
px = (gdouble) n * cos (mbvals.angle / 180.0 * G_PI);
......@@ -395,13 +415,16 @@ mblur_linear (GimpDrawable *drawable)
yy += s2;
e -= dx;
}
if (swapdir)
yy += s2;
else
xx += s1;
e += dy;
if ((xx < sel_x1) || (xx >= sel_x2) ||
(yy < sel_y1) || (yy >= sel_y2))
if ((xx < x1) || (xx >= x1 + width) ||
(yy < y1) || (yy >= y1 + height))
break;
}
......@@ -427,18 +450,35 @@ mblur_linear (GimpDrawable *drawable)
d[c] = sum[c] / i;
}
}
d += dest_rgn.bpp;
}
dest += dest_rgn.rowstride;
}
progress += dest_rgn.w * dest_rgn.h;
gimp_progress_update ((double) progress / max_progress);
if (preview)
{
gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview),
&dest_rgn);
}
else
{
progress += dest_rgn.w * dest_rgn.h;
gimp_progress_update ((gdouble) progress / max_progress);
}
}
gimp_pixel_fetcher_destroy (pft);
}
static void
mblur_radial (GimpDrawable *drawable)
mblur_radial (GimpDrawable *drawable,
GimpPreview *preview,
gint x1,
gint y1,
gint width,
gint height)
{
GimpPixelRgn dest_rgn;
GimpPixelFetcher *pft;
......@@ -467,7 +507,7 @@ mblur_radial (GimpDrawable *drawable)
center_y = mbvals.center_y;
gimp_pixel_rgn_init (&dest_rgn, drawable,
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
x1, y1, width, height, (preview == NULL), TRUE);
pft = gimp_pixel_fetcher_new (drawable, FALSE);
...