diff --git a/ChangeLog b/ChangeLog index 8e33b7b4e3..45280f926d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-03-31 Michael Natterer + + * app/gimpdnd.[ch]: minor cleanups. + + * libgimp/gimpwidgets.c: don't set a border width for the + radio_group's vbox if no frame around it was requested. + + * plug-ins/common/sample_colorize.c: add a separator between + image and sample. + + * plug-ins/common/iwarp.c: use the libgimp ui functions, removed + callbacks, a global s/gfloat/gdouble/, replaced the booleans + toggling the transform mode with a single variable containing an + enum value, indentation. + 2000-03-31 Sven Neumann * plug-ins/script-fu/scripts/beveled-pattern-heading.scm diff --git a/app/gimpdnd.c b/app/gimpdnd.c index 032b9d2c68..4184863ef7 100644 --- a/app/gimpdnd.c +++ b/app/gimpdnd.c @@ -167,6 +167,7 @@ static GimpDndDataDef dnd_data_defs[] = NULL, NULL, + NULL }, { diff --git a/app/gimpdnd.h b/app/gimpdnd.h index 7d3a29a31f..e233839fcb 100644 --- a/app/gimpdnd.h +++ b/app/gimpdnd.h @@ -100,49 +100,61 @@ typedef enum /* color dnd functions */ -typedef void (* GimpDndDropColorFunc) (GtkWidget *, guchar, guchar, guchar, - gpointer); -typedef void (* GimpDndDragColorFunc) (GtkWidget *, guchar *, guchar *, guchar *, - gpointer); +typedef void (* GimpDndDropColorFunc) (GtkWidget *widget, + guchar r, + guchar g, + guchar b, + gpointer data); +typedef void (* GimpDndDragColorFunc) (GtkWidget *widget, + guchar *r, + guchar *g, + guchar *b, + gpointer data); -void gimp_dnd_color_source_set (GtkWidget *widget, - GimpDndDragColorFunc get_color_func, - gpointer data); -void gimp_dnd_color_dest_set (GtkWidget *widget, - GimpDndDropColorFunc set_color_func, - gpointer data); +void gimp_dnd_color_source_set (GtkWidget *widget, + GimpDndDragColorFunc get_color_func, + gpointer data); +void gimp_dnd_color_dest_set (GtkWidget *widget, + GimpDndDropColorFunc set_color_func, + gpointer data); /* brush dnd functions */ -typedef void (* GimpDndDropBrushFunc) (GtkWidget *, GimpBrush *, - gpointer); -typedef GimpBrush * (* GimpDndDragBrushFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropBrushFunc) (GtkWidget *widget, + GimpBrush *brush, + gpointer data); +typedef GimpBrush * (* GimpDndDragBrushFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_brush_source_set (GtkWidget *widget, - GimpDndDragBrushFunc get_brush_func, - gpointer data); -void gimp_dnd_brush_dest_set (GtkWidget *widget, - GimpDndDropBrushFunc set_brush_func, - gpointer data); +void gimp_dnd_brush_source_set (GtkWidget *widget, + GimpDndDragBrushFunc get_brush_func, + gpointer data); +void gimp_dnd_brush_dest_set (GtkWidget *widget, + GimpDndDropBrushFunc set_brush_func, + gpointer data); /* pattern dnd functions */ -typedef void (* GimpDndDropPatternFunc) (GtkWidget *, GPattern *, - gpointer); -typedef GPattern * (* GimpDndDragPatternFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropPatternFunc) (GtkWidget *widget, + GPattern *pattern, + gpointer data); +typedef GPattern * (* GimpDndDragPatternFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_pattern_source_set (GtkWidget *widget, - GimpDndDragPatternFunc get_pattern_func, - gpointer data); -void gimp_dnd_pattern_dest_set (GtkWidget *widget, - GimpDndDropPatternFunc set_pattern_func, - gpointer data); +void gimp_dnd_pattern_source_set (GtkWidget *widget, + GimpDndDragPatternFunc get_pattern_func, + gpointer data); +void gimp_dnd_pattern_dest_set (GtkWidget *widget, + GimpDndDropPatternFunc set_pattern_func, + gpointer data); /* gradient dnd functions */ -typedef void (* GimpDndDropGradientFunc) (GtkWidget *, gradient_t *, - gpointer); -typedef gradient_t * (* GimpDndDragGradientFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropGradientFunc) (GtkWidget *widget, + gradient_t *gradient, + gpointer data); +typedef gradient_t * (* GimpDndDragGradientFunc) (GtkWidget *widget, + gpointer data); void gimp_dnd_gradient_source_set (GtkWidget *widget, GimpDndDragGradientFunc get_gradient_func, @@ -153,29 +165,33 @@ void gimp_dnd_gradient_dest_set (GtkWidget *widget, /* palette dnd functions */ -typedef void (* GimpDndDropPaletteFunc) (GtkWidget *, - PaletteEntries *, - gpointer); -typedef PaletteEntries * (* GimpDndDragPaletteFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropPaletteFunc) (GtkWidget *widget, + PaletteEntries *palette, + gpointer data); +typedef PaletteEntries * (* GimpDndDragPaletteFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_palette_source_set (GtkWidget *widget, - GimpDndDragPaletteFunc get_palette_func, - gpointer data); -void gimp_dnd_palette_dest_set (GtkWidget *widget, - GimpDndDropPaletteFunc set_palette_func, - gpointer data); +void gimp_dnd_palette_source_set (GtkWidget *widget, + GimpDndDragPaletteFunc get_palette_func, + gpointer data); +void gimp_dnd_palette_dest_set (GtkWidget *widget, + GimpDndDropPaletteFunc set_palette_func, + gpointer data); /* tool dnd functions */ -typedef void (* GimpDndDropToolFunc) (GtkWidget *, ToolType, gpointer); -typedef ToolType (* GimpDndDragToolFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropToolFunc) (GtkWidget *widget, + ToolType tool, + gpointer data); +typedef ToolType (* GimpDndDragToolFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_tool_source_set (GtkWidget *widget, - GimpDndDragToolFunc get_tool_func, - gpointer data); -void gimp_dnd_tool_dest_set (GtkWidget *widget, - GimpDndDropToolFunc set_tool_func, - gpointer data); +void gimp_dnd_tool_source_set (GtkWidget *widget, + GimpDndDragToolFunc get_tool_func, + gpointer data); +void gimp_dnd_tool_dest_set (GtkWidget *widget, + GimpDndDropToolFunc set_tool_func, + gpointer data); /* drawable dnd functions */ diff --git a/app/widgets/gimpdnd.c b/app/widgets/gimpdnd.c index 032b9d2c68..4184863ef7 100644 --- a/app/widgets/gimpdnd.c +++ b/app/widgets/gimpdnd.c @@ -167,6 +167,7 @@ static GimpDndDataDef dnd_data_defs[] = NULL, NULL, + NULL }, { diff --git a/app/widgets/gimpdnd.h b/app/widgets/gimpdnd.h index 7d3a29a31f..e233839fcb 100644 --- a/app/widgets/gimpdnd.h +++ b/app/widgets/gimpdnd.h @@ -100,49 +100,61 @@ typedef enum /* color dnd functions */ -typedef void (* GimpDndDropColorFunc) (GtkWidget *, guchar, guchar, guchar, - gpointer); -typedef void (* GimpDndDragColorFunc) (GtkWidget *, guchar *, guchar *, guchar *, - gpointer); +typedef void (* GimpDndDropColorFunc) (GtkWidget *widget, + guchar r, + guchar g, + guchar b, + gpointer data); +typedef void (* GimpDndDragColorFunc) (GtkWidget *widget, + guchar *r, + guchar *g, + guchar *b, + gpointer data); -void gimp_dnd_color_source_set (GtkWidget *widget, - GimpDndDragColorFunc get_color_func, - gpointer data); -void gimp_dnd_color_dest_set (GtkWidget *widget, - GimpDndDropColorFunc set_color_func, - gpointer data); +void gimp_dnd_color_source_set (GtkWidget *widget, + GimpDndDragColorFunc get_color_func, + gpointer data); +void gimp_dnd_color_dest_set (GtkWidget *widget, + GimpDndDropColorFunc set_color_func, + gpointer data); /* brush dnd functions */ -typedef void (* GimpDndDropBrushFunc) (GtkWidget *, GimpBrush *, - gpointer); -typedef GimpBrush * (* GimpDndDragBrushFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropBrushFunc) (GtkWidget *widget, + GimpBrush *brush, + gpointer data); +typedef GimpBrush * (* GimpDndDragBrushFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_brush_source_set (GtkWidget *widget, - GimpDndDragBrushFunc get_brush_func, - gpointer data); -void gimp_dnd_brush_dest_set (GtkWidget *widget, - GimpDndDropBrushFunc set_brush_func, - gpointer data); +void gimp_dnd_brush_source_set (GtkWidget *widget, + GimpDndDragBrushFunc get_brush_func, + gpointer data); +void gimp_dnd_brush_dest_set (GtkWidget *widget, + GimpDndDropBrushFunc set_brush_func, + gpointer data); /* pattern dnd functions */ -typedef void (* GimpDndDropPatternFunc) (GtkWidget *, GPattern *, - gpointer); -typedef GPattern * (* GimpDndDragPatternFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropPatternFunc) (GtkWidget *widget, + GPattern *pattern, + gpointer data); +typedef GPattern * (* GimpDndDragPatternFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_pattern_source_set (GtkWidget *widget, - GimpDndDragPatternFunc get_pattern_func, - gpointer data); -void gimp_dnd_pattern_dest_set (GtkWidget *widget, - GimpDndDropPatternFunc set_pattern_func, - gpointer data); +void gimp_dnd_pattern_source_set (GtkWidget *widget, + GimpDndDragPatternFunc get_pattern_func, + gpointer data); +void gimp_dnd_pattern_dest_set (GtkWidget *widget, + GimpDndDropPatternFunc set_pattern_func, + gpointer data); /* gradient dnd functions */ -typedef void (* GimpDndDropGradientFunc) (GtkWidget *, gradient_t *, - gpointer); -typedef gradient_t * (* GimpDndDragGradientFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropGradientFunc) (GtkWidget *widget, + gradient_t *gradient, + gpointer data); +typedef gradient_t * (* GimpDndDragGradientFunc) (GtkWidget *widget, + gpointer data); void gimp_dnd_gradient_source_set (GtkWidget *widget, GimpDndDragGradientFunc get_gradient_func, @@ -153,29 +165,33 @@ void gimp_dnd_gradient_dest_set (GtkWidget *widget, /* palette dnd functions */ -typedef void (* GimpDndDropPaletteFunc) (GtkWidget *, - PaletteEntries *, - gpointer); -typedef PaletteEntries * (* GimpDndDragPaletteFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropPaletteFunc) (GtkWidget *widget, + PaletteEntries *palette, + gpointer data); +typedef PaletteEntries * (* GimpDndDragPaletteFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_palette_source_set (GtkWidget *widget, - GimpDndDragPaletteFunc get_palette_func, - gpointer data); -void gimp_dnd_palette_dest_set (GtkWidget *widget, - GimpDndDropPaletteFunc set_palette_func, - gpointer data); +void gimp_dnd_palette_source_set (GtkWidget *widget, + GimpDndDragPaletteFunc get_palette_func, + gpointer data); +void gimp_dnd_palette_dest_set (GtkWidget *widget, + GimpDndDropPaletteFunc set_palette_func, + gpointer data); /* tool dnd functions */ -typedef void (* GimpDndDropToolFunc) (GtkWidget *, ToolType, gpointer); -typedef ToolType (* GimpDndDragToolFunc) (GtkWidget *, gpointer); +typedef void (* GimpDndDropToolFunc) (GtkWidget *widget, + ToolType tool, + gpointer data); +typedef ToolType (* GimpDndDragToolFunc) (GtkWidget *widget, + gpointer data); -void gimp_dnd_tool_source_set (GtkWidget *widget, - GimpDndDragToolFunc get_tool_func, - gpointer data); -void gimp_dnd_tool_dest_set (GtkWidget *widget, - GimpDndDropToolFunc set_tool_func, - gpointer data); +void gimp_dnd_tool_source_set (GtkWidget *widget, + GimpDndDragToolFunc get_tool_func, + gpointer data); +void gimp_dnd_tool_dest_set (GtkWidget *widget, + GimpDndDropToolFunc set_tool_func, + gpointer data); /* drawable dnd functions */ diff --git a/libgimp/gimpwidgets.c b/libgimp/gimpwidgets.c index caefa95c97..20a510f042 100644 --- a/libgimp/gimpwidgets.c +++ b/libgimp/gimpwidgets.c @@ -305,7 +305,6 @@ gimp_radio_group_new (gboolean in_frame, va_list args; vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); group = NULL; @@ -351,6 +350,8 @@ gimp_radio_group_new (gboolean in_frame, { GtkWidget *frame; + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); + frame = gtk_frame_new (frame_title); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); @@ -401,7 +402,6 @@ gimp_radio_group_new2 (gboolean in_frame, va_list args; vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); group = NULL; @@ -444,6 +444,8 @@ gimp_radio_group_new2 (gboolean in_frame, { GtkWidget *frame; + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); + frame = gtk_frame_new (frame_title); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); diff --git a/libgimpwidgets/gimpwidgets.c b/libgimpwidgets/gimpwidgets.c index caefa95c97..20a510f042 100644 --- a/libgimpwidgets/gimpwidgets.c +++ b/libgimpwidgets/gimpwidgets.c @@ -305,7 +305,6 @@ gimp_radio_group_new (gboolean in_frame, va_list args; vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); group = NULL; @@ -351,6 +350,8 @@ gimp_radio_group_new (gboolean in_frame, { GtkWidget *frame; + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); + frame = gtk_frame_new (frame_title); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); @@ -401,7 +402,6 @@ gimp_radio_group_new2 (gboolean in_frame, va_list args; vbox = gtk_vbox_new (FALSE, 1); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); group = NULL; @@ -444,6 +444,8 @@ gimp_radio_group_new2 (gboolean in_frame, { GtkWidget *frame; + gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); + frame = gtk_frame_new (frame_title); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); diff --git a/plug-ins/common/iwarp.c b/plug-ins/common/iwarp.c index d596cafee4..3a4948f651 100644 --- a/plug-ins/common/iwarp.c +++ b/plug-ins/common/iwarp.c @@ -50,177 +50,191 @@ #include "libgimp/stdplugins-intl.h" -#define MAX_PREVIEW_WIDTH 256 -#define MAX_PREVIEW_HEIGHT 256 +#define MAX_PREVIEW_WIDTH 256 +#define MAX_PREVIEW_HEIGHT 256 #define MAX_DEFORM_AREA_RADIUS 100 -#define SCALE_WIDTH 150 +#define SCALE_WIDTH 100 #define MAX_NUM_FRAMES 100 -typedef struct +typedef enum { - gfloat x; - gfloat y; -}vector_2d; - + GROW, + SHRINK, + MOVE, + REMOVE, + SWIRL_CCW, + SWIRL_CW +} DeformMode; typedef struct { - gint run; -}iwarp_interface; - + gint run; +} iwarp_interface; + typedef struct { - gint deform_area_radius; - gfloat deform_amount; - gint do_grow; - gint do_shrink; - gint do_move; - gint do_remove; - gint do_swirl_ccw; - gint do_swirl_cw; - gint do_bilinear; - gint do_supersample; - gfloat supersample_threshold; - gint max_supersample_depth; + gint deform_area_radius; + gdouble deform_amount; + DeformMode deform_mode; + gboolean do_bilinear; + gboolean do_supersample; + gdouble supersample_threshold; + gint max_supersample_depth; } iwarp_vals_t; /* Declare local functions. */ static void query (void); -static void run (char *name, - int nparams, +static void run (gchar *name, + gint nparams, GParam *param, - int *nreturn_vals, + gint *nreturn_vals, GParam **return_vals); -static gint iwarp_dialog(); -static void iwarp(); -static void iwarp_frame(); +static void iwarp (void); +static void iwarp_frame (void); -static void iwarp_ok_callback (GtkWidget *widget, - gpointer data); -static gint iwarp_motion_callback (GtkWidget *widget, - GdkEvent *event); -static void iwarp_iscale_update (GtkAdjustment *adjustment, - gint* scale_val); -static void iwarp_fscale_update (GtkAdjustment *adjustment, - gfloat* scale_val); -static void iwarp_toggle_update (GtkWidget *widget, - int *data); -static void iwarp_supersample_toggle (GtkWidget *widget, - int *data); -static void iwarp_animate_toggle (GtkWidget *widget, - int *data); +static gint iwarp_dialog (void); +static void iwarp_animate_dialog (GtkWidget *dlg, + GtkWidget *notebook); -static void iwarp_reset_callback (GtkWidget *widget, - gpointer data); +static void iwarp_settings_dialog (GtkWidget *dlg, + GtkWidget *notebook); +static void iwarp_ok_callback (GtkWidget *widget, + gpointer data); +static void iwarp_reset_callback (GtkWidget *widget, + gpointer data); -static void iwarp_update_preview(int x0, int y0,int x1,int y1); +static gint iwarp_motion_callback (GtkWidget *widget, + GdkEvent *event); -static gint32 iwarp_layer_copy(gint32 layerID); +static void iwarp_update_preview (gint x0, + gint y0, + gint x1, + gint y1); -static void iwarp_get_pixel(int x, int y, guchar *pixel); +static void iwarp_get_pixel (gint x, + gint y, + guchar *pixel); -static void iwarp_get_deform_vector(gfloat x, gfloat y, - gfloat* xv, gfloat* yv); - -static void iwarp_get_point(gfloat x, gfloat y, guchar *color); +static void iwarp_get_deform_vector (gdouble x, + gdouble y, + gdouble *xv, + gdouble *yv); -static gint iwarp_supersample_test(vector_2d* v0 , vector_2d* v1, - vector_2d* v2, vector_2d* v3); - -static void iwarp_getsample(vector_2d v0, vector_2d v1, - vector_2d v2, vector_2d v3, - gfloat x, gfloat y,gint* sample,gint* cc, - gint depth,gfloat scale); - -static void iwarp_supersample(gint sxl,gint syl ,gint sxr, gint syr, - guchar* dest_data,int stride, - int* progress,int max_progress); - -static guchar iwarp_transparent_color(int x, int y); +static void iwarp_get_point (gdouble x, + gdouble y, + guchar *color); -static void iwarp_cpy_images(); +static gint iwarp_supersample_test (GimpVector2 *v0, + GimpVector2 *v1, + GimpVector2 *v2, + GimpVector2 *v3); -static void iwarp_animate_dialog(GtkWidget* dlg, GtkWidget* notebook); - -static void iwarp_settings_dialog(GtkWidget* dlg, GtkWidget* notebook); +static void iwarp_getsample (GimpVector2 v0, + GimpVector2 v1, + GimpVector2 v2, + GimpVector2 v3, + gdouble x, + gdouble y, + gint *sample, + gint *cc, + gint depth, + gdouble scale); -static void iwarp_preview_get_pixel(int x, int y , guchar **color); +static void iwarp_supersample (gint sxl, + gint syl, + gint sxr, + gint syr, + guchar *dest_data, + gint stride, + gint *progress, + gint max_progress); -static void iwarp_preview_get_point( gfloat x, gfloat y,guchar* color); +static guchar iwarp_transparent_color (gint x, + gint y); -static void iwarp_deform(int x, int y, gfloat vx, gfloat vy); +static void iwarp_cpy_images (void); -static void iwarp_move(int x, int y,int xx, int yy); +static void iwarp_preview_get_pixel (gint x, + gint y, + guchar **color); + +static void iwarp_preview_get_point (gdouble x, + gdouble y, + guchar *color); + +static void iwarp_deform (gint x, + gint y, + gdouble vx, + gdouble vy); + +static void iwarp_move (gint x, + gint y, + gint xx, + gint yy); GPlugInInfo PLUG_IN_INFO = { - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ + NULL, /* init_proc */ + NULL, /* quit_proc */ + query, /* query_proc */ + run, /* run_proc */ }; static iwarp_interface wint = { FALSE }; + static iwarp_vals_t iwarp_vals = { - 20, - 0.3, - FALSE, - FALSE, - TRUE, - FALSE, - FALSE, - FALSE, - TRUE, - FALSE, - 2.0, - 2 -}; + 20, + 0.3, + MOVE, + TRUE, + FALSE, + 2.0, + 2 +}; - -static GDrawable *drawable = NULL; -static GDrawable *destdrawable = NULL; -static GtkWidget *preview = NULL; -static GtkWidget* supersample_frame; -static GtkWidget* animate_frame; -static guchar *srcimage = NULL; -static guchar *dstimage = NULL; -static gint preview_width, preview_height,sel_width,sel_height; -static gint image_bpp; -static gint preserve_trans; -static vector_2d* deform_vectors = NULL; -static vector_2d* deform_area_vectors = NULL; -static int lastx, lasty; -static gfloat filter[MAX_DEFORM_AREA_RADIUS]; -static int do_animate = FALSE; -static int do_animate_reverse = FALSE; -static int do_animate_ping_pong = FALSE; -static gfloat supersample_threshold_2; -static int xl,yl,xh,yh; -static int tile_width, tile_height; -static GTile* tile = NULL; -static gfloat pre2img, img2pre; -static int preview_bpp; -static gfloat animate_deform_value = 1.0; -static gint32 imageID; -static int animate_num_frames = 2; -static int frame_number; -static int layer_alpha; +static GDrawable *drawable = NULL; +static GDrawable *destdrawable = NULL; +static GtkWidget *preview = NULL; +static guchar *srcimage = NULL; +static guchar *dstimage = NULL; +static gint preview_width, preview_height; +static gint sel_width, sel_height; +static gint image_bpp; +static gint preserve_trans; +static GimpVector2 *deform_vectors = NULL; +static GimpVector2 *deform_area_vectors = NULL; +static gint lastx, lasty; +static gdouble filter[MAX_DEFORM_AREA_RADIUS]; +static gboolean do_animate = FALSE; +static gboolean do_animate_reverse = FALSE; +static gboolean do_animate_ping_pong = FALSE; +static gdouble supersample_threshold_2; +static gint xl, yl, xh, yh; +static gint tile_width, tile_height; +static GTile *tile = NULL; +static gdouble pre2img, img2pre; +static gint preview_bpp; +static gdouble animate_deform_value = 1.0; +static gint32 imageID; +static gint animate_num_frames = 2; +static gint frame_number; +static gint layer_alpha; MAIN () static void -query () +query (void) { static GParamDef args[] = { @@ -228,11 +242,7 @@ query () { PARAM_IMAGE, "image", "Input image (unused)" }, { PARAM_DRAWABLE, "drawable", "Input drawable" }, }; - static GParamDef *return_vals = NULL; - static int nargs = sizeof (args) / sizeof (args[0]); - static int nreturn_vals = 0; - - INIT_I18N(); + static gint nargs = sizeof (args) / sizeof (args[0]); gimp_install_procedure ("plug_in_iwarp", "Interactive warping of the specified drawable", @@ -243,15 +253,15 @@ query () N_("/Filters/Distorts/IWarp..."), "RGB*, GRAY*", PROC_PLUG_IN, - nargs, nreturn_vals, - args, return_vals); + nargs, 0, + args, NULL); } static void -run (char *name, - int nparams, +run (gchar *name, + gint nparams, GParam *param, - int *nreturn_vals, + gint *nreturn_vals, GParam **return_vals) { static GParam values[1]; @@ -263,31 +273,40 @@ run (char *name, /* Get the specified drawable */ destdrawable = drawable = gimp_drawable_get (param[2].data.d_drawable); imageID = param[1].data.d_int32; + /* Make sure that the drawable is gray or RGB color */ - if (gimp_drawable_is_rgb (drawable->id) || gimp_drawable_is_gray (drawable->id)) { - switch ( run_mode) { - case RUN_INTERACTIVE : + if (gimp_drawable_is_rgb (drawable->id) || + gimp_drawable_is_gray (drawable->id)) + { + switch (run_mode) + { + case RUN_INTERACTIVE: INIT_I18N_UI(); - gimp_get_data("plug_in_iwarp",&iwarp_vals); - gimp_tile_cache_ntiles(2*(drawable->width +gimp_tile_width()-1) / gimp_tile_width()); - if (iwarp_dialog()) iwarp(); - gimp_set_data("plug_in_iwarp",&iwarp_vals,sizeof(iwarp_vals_t)); + gimp_get_data ("plug_in_iwarp", &iwarp_vals); + gimp_tile_cache_ntiles (2 * (drawable->width + gimp_tile_width ()-1) / + gimp_tile_width ()); + if (iwarp_dialog()) + iwarp(); + gimp_set_data ("plug_in_iwarp", &iwarp_vals, sizeof (iwarp_vals_t)); gimp_displays_flush (); - break; - case RUN_NONINTERACTIVE : - status = STATUS_CALLING_ERROR; - break; - case RUN_WITH_LAST_VALS : - status = STATUS_CALLING_ERROR; + break; + + case RUN_NONINTERACTIVE: + status = STATUS_CALLING_ERROR; break; - default : - break; - } - } - else { + case RUN_WITH_LAST_VALS: + status = STATUS_CALLING_ERROR; + break; + + default: + break; + } + } + else + { status = STATUS_EXECUTION_ERROR; - } + } *nreturn_vals = 1; *return_vals = values; @@ -296,367 +315,469 @@ run (char *name, values[0].data.d_status = status; gimp_drawable_detach (drawable); - if (srcimage != NULL) g_free(srcimage); - if (dstimage != NULL) g_free(dstimage); - if (deform_vectors != NULL) g_free(deform_vectors); - if (deform_area_vectors != NULL) g_free(deform_area_vectors); + + g_free (srcimage); + g_free (dstimage); + g_free (deform_vectors); + g_free (deform_area_vectors); } - - - static void -iwarp_get_pixel(int x, int y, guchar *pixel) +iwarp_get_pixel (gint x, + gint y, + guchar *pixel) { - static gint old_col = -1 , old_row = -1; - guchar* data; - gint col, row; - int i; + static gint old_col = -1; + static gint old_row = -1; + guchar *data; + gint col, row; + gint i; - if (x>=xl && x < xh && y >=yl && y < yh) { - col = x / tile_width; - row = y / tile_height; - if ( col != old_col || row != old_row) { - gimp_tile_unref(tile,FALSE); - tile = gimp_drawable_get_tile(drawable,FALSE,row,col); - gimp_tile_ref(tile); - old_col = col; - old_row = row; - } - data = tile->data + (tile->ewidth * (y % tile_height) + x % tile_width) * image_bpp; - for (i=0; i=0 && x< (preview_width-1) && y>=0 && y<(preview_height-1)) { - xi = (int)x; - yi = (int)y; - dx = x-xi; - dy = y-yi; - i = (yi*preview_width+ xi); - mx0 = deform_vectors[i].x + (deform_vectors[i+1].x-deform_vectors[i].x)*dx; - mx1 = deform_vectors[i+preview_width].x + (deform_vectors[i+preview_width+1].x-deform_vectors[i+preview_width].x)*dx; - my0 = deform_vectors[i].y +dx * (deform_vectors[i+1].y-deform_vectors[i].y); - my1 = deform_vectors[i+preview_width].y + dx * (deform_vectors[i+preview_width+1].y-deform_vectors[i+preview_width].y); - *xv = mx0 + dy *( mx1-mx0); - *yv = my0 + dy * (my1-my0); - } - else *xv = *yv = 0.0; + if (x >= xl && x < xh && y >= yl && y < yh) + { + col = x / tile_width; + row = y / tile_height; + if (col != old_col || row != old_row) + { + gimp_tile_unref (tile, FALSE); + tile = gimp_drawable_get_tile (drawable, FALSE, row, col); + gimp_tile_ref (tile); + old_col = col; + old_row = row; + } + data = + tile->data + + (tile->ewidth * (y % tile_height) + + x % tile_width) * image_bpp; + for (i = 0; i < image_bpp; i++) + *pixel++ = *data++; + } + else + { + pixel[0] = pixel[1] = pixel[2] = pixel[3] = 0; + } } +static void +iwarp_get_deform_vector (gdouble x, + gdouble y, + gdouble *xv, + gdouble *yv) +{ + gint i, xi, yi; + gdouble dx, dy, my0, my1, mx0, mx1; + if (x >= 0 && x < (preview_width - 1) && y >= 0 && y < (preview_height - 1)) + { + xi = (gint) x; + yi = (gint) y; + dx = x-xi; + dy = y-yi; + i = (yi * preview_width + xi); + mx0 = + deform_vectors[i].x + + (deform_vectors[i+1].x - + deform_vectors[i].x) * dx; + mx1 = + deform_vectors[i+preview_width].x + + (deform_vectors[i+preview_width+1].x - + deform_vectors[i+preview_width].x) * dx; + my0 = + deform_vectors[i].y + + dx * (deform_vectors[i+1].y - + deform_vectors[i].y); + my1 = + deform_vectors[i+preview_width].y + + dx * (deform_vectors[i+preview_width+1].y - + deform_vectors[i+preview_width].y); + *xv = mx0 + dy * (mx1 - mx0); + *yv = my0 + dy * (my1 - my0); + } + else + { + *xv = *yv = 0.0; + } +} static void -iwarp_get_point(gfloat x, gfloat y, guchar *color) +iwarp_get_point (gdouble x, + gdouble y, + guchar *color) { - gfloat dx,dy,m0,m1; - guchar p0[4],p1[4],p2[4],p3[4]; - gint xi,yi,i; + gdouble dx, dy, m0, m1; + guchar p0[4], p1[4], p2[4], p3[4]; + gint xi, yi, i; - xi = (int)x; - yi = (int)y; - dx = x-xi; - dy = y-yi; - iwarp_get_pixel(xi,yi,p0); - iwarp_get_pixel(xi+1,yi,p1); - iwarp_get_pixel(xi,yi+1,p2); - iwarp_get_pixel(xi+1,yi+1,p3); - for (i = 0; i < image_bpp; i++) { - m0 = p0[i] + dx*(p1[i]-p0[i]); - m1 = p2[i] + dx*(p3[i]-p2[i]); - color[i] = (guchar)(m0 + dy*(m1-m0)); - } + xi = (gint) x; + yi = (gint) y; + dx = x - xi; + dy = y - yi; + iwarp_get_pixel (xi, yi, p0); + iwarp_get_pixel (xi + 1, yi, p1); + iwarp_get_pixel (xi, yi + 1, p2); + iwarp_get_pixel (xi + 1, yi + 1, p3); + for (i = 0; i < image_bpp; i++) + { + m0 = p0[i] + dx * (p1[i] - p0[i]); + m1 = p2[i] + dx * (p3[i] - p2[i]); + color[i] = (guchar) (m0 + dy * (m1 - m0)); + } } - -static gint -iwarp_supersample_test(vector_2d* v0 , vector_2d* v1, vector_2d* v2, vector_2d* v3) +static gboolean +iwarp_supersample_test (GimpVector2 *v0, + GimpVector2 *v1, + GimpVector2 *v2, + GimpVector2 *v3) { - gfloat dx,dy; + gdouble dx, dy; - dx = 1.0+v1->x - v0->x; - dy = v1->y - v0->y; - if (dx*dx+dy*dy > supersample_threshold_2 ) - return 1; - dx = 1.0+v2->x - v3->x; - dy = v2->y - v3->y; - if (dx*dx+dy*dy > supersample_threshold_2 ) - return 1; - dx = v2->x - v0->x; - dy = 1.0+v2->y - v0->y; - if (dx*dx+dy*dy > supersample_threshold_2 ) - return 1; - dx = v3->x - v1->x; - dy = 1.0+v3->y - v1->y; - if (dx*dx+dy*dy > supersample_threshold_2 ) - return 1; - return 0; + dx = 1.0+v1->x - v0->x; + dy = v1->y - v0->y; + if (dx * dx + dy * dy > supersample_threshold_2) + return TRUE; + + dx = 1.0+v2->x - v3->x; + dy = v2->y - v3->y; + if (dx*dx+dy*dy > supersample_threshold_2) + return TRUE; + + dx = v2->x - v0->x; + dy = 1.0+v2->y - v0->y; + if (dx*dx+dy*dy > supersample_threshold_2) + return TRUE; + + dx = v3->x - v1->x; + dy = 1.0+v3->y - v1->y; + if (dx*dx+dy*dy > supersample_threshold_2) + return TRUE; + + return FALSE; } static void -iwarp_getsample(vector_2d v0, vector_2d v1,vector_2d v2, vector_2d v3, - gfloat x, gfloat y,gint* sample,gint* cc, - gint depth,gfloat scale) +iwarp_getsample (GimpVector2 v0, + GimpVector2 v1, + GimpVector2 v2, + GimpVector2 v3, + gdouble x, + gdouble y, + gint *sample, + gint *cc, + gint depth, + gdouble scale) { - int i; - gfloat xv,yv; - vector_2d v01,v13,v23,v02,vm; - guchar c[4]; + gint i; + gdouble xv, yv; + GimpVector2 v01, v13, v23, v02, vm; + guchar c[4]; - if ((depth >= iwarp_vals.max_supersample_depth) - || (!iwarp_supersample_test(&v0,&v1,&v2,&v3))) { - iwarp_get_deform_vector(img2pre * (x - xl), img2pre * (y-yl),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - iwarp_get_point(pre2img*xv+x,pre2img*yv+y,c); - for (i=0; i< image_bpp; i++) sample[i] += c[i]; - (*cc)++; - } - else { - scale *= 0.5; - iwarp_get_deform_vector(img2pre * (x - xl), img2pre * (y-yl),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - iwarp_get_point(pre2img*xv+x,pre2img*yv+y,c); - for (i=0; i< image_bpp; i++) sample[i] += c[i]; - (*cc)++; - vm.x = xv; - vm.y = yv; + if ((depth >= iwarp_vals.max_supersample_depth) || + (!iwarp_supersample_test (&v0, &v1, &v2, &v3))) + { + iwarp_get_deform_vector (img2pre * (x - xl), + img2pre * (y - yl), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + iwarp_get_point (pre2img * xv + x, pre2img * yv + y, c); + for (i = 0; i < image_bpp; i++) + sample[i] += c[i]; + (*cc)++; + } + else + { + scale *= 0.5; + iwarp_get_deform_vector (img2pre * (x - xl), + img2pre * (y - yl), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + iwarp_get_point (pre2img * xv + x, pre2img * yv + y, c); + for (i = 0; i < image_bpp; i++) + sample[i] += c[i]; + (*cc)++; + vm.x = xv; + vm.y = yv; - iwarp_get_deform_vector(img2pre * (x - xl), img2pre * (y-yl-scale),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - v01.x = xv; - v01.y = yv; + iwarp_get_deform_vector (img2pre * (x - xl), + img2pre * (y - yl - scale), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + v01.x = xv; + v01.y = yv; - iwarp_get_deform_vector(img2pre * (x - xl+scale), img2pre * (y-yl),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - v13.x = xv; - v13.y = yv; + iwarp_get_deform_vector (img2pre * (x - xl + scale), + img2pre * (y - yl), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + v13.x = xv; + v13.y = yv; - iwarp_get_deform_vector(img2pre * (x - xl), img2pre * (y-yl+scale),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - v23.x = xv; - v23.y = yv; + iwarp_get_deform_vector (img2pre * (x - xl), + img2pre * (y - yl + scale), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + v23.x = xv; + v23.y = yv; + + iwarp_get_deform_vector (img2pre * (x - xl - scale), + img2pre * (y - yl), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + v02.x = xv; + v02.y = yv; - iwarp_get_deform_vector(img2pre * (x - xl-scale), img2pre * (y-yl),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - v02.x = xv; - v02.y = yv; - - iwarp_getsample(v0,v01,vm,v02,x-scale, y-scale,sample, cc, depth+1, - scale); - iwarp_getsample(v01,v1,v13,vm,x+scale, y-scale,sample, cc, depth+1, - scale); - iwarp_getsample(v02,vm,v23,v2,x-scale, y+scale,sample, cc, depth+1, - scale); - iwarp_getsample(vm,v13,v3,v23,x+scale, y+scale,sample, cc, depth+1, - scale); - } + iwarp_getsample (v0, v01, vm, v02, + x-scale, y-scale, + sample, cc, depth + 1, + scale); + iwarp_getsample (v01, v1, v13, vm, + x + scale, y - scale, + sample, cc, depth + 1, + scale); + iwarp_getsample (v02, vm, v23, v2, + x - scale, y + scale, + sample, cc, depth + 1, + scale); + iwarp_getsample (vm, v13, v3, v23, + x + scale, y + scale, + sample, cc, depth + 1, + scale); + } } - static void -iwarp_supersample(gint sxl,gint syl ,gint sxr, gint syr,guchar* dest_data,int stride, - int* progress,int max_progress) +iwarp_supersample (gint sxl, + gint syl, + gint sxr, + gint syr, + guchar *dest_data, + gint stride, + gint *progress, + gint max_progress) { - int i,wx,wy,col,row,cc; - vector_2d *srow,*srow_old, *vh; - gfloat xv,yv; - gint color[4]; - guchar *dest; + gint i, wx, wy, col, row, cc; + GimpVector2 *srow, *srow_old, *vh; + gdouble xv, yv; + gint color[4]; + guchar *dest; - wx = sxr-sxl+1; - wy = syr-syl+1; - srow = g_malloc((sxr-sxl+1)*2*sizeof(gfloat)); - srow_old = g_malloc((sxr-sxl+1)*2*sizeof(gfloat)); + wx = sxr - sxl + 1; + wy = syr - syl + 1; + srow = g_new (GimpVector2, sxr - sxl + 1); + srow_old = g_new (GimpVector2, sxr - sxl + 1); - for (i=sxl; i< (sxr+1); i++) { - iwarp_get_deform_vector(img2pre * (-0.5 +i-xl), img2pre * (-0.5+syl-yl),&xv,&yv); - xv *= animate_deform_value; yv *= animate_deform_value; - srow_old[i-sxl].x = xv; - srow_old[i-sxl].y = yv; - } + for (i = sxl; i < (sxr + 1); i++) + { + iwarp_get_deform_vector (img2pre * (-0.5 + i - xl), + img2pre * (-0.5 + syl - yl), + &xv, &yv); + xv *= animate_deform_value; + yv *= animate_deform_value; + srow_old[i-sxl].x = xv; + srow_old[i-sxl].y = yv; + } - for (col = syl; col 0.0 || fabs(yv) > 0.0) { - iwarp_get_point(pre2img * xv +col, pre2img *yv +row,color); - for (i=0; i 0.0 || fabs(yv) > 0.0) + { + iwarp_get_point (pre2img * xv + col, + pre2img *yv + row, + color); + for (i = 0; i < image_bpp; i++) + *dest++ = color[i]; + if (layer_alpha) + *dest++ = 255; + } + else + { + iwarp_get_pixel (col, row, color); + for (i = 0; i < image_bpp; i++) + *dest++ = color[i]; + if (layer_alpha) + *dest++ = 255; + } + } + dest_row += dest_rgn.rowstride; + gimp_progress_update ((gdouble) (progress) / max_progress); + } + } + else + { + supersample_threshold_2 = + iwarp_vals.supersample_threshold * iwarp_vals.supersample_threshold; + iwarp_supersample (dest_rgn.x, dest_rgn.y, + dest_rgn.x + dest_rgn.w, dest_rgn.y + dest_rgn.h, + dest_rgn.data, + dest_rgn.rowstride, + &progress, max_progress); + } + } + gimp_drawable_flush (destdrawable); gimp_drawable_merge_shadow (destdrawable->id, TRUE); gimp_drawable_update (destdrawable->id, xl, yl, (xh - xl), (yh - yl)); - } -static gint32 -iwarp_layer_copy(gint32 layerID) +static void +iwarp (void) { - GParam *return_vals; - int nreturn_vals; - gint32 nlayer; + gint i; + gint32 layerID; + gint32 *animlayers; + gchar *st; + gdouble delta; - return_vals = gimp_run_procedure ("gimp_layer_copy", - &nreturn_vals, - PARAM_LAYER, layerID, - PARAM_INT32, TRUE, - PARAM_END); - - if (return_vals[0].data.d_status == STATUS_SUCCESS) - nlayer = return_vals[1].data.d_layer; - else nlayer = -1; - gimp_destroy_params(return_vals, nreturn_vals); - return nlayer; -} - - - - -static void iwarp() -{ - int i; - gint32 layerID; - gint32 *animlayers; - gchar *st; - gfloat delta; - - - if (animate_num_frames > 1 && do_animate) { - animlayers = g_malloc(animate_num_frames * sizeof(gint32)); - if (do_animate_reverse) { - animate_deform_value = 1.0; - delta = -1.0/(animate_num_frames-1); - } - else { - animate_deform_value = 0.0; - delta = 1.0/(animate_num_frames-1); - } - layerID = gimp_image_get_active_layer(imageID); - if (image_bpp == 1 || image_bpp == 3) layer_alpha = TRUE; else layer_alpha = FALSE; - frame_number = 0; - for (i=0; i< animate_num_frames; i++) { - st = g_strdup_printf (_("Frame %d"),i); - animlayers[i] = iwarp_layer_copy(layerID); - gimp_layer_set_name(animlayers[i],st); - g_free (st); - destdrawable = gimp_drawable_get(animlayers[i]); - st = g_strdup_printf (_("Warping Frame Nr %d ..."),frame_number); - gimp_progress_init(st); - g_free (st); - if (animate_deform_value >0.0) iwarp_frame(); - gimp_image_add_layer(imageID,animlayers[i],0); - animate_deform_value = animate_deform_value + delta; - frame_number++; - } - if (do_animate_ping_pong) { - st = g_strdup_printf (_("Warping Frame Nr %d ..."),frame_number); - gimp_progress_init( _("Ping Pong")); - g_free (st); - for (i=0; i < animate_num_frames; i++) { - gimp_progress_update((double)i / (animate_num_frames-1)); - layerID = iwarp_layer_copy(animlayers[animate_num_frames-i-1]); - st = g_strdup_printf (_("Frame %d"),i+animate_num_frames); - gimp_layer_set_name(layerID,st); - g_free (st); - gimp_image_add_layer(imageID,layerID,0); - } - } - g_free(animlayers); - } - else { - animate_deform_value = 1.0; - iwarp_frame(); - } - if (tile != NULL) { - gimp_tile_unref(tile, FALSE); - tile = NULL; - } -} + if (animate_num_frames > 1 && do_animate) + { + animlayers = g_new (gint32, animate_num_frames); + if (do_animate_reverse) + { + animate_deform_value = 1.0; + delta = -1.0 / (animate_num_frames - 1); + } + else + { + animate_deform_value = 0.0; + delta = 1.0 / (animate_num_frames - 1); + } + layerID = gimp_image_get_active_layer (imageID); + if (image_bpp == 1 || image_bpp == 3) + layer_alpha = TRUE; + else + layer_alpha = FALSE; + frame_number = 0; + for (i = 0; i < animate_num_frames; i++) + { + st = g_strdup_printf (_("Frame %d"), i); + animlayers[i] = gimp_layer_copy (layerID); + gimp_layer_set_name (animlayers[i], st); + g_free (st); + destdrawable = gimp_drawable_get (animlayers[i]); + st = g_strdup_printf (_("Warping Frame Nr %d ..."), frame_number); + gimp_progress_init (st); + g_free (st); + if (animate_deform_value >0.0) + iwarp_frame (); + gimp_image_add_layer (imageID, animlayers[i], 0); + animate_deform_value = animate_deform_value + delta; + frame_number++; + } + if (do_animate_ping_pong) + { + st = g_strdup_printf (_("Warping Frame Nr %d ..."), frame_number); + gimp_progress_init (_("Ping Pong")); + g_free (st); + for (i = 0; i < animate_num_frames; i++) + { + gimp_progress_update ((gdouble) i / (animate_num_frames - 1)); + layerID = gimp_layer_copy (animlayers[animate_num_frames-i-1]); + st = g_strdup_printf (_("Frame %d"), i + animate_num_frames); + gimp_layer_set_name (layerID, st); + g_free (st); + gimp_image_add_layer (imageID, layerID, 0); + } + } + g_free (animlayers); + } + else + { + animate_deform_value = 1.0; + iwarp_frame (); + } + if (tile != NULL) + { + gimp_tile_unref (tile, FALSE); + tile = NULL; + } +} static guchar iwarp_transparent_color (gint x, @@ -670,34 +791,39 @@ iwarp_transparent_color (gint x, return GIMP_CHECK_LIGHT * 255; } else - if ((x % (GIMP_CHECK_SIZE * 4)) < (GIMP_CHECK_SIZE * 2)) - return GIMP_CHECK_DARK * 255; - else - return GIMP_CHECK_LIGHT * 255; + { + if ((x % (GIMP_CHECK_SIZE * 4)) < (GIMP_CHECK_SIZE * 2)) + return GIMP_CHECK_DARK * 255; + else + return GIMP_CHECK_LIGHT * 255; + } } static void iwarp_cpy_images (void) { - int i,j,k,p; - gfloat alpha; - guchar *srccolor, *dstcolor; + gint i, j, k, p; + gdouble alpha; + guchar *srccolor, *dstcolor; if (image_bpp == 1 || image_bpp ==3) - memcpy(dstimage,srcimage,preview_width *preview_height*preview_bpp); + { + memcpy (dstimage, srcimage, preview_width * preview_height * preview_bpp); + } else { - for (i=0; i< preview_width; i++) - for (j=0; j< preview_height; j++) + for (i = 0; i< preview_width; i++) + for (j = 0; j< preview_height; j++) { - p = (j*preview_width+i) ; - srccolor = srcimage + p*image_bpp; - alpha = (gfloat)srccolor[image_bpp-1]/255; - dstcolor = dstimage + p*preview_bpp; - for (k=0; k id, &xl, &yl, &xh, &yh); - sel_width = xh-xl; - sel_height = yh-yl; - image_bpp = gimp_drawable_bpp(drawable->id); - if (gimp_drawable_is_layer (drawable->id)) - preserve_trans = (gimp_layer_get_preserve_transparency (drawable->id)); - else - preserve_trans = FALSE; - if (image_bpp <3) preview_bpp = 1; else preview_bpp = 3; - dx = (gfloat) sel_width / MAX_PREVIEW_WIDTH; - dy = (gfloat) sel_height / MAX_PREVIEW_HEIGHT; - if (dx >dy) pre2img = dx; else pre2img = dy; - if (dx <=1.0 && dy <= 1.0) pre2img = 1.0; - img2pre = 1.0 / pre2img; - preview_width = (int)(sel_width / pre2img); - preview_height = (int)(sel_height / pre2img); - tile_width = gimp_tile_width(); - tile_height = gimp_tile_height(); + gimp_drawable_mask_bounds (drawable->id, &xl, &yl, &xh, &yh); + sel_width = xh-xl; + sel_height = yh-yl; + image_bpp = gimp_drawable_bpp (drawable->id); + if (gimp_drawable_is_layer (drawable->id)) + preserve_trans = (gimp_layer_get_preserve_transparency (drawable->id)); + else + preserve_trans = FALSE; + if (image_bpp < 3) + preview_bpp = 1; + else + preview_bpp = 3; + dx = (gdouble) sel_width / MAX_PREVIEW_WIDTH; + dy = (gdouble) sel_height / MAX_PREVIEW_HEIGHT; + if (dx >dy) + pre2img = dx; + else + pre2img = dy; + if (dx <=1.0 && dy <= 1.0) + pre2img = 1.0; + img2pre = 1.0 / pre2img; + preview_width = (gint) (sel_width / pre2img); + preview_height = (gint) (sel_height / pre2img); + tile_width = gimp_tile_width (); + tile_height = gimp_tile_height (); - srcimage = g_malloc(preview_width * preview_height * image_bpp * sizeof(guchar)); - dstimage = g_malloc(preview_width * preview_height * preview_bpp * sizeof(guchar)); - deform_vectors = g_malloc(preview_width * preview_height*sizeof(gfloat)*2); - deform_area_vectors = g_malloc((MAX_DEFORM_AREA_RADIUS*2+1)*(MAX_DEFORM_AREA_RADIUS*2+1)*sizeof(gfloat)*2); - linebuffer = g_malloc(sel_width* image_bpp *sizeof(guchar)); + srcimage = g_new (guchar, preview_width * preview_height * image_bpp); + dstimage = g_new (guchar, preview_width * preview_height * preview_bpp); + deform_vectors = g_new (GimpVector2, preview_width * preview_height); + deform_area_vectors = g_new (GimpVector2, + (MAX_DEFORM_AREA_RADIUS * 2 + 1) * + (MAX_DEFORM_AREA_RADIUS * 2 + 1)); + linebuffer = g_new (guchar, sel_width * image_bpp); - for (i=0; ivbox), main_hbox, + FALSE, FALSE, 0); + + frame = gtk_frame_new (_("Preview")); + gtk_box_pack_start (GTK_BOX (main_hbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_set_border_width (GTK_CONTAINER (abox), 4); + gtk_container_add (GTK_CONTAINER (frame), abox); + gtk_widget_show (abox); + + pframe = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (pframe), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (abox), pframe); + gtk_widget_show (pframe); + + if (preview_bpp == 3) + preview = gtk_preview_new (GTK_PREVIEW_COLOR); + else + preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE); + gtk_preview_size (GTK_PREVIEW (preview), preview_width, preview_height); + iwarp_update_preview (0, 0, preview_width, preview_height); + gtk_container_add (GTK_CONTAINER (pframe), preview); + gtk_widget_show (preview); - pframe = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (pframe), GTK_SHADOW_IN); - gtk_widget_show (pframe); + gtk_widget_set_events (preview, + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_BUTTON1_MOTION_MASK | + GDK_POINTER_MOTION_HINT_MASK); + gtk_signal_connect (GTK_OBJECT(preview), "event", + GTK_SIGNAL_FUNC (iwarp_motion_callback), + NULL); - if (preview_bpp == 3) preview = gtk_preview_new (GTK_PREVIEW_COLOR); - else preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE); - gtk_preview_size (GTK_PREVIEW (preview), preview_width, preview_height); - iwarp_update_preview(0,0,preview_width,preview_height); - gtk_container_add (GTK_CONTAINER (pframe), preview); - gtk_widget_show (preview); - - gtk_widget_set_events(preview,GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - gtk_signal_connect(GTK_OBJECT(preview), "event", - (GtkSignalFunc)iwarp_motion_callback,NULL); + notebook = gtk_notebook_new (); + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP); + gtk_box_pack_start (GTK_BOX (main_hbox), notebook, TRUE, TRUE, 0); - notebook = gtk_notebook_new(); - gtk_notebook_set_tab_pos(GTK_NOTEBOOK (notebook), GTK_POS_TOP); - - iwarp_settings_dialog(dlg,notebook); - iwarp_animate_dialog(dlg,notebook); - - gtk_widget_show(notebook); - - top_table = gtk_table_new(1, 2, FALSE); - gtk_container_border_width(GTK_CONTAINER(top_table), 6); - gtk_table_set_row_spacings(GTK_TABLE(top_table), 5); - gtk_table_set_col_spacings(GTK_TABLE(top_table), 3); - gtk_table_attach(GTK_TABLE(top_table), pframe, 0,1,0,1,0,0,0,0); - gtk_table_attach(GTK_TABLE(top_table), notebook, 1,2,0,1,0,0,0,0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), top_table, FALSE, FALSE, 0); - gtk_widget_show(top_table); - gtk_widget_show(dlg); - gtk_main (); - gdk_flush (); + iwarp_settings_dialog (dlg, notebook); + iwarp_animate_dialog (dlg, notebook); - return wint.run; + gtk_widget_show (notebook); + + gtk_widget_show (main_hbox); + gtk_widget_show (dlg); + + gtk_main (); + gdk_flush (); + + return wint.run; } - static void -iwarp_update_preview(int x0, int y0,int x1,int y1) +iwarp_update_preview (gint x0, + gint y0, + gint x1, + gint y1) { - int i; - GdkRectangle rect; + gint i; + GdkRectangle rect; - if (x0<0) x0=0; - if (y0<0) y0=0; - if (x1>=preview_width) x1=preview_width; - if (y1>=preview_height) y1=preview_height; - for (i = y0; i < y1; i++) + if (x0 < 0) + x0 = 0; + if (y0 < 0) + y0 = 0; + if (x1 >= preview_width) + x1 = preview_width; + if (y1 >= preview_height) + y1 = preview_height; + for (i = y0; i < y1; i++) gtk_preview_draw_row (GTK_PREVIEW (preview), dstimage + (i * preview_width + x0) * preview_bpp, x0, i,x1-x0); - rect.x = x0; - rect.y = y0; - rect.width = x1-x0; - rect.height = y1-y0; - gtk_widget_draw(preview,&rect); - gdk_flush(); + rect.x = x0; + rect.y = y0; + rect.width = x1-x0; + rect.height = y1-y0; + gtk_widget_draw (preview, &rect); + gdk_flush (); } - static void -iwarp_preview_get_pixel(int x, int y , guchar **color) +iwarp_preview_get_pixel (gint x, + gint y, + guchar **color) { - static guchar black[4] = {0,0,0,0}; + static guchar black[4] = { 0, 0, 0, 0 }; - if (x < 0 || x >= preview_width || y<0 || y >= preview_height) { - *color = black; - return; - } - *color = srcimage +(y*preview_width+ x)*image_bpp; + if (x < 0 || x >= preview_width || y<0 || y >= preview_height) + { + *color = black; + return; + } + *color = srcimage + (y * preview_width + x) * image_bpp; } - - static void -iwarp_preview_get_point( gfloat x, gfloat y,guchar* color) +iwarp_preview_get_point (gdouble x, + gdouble y, + guchar *color) { - int xi,yi,j; - gfloat dx,dy,m0,m1; - guchar *p0,*p1,*p2,*p3; + gint xi, yi, j; + gdouble dx, dy, m0, m1; + guchar *p0, *p1, *p2, *p3; - xi = (int)x; - yi = (int)y; - if (iwarp_vals.do_bilinear) { - dx = x-xi; - dy = y-yi; - iwarp_preview_get_pixel(xi,yi,&p0); - iwarp_preview_get_pixel(xi+1,yi,&p1); - iwarp_preview_get_pixel(xi,yi+1,&p2); - iwarp_preview_get_pixel(xi+1,yi+1,&p3); - for (j=0; j< image_bpp; j++) { - m0 = p0[j] +dx * (p1[j]-p0[j]); - m1 = p2[j]+ dx * (p3[j]-p2[j]); - color[j] = (guchar)(m0 + dy * (m1-m0)); - } - } - else { - iwarp_preview_get_pixel(xi,yi,&p0); - for (j=0; j < image_bpp; j++) color[j] = p0[j]; - } - + xi = (gint) x; + yi = (gint) y; + if (iwarp_vals.do_bilinear) + { + dx = x-xi; + dy = y-yi; + iwarp_preview_get_pixel (xi, yi, &p0); + iwarp_preview_get_pixel (xi + 1, yi, &p1); + iwarp_preview_get_pixel (xi, yi + 1, &p2); + iwarp_preview_get_pixel (xi + 1, yi + 1, &p3); + for (j = 0; j < image_bpp; j++) + { + m0 = p0[j] + dx * (p1[j] - p0[j]); + m1 = p2[j] + dx * (p3[j] - p2[j]); + color[j] = (guchar) (m0 + dy * (m1 - m0)); + } + } + else + { + iwarp_preview_get_pixel (xi, yi, &p0); + for (j = 0; j < image_bpp; j++) + color[j] = p0[j]; + } } - static void -iwarp_deform(int x, int y, gfloat vx, gfloat vy) +iwarp_deform (gint x, + int y, + gdouble vx, + gdouble vy) { - int xi,yi,ptr,fptr,x0,x1,y0,y1,radius2,length2; - gfloat deform_value,xn,yn,nvx=0,nvy=0,emh,em,edge_width,xv,yv,alpha; - guchar color[4]; + gint xi, yi, ptr, fptr, x0, x1, y0, y1, radius2, length2; + gdouble deform_value, xn, yn, nvx=0, nvy=0, emh, em, edge_width, xv, yv, alpha; + guchar color[4]; - if (x - iwarp_vals.deform_area_radius <0) x0 = -x; else x0 = -iwarp_vals.deform_area_radius; - if (x + iwarp_vals.deform_area_radius >= preview_width) x1 = preview_width-x-1; else x1 = iwarp_vals.deform_area_radius; - if (y - iwarp_vals.deform_area_radius <0) y0 = -y; else y0 = -iwarp_vals.deform_area_radius; - if (y + iwarp_vals.deform_area_radius >= preview_height) y1 = preview_height-y-1; else y1 = iwarp_vals.deform_area_radius; + if (x - iwarp_vals.deform_area_radius <0) + x0 = -x; + else + x0 = -iwarp_vals.deform_area_radius; - radius2 = iwarp_vals.deform_area_radius*iwarp_vals.deform_area_radius; - for (yi= y0; yi <= y1; yi++) - for (xi = x0; xi <= x1; xi++) { - length2 = (xi*xi+yi*yi)*MAX_DEFORM_AREA_RADIUS / radius2; - if (length2 < MAX_DEFORM_AREA_RADIUS) { - ptr = (y + yi) * preview_width + x + xi; - fptr = (yi+iwarp_vals.deform_area_radius) * (iwarp_vals.deform_area_radius*2+1) + xi+iwarp_vals.deform_area_radius; - - if (iwarp_vals.do_grow) { - deform_value = filter[length2] * 0.1* iwarp_vals.deform_amount; - nvx = -deform_value * xi; - nvy = -deform_value * yi; - } - else if (iwarp_vals.do_shrink) { - deform_value = filter[length2] * 0.1* iwarp_vals.deform_amount; - nvx = deform_value * xi; - nvy = deform_value * yi; - } - else if (iwarp_vals.do_swirl_cw) { - deform_value = filter[length2] * iwarp_vals.deform_amount * 0.5; - nvx = deform_value * yi; - nvy = -deform_value * xi; - } - else if (iwarp_vals.do_swirl_ccw) { - deform_value = filter[length2] *iwarp_vals.deform_amount * 0.5; - nvx = -deform_value * yi; - nvy = deform_value * xi; - } - else if (iwarp_vals.do_move) { - deform_value = filter[length2] * iwarp_vals.deform_amount; - nvx = deform_value * vx; - nvy = deform_value * vy; - } - if (iwarp_vals.do_remove) { - deform_value = 1.0-0.5*iwarp_vals.deform_amount*filter[length2]; - deform_area_vectors[fptr].x = deform_value * deform_vectors[ptr].x ; - deform_area_vectors[fptr].y = deform_value * deform_vectors[ptr].y ; - } - else { - edge_width = 0.2 * iwarp_vals.deform_area_radius; - emh = em = 1.0; - if (x+xi < edge_width) em = (gfloat)(x+xi) / (edge_width); - if (y+yi < edge_width) emh = (gfloat)(y+yi) / (edge_width); - if (emh = preview_width) + x1 = preview_width - x - 1; + else + x1 = iwarp_vals.deform_area_radius; - iwarp_get_deform_vector(nvx + x+ xi,nvy + y +yi, &xv , &yv); - xv = nvx +xv; - if (xv +x+xi <0.0) xv = -x-xi; - else if (xv + x +xi > (preview_width-1)) xv = preview_width - x -xi-1; - yv = nvy +yv; - if (yv +y+yi <0.0) yv = -y-yi; - else if (yv + y +yi > (preview_height-1)) yv = preview_height - y -yi-1; - deform_area_vectors[fptr].x =xv; - deform_area_vectors[fptr].y = yv; - } + if (y - iwarp_vals.deform_area_radius < 0) + y0 = -y; + else + y0 = -iwarp_vals.deform_area_radius; - xn = deform_area_vectors[fptr].x + x + xi; - yn = deform_area_vectors[fptr].y + y + yi; - - /* gcc - shut up! */ - alpha = 1; + if (y + iwarp_vals.deform_area_radius >= preview_height) + y1 = preview_height-y-1; + else + y1 = iwarp_vals.deform_area_radius; - /* Yeah, it is ugly but since color is a pointer into image-data - I must not change color[image_bpp - 1] ... */ + radius2 = iwarp_vals.deform_area_radius * iwarp_vals.deform_area_radius; - if (preserve_trans && (image_bpp == 4 || image_bpp == 2)) { - iwarp_preview_get_point (x + xi, y + yi, color); - alpha = (gfloat) color[image_bpp - 1] / 255; - } + for (yi = y0; yi <= y1; yi++) + for (xi = x0; xi <= x1; xi++) + { + length2 = (xi * xi + yi * yi) * MAX_DEFORM_AREA_RADIUS / radius2; + if (length2 < MAX_DEFORM_AREA_RADIUS) + { + ptr = (y + yi) * preview_width + x + xi; + fptr = + (yi + iwarp_vals.deform_area_radius) * + (iwarp_vals.deform_area_radius * 2 + 1) + + xi + + iwarp_vals.deform_area_radius; - iwarp_preview_get_point(xn,yn,color); + switch (iwarp_vals.deform_mode) + { + case GROW: + deform_value = filter[length2] * 0.1* iwarp_vals.deform_amount; + nvx = -deform_value * xi; + nvy = -deform_value * yi; + break; - if (!preserve_trans && (image_bpp == 4 || image_bpp == 2)) { - alpha = (gfloat) color[image_bpp - 1] / 255; - } + case SHRINK: + deform_value = filter[length2] * 0.1* iwarp_vals.deform_amount; + nvx = deform_value * xi; + nvy = deform_value * yi; + break; - if (preview_bpp == 3) { - if (image_bpp == 4) { - dstimage[ptr*3] = (guchar)(alpha*color[0]+ (1.0-alpha)*iwarp_transparent_color(x+xi,y+yi)); - dstimage[ptr*3+1] = (guchar)(alpha*color[1]+ (1.0-alpha)*iwarp_transparent_color(x+xi,y+yi)); - dstimage[ptr*3+2] = (guchar)(alpha*color[2]+ (1.0-alpha)*iwarp_transparent_color(x+xi,y+yi)); - } - else { - dstimage[ptr*3] = color[0]; - dstimage[ptr*3+1] = color[1]; - dstimage[ptr*3+2] = color[2]; - } - } - else { - if (image_bpp == 2) { - dstimage[ptr] = (guchar)(alpha *color[0]+ (1.0-alpha)*iwarp_transparent_color(x+xi,y+yi)) ; - } - else - dstimage[ptr] = color[0]; - } - } - } - - for (yi= y0; yi <= y1; yi++) - for (xi = x0; xi <= x1; xi++) { - length2 = (xi*xi+yi*yi)*MAX_DEFORM_AREA_RADIUS / radius2; - if (length2 (preview_width-1)) + xv = preview_width - x -xi-1; + yv = nvy +yv; + if (yv + y + yi < 0.0) + yv = -y - yi; + else if (yv + y + yi > (preview_height-1)) + yv = preview_height - y -yi - 1; + deform_area_vectors[fptr].x = xv; + deform_area_vectors[fptr].y = yv; + } + + xn = deform_area_vectors[fptr].x + x + xi; + yn = deform_area_vectors[fptr].y + y + yi; + + /* gcc - shut up! */ + alpha = 1; + + /* Yeah, it is ugly but since color is a pointer into image-data + * I must not change color[image_bpp - 1] ... + */ + if (preserve_trans && (image_bpp == 4 || image_bpp == 2)) + { + iwarp_preview_get_point (x + xi, y + yi, color); + alpha = (gdouble) color[image_bpp - 1] / 255; + } + + iwarp_preview_get_point (xn, yn, color); + + if (!preserve_trans && (image_bpp == 4 || image_bpp == 2)) + { + alpha = (gdouble) color[image_bpp - 1] / 255; + } + + if (preview_bpp == 3) + { + if (image_bpp == 4) + { + dstimage[ptr*3] = + (guchar) (alpha * color[0] + + (1.0 - alpha) * + iwarp_transparent_color (x + xi, y + yi)); + dstimage[ptr*3+1] = + (guchar) (alpha * color[1] + + (1.0 - alpha) * + iwarp_transparent_color (x + xi, y + yi)); + dstimage[ptr*3+2] = + (guchar) (alpha * color[2] + + (1.0 - alpha) * + iwarp_transparent_color (x + xi, y + yi)); + } + else + { + dstimage[ptr*3] = color[0]; + dstimage[ptr*3+1] = color[1]; + dstimage[ptr*3+2] = color[2]; + } + } + else + { + if (image_bpp == 2) + { + dstimage[ptr] = + (guchar) (alpha * color[0] + + (1.0 - alpha) * + iwarp_transparent_color (x + xi, y + yi)) ; + } + else + { + dstimage[ptr] = color[0]; + } + } + } + } + + for (yi = y0; yi <= y1; yi++) + for (xi = x0; xi <= x1; xi++) + { + length2 = (xi*xi+yi*yi) * MAX_DEFORM_AREA_RADIUS / radius2; + if (length2 type) { - case GDK_BUTTON_PRESS: + mb = (GdkEventButton *) event; + switch (event->type) + { + case GDK_BUTTON_PRESS: lastx = mb->x; lasty = mb->y; - break; - case GDK_BUTTON_RELEASE: - if (mb->state & GDK_BUTTON1_MASK) { - x = mb->x; - y = mb->y; - if (iwarp_vals.do_move) iwarp_move(x,y,lastx,lasty); - else iwarp_deform(x, y,0.0,0.0); - } - break; - case GDK_MOTION_NOTIFY : - if (mb->state & GDK_BUTTON1_MASK) { - x = mb->x; - y = mb->y; - if (iwarp_vals.do_move) iwarp_move(x,y,lastx,lasty); - else iwarp_deform(x, y,0.0,0.0); - lastx = x; - lasty = y; - gtk_widget_get_pointer(widget,NULL,NULL); - } - break; - default: - break; - } + break; + + case GDK_BUTTON_RELEASE: + if (mb->state & GDK_BUTTON1_MASK) + { + x = mb->x; + y = mb->y; + if (iwarp_vals.deform_mode == MOVE) + iwarp_move (x, y, lastx, lasty); + else + iwarp_deform (x, y, 0.0, 0.0); + } + break; -return FALSE; + case GDK_MOTION_NOTIFY: + if (mb->state & GDK_BUTTON1_MASK) + { + x = mb->x; + y = mb->y; + if (iwarp_vals.deform_mode == MOVE) + iwarp_move (x, y, lastx, lasty); + else + iwarp_deform (x, y, 0.0, 0.0); + lastx = x; + lasty = y; + gtk_widget_get_pointer (widget, NULL, NULL); + } + break; + + default: + break; + } + + return FALSE; } - -static void -iwarp_iscale_update (GtkAdjustment *adjustment, gint* scale_val) -{ - *scale_val = (gint)adjustment->value; -} - -static void -iwarp_fscale_update (GtkAdjustment *adjustment, gfloat* scale_val) -{ - *scale_val = adjustment->value; -} - - - -static void -iwarp_toggle_update (GtkWidget *widget, - int *data) -{ - if ( GTK_TOGGLE_BUTTON (widget)->active) *data = TRUE; - else *data = FALSE; -} - -static void -iwarp_supersample_toggle (GtkWidget *widget, - int *data) -{ - if ( GTK_TOGGLE_BUTTON (widget)->active) *data = TRUE; - else *data = FALSE; - gtk_widget_set_sensitive(supersample_frame,iwarp_vals.do_supersample); -} - -static void -iwarp_animate_toggle (GtkWidget *widget, - int *data) -{ - if ( GTK_TOGGLE_BUTTON (widget)->active) *data = TRUE; - else *data = FALSE; - gtk_widget_set_sensitive(animate_frame,do_animate); -} - - static void iwarp_reset_callback (GtkWidget *widget, - gpointer data) + gpointer data) { - int i; + gint i; - iwarp_cpy_images(); - for (i=0; i