mirror of https://github.com/GNOME/gimp.git
Added a preview and #if'ed out some unreachable code.
* plug-ins/common/engrave.c: Added a preview and #if'ed out some unreachable code.
This commit is contained in:
parent
ad1c2ca0fc
commit
b1f789d6f0
|
@ -1,3 +1,8 @@
|
|||
2004-09-25 DindinX <dindinx@gimp.org>
|
||||
|
||||
* plug-ins/common/engrave.c: Added a preview and #if'ed out some
|
||||
unreachable code.
|
||||
|
||||
2004-09-25 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimppickable.[ch]: added new vitrual function
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
typedef struct
|
||||
{
|
||||
gint height;
|
||||
gint limit;
|
||||
gboolean limit;
|
||||
gboolean preview;
|
||||
} EngraveValues;
|
||||
|
||||
static void query (void);
|
||||
|
@ -46,18 +47,26 @@ static void run (const gchar *name,
|
|||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static gboolean engrave_dialog (void);
|
||||
static gboolean engrave_dialog (GimpDrawable *drawable);
|
||||
|
||||
static void engrave (GimpDrawable *drawable);
|
||||
static void engrave (GimpDrawable *drawable,
|
||||
GimpDrawablePreview *preview);
|
||||
|
||||
#if 0
|
||||
static void engrave_large (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gint limit);
|
||||
gboolean limit,
|
||||
GimpDrawablePreview *preview);
|
||||
#endif
|
||||
|
||||
static void engrave_small (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gint limit,
|
||||
gint tile_width);
|
||||
gboolean limit,
|
||||
gint tile_width,
|
||||
GimpDrawablePreview *preview);
|
||||
|
||||
static void engrave_sub (gint height,
|
||||
gint limit,
|
||||
gboolean limit,
|
||||
gint bpp,
|
||||
gint color_n);
|
||||
|
||||
|
@ -71,10 +80,11 @@ GimpPlugInInfo PLUG_IN_INFO =
|
|||
|
||||
static EngraveValues pvals =
|
||||
{
|
||||
10
|
||||
10, /* height */
|
||||
FALSE, /* limit */
|
||||
TRUE /* preview */
|
||||
};
|
||||
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
|
@ -137,7 +147,7 @@ run (const gchar *name,
|
|||
gimp_get_data ("plug_in_engrave", &pvals);
|
||||
|
||||
/* First acquire information with a dialog */
|
||||
if (!engrave_dialog ())
|
||||
if (!engrave_dialog (drawable))
|
||||
{
|
||||
gimp_drawable_detach (drawable);
|
||||
return;
|
||||
|
@ -172,7 +182,7 @@ run (const gchar *name,
|
|||
gimp_progress_init (_("Engraving..."));
|
||||
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
|
||||
|
||||
engrave (drawable);
|
||||
engrave (drawable, NULL);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
|
@ -187,10 +197,11 @@ run (const gchar *name,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
engrave_dialog (void)
|
||||
engrave_dialog (GimpDrawable *drawable)
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *main_vbox;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *table;
|
||||
GtkWidget *toggle;
|
||||
GtkObject *adj;
|
||||
|
@ -198,7 +209,7 @@ engrave_dialog (void)
|
|||
|
||||
gimp_ui_init ("engrave", FALSE);
|
||||
|
||||
dlg = gimp_dialog_new (_("Engrave"), "engrave",
|
||||
dialog = gimp_dialog_new (_("Engrave"), "engrave",
|
||||
NULL, 0,
|
||||
gimp_standard_help_func, "plug-in-engrave",
|
||||
|
||||
|
@ -207,14 +218,21 @@ engrave_dialog (void)
|
|||
|
||||
NULL);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 0);
|
||||
gtk_widget_show (vbox);
|
||||
main_vbox = gtk_vbox_new (FALSE, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
|
||||
gtk_widget_show (main_vbox);
|
||||
|
||||
preview = gimp_drawable_preview_new (drawable, &pvals.preview);
|
||||
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
|
||||
gtk_widget_show (preview);
|
||||
g_signal_connect_swapped (preview, "invalidated",
|
||||
G_CALLBACK (engrave),
|
||||
drawable);
|
||||
|
||||
table = gtk_table_new (1, 3, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
||||
gtk_widget_show (table);
|
||||
|
||||
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
||||
|
@ -225,21 +243,27 @@ engrave_dialog (void)
|
|||
g_signal_connect (adj, "value_changed",
|
||||
G_CALLBACK (gimp_int_adjustment_update),
|
||||
&pvals.height);
|
||||
g_signal_connect_swapped (adj, "value_changed",
|
||||
G_CALLBACK (gimp_preview_invalidate),
|
||||
preview);
|
||||
|
||||
toggle = gtk_check_button_new_with_mnemonic (_("_Limit line width"));
|
||||
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), pvals.limit);
|
||||
gtk_widget_show (toggle);
|
||||
|
||||
g_signal_connect (toggle, "toggled",
|
||||
G_CALLBACK (gimp_toggle_button_update),
|
||||
&pvals.limit);
|
||||
g_signal_connect_swapped (toggle, "toggled",
|
||||
G_CALLBACK (gimp_preview_invalidate),
|
||||
preview);
|
||||
|
||||
gtk_widget_show (dlg);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
|
||||
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
||||
|
||||
gtk_widget_destroy (dlg);
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
return run;
|
||||
}
|
||||
|
@ -247,25 +271,32 @@ engrave_dialog (void)
|
|||
/* Engrave interface functions */
|
||||
|
||||
static void
|
||||
engrave (GimpDrawable *drawable)
|
||||
engrave (GimpDrawable *drawable,
|
||||
GimpDrawablePreview *preview)
|
||||
{
|
||||
gint tile_width;
|
||||
gint height;
|
||||
gint limit;
|
||||
gboolean limit;
|
||||
|
||||
tile_width = gimp_tile_width();
|
||||
height = pvals.height;
|
||||
limit = pvals.limit;
|
||||
/* [DindinX] this test is always false since
|
||||
* tile_width == 64 and height <= 16 */
|
||||
#if 0
|
||||
if (height >= tile_width)
|
||||
engrave_large (drawable, height, limit);
|
||||
engrave_large (drawable, height, limit, preview);
|
||||
else
|
||||
engrave_small (drawable, height, limit, tile_width);
|
||||
#endif
|
||||
engrave_small (drawable, height, limit, tile_width, preview);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
engrave_large (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gint limit)
|
||||
gboolean limit,
|
||||
GimpDrawablePreview *preview)
|
||||
{
|
||||
GimpPixelRgn src_rgn, dest_rgn;
|
||||
guchar *src_row, *dest_row;
|
||||
|
@ -280,8 +311,8 @@ engrave_large (GimpDrawable *drawable,
|
|||
|
||||
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
||||
|
||||
bpp = (gimp_drawable_is_rgb(drawable->drawable_id)) ? 3 : 1;
|
||||
average = g_new(gulong, bpp);
|
||||
bpp = (gimp_drawable_is_rgb (drawable->drawable_id)) ? 3 : 1;
|
||||
average = g_new (gulong, bpp);
|
||||
|
||||
/* Initialize progress */
|
||||
progress = 0;
|
||||
|
@ -292,7 +323,7 @@ engrave_large (GimpDrawable *drawable,
|
|||
for (x = x1; x < x2; ++x)
|
||||
{
|
||||
y_step = height - (y % height);
|
||||
y_step = MIN(y_step, x2 - x);
|
||||
y_step = MIN (y_step, x2 - x);
|
||||
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable, x, y, 1, y_step,
|
||||
FALSE, FALSE);
|
||||
|
@ -369,6 +400,7 @@ engrave_large (GimpDrawable *drawable,
|
|||
gimp_drawable_merge_shadow(drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update(drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -381,37 +413,53 @@ PixelArea area;
|
|||
|
||||
static void
|
||||
engrave_small (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gint limit,
|
||||
gint tile_width)
|
||||
gint line_height,
|
||||
gboolean limit,
|
||||
gint tile_width,
|
||||
GimpDrawablePreview *preview)
|
||||
{
|
||||
GimpPixelRgn src_rgn, dest_rgn;
|
||||
gint bpp, color_n;
|
||||
gint x1, y1, x2, y2;
|
||||
gint width, height;
|
||||
gint progress, max_progress;
|
||||
|
||||
/*
|
||||
For speed efficiency, operates on PixelAreas, whose each width and
|
||||
height are less than tile size.
|
||||
|
||||
If both ends of area cannot be divided by height ( as
|
||||
x1%height != 0 etc.), operates on the remainder pixels.
|
||||
If both ends of area cannot be divided by line_height ( as
|
||||
x1%line_height != 0 etc.), operates on the remainder pixels.
|
||||
*/
|
||||
|
||||
if (preview)
|
||||
{
|
||||
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
|
||||
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
|
||||
|
||||
x2 = x1 + width;
|
||||
y2 = y1 + height;
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
||||
|
||||
width = x2 - x1;
|
||||
height = y2 - y1;
|
||||
}
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable,
|
||||
x1, y1, x2 - x1, y2 - y1, FALSE, FALSE);
|
||||
x1, y1, width, height, FALSE, FALSE);
|
||||
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
||||
x1, y1, x2 - x1, y2 - y1, TRUE, TRUE);
|
||||
x1, y1, width, height, (preview == NULL), TRUE);
|
||||
|
||||
/* Initialize progress */
|
||||
progress = 0;
|
||||
max_progress = (x2 - x1) * (y2 - y1);
|
||||
max_progress = width * height;
|
||||
|
||||
bpp = drawable->bpp;
|
||||
color_n = (gimp_drawable_is_rgb (drawable->drawable_id)) ? 3 : 1;
|
||||
|
||||
area.width = (tile_width / height) * height;
|
||||
area.width = (tile_width / line_height) * line_height;
|
||||
area.data = g_new(guchar, (glong) bpp * area.width * area.width);
|
||||
|
||||
for (area.y = y1; area.y < y2;
|
||||
|
@ -424,13 +472,15 @@ engrave_small (GimpDrawable *drawable,
|
|||
gimp_pixel_rgn_get_rect (&src_rgn, area.data, area.x, area.y, 1,
|
||||
area.h);
|
||||
|
||||
engrave_sub (height, limit, bpp, color_n);
|
||||
|
||||
gimp_pixel_rgn_set_rect (&dest_rgn, area.data, area.x, area.y, 1,
|
||||
area.h);
|
||||
engrave_sub (line_height, limit, bpp, color_n);
|
||||
|
||||
gimp_pixel_rgn_set_rect (&dest_rgn, area.data,
|
||||
area.x, area.y, 1, area.h);
|
||||
}
|
||||
if (!preview)
|
||||
{
|
||||
/* Update progress */
|
||||
progress += area.h;
|
||||
progress += area.h * width;
|
||||
gimp_progress_update ((double) progress / (double) max_progress);
|
||||
}
|
||||
}
|
||||
|
@ -438,9 +488,16 @@ engrave_small (GimpDrawable *drawable,
|
|||
g_free(area.data);
|
||||
|
||||
/* update the engraved region */
|
||||
if (preview)
|
||||
{
|
||||
gimp_drawable_preview_draw_region (preview, &dest_rgn);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_drawable_flush (drawable);
|
||||
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue