1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Motion Blur plug-in for GIMP 0.99
|
|
|
|
* Copyright (C) 1997 Daniel Skarda (0rfelyus@atrey.karlin.mff.cuni.cz)
|
|
|
|
*
|
|
|
|
* This plug-in is port of Motion Blur plug-in for GIMP 0.54 by Thorsten Martinsen
|
|
|
|
* Copyright (C) 1996 Torsten Martinsen <torsten@danbbs.dk>
|
|
|
|
* Bresenham algorithm stuff hacked from HP2xx written by Heinz W. Werntges
|
|
|
|
* Changes for version 1.11/1.12 Copyright (C) 1996 Federico Mena Quintero
|
|
|
|
* quartic@polloux.fciencias.unam.mx
|
|
|
|
*
|
|
|
|
* I also used some code from Whirl and Pinch plug-in by Federico Mena Quintero
|
|
|
|
* (federico@nuclecu.unam.mx)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
/* Version 1.2
|
|
|
|
*
|
|
|
|
* Everything is new - no changes
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* Bilinear interpolation from original mblur for 0.54
|
|
|
|
* Speed all things up
|
|
|
|
* ? better caching scheme
|
|
|
|
* - while bluring along long trajektory do not averrage all
|
|
|
|
* pixels but averrage only few samples
|
|
|
|
* Function for weight of samples along trajectory
|
|
|
|
* Preview
|
|
|
|
* Support paths in GiMP 1.1 :-)
|
|
|
|
* Smash all bugs :-)
|
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-06-09 19:41:13 +08:00
|
|
|
#include <stdlib.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-05-29 09:28:24 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <libgimp/gimp.h>
|
2000-01-07 18:39:33 +08:00
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2000-01-01 00:39:04 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#define PLUG_IN_NAME "plug_in_mblur"
|
|
|
|
#define PLUG_IN_VERSION "Sep 1997, 1.2"
|
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
#define MBLUR_LINEAR 0
|
|
|
|
#define MBLUR_RADIAL 1
|
|
|
|
#define MBLUR_ZOOM 2
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
#define MBLUR_MAX MBLUR_ZOOM
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
gint32 mblur_type;
|
|
|
|
gint32 length;
|
|
|
|
gint32 angle;
|
1997-11-25 06:05:25 +08:00
|
|
|
} mblur_vals_t;
|
|
|
|
|
|
|
|
/***** Prototypes *****/
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
static void query (void);
|
2001-01-15 08:06:43 +08:00
|
|
|
static void run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2001-01-15 08:06:43 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals);
|
2000-01-11 23:48:00 +08:00
|
|
|
static void mblur (void);
|
|
|
|
static void mblur_linear (void);
|
|
|
|
static void mblur_radial (void);
|
|
|
|
static void mblur_zoom (void);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
static void dialog_ok_callback (GtkWidget *, gpointer);
|
2000-01-11 23:48:00 +08:00
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
static gboolean mblur_dialog (void);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/***** Variables *****/
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
2000-01-11 23:48:00 +08:00
|
|
|
{
|
2000-01-18 01:02:26 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run /* run_proc */
|
2000-01-11 23:48:00 +08:00
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
static mblur_vals_t mbvals =
|
|
|
|
{
|
|
|
|
MBLUR_LINEAR, /* mblur_type */
|
|
|
|
5, /* length */
|
|
|
|
45 /* radius */
|
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-03-26 10:08:31 +08:00
|
|
|
static gboolean mb_run = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
static gint img_width, img_height, img_bpp;
|
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;
|
|
|
|
|
|
|
|
/***** Functions *****/
|
|
|
|
|
|
|
|
MAIN()
|
|
|
|
|
|
|
|
static void
|
2000-01-11 23:48:00 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
2000-01-11 23:48:00 +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" },
|
|
|
|
{ GIMP_PDB_INT32, "type", "Type of motion blur (0 - linear, 1 - radial, 2 - zoom)" },
|
|
|
|
{ GIMP_PDB_INT32, "length", "Length" },
|
|
|
|
{ GIMP_PDB_INT32, "angle", "Angle" }
|
2000-05-02 01:01:18 +08:00
|
|
|
};
|
2000-01-01 00:39:04 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_NAME,
|
2000-03-08 21:53:54 +08:00
|
|
|
"Motion blur of image",
|
2000-05-02 01:01:18 +08:00
|
|
|
"This plug-in simulates the effect seen when "
|
|
|
|
"photographing a moving object at a slow shutter "
|
|
|
|
"speed. Done by adding multiple displaced copies.",
|
2000-01-11 23:48:00 +08:00
|
|
|
"Torsten Martinsen, Federico Mena Quintero and Daniel Skarda",
|
2000-03-08 21:53:54 +08:00
|
|
|
"Torsten Martinsen, Federico Mena Quintero and Daniel Skarda",
|
2000-01-11 23:48:00 +08:00
|
|
|
PLUG_IN_VERSION,
|
|
|
|
N_("<Image>/Filters/Blur/Motion Blur..."),
|
|
|
|
"RGB*, GRAY*",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (args), 0,
|
2000-05-02 01:01:18 +08:00
|
|
|
args, NULL);
|
2000-01-11 23:48:00 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2001-01-15 08:06:43 +08:00
|
|
|
run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2001-01-15 08:06:43 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 08:06:43 +08:00
|
|
|
static GimpParam values[1];
|
2001-12-29 21:26:29 +08:00
|
|
|
GimpRunMode run_mode;
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPDBStatusType status;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_SUCCESS;
|
1997-11-25 06:05:25 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Get the active drawable info */
|
|
|
|
|
2000-01-11 23:48:00 +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_bpp = gimp_drawable_bpp (drawable->drawable_id);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-15 04:07:38 +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
|
|
|
|
|
|
|
/* Calculate scaling parameters */
|
|
|
|
|
|
|
|
sel_width = sel_x2 - sel_x1;
|
|
|
|
sel_height = sel_y2 - sel_y1;
|
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
cen_x = (gdouble) (sel_x1 + sel_x2 - 1) / 2.0;
|
|
|
|
cen_y = (gdouble) (sel_y1 + sel_y2 - 1) / 2.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2000-01-11 23:48:00 +08:00
|
|
|
INIT_I18N_UI();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (PLUG_IN_NAME, &mbvals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Get information from the dialog */
|
|
|
|
if (!mblur_dialog())
|
|
|
|
return;
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2000-01-11 23:48:00 +08:00
|
|
|
INIT_I18N();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Make sure all the arguments are present */
|
|
|
|
if (nparams != 6)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2000-01-11 23:48:00 +08:00
|
|
|
{
|
|
|
|
mbvals.mblur_type = param[3].data.d_int32;
|
|
|
|
mbvals.length = param[4].data.d_int32;
|
|
|
|
mbvals.angle = param[5].data.d_int32;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((mbvals.mblur_type < 0) && (mbvals.mblur_type > MBLUR_ZOOM))
|
2000-08-22 09:26:57 +08:00
|
|
|
status= GIMP_PDB_CALLING_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-01-11 23:48:00 +08:00
|
|
|
INIT_I18N();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (PLUG_IN_NAME, &mbvals);
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Blur 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-11 23:48:00 +08:00
|
|
|
{
|
|
|
|
/* Set the tile cache size */
|
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->width +
|
|
|
|
gimp_tile_width () - 1) / gimp_tile_width ());
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Run! */
|
|
|
|
mblur ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* If run mode is interactive, flush displays */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_displays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
/* Store data */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_set_data (PLUG_IN_NAME, &mbvals, sizeof(mblur_vals_t));
|
|
|
|
}
|
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
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_linear (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 08:06:43 +08:00
|
|
|
GimpPixelRgn dest_rgn;
|
2002-11-21 06:58:52 +08:00
|
|
|
GimpPixelFetcher *pft;
|
2001-01-15 08:06:43 +08:00
|
|
|
gpointer pr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
guchar *dest;
|
|
|
|
guchar *d;
|
|
|
|
guchar pixel[4];
|
|
|
|
gint32 sum[4];
|
|
|
|
gint progress, max_progress;
|
|
|
|
gint c;
|
|
|
|
gint x, y, i, xx, yy, n;
|
|
|
|
gint dx, dy, px, py, swapdir, err, e, s1, s2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
pft = gimp_pixel_fetcher_new (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_set_bg_color (pft);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
progress = 0;
|
|
|
|
max_progress = sel_width * sel_height;
|
|
|
|
|
|
|
|
n = mbvals.length;
|
2001-10-23 18:09:17 +08:00
|
|
|
px = (gdouble) n * cos (mbvals.angle / 180.0 * G_PI);
|
|
|
|
py = (gdouble) n * sin (mbvals.angle / 180.0 * G_PI);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization for Bresenham algorithm:
|
|
|
|
* dx = abs(x2-x1), s1 = sign(x2-x1)
|
|
|
|
* dy = abs(y2-y1), s2 = sign(y2-y1)
|
|
|
|
*/
|
2000-01-11 23:48:00 +08:00
|
|
|
if ((dx = px) != 0)
|
|
|
|
{
|
|
|
|
if (dx < 0)
|
|
|
|
{
|
|
|
|
dx = -dx;
|
|
|
|
s1 = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
s1 = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-11 23:48:00 +08:00
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
s1 = 0;
|
2000-01-11 23:48:00 +08:00
|
|
|
|
|
|
|
if ((dy = py) != 0)
|
|
|
|
{
|
|
|
|
if (dy < 0)
|
|
|
|
{
|
|
|
|
dy = -dy;
|
|
|
|
s2 = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
s2 = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-11 23:48:00 +08:00
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
s2 = 0;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
if (dy > dx)
|
|
|
|
{
|
|
|
|
swapdir = dx;
|
|
|
|
dx = dy;
|
|
|
|
dy = swapdir;
|
|
|
|
swapdir = 1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
swapdir = 0;
|
|
|
|
|
|
|
|
dy *= 2;
|
|
|
|
err = dy - dx; /* Initial error term */
|
|
|
|
dx *= 2;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
|
|
|
{
|
|
|
|
dest = dest_rgn.data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++)
|
|
|
|
{
|
|
|
|
d = dest;
|
|
|
|
|
|
|
|
for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++)
|
|
|
|
{
|
|
|
|
xx = x; yy = y; e = err;
|
|
|
|
for (c= 0; c < img_bpp; c++)
|
|
|
|
sum[c]= 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; )
|
|
|
|
{
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, pixel);
|
2000-01-11 23:48:00 +08:00
|
|
|
for (c= 0; c < img_bpp; c++)
|
|
|
|
sum[c]+= pixel[c];
|
|
|
|
i++;
|
|
|
|
|
2001-10-23 18:09:17 +08:00
|
|
|
while (e >= 0 && dx)
|
2000-01-11 23:48:00 +08:00
|
|
|
{
|
|
|
|
if (swapdir)
|
|
|
|
xx += s1;
|
|
|
|
else
|
|
|
|
yy += s2;
|
|
|
|
e -= dx;
|
|
|
|
}
|
|
|
|
if (swapdir)
|
|
|
|
yy += s2;
|
|
|
|
else
|
|
|
|
xx += s1;
|
|
|
|
e += dy;
|
|
|
|
if ((xx < sel_x1) || (xx >= sel_x2) ||
|
|
|
|
(yy < sel_y1) || (yy >= sel_y2))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( i==0 )
|
|
|
|
{
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, d);
|
2000-01-11 23:48:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (c=0; c < img_bpp; c++)
|
|
|
|
d[c]= sum[c] / i;
|
|
|
|
}
|
|
|
|
d+= dest_rgn.bpp;
|
|
|
|
}
|
|
|
|
dest += dest_rgn.rowstride;
|
|
|
|
}
|
|
|
|
progress += dest_rgn.w * dest_rgn.h;
|
|
|
|
gimp_progress_update ((double) progress / max_progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_destroy (pft);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_radial (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn dest_rgn;
|
2002-11-21 06:58:52 +08:00
|
|
|
GimpPixelFetcher *pft;
|
1997-11-25 06:05:25 +08:00
|
|
|
gpointer pr;
|
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
guchar *dest;
|
|
|
|
guchar *d;
|
|
|
|
guchar pixel[4];
|
1997-11-25 06:05:25 +08:00
|
|
|
gint32 sum[4];
|
|
|
|
|
|
|
|
gint progress, max_progress, c;
|
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
gint x, y, i, n, xr, yr;
|
|
|
|
gint count, R, r, w, h, step;
|
|
|
|
gfloat angle, theta, * ct, * st, offset, xx, yy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
|
|
|
|
xx = 0.0;
|
|
|
|
yy = 0.0;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
pft = gimp_pixel_fetcher_new (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_set_bg_color (pft);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
progress = 0;
|
|
|
|
max_progress = sel_width * sel_height;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
angle = ((float) mbvals.angle) / 180.0 * G_PI;
|
|
|
|
w = MAX (img_width-cen_x, cen_x);
|
|
|
|
h = MAX (img_height-cen_y, cen_y);
|
|
|
|
R = sqrt (w * w + h * h);
|
|
|
|
n = 4 * angle * sqrt (R) + 2;
|
|
|
|
theta = angle / ((float) (n - 1));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-11 18:33:51 +08:00
|
|
|
ct = g_new (float, n);
|
|
|
|
st = g_new (float, n);
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
offset = theta * (n - 1) / 2;
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
ct[i] = cos (theta * i - offset);
|
|
|
|
st[i] = sin (theta * i - offset);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
|
|
|
{
|
|
|
|
dest = dest_rgn.data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++)
|
|
|
|
{
|
|
|
|
d = dest;
|
|
|
|
|
|
|
|
for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++)
|
|
|
|
{
|
|
|
|
xr = x-cen_x;
|
|
|
|
yr = y-cen_y;
|
|
|
|
r = sqrt (xr * xr + yr * yr);
|
|
|
|
if (r == 0)
|
|
|
|
step = 1;
|
|
|
|
else if ((step = R / r) == 0)
|
|
|
|
step = 1;
|
|
|
|
else if (step > n-1)
|
|
|
|
step = n-1;
|
|
|
|
|
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
sum[c] = 0;
|
|
|
|
|
|
|
|
for (i = 0, count = 0; i < n; i += step)
|
|
|
|
{
|
|
|
|
xx = cen_x + xr * ct[i] - yr * st[i];
|
|
|
|
yy = cen_y + xr * st[i] + yr * ct[i];
|
|
|
|
if ((yy < sel_y1) || (yy >= sel_y2) ||
|
|
|
|
(xx < sel_x1) || (xx >= sel_x2))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
++count;
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, pixel);
|
2000-01-11 23:48:00 +08:00
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
sum[c] += pixel[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
{
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, d);
|
2000-01-11 23:48:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
d[c]= sum[c] / count;
|
|
|
|
}
|
|
|
|
d += dest_rgn.bpp;
|
|
|
|
}
|
|
|
|
dest += dest_rgn.rowstride;
|
|
|
|
}
|
|
|
|
progress += dest_rgn.w * dest_rgn.h;
|
|
|
|
gimp_progress_update ((double) progress / max_progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_destroy (pft);
|
2000-01-11 23:48:00 +08:00
|
|
|
|
|
|
|
g_free (ct);
|
|
|
|
g_free (st);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_zoom (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn dest_rgn;
|
2002-11-21 06:58:52 +08:00
|
|
|
GimpPixelFetcher *pft;
|
1997-11-25 06:05:25 +08:00
|
|
|
gpointer pr;
|
|
|
|
|
|
|
|
guchar *dest, *d;
|
2001-01-15 08:06:43 +08:00
|
|
|
guchar pixel[4];
|
1997-11-25 06:05:25 +08:00
|
|
|
gint32 sum[4];
|
|
|
|
|
|
|
|
gint progress, max_progress;
|
|
|
|
int x, y, i, xx, yy, n, c;
|
|
|
|
float f;
|
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
|
|
|
|
xx = 0.0;
|
|
|
|
yy = 0.0;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
|
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
pft = gimp_pixel_fetcher_new (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_set_bg_color (pft);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
progress = 0;
|
|
|
|
max_progress = sel_width * sel_height;
|
|
|
|
|
|
|
|
n = mbvals.length;
|
|
|
|
f = 0.02;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
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
|
|
|
{
|
|
|
|
dest = dest_rgn.data;
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++)
|
|
|
|
{
|
|
|
|
d = dest;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-11 23:48:00 +08:00
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
sum[c] = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
xx = cen_x + (x-cen_x) * (1.0 + f * i);
|
|
|
|
yy = cen_y + (y-cen_y) * (1.0 + f * i);
|
|
|
|
|
|
|
|
if ((yy < sel_y1) || (yy >= sel_y2) ||
|
|
|
|
(xx < sel_x1) || (xx >= sel_x2))
|
|
|
|
break;
|
|
|
|
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, pixel);
|
2000-01-11 23:48:00 +08:00
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
sum[c] += pixel[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_get_pixel (pft, xx, yy, d);
|
2000-01-11 23:48:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (c = 0; c < img_bpp; c++)
|
|
|
|
d[c] = sum[c] / i;
|
|
|
|
}
|
|
|
|
d += dest_rgn.bpp;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-11 23:48:00 +08:00
|
|
|
dest += dest_rgn.rowstride;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
progress += dest_rgn.w * dest_rgn.h;
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_progress_update ((double) progress / max_progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-11-21 06:58:52 +08:00
|
|
|
gimp_pixel_fetcher_destroy (pft);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-11 23:48:00 +08:00
|
|
|
gimp_progress_init (_("Blurring..."));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (mbvals.mblur_type)
|
|
|
|
{
|
|
|
|
case MBLUR_LINEAR:
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_linear ();
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
case MBLUR_RADIAL:
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_radial ();
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
case MBLUR_ZOOM:
|
2000-01-11 23:48:00 +08:00
|
|
|
mblur_zoom ();
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
2000-01-11 23:48:00 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-01-11 23:48:00 +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,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************
|
|
|
|
* UI
|
|
|
|
****************************************/
|
|
|
|
|
1998-03-26 10:08:31 +08:00
|
|
|
static gboolean
|
2000-01-07 18:39:33 +08:00
|
|
|
mblur_dialog (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-07 18:39:33 +08:00
|
|
|
GtkWidget *dialog;
|
2000-02-01 04:47:44 +08:00
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *frame;
|
2000-01-11 23:48:00 +08:00
|
|
|
GtkWidget *table;
|
2000-01-07 18:39:33 +08:00
|
|
|
GtkObject *adjustment;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
gimp_ui_init ("mblur", FALSE);
|
2000-01-07 18:39:33 +08:00
|
|
|
|
|
|
|
dialog = gimp_dialog_new (_("Motion Blur"), "mblur",
|
2000-05-23 01:10:28 +08:00
|
|
|
gimp_standard_help_func, "filters/mblur.html",
|
2000-01-07 18:39:33 +08:00
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, TRUE, FALSE,
|
|
|
|
|
2001-08-04 03:52:08 +08:00
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
2000-01-07 18:39:33 +08:00
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
2001-11-29 21:23:44 +08:00
|
|
|
GTK_STOCK_OK, dialog_ok_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
NULL);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (dialog, "destroy",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gtk_main_quit),
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
frame = gimp_radio_group_new2 (TRUE, _("Blur Type"),
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&mbvals.mblur_type,
|
|
|
|
GINT_TO_POINTER (mbvals.mblur_type),
|
|
|
|
|
2002-05-11 18:33:51 +08:00
|
|
|
_("_Linear"),
|
2001-12-29 21:26:29 +08:00
|
|
|
GINT_TO_POINTER (MBLUR_LINEAR), NULL,
|
|
|
|
|
2002-05-11 18:33:51 +08:00
|
|
|
_("_Radial"),
|
2001-12-29 21:26:29 +08:00
|
|
|
GINT_TO_POINTER (MBLUR_RADIAL), NULL,
|
|
|
|
|
2002-05-11 18:33:51 +08:00
|
|
|
_("_Zoom"),
|
2001-12-29 21:26:29 +08:00
|
|
|
GINT_TO_POINTER (MBLUR_ZOOM), NULL,
|
2000-01-11 23:48:00 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (_("Blur Parameters"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
table = gtk_table_new (2, 3, FALSE);
|
2000-01-11 23:48:00 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2000-02-01 04:47:44 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
adjustment = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2002-09-07 04:44:47 +08:00
|
|
|
_("L_ength:"), 150, 3,
|
2000-01-18 01:02:26 +08:00
|
|
|
mbvals.length, 0.0, 256.0, 1.0, 8.0, 0,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-18 01:02:26 +08:00
|
|
|
NULL, NULL);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adjustment, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
&mbvals.length);
|
2000-01-11 23:48:00 +08:00
|
|
|
|
2000-01-18 01:02:26 +08:00
|
|
|
adjustment = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-09-07 04:44:47 +08:00
|
|
|
_("_Angle:"), 150, 3,
|
2000-01-18 01:02:26 +08:00
|
|
|
mbvals.angle, 0.0, 360.0, 1.0, 15.0, 0,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-18 01:02:26 +08:00
|
|
|
NULL, NULL);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adjustment, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
&mbvals.angle);
|
2000-01-11 23:48:00 +08:00
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
gdk_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return mb_run;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-07 18:39:33 +08:00
|
|
|
dialog_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
mb_run= TRUE;
|
|
|
|
|
2000-01-07 18:39:33 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|