1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2006-02-02 05:36:47 +08:00
|
|
|
* Polarize plug-in --- maps a rectangle to a circle or vice-versa
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1997 Daniel Dunbar
|
|
|
|
* Email: ddunbar@diads.com
|
|
|
|
* WWW: http://millennium.diads.com/gimp/
|
|
|
|
* Copyright (C) 1997 Federico Mena Quintero
|
|
|
|
* federico@nuclecu.unam.mx
|
|
|
|
* Copyright (C) 1996 Marc Bless
|
|
|
|
* E-mail: bless@ai-lab.fh-furtwangen.de
|
|
|
|
* WWW: www.ai-lab.fh-furtwangen.de/~bless
|
|
|
|
*
|
|
|
|
* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
1998-02-20 18:41:20 +08:00
|
|
|
/* Version 1.0:
|
|
|
|
* This is the follow-up release. It contains a few minor changes, the
|
|
|
|
* most major being that the first time I released the wrong version of
|
|
|
|
* the code, and this time the changes have been fixed. I also added
|
|
|
|
* tooltips to the dialog.
|
|
|
|
*
|
|
|
|
* Feel free to email me if you have any comments or suggestions on this
|
|
|
|
* plugin.
|
|
|
|
* --Daniel Dunbar
|
|
|
|
* ddunbar@diads.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Version .5:
|
|
|
|
* This is the first version publicly released, it will probably be the
|
|
|
|
* last also unless i can think of some features i want to add.
|
|
|
|
*
|
|
|
|
* This plug-in was created with loads of help from quartic (Frederico
|
|
|
|
* Mena Quintero), and would surely not have come about without it.
|
|
|
|
*
|
|
|
|
* The polar algorithms is copied from Marc Bless' polar plug-in for
|
|
|
|
* .54, many thanks to him also.
|
2003-11-06 23:27:05 +08:00
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
* If you can think of a neat addition to this plug-in, or any other
|
|
|
|
* info about it, please email me at ddunbar@diads.com.
|
|
|
|
* - Daniel Dunbar
|
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2000-01-03 21:01:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#define WITHIN(a, b, c) ((((a) <= (b)) && ((b) <= (c))) ? 1 : 0)
|
|
|
|
|
|
|
|
|
|
|
|
/***** Magic numbers *****/
|
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-polar-coords"
|
|
|
|
#define PLUG_IN_BINARY "polar"
|
1997-11-25 06:05:25 +08:00
|
|
|
#define PLUG_IN_VERSION "July 1997, 0.5"
|
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
#define SCALE_WIDTH 200
|
|
|
|
#define ENTRY_WIDTH 60
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/***** Types *****/
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2004-10-03 06:00:29 +08:00
|
|
|
gdouble circle;
|
|
|
|
gdouble angle;
|
|
|
|
gboolean backwards;
|
|
|
|
gboolean inverse;
|
|
|
|
gboolean polrec;
|
1997-11-25 06:05:25 +08:00
|
|
|
} polarize_vals_t;
|
|
|
|
|
|
|
|
/***** Prototypes *****/
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
static void query (void);
|
2003-07-02 20:03:08 +08:00
|
|
|
static void run (const gchar *name,
|
2004-07-18 09:45:57 +08:00
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
static void polarize (GimpDrawable *drawable);
|
|
|
|
static gboolean calc_undistorted_coords (double wx,
|
|
|
|
double wy,
|
|
|
|
double *x,
|
|
|
|
double *y);
|
2000-01-15 01:06:35 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
static gboolean polarize_dialog (GimpDrawable *drawable);
|
|
|
|
static void dialog_update_preview (GimpDrawable *drawable,
|
|
|
|
GimpPreview *preview);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/***** Variables *****/
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
2000-01-15 01:06:35 +08:00
|
|
|
{
|
2000-02-04 23:12:17 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run /* run_proc */
|
2000-01-15 01:06:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static polarize_vals_t pcvals =
|
|
|
|
{
|
|
|
|
100.0, /* circle */
|
2004-10-03 06:00:29 +08:00
|
|
|
0.0, /* angle */
|
|
|
|
FALSE, /* backwards */
|
|
|
|
TRUE, /* inverse */
|
2005-09-20 06:58:16 +08:00
|
|
|
TRUE /* polar to rectangular? */
|
2000-01-15 01:06:35 +08:00
|
|
|
};
|
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
static gint img_width, img_height, img_has_alpha;
|
1997-11-25 06:05:25 +08:00
|
|
|
static gint sel_x1, sel_y1, sel_x2, sel_y2;
|
|
|
|
static gint sel_width, sel_height;
|
|
|
|
|
|
|
|
static double cen_x, cen_y;
|
|
|
|
static double scale_x, scale_y;
|
|
|
|
|
|
|
|
/***** Functions *****/
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
MAIN ()
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2000-01-15 01:06:35 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef args[] =
|
2000-01-15 01:06:35 +08:00
|
|
|
{
|
2005-08-15 19:07:27 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
|
2004-05-07 21:15:52 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
|
|
|
{ GIMP_PDB_FLOAT, "circle", "Circle depth in %" },
|
|
|
|
{ GIMP_PDB_FLOAT, "angle", "Offset angle" },
|
|
|
|
{ GIMP_PDB_INT32, "backwards", "Map backwards?" },
|
|
|
|
{ GIMP_PDB_INT32, "inverse", "Map from top?" },
|
|
|
|
{ GIMP_PDB_INT32, "polrec", "Polar to rectangular?" }
|
2000-01-15 01:06:35 +08:00
|
|
|
};
|
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-17 17:29:48 +08:00
|
|
|
N_("Convert image to or from polar coordinates"),
|
2004-07-18 09:45:57 +08:00
|
|
|
"Remaps and image from rectangular coordinates "
|
2004-05-07 21:15:52 +08:00
|
|
|
"to polar coordinates "
|
2004-07-18 09:45:57 +08:00
|
|
|
"or vice versa",
|
|
|
|
"Daniel Dunbar and Federico Mena Quintero",
|
|
|
|
"Daniel Dunbar and Federico Mena Quintero",
|
|
|
|
PLUG_IN_VERSION,
|
2006-02-02 05:36:47 +08:00
|
|
|
N_("P_olar Coordinates..."),
|
2004-07-18 09:45:57 +08:00
|
|
|
"RGB*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 21:15:52 +08:00
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Distorts");
|
2000-01-15 01:06:35 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2003-07-02 20:03:08 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParam values[1];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
GimpDrawable *drawable;
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPDBStatusType status;
|
2004-09-02 09:23:09 +08:00
|
|
|
GimpRunMode run_mode;
|
|
|
|
gdouble xhsiz, yhsiz;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_SUCCESS;
|
2000-01-15 01:06:35 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
2000-01-15 01:06:35 +08:00
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Get the active drawable info */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
img_width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
img_height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id,
|
|
|
|
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Calculate scaling parameters */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
sel_width = sel_x2 - sel_x1;
|
|
|
|
sel_height = sel_y2 - sel_y1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
cen_x = (double) (sel_x1 + sel_x2 - 1) / 2.0;
|
|
|
|
cen_y = (double) (sel_y1 + sel_y2 - 1) / 2.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
xhsiz = (double) (sel_width - 1) / 2.0;
|
|
|
|
yhsiz = (double) (sel_height - 1) / 2.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (xhsiz < yhsiz)
|
|
|
|
{
|
|
|
|
scale_x = yhsiz / xhsiz;
|
|
|
|
scale_y = 1.0;
|
|
|
|
}
|
|
|
|
else if (xhsiz > yhsiz)
|
|
|
|
{
|
|
|
|
scale_x = 1.0;
|
|
|
|
scale_y = xhsiz / yhsiz;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scale_x = 1.0;
|
|
|
|
scale_y = 1.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* See how we will run */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &pcvals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Get information from the dialog */
|
2004-10-03 06:00:29 +08:00
|
|
|
if (! polarize_dialog (drawable))
|
2004-07-18 09:45:57 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Make sure all the arguments are present */
|
|
|
|
if (nparams != 8)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
2000-02-04 23:12:17 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
pcvals.circle = param[3].data.d_float;
|
|
|
|
pcvals.angle = param[4].data.d_float;
|
|
|
|
pcvals.backwards = param[5].data.d_int32;
|
|
|
|
pcvals.inverse = param[6].data.d_int32;
|
|
|
|
pcvals.polrec = param[7].data.d_int32;
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &pcvals);
|
2000-01-15 01:06:35 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Distort the image */
|
2000-08-22 09:26:57 +08:00
|
|
|
if ((status == GIMP_PDB_SUCCESS) &&
|
2001-06-15 04:07:38 +08:00
|
|
|
(gimp_drawable_is_rgb (drawable->drawable_id) ||
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id)))
|
2000-01-15 01:06:35 +08:00
|
|
|
{
|
|
|
|
/* Set the tile cache size */
|
2000-05-02 01:01:18 +08:00
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->width + gimp_tile_width() - 1) /
|
2004-07-18 09:45:57 +08:00
|
|
|
gimp_tile_width ());
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Run! */
|
2004-10-03 06:00:29 +08:00
|
|
|
polarize (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* If run mode is interactive, flush displays */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2004-07-18 09:45:57 +08:00
|
|
|
gimp_displays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
/* Store data */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_set_data (PLUG_IN_PROC, &pcvals, sizeof (polarize_vals_t));
|
2000-01-15 01:06:35 +08:00
|
|
|
}
|
2000-08-22 09:26:57 +08:00
|
|
|
else if (status == GIMP_PDB_SUCCESS)
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
2000-01-15 01:06:35 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2003-09-25 04:17:43 +08:00
|
|
|
polarize_func (gint x,
|
2004-07-18 09:45:57 +08:00
|
|
|
gint y,
|
|
|
|
guchar *dest,
|
|
|
|
gint bpp,
|
|
|
|
gpointer data)
|
2000-01-15 01:06:35 +08:00
|
|
|
{
|
2000-05-02 01:01:18 +08:00
|
|
|
double cx, cy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
if (calc_undistorted_coords (x, y, &cx, &cy))
|
|
|
|
{
|
|
|
|
guchar pixel1[4], pixel2[4], pixel3[4], pixel4[4];
|
2004-07-18 08:30:56 +08:00
|
|
|
guchar *values[4];
|
2003-09-25 04:17:43 +08:00
|
|
|
GimpPixelFetcher *pft = (GimpPixelFetcher*) data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 08:30:56 +08:00
|
|
|
values[0] = pixel1;
|
|
|
|
values[1] = pixel2;
|
|
|
|
values[2] = pixel3;
|
|
|
|
values[3] = pixel4;
|
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, cx, cy, pixel1);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy, pixel2);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, cx, cy + 1, pixel3);
|
|
|
|
gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy + 1, pixel4);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
gimp_bilinear_pixels_8 (dest, cx, cy, bpp, img_has_alpha, values);
|
|
|
|
}
|
|
|
|
else
|
2000-01-15 01:06:35 +08:00
|
|
|
{
|
2003-09-25 04:17:43 +08:00
|
|
|
gint b;
|
|
|
|
for (b = 0; b < bpp; b++)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
dest[b] = 255;
|
|
|
|
}
|
2003-09-25 04:17:43 +08:00
|
|
|
}
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
static void
|
2004-10-03 06:00:29 +08:00
|
|
|
polarize (GimpDrawable *drawable)
|
2003-09-25 04:17:43 +08:00
|
|
|
{
|
2004-03-13 06:46:25 +08:00
|
|
|
GimpRgnIterator *iter;
|
2003-09-25 04:17:43 +08:00
|
|
|
GimpPixelFetcher *pft;
|
2004-03-13 06:46:25 +08:00
|
|
|
GimpRGB background;
|
2000-05-02 01:01:18 +08:00
|
|
|
|
2004-03-13 06:46:25 +08:00
|
|
|
pft = gimp_pixel_fetcher_new (drawable, FALSE);
|
|
|
|
|
2004-09-23 02:43:09 +08:00
|
|
|
gimp_context_get_background (&background);
|
2004-03-13 06:46:25 +08:00
|
|
|
gimp_pixel_fetcher_set_bg_color (pft, &background);
|
2003-09-25 04:17:43 +08:00
|
|
|
|
2006-02-02 05:36:47 +08:00
|
|
|
gimp_progress_init (_("Polar coordinates"));
|
2004-03-13 06:46:25 +08:00
|
|
|
|
2004-09-02 09:23:09 +08:00
|
|
|
iter = gimp_rgn_iterator_new (drawable, 0);
|
2003-09-25 04:17:43 +08:00
|
|
|
gimp_rgn_iterator_dest (iter, polarize_func, pft);
|
|
|
|
gimp_rgn_iterator_free (iter);
|
2004-03-13 06:46:25 +08:00
|
|
|
|
2003-09-25 04:17:43 +08:00
|
|
|
gimp_pixel_fetcher_destroy (pft);
|
2000-01-15 01:06:35 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-25 03:55:37 +08:00
|
|
|
static gboolean
|
2000-05-02 01:01:18 +08:00
|
|
|
calc_undistorted_coords (gdouble wx,
|
2004-07-18 09:45:57 +08:00
|
|
|
gdouble wy,
|
|
|
|
gdouble *x,
|
|
|
|
gdouble *y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-07-25 03:55:37 +08:00
|
|
|
gboolean inside;
|
2004-03-13 06:46:25 +08:00
|
|
|
gdouble phi, phi2;
|
|
|
|
gdouble xx, xm, ym, yy;
|
|
|
|
gint xdiff, ydiff;
|
|
|
|
gdouble r;
|
|
|
|
gdouble m;
|
|
|
|
gdouble xmax, ymax, rmax;
|
|
|
|
gdouble x_calc, y_calc;
|
|
|
|
gdouble xi, yi;
|
|
|
|
gdouble circle, angl, t, angle;
|
|
|
|
gint x1, x2, y1, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
|
|
|
|
phi = 0.0;
|
2004-03-13 06:46:25 +08:00
|
|
|
r = 0.0;
|
|
|
|
|
|
|
|
x1 = 0;
|
|
|
|
y1 = 0;
|
|
|
|
x2 = img_width;
|
|
|
|
y2 = img_height;
|
|
|
|
xdiff = x2 - x1;
|
|
|
|
ydiff = y2 - y1;
|
|
|
|
xm = xdiff / 2.0;
|
|
|
|
ym = ydiff / 2.0;
|
1998-02-20 18:41:20 +08:00
|
|
|
circle = pcvals.circle;
|
2004-03-13 06:46:25 +08:00
|
|
|
angle = pcvals.angle;
|
|
|
|
angl = (gdouble) angle / 180.0 * G_PI;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (pcvals.polrec)
|
|
|
|
{
|
|
|
|
if (wx >= cen_x)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
if (wy > cen_y)
|
|
|
|
{
|
|
|
|
phi = G_PI - atan (((double)(wx - cen_x))/
|
|
|
|
((double)(wy - cen_y)));
|
|
|
|
}
|
|
|
|
else if (wy < cen_y)
|
|
|
|
{
|
|
|
|
phi = atan (((double)(wx - cen_x))/((double)(cen_y - wy)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
phi = G_PI / 2;
|
|
|
|
}
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else if (wx < cen_x)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
if (wy < cen_y)
|
|
|
|
{
|
|
|
|
phi = 2 * G_PI - atan (((double)(cen_x -wx)) /
|
|
|
|
((double)(cen_y - wy)));
|
|
|
|
}
|
|
|
|
else if (wy > cen_y)
|
|
|
|
{
|
|
|
|
phi = G_PI + atan (((double)(cen_x - wx))/
|
|
|
|
((double)(wy - cen_y)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
phi = 1.5 * G_PI;
|
|
|
|
}
|
|
|
|
}
|
2003-09-25 04:17:43 +08:00
|
|
|
|
|
|
|
r = sqrt (SQR (wx - cen_x) + SQR (wy - cen_y));
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (wx != cen_x)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
m = fabs (((double)(wy - cen_y)) / ((double)(wx - cen_x)));
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
m = 0;
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (m <= ((double)(y2 - y1) / (double)(x2 - x1)))
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
if (wx == cen_x)
|
|
|
|
{
|
|
|
|
xmax = 0;
|
|
|
|
ymax = cen_y - y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmax = cen_x - x1;
|
|
|
|
ymax = m * xmax;
|
|
|
|
}
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
ymax = cen_y - y1;
|
|
|
|
xmax = ymax / m;
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
rmax = sqrt ( (double)(SQR (xmax) + SQR (ymax)) );
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
t = ((cen_y - y1) < (cen_x - x1)) ? (cen_y - y1) : (cen_x - x1);
|
|
|
|
rmax = (rmax - t) / 100 * (100 - circle) + t;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
phi = fmod (phi + angl, 2*G_PI);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (pcvals.backwards)
|
2004-07-18 09:45:57 +08:00
|
|
|
x_calc = x2 - 1 - (x2 - x1 - 1)/(2*G_PI) * phi;
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
x_calc = (x2 - x1 - 1)/(2*G_PI) * phi + x1;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (pcvals.inverse)
|
2004-07-18 09:45:57 +08:00
|
|
|
y_calc = (y2 - y1)/rmax * r + y1;
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
y_calc = y2 - (y2 - y1)/rmax * r;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pcvals.backwards)
|
2004-07-18 09:45:57 +08:00
|
|
|
phi = (2 * G_PI) * (x2 - wx) / xdiff;
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
phi = (2 * G_PI) * (wx - x1) / xdiff;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
phi = fmod (phi + angl, 2 * G_PI);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (phi >= 1.5 * G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
phi2 = 2 * G_PI - phi;
|
2003-09-25 04:17:43 +08:00
|
|
|
else if (phi >= G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
phi2 = phi - G_PI;
|
2003-09-25 04:17:43 +08:00
|
|
|
else if (phi >= 0.5 * G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
phi2 = G_PI - phi;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
phi2 = phi;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
xx = tan (phi2);
|
|
|
|
if (xx != 0)
|
2004-07-18 09:45:57 +08:00
|
|
|
m = (double) 1.0 / xx;
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
m = 0;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (m <= ((double)(ydiff) / (double)(xdiff)))
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
if (phi2 == 0)
|
|
|
|
{
|
|
|
|
xmax = 0;
|
|
|
|
ymax = ym - y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmax = xm - x1;
|
|
|
|
ymax = m * xmax;
|
|
|
|
}
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
ymax = ym - y1;
|
|
|
|
xmax = ymax / m;
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
rmax = sqrt ((double)(SQR (xmax) + SQR (ymax)));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
t = ((ym - y1) < (xm - x1)) ? (ym - y1) : (xm - x1);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
rmax = (rmax - t) / 100.0 * (100 - circle) + t;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (pcvals.inverse)
|
2004-07-18 09:45:57 +08:00
|
|
|
r = rmax * (double)((wy - y1) / (double)(ydiff));
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
r = rmax * (double)((y2 - wy) / (double)(ydiff));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
xx = r * sin (phi2);
|
|
|
|
yy = r * cos (phi2);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
if (phi >= 1.5 * G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
x_calc = (double)xm - xx;
|
|
|
|
y_calc = (double)ym - yy;
|
|
|
|
}
|
2003-09-25 04:17:43 +08:00
|
|
|
else if (phi >= G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
x_calc = (double)xm - xx;
|
|
|
|
y_calc = (double)ym + yy;
|
|
|
|
}
|
2003-09-25 04:17:43 +08:00
|
|
|
else if (phi >= 0.5 * G_PI)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
x_calc = (double)xm + xx;
|
|
|
|
y_calc = (double)ym + yy;
|
|
|
|
}
|
2000-01-15 01:06:35 +08:00
|
|
|
else
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
x_calc = (double)xm + xx;
|
|
|
|
y_calc = (double)ym - yy;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2003-09-25 04:17:43 +08:00
|
|
|
|
|
|
|
xi = (int) (x_calc + 0.5);
|
|
|
|
yi = (int) (y_calc + 0.5);
|
|
|
|
|
|
|
|
inside = (WITHIN (0, xi, img_width - 1) && WITHIN (0, yi, img_height - 1));
|
|
|
|
if (inside)
|
|
|
|
{
|
|
|
|
*x = x_calc;
|
|
|
|
*y = y_calc;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
return inside;
|
|
|
|
}
|
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
static gboolean
|
|
|
|
polarize_dialog (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-15 01:06:35 +08:00
|
|
|
GtkWidget *dialog;
|
2004-10-03 06:00:29 +08:00
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *preview;
|
2000-01-15 01:06:35 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *hbox;
|
2004-05-19 01:06:06 +08:00
|
|
|
GtkWidget *toggle;
|
2000-01-15 01:06:35 +08:00
|
|
|
GtkObject *adj;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
2000-01-08 23:23:28 +08:00
|
|
|
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-02-02 05:36:47 +08:00
|
|
|
dialog = gimp_dialog_new (_("Polar Coordinates"), PLUG_IN_BINARY,
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2005-08-15 19:07:27 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-08-15 19:07:27 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
/* Preview */
|
2005-09-20 06:58:16 +08:00
|
|
|
preview = gimp_zoom_preview_new (drawable);
|
2004-10-03 06:00:29 +08:00
|
|
|
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
|
2004-08-06 09:28:01 +08:00
|
|
|
gtk_widget_show (preview);
|
2004-10-03 06:00:29 +08:00
|
|
|
g_signal_connect_swapped (preview, "invalidated",
|
|
|
|
G_CALLBACK (dialog_update_preview),
|
|
|
|
drawable);
|
2000-01-08 23:23:28 +08:00
|
|
|
|
|
|
|
/* Controls */
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
table = gtk_table_new (2, 3, FALSE);
|
2004-05-19 01:06:06 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
2004-10-03 06:00:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2000-01-15 01:06:35 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2004-07-18 09:45:57 +08:00
|
|
|
_("Circle _depth in percent:"), SCALE_WIDTH, 0,
|
|
|
|
pcvals.circle, 0.0, 100.0, 1.0, 10.0, 2,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (adj, "value-changed",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
2001-12-31 08:21:10 +08:00
|
|
|
&pcvals.circle);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (adj, "value-changed",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2000-01-15 01:06:35 +08:00
|
|
|
|
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2004-07-18 09:45:57 +08:00
|
|
|
_("Offset _angle:"), SCALE_WIDTH, 0,
|
|
|
|
pcvals.angle, 0.0, 359.0, 1.0, 15.0, 2,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (adj, "value-changed",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
2001-12-31 08:21:10 +08:00
|
|
|
&pcvals.angle);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (adj, "value-changed",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2000-01-08 23:23:28 +08:00
|
|
|
|
|
|
|
/* togglebuttons for backwards, top, polar->rectangular */
|
2004-05-19 01:06:06 +08:00
|
|
|
hbox = gtk_hbox_new (TRUE, 6);
|
2004-10-03 06:00:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
|
2000-01-08 23:23:28 +08:00
|
|
|
|
2004-06-21 06:47:33 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_Map backwards"));
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), pcvals.backwards);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gimp_help_set_help_data (toggle,
|
2004-07-18 09:45:57 +08:00
|
|
|
_("If checked the mapping will begin at the right "
|
|
|
|
"side, as opposed to beginning at the left."),
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
2001-12-31 08:21:10 +08:00
|
|
|
&pcvals.backwards);
|
2004-10-03 06:00:29 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2004-06-21 06:47:33 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("Map from _top"));
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), pcvals.inverse);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gimp_help_set_help_data (toggle,
|
2004-07-18 09:45:57 +08:00
|
|
|
_("If unchecked the mapping will put the bottom "
|
|
|
|
"row in the middle and the top row on the "
|
|
|
|
"outside. If checked it will be the opposite."),
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
2001-12-31 08:21:10 +08:00
|
|
|
&pcvals.inverse);
|
2004-10-03 06:00:29 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2004-06-21 06:47:33 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("To _polar"));
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), pcvals.polrec);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gimp_help_set_help_data (toggle,
|
2004-07-18 09:45:57 +08:00
|
|
|
_("If unchecked the image will be circularly "
|
|
|
|
"mapped onto a rectangle. If checked the image "
|
|
|
|
"will be mapped onto a circle."),
|
|
|
|
NULL);
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2004-10-03 06:00:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
2001-12-31 08:21:10 +08:00
|
|
|
&pcvals.polrec);
|
2004-10-03 06:00:29 +08:00
|
|
|
g_signal_connect_swapped (toggle, "toggled",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2001-12-31 08:21:10 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
/* Done */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_show (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
2000-01-08 23:23:28 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
static void
|
2004-10-03 06:00:29 +08:00
|
|
|
dialog_update_preview (GimpDrawable *drawable,
|
|
|
|
GimpPreview *preview)
|
2000-01-08 23:23:28 +08:00
|
|
|
{
|
2000-05-02 01:01:18 +08:00
|
|
|
gdouble left, right, bottom, top;
|
|
|
|
gdouble dx, dy;
|
|
|
|
gdouble px, py;
|
|
|
|
gdouble cx = 0.0, cy = 0.0;
|
|
|
|
gint ix, iy;
|
|
|
|
gint x, y;
|
2004-10-03 06:00:29 +08:00
|
|
|
gint width, height;
|
2004-07-18 09:45:57 +08:00
|
|
|
gint bpp;
|
2000-05-02 01:01:18 +08:00
|
|
|
gdouble scale_x, scale_y;
|
2003-07-25 03:55:37 +08:00
|
|
|
guchar *p_ul, *i;
|
2004-03-13 06:46:25 +08:00
|
|
|
GimpRGB background;
|
2000-05-02 01:01:18 +08:00
|
|
|
guchar outside[4];
|
2004-10-03 06:00:29 +08:00
|
|
|
guchar *buffer, *preview_cache;
|
2004-07-18 09:45:57 +08:00
|
|
|
guchar k;
|
2000-05-02 01:01:18 +08:00
|
|
|
|
2004-09-23 02:43:09 +08:00
|
|
|
gimp_context_get_background (&background);
|
2004-03-13 06:46:25 +08:00
|
|
|
gimp_rgb_set_alpha (&background, 0.0);
|
|
|
|
gimp_drawable_get_color_uchar (drawable->drawable_id, &background, outside);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
left = sel_x1;
|
|
|
|
right = sel_x2 - 1;
|
|
|
|
bottom = sel_y2 - 1;
|
|
|
|
top = sel_y1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
preview_cache = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
|
|
|
|
&width, &height, &bpp);
|
2004-10-03 06:00:29 +08:00
|
|
|
dx = (right - left) / (width - 1);
|
|
|
|
dy = (bottom - top) / (height - 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
scale_x = (double) width / (right - left + 1);
|
|
|
|
scale_y = (double) height / (bottom - top + 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
py = top;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
buffer = g_new (guchar, bpp * width * height);
|
2004-08-06 09:28:01 +08:00
|
|
|
p_ul = buffer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
for (y = 0; y < height; y++)
|
2000-01-08 23:23:28 +08:00
|
|
|
{
|
|
|
|
px = left;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
for (x = 0; x < width; x++)
|
2004-07-18 09:45:57 +08:00
|
|
|
{
|
|
|
|
calc_undistorted_coords (px, py, &cx, &cy);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
cx = (cx - left) * scale_x;
|
|
|
|
cy = (cy - top) * scale_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
ix = (int) (cx + 0.5);
|
|
|
|
iy = (int) (cy + 0.5);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
if ((ix >= 0) && (ix < width) &&
|
|
|
|
(iy >= 0) && (iy < height))
|
|
|
|
i = preview_cache + bpp * (width * iy + ix);
|
2004-07-18 09:45:57 +08:00
|
|
|
else
|
|
|
|
i = outside;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
for (k = 0; k < bpp; k ++)
|
|
|
|
p_ul[k] = i[k];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
p_ul += bpp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-18 09:45:57 +08:00
|
|
|
px += dx;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
py += dy;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
gimp_preview_draw_buffer (preview, buffer, bpp * width);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-03 06:00:29 +08:00
|
|
|
g_free (buffer);
|
|
|
|
g_free (preview_cache);
|
2000-01-08 23:23:28 +08:00
|
|
|
}
|