2000-05-23 21:00:40 +08:00
|
|
|
/*
|
|
|
|
* illusion.c -- This is a plug-in for the GIMP 1.0
|
2001-10-19 07:09:40 +08:00
|
|
|
*
|
2000-05-23 21:00:40 +08:00
|
|
|
* 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
|
2001-10-19 07:09:40 +08:00
|
|
|
*
|
2000-05-23 21:00:40 +08:00
|
|
|
* 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.
|
2001-10-19 07:09:40 +08:00
|
|
|
*
|
2000-05-23 21:00:40 +08:00
|
|
|
* 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.
|
2001-10-19 07:09:40 +08:00
|
|
|
*
|
2000-05-23 21:00:40 +08:00
|
|
|
* 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-12-09 13:57:33 +08:00
|
|
|
|
1999-12-29 04:04:19 +08:00
|
|
|
#include "config.h"
|
2000-01-07 18:39:33 +08:00
|
|
|
|
1998-06-09 19:41:13 +08:00
|
|
|
#include <stdio.h>
|
1997-12-09 13:57:33 +08:00
|
|
|
#include <stdlib.h>
|
2000-10-01 04:13:06 +08:00
|
|
|
#include <string.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
|
1999-12-29 04:04:19 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
#define PLUG_IN_NAME "plug_in_illusion"
|
2000-05-23 21:00:40 +08:00
|
|
|
#define PLUG_IN_VERSION "v0.8 (May 14 2000)"
|
|
|
|
|
|
|
|
#define PREVIEW_SIZE 128
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (gchar *name,
|
|
|
|
gint nparam,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2000-05-02 01:01:18 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals);
|
2000-01-18 01:02:26 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
static void filter (GimpDrawable *drawable);
|
2000-05-23 21:00:40 +08:00
|
|
|
static void filter_preview (void);
|
|
|
|
static void fill_preview_with_thumb (GtkWidget *preview_widget,
|
|
|
|
gint32 drawable_ID);
|
2000-08-22 09:26:57 +08:00
|
|
|
static gboolean dialog (GimpDrawable *drawable);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-12-09 13:57:33 +08:00
|
|
|
gint32 division;
|
2000-05-23 21:00:40 +08:00
|
|
|
gint type1;
|
|
|
|
gint type2;
|
|
|
|
} IllValues;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
2000-05-23 21:00:40 +08:00
|
|
|
run /* run_proc */
|
1997-12-09 13:57:33 +08:00
|
|
|
};
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
static IllValues parameters =
|
2000-01-18 01:02:26 +08:00
|
|
|
{
|
2000-05-23 21:00:40 +08:00
|
|
|
8, /* division */
|
|
|
|
1, /* type 1 */
|
|
|
|
0 /* type 2 */
|
1997-12-09 13:57:33 +08:00
|
|
|
};
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
static GtkWidget *preview;
|
2000-05-27 06:48:00 +08:00
|
|
|
static guchar *preview_cache;
|
|
|
|
static gint preview_cache_rowstride;
|
|
|
|
static gint preview_cache_bpp;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
MAIN ()
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
static void
|
|
|
|
query (void)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "interactive / non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "input drawable" },
|
2001-10-19 07:09:40 +08:00
|
|
|
{ GIMP_PDB_INT32, "division", "the number of divisions" },
|
|
|
|
{ GIMP_PDB_INT32, "type1", "Use Type 1 (default=1)" },
|
|
|
|
{ GIMP_PDB_INT32, "type2", "Use Type 2 (default=0)" }
|
1997-12-09 13:57:33 +08:00
|
|
|
};
|
2001-10-19 07:09:40 +08:00
|
|
|
static gint nargs = sizeof (args) / sizeof (args[0]);
|
1999-12-29 04:04:19 +08:00
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_NAME,
|
2000-03-08 21:53:54 +08:00
|
|
|
"produce illusion",
|
|
|
|
"produce illusion",
|
2000-01-07 18:39:33 +08:00
|
|
|
"Hirotsuna Mizuno <s1041150@u-aizu.ac.jp>",
|
|
|
|
"Hirotsuna Mizuno",
|
|
|
|
PLUG_IN_VERSION,
|
|
|
|
N_("<Image>/Filters/Map/Illusion..."),
|
|
|
|
"RGB*, GRAY*",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2000-05-02 01:01:18 +08:00
|
|
|
nargs, 0,
|
|
|
|
args, NULL);
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
static void
|
2000-01-18 01:02:26 +08:00
|
|
|
run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *params,
|
2000-01-18 01:02:26 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunModeType run_mode;
|
|
|
|
static GimpParam returnv[1];
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
run_mode = params[0].data.d_int32;
|
2000-01-07 18:39:33 +08:00
|
|
|
drawable = gimp_drawable_get (params[2].data.d_drawable);
|
2000-01-18 01:02:26 +08:00
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = returnv;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* get the drawable info */
|
|
|
|
|
|
|
|
/* switch the run mode */
|
2000-01-07 18:39:33 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2000-01-07 18:39:33 +08:00
|
|
|
INIT_I18N_UI();
|
|
|
|
gimp_get_data (PLUG_IN_NAME, ¶meters);
|
2000-05-23 21:00:40 +08:00
|
|
|
if (! dialog(drawable))
|
2000-01-18 01:02:26 +08:00
|
|
|
return;
|
2000-05-23 21:00:40 +08:00
|
|
|
gimp_set_data (PLUG_IN_NAME, ¶meters, sizeof (IllValues));
|
2000-05-27 06:48:00 +08:00
|
|
|
g_free(preview_cache);
|
2000-01-07 18:39:33 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2000-05-23 21:00:40 +08:00
|
|
|
if (nparams != 6)
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-07 18:39:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parameters.division = params[3].data.d_int32;
|
2000-05-23 21:00:40 +08:00
|
|
|
parameters.type1 = params[4].data.d_int32;
|
|
|
|
parameters.type2 = params[5].data.d_int32;
|
2000-01-07 18:39:33 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-01-07 18:39:33 +08:00
|
|
|
gimp_get_data (PLUG_IN_NAME, ¶meters);
|
|
|
|
break;
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
2001-06-15 04:07:38 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id))
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width() + 1));
|
2000-05-23 21:00:40 +08:00
|
|
|
gimp_progress_init (_("Illusion..."));
|
2000-01-07 18:39:33 +08:00
|
|
|
filter (drawable);
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2000-01-07 18:39:33 +08:00
|
|
|
gimp_displays_flush ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2000-01-07 18:39:33 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
returnv[0].type = GIMP_PDB_STATUS;
|
1997-12-09 13:57:33 +08:00
|
|
|
returnv[0].data.d_status = status;
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
static void
|
2000-08-22 09:26:57 +08:00
|
|
|
filter (GimpDrawable *drawable)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn srcPR, destPR;
|
1997-12-09 13:57:33 +08:00
|
|
|
guchar **pixels;
|
|
|
|
guchar **destpixels;
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
gint x, y, b;
|
2000-05-23 21:00:40 +08:00
|
|
|
gint xx = 0;
|
|
|
|
gint yy = 0;
|
1997-12-09 13:57:33 +08:00
|
|
|
gdouble scale, radius, cx, cy, angle, offset;
|
2000-05-23 21:00:40 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
image_width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
image_height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
image_bpp = gimp_drawable_bpp (drawable->drawable_id);
|
|
|
|
image_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id,&x1, &y1, &x2, &y2);
|
2000-05-23 21:00:40 +08:00
|
|
|
select_width = x2 - x1;
|
|
|
|
select_height = y2 - y1;
|
|
|
|
center_x = x1 + (gdouble)select_width / 2;
|
|
|
|
center_y = y1 + (gdouble)select_height / 2;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
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);
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
pixels = g_new (guchar *, image_height);
|
|
|
|
destpixels = g_new (guchar *, image_height);
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
for (y = 0; y < image_height; y++)
|
|
|
|
{
|
2000-05-23 21:00:40 +08:00
|
|
|
pixels[y] = g_new (guchar, image_width * image_bpp);
|
|
|
|
destpixels[y] = g_new (guchar, image_width * image_bpp);
|
2000-01-07 18:39:33 +08:00
|
|
|
gimp_pixel_rgn_get_row (&srcPR, pixels[y], 0, y, image_width);
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
scale = sqrt (select_width * select_width + select_height * select_height) / 2;
|
|
|
|
offset = (gint) (scale / 2);
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
for (y = y1; y < y2; y++)
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
|
|
|
cy = ((gdouble)y - center_y) / scale;
|
2000-05-23 21:00:40 +08:00
|
|
|
for (x = x1; x < x2; x++)
|
2000-01-07 18:39:33 +08:00
|
|
|
{
|
|
|
|
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));
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
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);
|
2000-05-23 21:00:40 +08:00
|
|
|
gimp_progress_update ((double) (y - y1) / (double) select_height);
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
2000-01-07 18:39:33 +08:00
|
|
|
|
|
|
|
gimp_drawable_flush (drawable);
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable->drawable_id,
|
2000-05-23 21:00:40 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-05-27 06:48:00 +08:00
|
|
|
static void
|
|
|
|
preview_do_row(gint row,
|
|
|
|
gint width,
|
|
|
|
guchar *even,
|
|
|
|
guchar *odd,
|
|
|
|
guchar *src)
|
|
|
|
{
|
|
|
|
gint x;
|
|
|
|
|
|
|
|
guchar *p0 = even;
|
|
|
|
guchar *p1 = odd;
|
|
|
|
|
|
|
|
gdouble r, g, b, a;
|
|
|
|
gdouble c0, c1;
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
if (preview_cache_bpp == 4)
|
|
|
|
{
|
|
|
|
r = ((gdouble)src[x*4+0]) / 255.0;
|
|
|
|
g = ((gdouble)src[x*4+1]) / 255.0;
|
|
|
|
b = ((gdouble)src[x*4+2]) / 255.0;
|
|
|
|
a = ((gdouble)src[x*4+3]) / 255.0;
|
|
|
|
}
|
|
|
|
else if (preview_cache_bpp == 3)
|
|
|
|
{
|
|
|
|
r = ((gdouble)src[x*3+0]) / 255.0;
|
|
|
|
g = ((gdouble)src[x*3+1]) / 255.0;
|
|
|
|
b = ((gdouble)src[x*3+2]) / 255.0;
|
|
|
|
a = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = ((gdouble)src[x*preview_cache_bpp+0]) / 255.0;
|
|
|
|
g = b = r;
|
|
|
|
if (preview_cache_bpp == 2)
|
|
|
|
a = ((gdouble)src[x*preview_cache_bpp+1]) / 255.0;
|
|
|
|
else
|
|
|
|
a = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((x / GIMP_CHECK_SIZE) & 1)
|
|
|
|
{
|
|
|
|
c0 = GIMP_CHECK_LIGHT;
|
|
|
|
c1 = GIMP_CHECK_DARK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c0 = GIMP_CHECK_DARK;
|
|
|
|
c1 = GIMP_CHECK_LIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p0++ = (c0 + (r - c0) * a) * 255.0;
|
|
|
|
*p0++ = (c0 + (g - c0) * a) * 255.0;
|
|
|
|
*p0++ = (c0 + (b - c0) * a) * 255.0;
|
|
|
|
|
|
|
|
*p1++ = (c1 + (r - c1) * a) * 255.0;
|
|
|
|
*p1++ = (c1 + (g - c1) * a) * 255.0;
|
|
|
|
*p1++ = (c1 + (b - c1) * a) * 255.0;
|
|
|
|
|
|
|
|
} /* for */
|
|
|
|
|
|
|
|
if ((row / GIMP_CHECK_SIZE) & 1)
|
|
|
|
{
|
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), (guchar *)odd, 0, row, width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), (guchar *)even, 0, row, width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
static void
|
|
|
|
filter_preview (void)
|
|
|
|
{
|
|
|
|
guchar **pixels;
|
|
|
|
guchar **destpixels;
|
2000-05-27 06:48:00 +08:00
|
|
|
guchar *even, *odd;
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
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;
|
2000-05-27 06:48:00 +08:00
|
|
|
image_bpp = preview_cache_bpp;
|
2000-05-23 21:00:40 +08:00
|
|
|
center_x = (gdouble)image_width / 2;
|
|
|
|
center_y = (gdouble)image_height / 2;
|
|
|
|
|
|
|
|
pixels = g_new (guchar *, image_height);
|
|
|
|
destpixels = g_new (guchar *, image_height);
|
|
|
|
|
2000-05-27 06:48:00 +08:00
|
|
|
even = g_malloc (image_width * 3);
|
|
|
|
odd = g_malloc (image_width * 3);
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
for (y = 0; y < image_height; y++)
|
|
|
|
{
|
2000-05-27 06:48:00 +08:00
|
|
|
pixels[y] = g_new (guchar, preview_cache_rowstride);
|
|
|
|
destpixels[y] = g_new (guchar, preview_cache_rowstride);
|
2000-05-24 02:52:14 +08:00
|
|
|
memcpy (pixels[y],
|
2000-05-27 06:48:00 +08:00
|
|
|
preview_cache + preview_cache_rowstride * y,
|
|
|
|
preview_cache_rowstride);
|
2000-05-23 21:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2000-01-07 18:39:33 +08:00
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
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];
|
|
|
|
}
|
2000-05-27 06:48:00 +08:00
|
|
|
|
|
|
|
preview_do_row(y,
|
|
|
|
image_width,
|
|
|
|
even,
|
|
|
|
odd,
|
|
|
|
destpixels[y]);
|
2000-05-23 21:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (y = 0; y < image_height; y++)
|
|
|
|
g_free (pixels[y]);
|
2000-01-07 18:39:33 +08:00
|
|
|
g_free (pixels);
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
for (y = 0; y < image_height; y++)
|
|
|
|
g_free (destpixels[y]);
|
2000-01-07 18:39:33 +08:00
|
|
|
g_free (destpixels);
|
2000-05-23 21:00:40 +08:00
|
|
|
|
2000-05-27 06:48:00 +08:00
|
|
|
g_free (even);
|
|
|
|
g_free (odd);
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
gtk_widget_queue_draw (preview);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2000-08-22 09:26:57 +08:00
|
|
|
preview_widget (GimpDrawable *drawable)
|
2000-05-23 21:00:40 +08:00
|
|
|
{
|
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
2001-06-15 04:07:38 +08:00
|
|
|
fill_preview_with_thumb (preview, drawable->drawable_id);
|
2000-05-23 21:00:40 +08:00
|
|
|
|
|
|
|
return preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_preview_with_thumb (GtkWidget *widget,
|
|
|
|
gint32 drawable_ID)
|
|
|
|
{
|
|
|
|
guchar *drawable_data;
|
|
|
|
gint bpp;
|
2000-05-27 06:48:00 +08:00
|
|
|
gint y;
|
2000-05-23 21:00:40 +08:00
|
|
|
gint width = PREVIEW_SIZE;
|
|
|
|
gint height = PREVIEW_SIZE;
|
|
|
|
guchar *src;
|
|
|
|
guchar *even, *odd;
|
|
|
|
|
|
|
|
bpp = 0; /* Only returned */
|
|
|
|
|
|
|
|
drawable_data =
|
|
|
|
gimp_drawable_get_thumbnail_data (drawable_ID, &width, &height, &bpp);
|
|
|
|
|
|
|
|
if (width < 1 || height < 1)
|
|
|
|
return;
|
|
|
|
|
2000-05-27 06:48:00 +08:00
|
|
|
preview_cache = drawable_data;
|
|
|
|
preview_cache_rowstride = width * bpp;
|
|
|
|
preview_cache_bpp = bpp;
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
gtk_preview_size (GTK_PREVIEW (widget), width, height);
|
|
|
|
|
|
|
|
even = g_malloc (width * 3);
|
|
|
|
odd = g_malloc (width * 3);
|
|
|
|
src = drawable_data;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
2000-05-27 06:48:00 +08:00
|
|
|
preview_do_row(y,width,even,odd,preview_cache + (y*width*bpp));
|
2000-05-23 21:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (even);
|
|
|
|
g_free (odd);
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
static gboolean dialog_status = FALSE;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
static void
|
|
|
|
dialog_ok_handler (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
dialog_status = TRUE;
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
static gboolean
|
2000-08-22 09:26:57 +08:00
|
|
|
dialog (GimpDrawable *mangle)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-05-23 21:00:40 +08:00
|
|
|
GtkWidget *dlg;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *abox;
|
2000-01-26 01:46:56 +08:00
|
|
|
GtkWidget *frame;
|
2000-01-18 01:02:26 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkObject *adj;
|
2000-05-23 21:00:40 +08:00
|
|
|
GtkWidget *radio;
|
|
|
|
GSList *group = NULL;
|
|
|
|
|
|
|
|
gimp_ui_init ("illusion", TRUE);
|
|
|
|
|
|
|
|
dlg = gimp_dialog_new (_("Illusion"), "illusion",
|
|
|
|
gimp_standard_help_func, "filters/illusion.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, TRUE, FALSE,
|
|
|
|
|
2001-08-04 03:52:08 +08:00
|
|
|
GTK_STOCK_OK, dialog_ok_handler,
|
2000-05-23 21:00:40 +08:00
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
2001-08-04 03:52:08 +08:00
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
2000-05-23 21:00:40 +08:00
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
|
2000-01-07 18:39:33 +08:00
|
|
|
GTK_SIGNAL_FUNC (gtk_main_quit),
|
|
|
|
NULL);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
/* Initialize Tooltips */
|
|
|
|
gimp_help_init ();
|
|
|
|
|
|
|
|
main_vbox = gtk_vbox_new (FALSE, 3);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (_("Preview"));
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), 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);
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), frame);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
preview = preview_widget (mangle);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
|
|
filter_preview();
|
|
|
|
gtk_widget_show (preview);
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
frame = gtk_frame_new (_("Parameter Settings"));
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
|
2000-05-23 21:00:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0 );
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
table = gtk_table_new (3, 2, FALSE);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
spinbutton = gimp_spin_button_new (&adj, parameters.division,
|
2000-05-23 21:00:40 +08:00
|
|
|
-32, 64, 1, 10, 0, 1, 0);
|
2000-01-31 11:13:02 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
2000-01-18 01:02:26 +08:00
|
|
|
_("Division:"), 1.0, 0.5,
|
2000-01-31 11:13:02 +08:00
|
|
|
spinbutton, 1, TRUE);
|
2000-01-18 01:02:26 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
|
|
|
|
¶meters.division);
|
2000-05-23 21:00:40 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
|
|
|
GTK_SIGNAL_FUNC (filter_preview),
|
|
|
|
NULL);
|
|
|
|
|
2001-04-11 02:36:37 +08:00
|
|
|
radio = gtk_radio_button_new_with_label (group, _("Mode 1"));
|
2000-05-23 21:00:40 +08:00
|
|
|
group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
|
|
|
|
gtk_signal_connect (GTK_OBJECT (radio), "toggled",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
|
|
|
|
¶meters.type1);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (radio), "toggled",
|
|
|
|
GTK_SIGNAL_FUNC (filter_preview),
|
|
|
|
NULL);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), parameters.type1);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), radio, 0, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (radio);
|
|
|
|
|
2001-04-11 02:36:37 +08:00
|
|
|
radio = gtk_radio_button_new_with_label (group, _("Mode 2"));
|
2000-05-23 21:00:40 +08:00
|
|
|
group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
|
|
|
|
gtk_signal_connect (GTK_OBJECT (radio), "toggled",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
|
|
|
|
¶meters.type2);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (radio), "toggled",
|
|
|
|
GTK_SIGNAL_FUNC (filter_preview),
|
|
|
|
NULL);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), parameters.type2);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), radio, 0, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (radio);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 21:00:40 +08:00
|
|
|
gtk_widget_show (dlg);
|
2000-01-07 18:39:33 +08:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
gdk_flush ();
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
return dialog_status;
|
|
|
|
}
|