mirror of https://github.com/GNOME/gimp.git
use gimp_preview_invalidate() where appropriate.
* plug-ins/common/cartoon.c: use gimp_preview_invalidate() where appropriate. * plug-ins/common/photocopy.c: Added a preview.
This commit is contained in:
parent
4bfbd2c5c3
commit
d44e08aed7
|
@ -1,3 +1,10 @@
|
|||
2004-09-05 DindinX <david@dindinx.org>
|
||||
|
||||
* plug-ins/common/cartoon.c: use gimp_preview_invalidate() where
|
||||
appropriate.
|
||||
|
||||
* plug-ins/common/photocopy.c: Added a preview.
|
||||
|
||||
2004-09-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* configure.in: bumped version number to 2.1.5.
|
||||
|
|
|
@ -60,7 +60,6 @@ static void run (const gchar *name,
|
|||
static void cartoon (GimpDrawable *drawable,
|
||||
GimpDrawablePreview *preview);
|
||||
static gboolean cartoon_dialog (GimpDrawable *drawable);
|
||||
static void preview_update (GtkWidget *widget);
|
||||
|
||||
static gdouble compute_ramp (guchar *dest1,
|
||||
guchar *dest2,
|
||||
|
@ -847,7 +846,7 @@ cartoon_dialog (GimpDrawable *drawable)
|
|||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&cvals.mask_radius);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (preview_update), preview);
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
/* Label, scale, entry for cvals.amount */
|
||||
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
||||
|
@ -860,7 +859,7 @@ cartoon_dialog (GimpDrawable *drawable)
|
|||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&cvals.pct_black);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (preview_update), preview);
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
gtk_widget_show (dlg);
|
||||
|
||||
|
@ -870,11 +869,3 @@ cartoon_dialog (GimpDrawable *drawable)
|
|||
|
||||
return run;
|
||||
}
|
||||
|
||||
static void
|
||||
preview_update (GtkWidget *widget)
|
||||
{
|
||||
GimpDrawablePreview *preview = GIMP_DRAWABLE_PREVIEW (widget);
|
||||
|
||||
cartoon (preview->drawable, preview);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ typedef struct
|
|||
gdouble threshold;
|
||||
gdouble pct_black;
|
||||
gdouble pct_white;
|
||||
gboolean update_preview;
|
||||
} PhotocopyVals;
|
||||
|
||||
|
||||
|
@ -61,7 +62,8 @@ static void run (const gchar *name,
|
|||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static void photocopy (GimpDrawable *drawable);
|
||||
static void photocopy (GimpDrawable *drawable,
|
||||
GimpDrawablePreview *preview);
|
||||
static gboolean photocopy_dialog (GimpDrawable *drawable);
|
||||
|
||||
static gdouble compute_ramp (guchar *dest1,
|
||||
|
@ -103,6 +105,7 @@ static PhotocopyVals pvals =
|
|||
0.75, /* threshold */
|
||||
0.2, /* pct_black */
|
||||
0.2, /* pct_white */
|
||||
TRUE /* update_preview */
|
||||
};
|
||||
|
||||
|
||||
|
@ -224,7 +227,7 @@ run (const gchar *name,
|
|||
/* set the tile cache size */
|
||||
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
|
||||
|
||||
photocopy (drawable);
|
||||
photocopy (drawable, NULL);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
|
@ -263,7 +266,8 @@ run (const gchar *name,
|
|||
* pixel intensity = white
|
||||
*/
|
||||
static void
|
||||
photocopy (GimpDrawable *drawable)
|
||||
photocopy (GimpDrawable *drawable,
|
||||
GimpDrawablePreview *preview)
|
||||
{
|
||||
GimpPixelRgn src_rgn, dest_rgn;
|
||||
GimpPixelRgn *pr;
|
||||
|
@ -297,11 +301,20 @@ photocopy (GimpDrawable *drawable)
|
|||
gdouble std_dev2;
|
||||
gdouble ramp_down;
|
||||
gdouble ramp_up;
|
||||
guchar *preview_buffer = NULL;
|
||||
|
||||
if (preview)
|
||||
{
|
||||
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
|
||||
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
||||
|
||||
width = (x2 - x1);
|
||||
height = (y2 - y1);
|
||||
}
|
||||
bytes = drawable->bpp;
|
||||
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
||||
|
||||
|
@ -317,7 +330,7 @@ photocopy (GimpDrawable *drawable)
|
|||
max_progress = width * height * 3;
|
||||
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable,
|
||||
0, 0, drawable->width, drawable->height, FALSE, FALSE);
|
||||
x1, y1, width, height, FALSE, FALSE);
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
|
||||
pr != NULL;
|
||||
|
@ -347,9 +360,12 @@ photocopy (GimpDrawable *drawable)
|
|||
dest_ptr += width;
|
||||
}
|
||||
|
||||
if (!preview)
|
||||
{
|
||||
progress += src_rgn.w * src_rgn.h;
|
||||
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate the standard deviations */
|
||||
radius = MAX (1.0, 10 * (1.0 - pvals.sharpness));
|
||||
|
@ -422,10 +438,13 @@ photocopy (GimpDrawable *drawable)
|
|||
transfer_pixels (val_p1, val_m1, dest1 + col, width, height);
|
||||
transfer_pixels (val_p2, val_m2, dest2 + col, width, height);
|
||||
|
||||
if (!preview)
|
||||
{
|
||||
progress += height;
|
||||
if ((col % 5) == 0)
|
||||
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
|
||||
}
|
||||
}
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
|
@ -493,10 +512,13 @@ photocopy (GimpDrawable *drawable)
|
|||
transfer_pixels (val_p1, val_m1, dest1 + row * width, 1, width);
|
||||
transfer_pixels (val_p2, val_m2, dest2 + row * width, 1, width);
|
||||
|
||||
if (!preview)
|
||||
{
|
||||
progress += width;
|
||||
if ((row % 5) == 0)
|
||||
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the ramp value which sets 'pct_black' % of the darkened pixels black */
|
||||
ramp_down = compute_ramp (dest1, dest2, width * height, pvals.pct_black, 1);
|
||||
|
@ -504,19 +526,35 @@ photocopy (GimpDrawable *drawable)
|
|||
|
||||
/* Initialize the pixel regions. */
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE);
|
||||
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, width, height, TRUE, TRUE);
|
||||
if (preview)
|
||||
{
|
||||
preview_buffer = g_new (guchar, width * height * bytes);
|
||||
pr = gimp_pixel_rgns_register (1, &src_rgn);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
||||
x1, y1, width, height,
|
||||
TRUE, TRUE);
|
||||
pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
|
||||
}
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process (pr))
|
||||
while (pr)
|
||||
{
|
||||
guchar *src_ptr = src_rgn.data;
|
||||
guchar *dest_ptr = dest_rgn.data;
|
||||
guchar *dest_ptr;
|
||||
guchar *blur_ptr = dest1 + (src_rgn.y - y1) * width + (src_rgn.x - x1);
|
||||
guchar *avg_ptr = dest2 + (src_rgn.y - y1) * width + (src_rgn.x - x1);
|
||||
gdouble diff, mult;
|
||||
gdouble lightness = 0.0;
|
||||
|
||||
if (preview)
|
||||
dest_ptr =
|
||||
preview_buffer +
|
||||
((src_rgn.y - y1) * width + (src_rgn.x - x1)) * bytes;
|
||||
else
|
||||
dest_ptr = dest_rgn.data;
|
||||
|
||||
for (row = 0; row < src_rgn.h; row++)
|
||||
{
|
||||
for (col = 0; col < src_rgn.w; col++)
|
||||
|
@ -549,35 +587,51 @@ photocopy (GimpDrawable *drawable)
|
|||
|
||||
if (bytes < 3)
|
||||
{
|
||||
dest_ptr[col * dest_rgn.bpp] = (guchar) lightness;
|
||||
dest_ptr[col * bytes] = (guchar) lightness;
|
||||
if (has_alpha)
|
||||
dest_ptr[col * dest_rgn.bpp + 1] = src_ptr[col * src_rgn.bpp + 1];
|
||||
dest_ptr[col * bytes + 1] = src_ptr[col * src_rgn.bpp + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
dest_ptr[col * dest_rgn.bpp + 0] = lightness;
|
||||
dest_ptr[col * dest_rgn.bpp + 1] = lightness;
|
||||
dest_ptr[col * dest_rgn.bpp + 2] = lightness;
|
||||
dest_ptr[col * bytes + 0] = lightness;
|
||||
dest_ptr[col * bytes + 1] = lightness;
|
||||
dest_ptr[col * bytes + 2] = lightness;
|
||||
|
||||
if (has_alpha)
|
||||
dest_ptr[col * dest_rgn.bpp + 3] = src_ptr[col * src_rgn.bpp + 3];
|
||||
dest_ptr[col * bytes + 3] = src_ptr[col * src_rgn.bpp + 3];
|
||||
}
|
||||
}
|
||||
|
||||
src_ptr += src_rgn.rowstride;
|
||||
if (preview)
|
||||
dest_ptr += width * bytes;
|
||||
else
|
||||
dest_ptr += dest_rgn.rowstride;
|
||||
blur_ptr += width;
|
||||
avg_ptr += width;
|
||||
}
|
||||
|
||||
if (!preview)
|
||||
{
|
||||
progress += src_rgn.w * src_rgn.h;
|
||||
gimp_progress_update ((gdouble) progress / (gdouble) max_progress);
|
||||
}
|
||||
|
||||
pr = gimp_pixel_rgns_process (pr);
|
||||
}
|
||||
|
||||
if (preview)
|
||||
{
|
||||
gimp_drawable_preview_draw (preview, preview_buffer);
|
||||
g_free (preview_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* merge the shadow, update the drawable */
|
||||
gimp_drawable_flush (drawable);
|
||||
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
|
||||
gimp_drawable_update (drawable->drawable_id, x1, y1, width, height);
|
||||
}
|
||||
|
||||
/* free up buffers */
|
||||
g_free (val_p1);
|
||||
|
@ -784,6 +838,9 @@ static gboolean
|
|||
photocopy_dialog (GimpDrawable *drawable)
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *table;
|
||||
GtkObject *scale_data;
|
||||
gint run;
|
||||
|
@ -799,11 +856,25 @@ photocopy_dialog (GimpDrawable *drawable)
|
|||
|
||||
NULL);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->vbox), vbox);
|
||||
gtk_widget_show (vbox);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 12);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
preview = gimp_drawable_preview_new (drawable, &pvals.update_preview);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
|
||||
gtk_widget_show (preview);
|
||||
g_signal_connect_swapped (preview, "invalidated",
|
||||
G_CALLBACK (photocopy), drawable);
|
||||
|
||||
table = gtk_table_new (4, 3, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (table), 12);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->vbox), table);
|
||||
gtk_container_add (GTK_CONTAINER (vbox), table);
|
||||
gtk_widget_show (table);
|
||||
|
||||
/* Label, scale, entry for pvals.amount */
|
||||
|
@ -816,6 +887,8 @@ photocopy_dialog (GimpDrawable *drawable)
|
|||
g_signal_connect (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&pvals.mask_radius);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
/* Label, scale, entry for pvals.amount */
|
||||
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
||||
|
@ -827,6 +900,8 @@ photocopy_dialog (GimpDrawable *drawable)
|
|||
g_signal_connect (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&pvals.sharpness);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
/* Label, scale, entry for pvals.amount */
|
||||
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
|
||||
|
@ -838,6 +913,8 @@ photocopy_dialog (GimpDrawable *drawable)
|
|||
g_signal_connect (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&pvals.pct_black);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
/* Label, scale, entry for pvals.amount */
|
||||
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
|
||||
|
@ -849,6 +926,8 @@ photocopy_dialog (GimpDrawable *drawable)
|
|||
g_signal_connect (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_double_adjustment_update),
|
||||
&pvals.pct_white);
|
||||
g_signal_connect_swapped (scale_data, "value_changed",
|
||||
G_CALLBACK (gimp_preview_invalidate), preview);
|
||||
|
||||
gtk_widget_show (dlg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue