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

plug-ins/common/flarefx.c a more elegant way to update the preview when

2000-05-23  Sven Neumann  <sven@gimp.org>

* plug-ins/common/flarefx.c
* plug-ins/common/glasstile.c: a more elegant way to update
  the preview when parameters change.

* plug-ins/common/grid.c: if a selection is active, show the
  selected area in the preview.

* plug-ins/common/illusion.c: applied modified version of
  gimp-timecop-200005-7.illusion which adds a preview to the
  illusion plug-in.

* plug-ins/common/jigsaw.c: applied modified version of
  gimp-timecop-200005-8.jigsaw which adds a preview to the
  jigsaw plug-in.

* plug-ins/common/max_rgb.c: applied modified version of
  gimp-timecop-200005-9.max_rgb which adds a preview to the
  max_rgb plug-in.

* plug-ins/common/noisify.c: applied modified version of
  gimp-timecop-200005-10.noisify which adds a preview to the
  noisify plug-in.

* plug-ins/common/nova.c: applied modified version of
  gimp-timecop-200005-11.nova which adds a preview to the
  nova plug-in.
parent c60771af
2000-05-23 Sven Neumann <sven@gimp.org>
* plug-ins/common/flarefx.c
* plug-ins/common/glasstile.c: a more elegant way to update
the preview when parameters change.
* plug-ins/common/grid.c: if a selection is active, show the
selected area in the preview.
* plug-ins/common/illusion.c: applied modified version of
gimp-timecop-200005-7.illusion which adds a preview to the
illusion plug-in.
* plug-ins/common/jigsaw.c: applied modified version of
gimp-timecop-200005-8.jigsaw which adds a preview to the
jigsaw plug-in.
* plug-ins/common/max_rgb.c: applied modified version of
gimp-timecop-200005-9.max_rgb which adds a preview to the
max_rgb plug-in.
* plug-ins/common/noisify.c: applied modified version of
gimp-timecop-200005-10.noisify which adds a preview to the
noisify plug-in.
* plug-ins/common/nova.c: applied modified version of
gimp-timecop-200005-11.nova which adds a preview to the
nova plug-in.
2000-05-23 Sven Neumann <sven@gimp.org>
* plug-ins/common/flarefx.c
......
......@@ -135,8 +135,6 @@ static GtkWidget *preview_widget (GDrawable *drawable);
static gint flare_dialog (GDrawable *drawable);
static void flare_ok_callback (GtkWidget *widget,
gpointer data);
static void flare_show_cursor_callback (GtkWidget *widget,
gpointer data);
static GtkWidget * flare_center_create (GDrawable *drawable);
static void flare_center_destroy (GtkWidget *widget,
......@@ -320,7 +318,6 @@ flare_dialog (GDrawable *drawable)
{
GtkWidget *dlg;
GtkWidget *main_vbox;
GtkWidget *toggle;
GtkWidget *frame;
FlareCenter *center;
......@@ -355,18 +352,6 @@ flare_dialog (GDrawable *drawable)
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0);
/* show / hide cursor */
toggle = gtk_check_button_new_with_label (_("Show Cursor"));
gtk_container_set_border_width (GTK_CONTAINER (toggle), 6);
gtk_object_set_user_data (GTK_OBJECT (toggle), center);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), show_cursor);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
GTK_SIGNAL_FUNC (flare_show_cursor_callback),
&show_cursor);
gtk_box_pack_start (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle);
gtk_widget_show (frame);
gtk_widget_show (dlg);
......@@ -386,17 +371,6 @@ flare_ok_callback (GtkWidget *widget,
gtk_widget_destroy (GTK_WIDGET (data));
}
static void
flare_show_cursor_callback (GtkWidget *widget,
gpointer data)
{
FlareCenter *center;
center = gtk_object_get_user_data (GTK_OBJECT (widget));
gimp_toggle_button_update (widget, data);
FlareFX (center->drawable, TRUE);
}
/* --- Filter functions --- */
static void
FlareFX (GDrawable *drawable,
......@@ -417,12 +391,10 @@ FlareFX (GDrawable *drawable,
width = GTK_PREVIEW (preview)->buffer_width;
height = GTK_PREVIEW (preview)->buffer_height;
bytes = GTK_PREVIEW (preview)->bpp;
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
xs = (gdouble)fvals.posx * preview_scale_x;
ys = (gdouble)fvals.posy * preview_scale_y;
/* now, we clobber the x1 x2 y1 y2 with the real sizes */
x1 = y1 = 0;
x2 = width;
y2 = height;
......@@ -772,6 +744,7 @@ flare_center_create (GDrawable *drawable)
GtkWidget *label;
GtkWidget *pframe;
GtkWidget *spinbutton;
GtkWidget *check;
center = g_new (FlareCenter, 1);
center->drawable = drawable;
......@@ -794,7 +767,7 @@ flare_center_create (GDrawable *drawable)
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
table = gtk_table_new (2, 4, FALSE);
table = gtk_table_new (3, 4, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 4);
gtk_table_set_col_spacing (GTK_TABLE (table), 1, 6);
......@@ -860,11 +833,26 @@ flare_center_create (GDrawable *drawable)
gtk_object_set_user_data (GTK_OBJECT (frame), center);
gtk_widget_show (frame);
/* show / hide cursor */
check = gtk_check_button_new_with_label (_("Show Cursor"));
gtk_table_attach (GTK_TABLE (table), check, 0, 4, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), show_cursor);
gtk_signal_connect (GTK_OBJECT (check), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&show_cursor);
gtk_signal_connect_object (GTK_OBJECT (check), "toggled",
GTK_SIGNAL_FUNC (FlareFX),
(gpointer)drawable);
gtk_widget_show (check);
flare_center_cursor_update (center);
center->cursor = FALSE; /* Make sure that the cursor has not been drawn */
center->in_call = FALSE; /* End of initialization */
FlareFX(drawable, 1);
FlareFX (drawable, TRUE);
DEBUG1 ("fvals center=%d,%d\n", fvals.posx, fvals.posy);
DEBUG1 ("center cur=%d,%d\n", center->curx, center->cury);
......
......@@ -71,8 +71,6 @@ static void run (gchar *name,
GParam **return_vals);
static gint glass_dialog (GDrawable *drawable);
static void tile_int_adjustment_update (GtkAdjustment *adj,
gpointer data);
static void glass_ok_callback (GtkWidget *widget,
gpointer data);
......@@ -302,10 +300,12 @@ glass_dialog (GDrawable *drawable)
gtvals.xblock, 10, 50, 2, 10, 0,
TRUE, 0, 0,
NULL, NULL);
gtk_object_set_data (GTK_OBJECT (adj), "drawable", drawable);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (tile_int_adjustment_update),
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&gtvals.xblock);
gtk_signal_connect_object (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (glasstile),
(gpointer)drawable);
/* Horizontal scale - Height */
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
......@@ -315,8 +315,11 @@ glass_dialog (GDrawable *drawable)
NULL, NULL);
gtk_object_set_data (GTK_OBJECT (adj), "drawable", drawable);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (tile_int_adjustment_update),
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&gtvals.yblock);
gtk_signal_connect_object (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (glasstile),
(gpointer)drawable);
gtk_widget_show (frame);
gtk_widget_show (table);
......@@ -329,17 +332,6 @@ glass_dialog (GDrawable *drawable)
return gt_int.run;
}
static void
tile_int_adjustment_update (GtkAdjustment *adj,
gpointer data)
{
GDrawable *drawable;
gimp_int_adjustment_update (adj, data);
drawable = gtk_object_get_data (GTK_OBJECT (adj), "drawable");
glasstile (drawable, TRUE);
}
static void
glass_ok_callback (GtkWidget *widget,
gpointer data)
......@@ -362,6 +354,7 @@ preview_widget (GDrawable *drawable)
(GTK_PREVIEW (preview)->bpp);
preview_bits = g_malloc (size);
memcpy (preview_bits, GTK_PREVIEW (preview)->buffer, size);
return preview;
}
......
......@@ -1000,6 +1000,7 @@ fill_preview (GtkWidget *widget,
GPixelRgn srcPR;
gint width;
gint height;
gint x1, x2, y1, y2;
gint bpp;
gint x, y;
guchar *src;
......@@ -1008,16 +1009,24 @@ fill_preview (GtkWidget *widget,
guchar *p0, *p1;
guchar *even, *odd;
width = MIN (gimp_drawable_width (drawable->id), PREVIEW_SIZE);
height = MIN (gimp_drawable_height (drawable->id), PREVIEW_SIZE);
bpp = gimp_drawable_bpp (drawable->id);
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
if (x2 - x1 > PREVIEW_SIZE)
x2 = x1 + PREVIEW_SIZE;
if (y2 - y1 > PREVIEW_SIZE)
y2 = y1 + PREVIEW_SIZE;
width = x2 - x1;
height = y2 - y1;
bpp = gimp_drawable_bpp (drawable->id);
if (width < 1 || height < 1)
return;
gtk_preview_size (GTK_PREVIEW (widget), width, height);
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, x2, y2, FALSE, FALSE);
even = g_malloc (width * 3);
odd = g_malloc (width * 3);
......@@ -1025,7 +1034,7 @@ fill_preview (GtkWidget *widget,
for (y = 0; y < height; y++)
{
gimp_pixel_rgn_get_row (&srcPR, src, 0, y, width);
gimp_pixel_rgn_get_row (&srcPR, src, x1, y + y1, width);
p0 = even;
p1 = odd;
......
/*******************************************************************************
illusion.c -- This is a plug-in for the GIMP 1.0
Copyright (C) 1997 Hirotsuna Mizuno
s1041150@u-aizu.ac.jp
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.
*******************************************************************************/
/*
* illusion.c -- This is a plug-in for the GIMP 1.0
*
* Copyright (C) 1997 Hirotsuna Mizuno
* s1041150@u-aizu.ac.jp
*
* Preview and new mode added May 2000 by tim copperfield
* timecop@japan.co.jp
* http://www.ne.jp/asahi/linux/timecop
*
* 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.
*
*/
#include "config.h"
......@@ -35,7 +38,9 @@
#define PLUG_IN_NAME "plug_in_illusion"
#define PLUG_IN_VERSION "v0.7 (Dec. 25 1997)"
#define PLUG_IN_VERSION "v0.8 (May 14 2000)"
#define PREVIEW_SIZE 128
/******************************************************************************/
......@@ -46,15 +51,20 @@ static void run (gchar *name,
gint *nreturn_vals,
GParam **return_vals);
static void filter (GDrawable *drawable);
static gboolean dialog (void);
static void filter (GDrawable *drawable);
static void filter_preview (void);
static void fill_preview_with_thumb (GtkWidget *preview_widget,
gint32 drawable_ID);
static gboolean dialog (GDrawable *drawable);
/******************************************************************************/
typedef struct
{
gint32 division;
} parameter_t;
gint type1;
gint type2;
} IllValues;
/******************************************************************************/
......@@ -63,26 +73,19 @@ GPlugInInfo PLUG_IN_INFO =
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
run /* run_proc */
};
static parameter_t parameters =
static IllValues parameters =
{
8
8, /* division */
1, /* type 1 */
0 /* type 2 */
};
static gint image_width;
static gint image_height;
static gint image_bpp;
static gint image_has_alpha;
static gint select_x1;
static gint select_y1;
static gint select_x2;
static gint select_y2;
static gint select_width;
static gint select_height;
static gdouble center_x;
static gdouble center_y;
static guchar *preview_bits;
static GtkWidget *preview;
/******************************************************************************/
......@@ -135,16 +138,6 @@ run (gchar *name,
*return_vals = returnv;
/* get the drawable info */
image_width = gimp_drawable_width (drawable->id);
image_height = gimp_drawable_height (drawable->id);
image_bpp = gimp_drawable_bpp (drawable->id);
image_has_alpha = gimp_drawable_has_alpha (drawable->id);
gimp_drawable_mask_bounds (drawable->id,
&select_x1, &select_y1, &select_x2, &select_y2);
select_width = select_x2 - select_x1;
select_height = select_y2 - select_y1;
center_x = select_x1 + (gdouble)select_width / 2;
center_y = select_y1 + (gdouble)select_height / 2;
/* switch the run mode */
switch (run_mode)
......@@ -152,19 +145,22 @@ run (gchar *name,
case RUN_INTERACTIVE:
INIT_I18N_UI();
gimp_get_data (PLUG_IN_NAME, &parameters);
if (! dialog())
if (! dialog(drawable))
return;
gimp_set_data (PLUG_IN_NAME, &parameters, sizeof (parameter_t));
gimp_set_data (PLUG_IN_NAME, &parameters, sizeof (IllValues));
g_free(preview_bits);
break;
case RUN_NONINTERACTIVE:
if (nparams != 4)
if (nparams != 6)
{
status = STATUS_CALLING_ERROR;
}
else
{
parameters.division = params[3].data.d_int32;
parameters.type1 = params[4].data.d_int32;
parameters.type2 = params[5].data.d_int32;
}
break;
......@@ -179,6 +175,7 @@ run (gchar *name,
gimp_drawable_is_gray (drawable->id))
{
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width() + 1));
gimp_progress_init (_("Illusion..."));
filter (drawable);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush ();
......@@ -203,72 +200,303 @@ filter (GDrawable *drawable)
GPixelRgn srcPR, destPR;
guchar **pixels;
guchar **destpixels;
gint image_width;
gint image_height;
gint image_bpp;
gint image_has_alpha;
gint x1;
gint y1;
gint x2;
gint y2;
gint select_width;
gint select_height;
gdouble center_x;
gdouble center_y;
gint x, y, b;
gint xx, yy;
gint xx = 0;
gint yy = 0;
gdouble scale, radius, cx, cy, angle, offset;
image_width = gimp_drawable_width (drawable->id);
image_height = gimp_drawable_height (drawable->id);
image_bpp = gimp_drawable_bpp (drawable->id);
image_has_alpha = gimp_drawable_has_alpha (drawable->id);
gimp_drawable_mask_bounds (drawable->id,&x1, &y1, &x2, &y2);
select_width = x2 - x1;
select_height = y2 - y1;
center_x = x1 + (gdouble)select_width / 2;
center_y = y1 + (gdouble)select_height / 2;
gimp_pixel_rgn_init (&srcPR, drawable,
0, 0, image_width, image_height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable,
0, 0, image_width, image_height, TRUE, TRUE);
pixels = (guchar **) g_malloc (image_height * sizeof (guchar *));
destpixels = (guchar **) g_malloc (image_height * sizeof (guchar *));
pixels = g_new (guchar *, image_height);
destpixels = g_new (guchar *, image_height);
for (y = 0; y < image_height; y++)
{
pixels[y] = (guchar *) g_malloc (image_width * image_bpp);
destpixels[y] = (guchar *) g_malloc (image_width * image_bpp);
pixels[y] = g_new (guchar, image_width * image_bpp);
destpixels[y] = g_new (guchar, image_width * image_bpp);
gimp_pixel_rgn_get_row (&srcPR, pixels[y], 0, y, image_width);
}
/*
for( y = select_y1; y < select_y2; y++ ){
for( x = select_x1; x < select_x2; x++ ){
for( b = 0; b < image_bpp; b++ ){
destpixels[y][x*image_bpp+b] = 0;
}
}
}
*/
gimp_progress_init (PLUG_IN_NAME);
scale = sqrt (select_width * select_width + select_height * select_height) / 2;
offset = (gint) (scale / 2);
for (y = select_y1; y < select_y2; y++)
for (y = y1; y < y2; y++)
{
cy = ((gdouble)y - center_y) / scale;
for (x = select_x1; x < select_x2; x++)
for (x = x1; x < x2; x++)
{
cx = ((gdouble)x - center_x) / scale;
angle = floor (atan2 (cy, cx) * parameters.division / G_PI_2)
* G_PI_2 / parameters.division + (G_PI / parameters.division);
radius = sqrt ((gdouble) (cx * cx + cy * cy));
xx = x - offset * cos (angle);
yy = y - offset * sin (angle);
if (xx < 0) xx = 0;
else if (image_width <= xx) xx = image_width - 1;
if (yy < 0) yy = 0;
else if (image_height <= yy) yy = image_height - 1;
if (parameters.type1)
{
xx = x - offset * cos (angle);
yy = y - offset * sin (angle);
}
if (parameters.type2)
{
xx = x - offset * sin (angle);
yy = y - offset * cos (angle);
}
if (xx < 0)
xx = 0;
else if (image_width <= xx)
xx = image_width - 1;
if (yy < 0)
yy = 0;
else if (image_height <= yy)
yy = image_height - 1;
for (b = 0; b < image_bpp; b++)
destpixels[y][x*image_bpp+b] =
(1-radius) * pixels[y][x * image_bpp + b]
+ radius * pixels[yy][xx * image_bpp + b];
}
gimp_pixel_rgn_set_row (&destPR, destpixels[y], 0, y, image_width);
gimp_progress_update ((double) (y - select_y1) / (double) select_height);
gimp_progress_update ((double) (y - y1) / (double) select_height);
}
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_drawable_update (drawable->id,
select_x1, select_y1, select_width, select_height);
x1, y1, select_width, select_height);
for (y = y1; y < y2; y++) g_free (pixels[y-y1]);
g_free (pixels);
for (y = y1; y < y2; y++) g_free (destpixels[y-y1]);
g_free (destpixels);
}
static void
filter_preview (void)
{
guchar **pixels;
guchar **destpixels;
gint image_width;
gint image_height;
gint image_bpp;
gdouble center_x;
gdouble center_y;
gint x, y, b;
gint xx = 0;
gint yy = 0;
gdouble scale, radius, cx, cy, angle, offset;
image_width = GTK_PREVIEW (preview)->buffer_width;
image_height = GTK_PREVIEW (preview)->buffer_height;
image_bpp = GTK_PREVIEW (preview)->bpp;
center_x = (gdouble)image_width / 2;
center_y = (gdouble)image_height / 2;
pixels = g_new (guchar *, image_height);
destpixels = g_new (guchar *, image_height);
for (y = 0; y < image_height; y++)
{
pixels[y] = g_new (guchar, image_width * image_bpp);
destpixels[y] = g_new (guchar, image_width * image_bpp);
memcpy (pixels[y], preview_bits + (image_width * image_bpp * y),
image_width * image_bpp);
}
scale = sqrt (image_width * image_width + image_height * image_height) / 2;
offset = (gint) (scale / 2);
for (y = 0; y < image_height; y++)
{
cy = ((gdouble)y - center_y) / scale;
for (x = 0; x < image_width; x++)
{
cx = ((gdouble)x - center_x) / scale;
angle = floor (atan2 (cy, cx) * parameters.division / G_PI_2)
* G_PI_2 / parameters.division + (G_PI / parameters.division);
radius = sqrt ((gdouble) (cx * cx + cy * cy));
if (parameters.type1)
{
xx = x - offset * cos (angle);
yy = y - offset * sin (angle);
}
for (y = select_y1; y < select_y2; y++) g_free (pixels[y-select_y1]);
if (parameters.type2)
{
xx = x - offset * sin (angle);
yy = y - offset * cos (angle);
}
if (xx < 0)
xx = 0;
else if (image_width <= xx)
xx = image_width - 1;
if (yy < 0)
yy = 0;
else if (image_height <= yy)
yy = image_height - 1;