gimp/plug-ins/common/ripple.c

804 lines
22 KiB
C
Raw Normal View History

1997-11-25 06:05:25 +08:00
/* Ripple --- image filter plug-in for The Gimp image manipulation program
* Copyright (C) 1997 Brian Degenhardt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*
* Please direct all comments, questions, bug reports etc to Brian Degenhardt
* bdegenha@ucsd.edu
*
* You can contact the original The Gimp authors at gimp@xcf.berkeley.edu
*/
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc 1999-09-01 Tor Lillqvist <tml@iki.fi> * app/appenv.h * libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc from app/appenv.h here, so plug-ins can use them, too. Remove some commented-out old stuff in appenv.h. * libgimp/gimp.h: Include gimpmath.h. * libgimp/gimp.c (gimp_main): Win32: Don't install signal handlers, we can't do anything useful in the handler ourselves anyway (it would be nice to print out a backtrace, but that seems pretty hard to do, even if not impossible). Let Windows inform the user about the crash. If the plug-in was compiled with MSVC, and the user also has it, she is offered a chance to start the debugger automatically anyway. * app/*several*.c: Include gimpmath.h for G_PI etc. Don't include <math.h>, as gimpmath.h includes it. * plug-ins/*/*many*.c: Include config.h. Don't include <math.h>. Remove all the duplicated definitions of G_PI and rint(). Use RINT() instead of rint(). * app/app_procs.[ch]: app_exit() takes a gboolean. * app/batch.c * app/commands.c * app/interface.c: Call app_exit() with FALSE or TRUE. * app/main.c (on_error): Call gimp_fatal_error. (main): Don't install any signal handler on Win32 here, either. * app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format the message and call MessageBox with it. g_on_error_query doesn't do anything useful on Win32, and printf'ing a message to stdout or stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
#include "config.h"
1997-11-25 06:05:25 +08:00
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc 1999-09-01 Tor Lillqvist <tml@iki.fi> * app/appenv.h * libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc from app/appenv.h here, so plug-ins can use them, too. Remove some commented-out old stuff in appenv.h. * libgimp/gimp.h: Include gimpmath.h. * libgimp/gimp.c (gimp_main): Win32: Don't install signal handlers, we can't do anything useful in the handler ourselves anyway (it would be nice to print out a backtrace, but that seems pretty hard to do, even if not impossible). Let Windows inform the user about the crash. If the plug-in was compiled with MSVC, and the user also has it, she is offered a chance to start the debugger automatically anyway. * app/*several*.c: Include gimpmath.h for G_PI etc. Don't include <math.h>, as gimpmath.h includes it. * plug-ins/*/*many*.c: Include config.h. Don't include <math.h>. Remove all the duplicated definitions of G_PI and rint(). Use RINT() instead of rint(). * app/app_procs.[ch]: app_exit() takes a gboolean. * app/batch.c * app/commands.c * app/interface.c: Call app_exit() with FALSE or TRUE. * app/main.c (on_error): Call gimp_fatal_error. (main): Don't install any signal handler on Win32 here, either. * app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format the message and call MessageBox with it. g_on_error_query doesn't do anything useful on Win32, and printf'ing a message to stdout or stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
1997-11-25 06:05:25 +08:00
1997-11-25 06:05:25 +08:00
/* Some useful macros */
#define SCALE_WIDTH 200
#define TILE_CACHE_SIZE 16
1997-11-25 06:05:25 +08:00
#define HORIZONTAL 0
#define VERTICAL 1
1997-11-25 06:05:25 +08:00
#define SMEAR 0
#define WRAP 1
1997-11-25 06:05:25 +08:00
#define BLACK 2
#define SAWTOOTH 0
#define SINE 1
typedef struct
{
gint period;
gint amplitude;
gint orientation;
gint edges;
gint waveform;
gint antialias;
gint tile;
1997-11-25 06:05:25 +08:00
} RippleValues;
typedef struct
{
1997-11-25 06:05:25 +08:00
gint run;
} RippleInterface;
/* Declare local functions.
*/
static void query (void);
static void run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals);
static void ripple (GDrawable *drawable);
static gint ripple_dialog (void);
static void ripple_ok_callback (GtkWidget *widget,
gpointer data);
static GTile * ripple_pixel (GDrawable *drawable,
GTile *tile,
gint x1,
gint y1,
gint x2,
gint y2,
gint x,
gint y,
gint *row,
gint *col,
guchar *pixel);
static gdouble displace_amount (gint location);
static guchar averagetwo (gdouble location,
guchar *v);
static guchar averagefour (gdouble location,
guchar *v);
1997-11-25 06:05:25 +08:00
/***** Local vars *****/
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
1997-11-25 06:05:25 +08:00
};
static RippleValues rvals =
{
20, /* period */
5, /* amplitude */
1997-11-25 06:05:25 +08:00
HORIZONTAL, /* orientation */
WRAP, /* edges */
SINE, /* waveform */
TRUE, /* antialias */
TRUE /* tile */
1997-11-25 06:05:25 +08:00
};
static RippleInterface rpint =
{
FALSE /* run */
};
/***** Functions *****/
MAIN ()
static void
query (void)
1997-11-25 06:05:25 +08:00
{
static GParamDef args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image (unused)" },
{ PARAM_DRAWABLE, "drawable", "Input drawable" },
{ PARAM_INT32, "period", "period; number of pixels for one wave to complete" },
{ PARAM_INT32, "amplitude", "amplitude; maximum displacement of wave" },
{ PARAM_INT32, "orientation", "orientation; 0 = Horizontal, 1 = Vertical" },
{ PARAM_INT32, "edges", "edges; 0 = smear, 1 = wrap, 2 = black" },
{ PARAM_INT32, "waveform", "0 = sawtooth, 1 = sine wave" },
{ PARAM_INT32, "antialias", "antialias; True or False" },
{ PARAM_INT32, "tile", "tile; if this is true, the image will retain it's tilability" }
1997-11-25 06:05:25 +08:00
};
static gint nargs = sizeof (args) / sizeof (args[0]);
gimp_install_procedure ("plug_in_ripple",
2000-01-31 10:32:30 +08:00
"Ripple the contents of the specified drawable",
"Ripples the pixels of the specified drawable. Each row or column will be displaced a certain number of pixels coinciding with the given wave form",
1997-11-25 06:05:25 +08:00
"Brian Degenhardt <bdegenha@ucsd.edu>",
"Brian Degenhardt",
"1997",
N_("<Image>/Filters/Distorts/Ripple..."),
1997-11-25 06:05:25 +08:00
"RGB*, GRAY*",
PROC_PLUG_IN,
nargs, 0,
args, NULL);
1997-11-25 06:05:25 +08:00
}
static void
run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals)
{
static GParam values[1];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
run_mode = param[0].data.d_int32;
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
*nreturn_vals = 1;
*return_vals = values;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
switch (run_mode)
{
case RUN_INTERACTIVE:
INIT_I18N_UI();
1997-11-25 06:05:25 +08:00
/* Possibly retrieve data */
gimp_get_data ("plug_in_ripple", &rvals);
/* First acquire information with a dialog */
if (! ripple_dialog ())
return;
break;
case RUN_NONINTERACTIVE:
INIT_I18N();
1997-11-25 06:05:25 +08:00
/* Make sure all the arguments are there! */
if (nparams != 10)
{
status = STATUS_CALLING_ERROR;
}
else
1997-11-25 06:05:25 +08:00
{
rvals.period = param[3].data.d_int32;
rvals.amplitude = param[4].data.d_int32;
rvals.orientation = (param[5].data.d_int32) ? VERTICAL : HORIZONTAL;
rvals.edges = (param[6].data.d_int32);
rvals.waveform = param[7].data.d_int32;
rvals.antialias = (param[8].data.d_int32) ? TRUE : FALSE;
rvals.tile = (param[9].data.d_int32) ? TRUE : FALSE;
if (rvals.edges < SMEAR || rvals.edges > BLACK)
status = STATUS_CALLING_ERROR;
}
1997-11-25 06:05:25 +08:00
break;
case RUN_WITH_LAST_VALS:
INIT_I18N();
1997-11-25 06:05:25 +08:00
/* Possibly retrieve data */
gimp_get_data ("plug_in_ripple", &rvals);
break;
default:
break;
}
if (status == STATUS_SUCCESS)
{
/* Make sure that the drawable is gray or RGB color */
if (gimp_drawable_is_rgb (drawable->id) ||
gimp_drawable_is_gray (drawable->id))
1997-11-25 06:05:25 +08:00
{
gimp_progress_init ( _("Rippling..."));
1997-11-25 06:05:25 +08:00
/* set the tile cache size */
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
/* run the ripple effect */
ripple (drawable);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush ();
/* Store data */
if (run_mode == RUN_INTERACTIVE)
gimp_set_data ("plug_in_ripple", &rvals, sizeof (RippleValues));
}
else
{
/* gimp_message ("ripple: cannot operate on indexed color images"); */
status = STATUS_EXECUTION_ERROR;
}
}
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
static void
ripple (GDrawable *drawable)
{
GPixelRgn dest_rgn;
GTile * tile = NULL;
gint row = -1;
gint col = -1;
gpointer pr;
gint width, height;
gint bytes;
guchar *destline;
guchar *dest;
guchar *otherdest;
guchar pixel[4][4];
gint x1, y1, x2, y2;
gint x, y;
gint progress, max_progress;
gdouble needx, needy;
guchar values[4];
guchar val;
gint xi, yi;
gint k;
/* Get selection area */
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
if ( rvals.tile )
{
1997-11-25 06:05:25 +08:00
rvals.edges = WRAP;
rvals.period = (width / (width / rvals.period) *
(rvals.orientation == HORIZONTAL) +
height / (height / rvals.period) *
(rvals.orientation == VERTICAL));
}
1997-11-25 06:05:25 +08:00
progress = 0;
max_progress = (x2 - x1) * (y2 - y1);
/* Ripple the image. It's a pretty simple algorithm. If horizontal
1997-11-25 06:05:25 +08:00
is selected, then every row is displaced a number of pixels that
follows the pattern of the waveform selected. The effect is
just reproduced with columns if vertical is selected.
*/
1997-11-25 06:05:25 +08:00
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
1997-11-25 06:05:25 +08:00
if (rvals.orientation == VERTICAL)
{
1997-11-25 06:05:25 +08:00
destline = dest_rgn.data;
for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++)
{
1997-11-25 06:05:25 +08:00
dest = destline;
for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++)
{
1997-11-25 06:05:25 +08:00
otherdest = dest;
needy = y + displace_amount(x);
yi = floor(needy);
/* Tile the image. */
1997-11-25 06:05:25 +08:00
if (rvals.edges == WRAP)
{
1997-11-25 06:05:25 +08:00
needy = fmod(needy + height, height);
yi = (yi + height) % height;
}
/* Smear out the edges of the image by repeating pixels. */
1997-11-25 06:05:25 +08:00
else if (rvals.edges == SMEAR)
{
1997-11-25 06:05:25 +08:00
if (yi < 0)
yi = 0;
1997-11-25 06:05:25 +08:00
else if (yi > height - 1)
yi = height - 1;
}
1997-11-25 06:05:25 +08:00
if ( rvals.antialias)
{
1997-11-25 06:05:25 +08:00
if (yi == height - 1)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*otherdest++ = pixel[0][k];
}
1997-11-25 06:05:25 +08:00
else if (needy < 0 && needy > -1)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, 0, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*otherdest++ = pixel[0][k];
}
1997-11-25 06:05:25 +08:00
else if (yi == height - 2 || yi == 0)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi, &row, &col, pixel[0]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi + 1, &row, &col, pixel[1]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
{
1997-11-25 06:05:25 +08:00
values[0] = pixel[0][k];
values[1] = pixel[1][k];
val = averagetwo(needy, values);
*otherdest++ = val;
}
}
1997-11-25 06:05:25 +08:00
else
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi, &row, &col, pixel[0]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi + 1, &row, &col, pixel[1]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi - 1, &row, &col, pixel[2]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi + 2, &row, &col, pixel[3]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
{
1997-11-25 06:05:25 +08:00
values[0] = pixel[0][k];
values[1] = pixel[1][k];
values[2] = pixel[2][k];
values[3] = pixel[3][k];
val = averagefour (needy, values);
1997-11-25 06:05:25 +08:00
*otherdest++ = val;
}
}
} /* antialias */
1997-11-25 06:05:25 +08:00
else
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
x, yi, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*otherdest++ = pixel[0][k];
}
1997-11-25 06:05:25 +08:00
dest += dest_rgn.rowstride;
} /* for */
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
destline++;
} /* for */
1997-11-25 06:05:25 +08:00
progress += dest_rgn.w * dest_rgn.h;
gimp_progress_update ((double) progress / (double) max_progress);
}
1997-11-25 06:05:25 +08:00
else /* HORIZONTAL */
{
1997-11-25 06:05:25 +08:00
destline = dest_rgn.data;
for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++)
{
1997-11-25 06:05:25 +08:00
dest = destline;
for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++)
{
1997-11-25 06:05:25 +08:00
needx = x + displace_amount(y);
xi = floor (needx);
1997-11-25 06:05:25 +08:00
/* Tile the image. */
1997-11-25 06:05:25 +08:00
if (rvals.edges == WRAP)
{
1997-11-25 06:05:25 +08:00
needx = fmod((needx + width), width);
xi = (xi + width) % width;
}
/* Smear out the edges of the image by repeating pixels. */
1997-11-25 06:05:25 +08:00
else if (rvals.edges == SMEAR)
{
1997-11-25 06:05:25 +08:00
if (xi < 0)
xi = 0;
1997-11-25 06:05:25 +08:00
else if (xi > width - 1)
xi = width - 1;
}
1997-11-25 06:05:25 +08:00
if ( rvals.antialias)
{
1997-11-25 06:05:25 +08:00
if (xi == width - 1)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi, y, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*dest++ = pixel[0][k];
}
1997-11-25 06:05:25 +08:00
else if (floor(needx) == -1)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
0, y, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*dest++ = pixel[0][k];
}
1997-11-25 06:05:25 +08:00
else if (xi == width - 2 || xi == 0)
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi, y, &row, &col, pixel[0]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi + 1, y, &row, &col, pixel[1]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
{
1997-11-25 06:05:25 +08:00
values[0] = pixel[0][k];
values[1] = pixel[1][k];
val = averagetwo (needx, values);
1997-11-25 06:05:25 +08:00
*dest++ = val;
}
}
1997-11-25 06:05:25 +08:00
else
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi, y, &row, &col, pixel[0]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi + 1, y, &row, &col, pixel[1]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi - 1 , y, &row, &col, pixel[2]);
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi + 2, y, &row, &col, pixel[3]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
{
1997-11-25 06:05:25 +08:00
values[0] = pixel[0][k];
values[1] = pixel[1][k];
values[2] = pixel[2][k];
values[3] = pixel[3][k];
val = averagefour (needx, values);
1997-11-25 06:05:25 +08:00
*dest++ = val;
}
}
} /* antialias */
1997-11-25 06:05:25 +08:00
else
{
tile = ripple_pixel (drawable, tile,
x1, y1, x2, y2,
xi, y, &row, &col, pixel[0]);
1997-11-25 06:05:25 +08:00
for (k = 0; k < bytes; k++)
*dest++ = pixel[0][k];
}
} /* for */
1997-11-25 06:05:25 +08:00
destline += dest_rgn.rowstride;
} /* for */
1997-11-25 06:05:25 +08:00
progress += dest_rgn.w * dest_rgn.h;
gimp_progress_update ((double) progress / (double) max_progress);
}
} /* for */
1997-11-25 06:05:25 +08:00
if (tile)
gimp_tile_unref (tile, FALSE);
1997-11-25 06:05:25 +08:00
/* update the region */
1997-11-25 06:05:25 +08:00
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1));
} /* ripple */
static gint
ripple_dialog (void)
1997-11-25 06:05:25 +08:00
{
GtkWidget *dlg;
GtkWidget *toggle;
GtkWidget *toggle_vbox;
GtkWidget *main_vbox;
GtkWidget *frame;
GtkWidget *table;
GtkObject *scale_data;
gimp_ui_init ("ripple", TRUE);
dlg = gimp_dialog_new (_("Ripple"), "ripple",
gimp_standard_help_func, "filters/ripple.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
_("OK"), ripple_ok_callback,
NULL, NULL, NULL, TRUE, FALSE,
_("Cancel"), gtk_widget_destroy,
NULL, 1, NULL, FALSE, TRUE,
NULL);
gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
/* The main vbox */
main_vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_vbox,
FALSE, FALSE, 0);
/* The table to hold the four frames of options */
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
/* Options section */
frame = gtk_frame_new ( _("Options"));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
toggle_vbox = gtk_vbox_new (FALSE, 1);
gtk_container_set_border_width (GTK_CONTAINER (toggle_vbox), 2);
gtk_container_add (GTK_CONTAINER (frame), toggle_vbox);
toggle = gtk_check_button_new_with_label (_("Antialiasing"));
gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&rvals.antialias);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), rvals.antialias);
gtk_widget_show (toggle);
toggle = gtk_check_button_new_with_label ( _("Retain Tilability"));
gtk_box_pack_start (GTK_BOX (toggle_vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&rvals.tile);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (rvals.tile));
gtk_widget_show (toggle);
gtk_widget_show (toggle_vbox);
gtk_widget_show (frame);
/* Orientation toggle box */
frame =
gimp_radio_group_new2 (TRUE, _("Orientation"),
gimp_radio_button_update,
&rvals.orientation, (gpointer) rvals.orientation,
_("Horizontal"), (gpointer) HORIZONTAL, NULL,
_("Vertical"), (gpointer) VERTICAL, NULL,
NULL);
gtk_table_attach (GTK_TABLE (table), frame, 1, 2, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (frame);
1997-11-25 06:05:25 +08:00
/* Edges toggle box */
frame = gimp_radio_group_new2 (TRUE, _("Edges"),
gimp_radio_button_update,
&rvals.edges, (gpointer) rvals.edges,
_("Wrap"), (gpointer) WRAP, NULL,
_("Smear"), (gpointer) SMEAR, NULL,
_("Black"), (gpointer) BLACK, NULL,
NULL);
gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 1, 2,
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
/* Wave toggle box */
frame = gimp_radio_group_new2 (TRUE, _("Wave Type"),
gimp_radio_button_update,
&rvals.waveform, (gpointer) rvals.waveform,
_("Sawtooth"), (gpointer) SAWTOOTH, NULL,
_("Sine"), (gpointer) SINE, NULL,
NULL);
gtk_table_attach (GTK_TABLE (table), frame, 1, 2, 1, 2,
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
gtk_widget_show (table);
1997-11-25 06:05:25 +08:00
/* Parameter Settings */
frame = gtk_frame_new ( _("Parameter Settings"));
1997-11-25 06:05:25 +08:00
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
1997-11-25 06:05:25 +08:00
gtk_container_add (GTK_CONTAINER (frame), table);
/* Period */
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("Period:"), SCALE_WIDTH, 0,
rvals.period, 0, 200, 1, 10, 0,
TRUE, 0, 0,
NULL, NULL);
1997-11-25 06:05:25 +08:00
gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
1997-11-25 06:05:25 +08:00
&rvals.period);
/* Amplitude */
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("Amplitude:"), SCALE_WIDTH, 0,
rvals.amplitude, 0, 200, 1, 10, 0,
TRUE, 0, 0,
NULL, NULL);
1997-11-25 06:05:25 +08:00
gtk_signal_connect (GTK_OBJECT (scale_data), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
1997-11-25 06:05:25 +08:00
&rvals.amplitude);
gtk_widget_show (frame);
gtk_widget_show (table);
1997-11-25 06:05:25 +08:00
gtk_widget_show (main_vbox);
gtk_widget_show (dlg);
gtk_main ();
gdk_flush ();
1997-11-25 06:05:25 +08:00
return rpint.run;
}
static GTile *
ripple_pixel (GDrawable *drawable,
GTile *tile,
gint x1,
gint y1,
gint x2,
gint y2,
gint x,
gint y,
gint *row,
gint *col,
guchar *pixel)
1997-11-25 06:05:25 +08:00
{
static guchar empty_pixel[4] = {0, 0, 0, 0};
1997-11-25 06:05:25 +08:00
guchar *data;
gint b;
1997-11-25 06:05:25 +08:00
if (x >= x1 && y >= y1 && x < x2 && y < y2)
{
if ((x >> 6 != *col) || (y >> 6 != *row))
{
*col = x / 64;
*row = y / 64;
if (tile)
gimp_tile_unref (tile, FALSE);
tile = gimp_drawable_get_tile (drawable, FALSE, *row, *col);
gimp_tile_ref (tile);
}
data = tile->data + tile->bpp * (tile->ewidth * (y % 64) + (x % 64));
}
else
data = empty_pixel;
for (b = 0; b < drawable->bpp; b++)
pixel[b] = data[b];
return tile;
}
/* Ripple interface functions */
static void
ripple_ok_callback (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
rpint.run = TRUE;
1997-11-25 06:05:25 +08:00
gtk_widget_destroy (GTK_WIDGET (data));
}
static guchar
averagetwo (gdouble location,
guchar *v)
1997-11-25 06:05:25 +08:00
{
location = fmod(location, 1.0);
return (guchar) ((1.0 - location) * v[0] + location * v[1]);
}
1997-11-25 06:05:25 +08:00
static guchar
averagefour (gdouble location,
guchar *v)
1997-11-25 06:05:25 +08:00
{
location = fmod(location, 1.0);
1997-11-25 06:05:25 +08:00
return ((1.0 - location) * (v[0] + v[2]) + location * (v[1] + v[3]))/2;
1997-11-25 06:05:25 +08:00
}
static gdouble
displace_amount (gint location)
{
switch (rvals.waveform)
1997-11-25 06:05:25 +08:00
{
case SINE:
return rvals.amplitude*sin(location*(2*G_PI)/(double)rvals.period);
case SAWTOOTH:
return floor (rvals.amplitude *
(fabs ((((location%rvals.period) /
(double)rvals.period) * 4) - 2) - 1));
1997-11-25 06:05:25 +08:00
}
return 0;
1997-11-25 06:05:25 +08:00
}