1997-11-25 06:05:25 +08:00
|
|
|
/* Cubism --- image filter plug-in for The Gimp image manipulation program
|
|
|
|
* Copyright (C) 1996 Spencer Kimball, Tracy Scott
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* You can contact me at quartic@polloux.fciencias.unam.mx
|
|
|
|
* You can contact the original The Gimp authors at gimp@xcf.berkeley.edu
|
1998-10-12 12:33:20 +08:00
|
|
|
* Speedups by Elliot Lee
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-01-07 00:40:17 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-10-22 17:49:46 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
#define SCALE_WIDTH 125
|
|
|
|
#define BLACK 0
|
|
|
|
#define BG 1
|
2000-08-23 02:44:59 +08:00
|
|
|
#define SUPERSAMPLE 4
|
2000-01-13 23:39:26 +08:00
|
|
|
#define MAX_POINTS 4
|
|
|
|
#define MIN_ANGLE -36000
|
|
|
|
#define MAX_ANGLE 36000
|
|
|
|
#define RANDOMNESS 5
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2000-05-01 05:03:44 +08:00
|
|
|
gint npts;
|
|
|
|
GimpVector2 pts[MAX_POINTS];
|
1997-11-25 06:05:25 +08:00
|
|
|
} Polygon;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gdouble tile_size;
|
|
|
|
gdouble tile_saturation;
|
|
|
|
gint bg_color;
|
|
|
|
} CubismVals;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint run;
|
|
|
|
} CubismInterface;
|
|
|
|
|
|
|
|
/* Declare local functions.
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
static void cubism (GimpDrawable *drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 08:06:43 +08:00
|
|
|
static void fill_poly_color (Polygon *poly,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpDrawable *drawable,
|
2001-01-15 08:06:43 +08:00
|
|
|
guchar *col);
|
1997-11-25 06:05:25 +08:00
|
|
|
static void convert_segment (gint x1,
|
|
|
|
gint y1,
|
|
|
|
gint x2,
|
|
|
|
gint y2,
|
|
|
|
gint offset,
|
2000-05-01 05:03:44 +08:00
|
|
|
gint *min,
|
|
|
|
gint *max);
|
1997-11-25 06:05:25 +08:00
|
|
|
static void randomize_indices (gint count,
|
2000-05-01 05:03:44 +08:00
|
|
|
gint *indices);
|
|
|
|
static gdouble calc_alpha_blend (gdouble *vec,
|
1998-10-12 12:33:20 +08:00
|
|
|
gdouble one_over_dist,
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2000-05-01 05:03:44 +08:00
|
|
|
static void polygon_add_point (Polygon *poly,
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2000-05-01 05:03:44 +08:00
|
|
|
static void polygon_translate (Polygon *poly,
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble tx,
|
|
|
|
gdouble ty);
|
2000-05-01 05:03:44 +08:00
|
|
|
static void polygon_rotate (Polygon *poly,
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble theta);
|
2000-05-01 05:03:44 +08:00
|
|
|
static gint polygon_extents (Polygon *poly,
|
|
|
|
gdouble *min_x,
|
|
|
|
gdouble *min_y,
|
|
|
|
gdouble *max_x,
|
|
|
|
gdouble *max_y);
|
|
|
|
static void polygon_reset (Polygon *poly);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
static gint cubism_dialog (void);
|
2000-05-01 05:03:44 +08:00
|
|
|
static void cubism_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
static CubismVals cvals =
|
|
|
|
{
|
|
|
|
10.0, /* tile_size */
|
|
|
|
2.5, /* tile_saturation */
|
|
|
|
BLACK /* bg_color */
|
|
|
|
};
|
|
|
|
|
|
|
|
static CubismInterface cint =
|
|
|
|
{
|
|
|
|
FALSE /* run */
|
|
|
|
};
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-01 05:03:44 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
2000-01-16 23:38:38 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
1997-11-25 06:05:25 +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_FLOAT, "tile_size", "Average diameter of each tile (in pixels)" },
|
|
|
|
{ GIMP_PDB_FLOAT, "tile_saturation", "Expand tiles by this amount" },
|
|
|
|
{ GIMP_PDB_INT32, "bg_color", "Background color: { BLACK (0), BG (1) }" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
gimp_install_procedure ("plug_in_cubism",
|
2000-01-31 10:32:30 +08:00
|
|
|
"Convert the input drawable into a collection of rotated squares",
|
|
|
|
"Help not yet written for this plug-in",
|
1997-11-25 06:05:25 +08:00
|
|
|
"Spencer Kimball & Tracy Scott",
|
|
|
|
"Spencer Kimball & Tracy Scott",
|
|
|
|
"1996",
|
1999-11-24 04:29:20 +08:00
|
|
|
N_("<Image>/Filters/Artistic/Cubism..."),
|
1997-11-25 06:05:25 +08:00
|
|
|
"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-01 05:03:44 +08:00
|
|
|
args, NULL);
|
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
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpDrawable *active_drawable;
|
2001-12-19 08:13:16 +08:00
|
|
|
GimpRunMode run_mode;
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-29 03:23:22 +08:00
|
|
|
INIT_I18N_UI();
|
1999-05-30 00:35:47 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data ("plug_in_cubism", &cvals);
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
|
|
|
if (! cubism_dialog ())
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 6)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 08:06:43 +08:00
|
|
|
cvals.tile_size = param[3].data.d_float;
|
1997-11-25 06:05:25 +08:00
|
|
|
cvals.tile_saturation = param[4].data.d_float;
|
2001-01-15 08:06:43 +08:00
|
|
|
cvals.bg_color = param[5].data.d_int32;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS &&
|
1997-11-25 06:05:25 +08:00
|
|
|
(cvals.bg_color < BLACK || cvals.bg_color > BG))
|
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:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data ("plug_in_cubism", &cvals);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the active drawable */
|
|
|
|
active_drawable = gimp_drawable_get (param[2].data.d_drawable);
|
|
|
|
|
|
|
|
/* Render the cubism effect */
|
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 (active_drawable->drawable_id) ||
|
|
|
|
gimp_drawable_is_gray (active_drawable->drawable_id)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* set cache size */
|
|
|
|
gimp_tile_cache_ntiles (SQR (4 * cvals.tile_size * cvals.tile_saturation) / SQR (gimp_tile_width ()));
|
|
|
|
|
|
|
|
cubism (active_drawable);
|
|
|
|
|
|
|
|
/* If the run mode is interactive, flush the displays */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_displays_flush ();
|
|
|
|
|
|
|
|
/* Store mvals data */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_set_data ("plug_in_cubism", &cvals, sizeof (CubismVals));
|
|
|
|
}
|
2000-08-22 09:26:57 +08:00
|
|
|
else if (status == GIMP_PDB_SUCCESS)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* gimp_message ("cubism: cannot operate on indexed color images"); */
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
gimp_drawable_detach (active_drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2000-01-07 00:40:17 +08:00
|
|
|
cubism_dialog (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dlg;
|
|
|
|
GtkWidget *toggle;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkObject *scale_data;
|
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
gimp_ui_init ("cubism", FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-07 00:40:17 +08:00
|
|
|
dlg = gimp_dialog_new (_("Cubism"), "cubism",
|
2000-05-23 01:10:28 +08:00
|
|
|
gimp_standard_help_func, "filters/cubism.html",
|
2000-01-07 00:40:17 +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 00:40:17 +08:00
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
2001-11-29 21:23:44 +08:00
|
|
|
GTK_STOCK_OK, cubism_ok_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
2000-01-07 00:40:17 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (dlg, "destroy",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gtk_main_quit),
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* parameter settings */
|
1999-05-30 00:35:47 +08:00
|
|
|
frame = gtk_frame_new (_("Parameter Settings"));
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, TRUE, TRUE, 0);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
table = gtk_table_new (3, 3, FALSE);
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2000-01-16 23:38:38 +08:00
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 4);
|
2000-08-28 08:42:32 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 6);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
|
2002-06-09 00:18:25 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_Use Background Color"));
|
2000-01-16 23:38:38 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), toggle, 0, 3, 0, 1,
|
2000-01-13 23:39:26 +08:00
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&cvals.bg_color);
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
|
|
|
|
(cvals.bg_color == BG));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-09-07 04:44:47 +08:00
|
|
|
_("_Tile Size:"), SCALE_WIDTH, 5,
|
2000-01-16 23:38:38 +08:00
|
|
|
cvals.tile_size, 0.0, 100.0, 1.0, 10.0, 1,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-16 23:38:38 +08:00
|
|
|
NULL, NULL);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (scale_data, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&cvals.tile_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
scale_data =
|
|
|
|
gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
|
2002-09-07 04:44:47 +08:00
|
|
|
_("T_ile Saturation:"), SCALE_WIDTH, 5,
|
2000-01-16 23:38:38 +08:00
|
|
|
cvals.tile_saturation, 0.0, 10.0, 0.1, 1, 1,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-16 23:38:38 +08:00
|
|
|
NULL, NULL);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (scale_data, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&cvals.tile_saturation);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gtk_widget_show (table);
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
gdk_flush ();
|
|
|
|
|
|
|
|
return cint.run;
|
|
|
|
}
|
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
static void
|
|
|
|
cubism_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
cint.run = TRUE;
|
|
|
|
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2003-01-31 05:58:11 +08:00
|
|
|
cubism (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn src_rgn;
|
2003-01-31 05:58:11 +08:00
|
|
|
guchar bg_col[4];
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble x, y;
|
|
|
|
gdouble width, height;
|
|
|
|
gdouble theta;
|
|
|
|
gint ix, iy;
|
|
|
|
gint rows, cols;
|
|
|
|
gint i, j, count;
|
|
|
|
gint num_tiles;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
Polygon poly;
|
|
|
|
guchar col[4];
|
|
|
|
guchar *dest;
|
|
|
|
gint bytes;
|
|
|
|
gint has_alpha;
|
|
|
|
gint *random_indices;
|
|
|
|
gpointer pr;
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
GRand *gr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
gr = g_rand_new();
|
2001-06-15 04:07:38 +08:00
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
1997-11-25 06:05:25 +08:00
|
|
|
bytes = drawable->bpp;
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
2003-01-31 05:58:11 +08:00
|
|
|
|
|
|
|
/* determine the background color */
|
|
|
|
if (cvals.bg_color == BLACK)
|
|
|
|
{
|
|
|
|
bg_col[0] = bg_col[1] = bg_col[2] = bg_col[3] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_get_bg_guchar (drawable, TRUE, bg_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_progress_init (_("Cubistic Transformation"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
cols = ((x2 - x1) + cvals.tile_size - 1) / cvals.tile_size;
|
|
|
|
rows = ((y2 - y1) + cvals.tile_size - 1) / cvals.tile_size;
|
|
|
|
|
|
|
|
/* Fill the image with the background color */
|
2000-01-13 23:39:26 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
|
|
|
|
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
count = src_rgn.w * src_rgn.h;
|
|
|
|
dest = src_rgn.data;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
*dest++ = bg_col[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
num_tiles = (rows + 1) * (cols + 1);
|
2000-05-01 05:03:44 +08:00
|
|
|
random_indices = g_new (gint, num_tiles);
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i < num_tiles; i++)
|
|
|
|
random_indices[i] = i;
|
|
|
|
|
|
|
|
randomize_indices (num_tiles, random_indices);
|
|
|
|
|
|
|
|
count = 0;
|
2000-01-13 23:39:26 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
2003-01-31 05:58:11 +08:00
|
|
|
x1, y1, x2 - x1, y2 - y1, FALSE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
while (count < num_tiles)
|
|
|
|
{
|
|
|
|
i = random_indices[count] / (cols + 1);
|
|
|
|
j = random_indices[count] % (cols + 1);
|
2001-01-15 08:06:43 +08:00
|
|
|
x = j * cvals.tile_size + (cvals.tile_size / 4.0)
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
- g_rand_double_range (gr, 0, cvals.tile_size/2.0) + x1;
|
2001-01-15 08:06:43 +08:00
|
|
|
y = i * cvals.tile_size + (cvals.tile_size / 4.0)
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
- g_rand_double_range (gr, 0, cvals.tile_size/2.0) + y1;
|
2003-01-31 05:58:11 +08:00
|
|
|
width = (cvals.tile_size +
|
|
|
|
g_rand_double_range (gr, 0, cvals.tile_size / 4.0) -
|
|
|
|
cvals.tile_size / 8.0) * cvals.tile_saturation;
|
|
|
|
height = (cvals.tile_size +
|
|
|
|
g_rand_double_range (gr, 0, cvals.tile_size / 4.0) -
|
|
|
|
cvals.tile_size / 8.0) * cvals.tile_saturation;
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
theta = g_rand_double_range (gr, 0, 2 * G_PI);
|
1997-11-25 06:05:25 +08:00
|
|
|
polygon_reset (&poly);
|
|
|
|
polygon_add_point (&poly, -width / 2.0, -height / 2.0);
|
|
|
|
polygon_add_point (&poly, width / 2.0, -height / 2.0);
|
|
|
|
polygon_add_point (&poly, width / 2.0, height / 2.0);
|
|
|
|
polygon_add_point (&poly, -width / 2.0, height / 2.0);
|
|
|
|
polygon_rotate (&poly, theta);
|
|
|
|
polygon_translate (&poly, x, y);
|
|
|
|
|
|
|
|
/* bounds check on x, y */
|
2003-01-31 05:58:11 +08:00
|
|
|
ix = CLAMP (x, x1, x2 - 1);
|
|
|
|
iy = CLAMP (y, y1, y2 - 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gimp_pixel_rgn_get_pixel (&src_rgn, col, ix, iy);
|
|
|
|
|
2003-01-31 05:58:11 +08:00
|
|
|
if (!has_alpha || col[bytes - 1])
|
1997-11-25 06:05:25 +08:00
|
|
|
fill_poly_color (&poly, drawable, col);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if ((count % 5) == 0)
|
|
|
|
gimp_progress_update ((double) count / (double) num_tiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
2000-05-01 05:03:44 +08:00
|
|
|
g_free (random_indices);
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
g_rand_free (gr);
|
2003-01-31 05:58:11 +08:00
|
|
|
|
|
|
|
/* merge the shadow, update the drawable */
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
|
|
|
gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-10-22 17:49:46 +08:00
|
|
|
static inline gdouble
|
1998-10-12 12:33:20 +08:00
|
|
|
calc_alpha_blend (gdouble *vec,
|
|
|
|
gdouble one_over_dist,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
gdouble r;
|
|
|
|
|
|
|
|
if (!one_over_dist)
|
|
|
|
return 1.0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = (vec[0] * x + vec[1] * y) * one_over_dist;
|
|
|
|
if (r < 0.2)
|
|
|
|
r = 0.2;
|
|
|
|
else if (r > 1.0)
|
|
|
|
r = 1.0;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
|
|
|
fill_poly_color (Polygon *poly,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpDrawable *drawable,
|
1997-11-25 06:05:25 +08:00
|
|
|
guchar *col)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn src_rgn;
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble dmin_x, dmin_y;
|
|
|
|
gdouble dmax_x, dmax_y;
|
|
|
|
gint xs, ys;
|
|
|
|
gint xe, ye;
|
|
|
|
gint min_x, min_y;
|
|
|
|
gint max_x, max_y;
|
|
|
|
gint size_x, size_y;
|
1998-10-22 17:49:46 +08:00
|
|
|
gint * max_scanlines, *max_scanlines_iter;
|
|
|
|
gint * min_scanlines, *min_scanlines_iter;
|
1997-11-25 06:05:25 +08:00
|
|
|
gint val;
|
|
|
|
gint alpha;
|
|
|
|
gint bytes;
|
|
|
|
guchar buf[4];
|
1998-10-12 12:33:20 +08:00
|
|
|
gint i, j, x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
gdouble sx, sy;
|
|
|
|
gdouble ex, ey;
|
|
|
|
gdouble xx, yy;
|
|
|
|
gdouble vec[2];
|
1998-10-12 12:33:20 +08:00
|
|
|
gdouble dist, one_over_dist;
|
1997-11-25 06:05:25 +08:00
|
|
|
gint x1, y1, x2, y2;
|
1998-10-12 12:33:20 +08:00
|
|
|
gint *vals, *vals_iter, *vals_end;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
sx = poly->pts[0].x;
|
|
|
|
sy = poly->pts[0].y;
|
|
|
|
ex = poly->pts[1].x;
|
|
|
|
ey = poly->pts[1].y;
|
|
|
|
|
|
|
|
dist = sqrt (SQR (ex - sx) + SQR (ey - sy));
|
|
|
|
if (dist > 0.0)
|
|
|
|
{
|
1998-10-12 12:33:20 +08:00
|
|
|
one_over_dist = 1/dist;
|
|
|
|
vec[0] = (ex - sx) * one_over_dist;
|
|
|
|
vec[1] = (ey - sy) * one_over_dist;
|
2000-01-13 23:39:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
one_over_dist = 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
bytes = drawable->bpp;
|
|
|
|
|
|
|
|
polygon_extents (poly, &dmin_x, &dmin_y, &dmax_x, &dmax_y);
|
|
|
|
min_x = (gint) dmin_x;
|
|
|
|
min_y = (gint) dmin_y;
|
|
|
|
max_x = (gint) dmax_x;
|
|
|
|
max_y = (gint) dmax_y;
|
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
size_y = (max_y - min_y) * SUPERSAMPLE;
|
|
|
|
size_x = (max_x - min_x) * SUPERSAMPLE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
min_scanlines = min_scanlines_iter = g_new (gint, size_y);
|
|
|
|
max_scanlines = max_scanlines_iter = g_new (gint, size_y);
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i < size_y; i++)
|
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
min_scanlines[i] = max_x * SUPERSAMPLE;
|
|
|
|
max_scanlines[i] = min_x * SUPERSAMPLE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-10-12 12:33:20 +08:00
|
|
|
if(poly->npts) {
|
|
|
|
gint poly_npts = poly->npts;
|
2000-05-01 05:03:44 +08:00
|
|
|
GimpVector2 *curptr;
|
1998-10-12 12:33:20 +08:00
|
|
|
|
|
|
|
xs = (gint) (poly->pts[poly_npts-1].x);
|
|
|
|
ys = (gint) (poly->pts[poly_npts-1].y);
|
|
|
|
xe = (gint) poly->pts[0].x;
|
|
|
|
ye = (gint) poly->pts[0].y;
|
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
xs *= SUPERSAMPLE;
|
|
|
|
ys *= SUPERSAMPLE;
|
|
|
|
xe *= SUPERSAMPLE;
|
|
|
|
ye *= SUPERSAMPLE;
|
1998-10-12 12:33:20 +08:00
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
convert_segment (xs, ys, xe, ye, min_y * SUPERSAMPLE,
|
1998-10-12 12:33:20 +08:00
|
|
|
min_scanlines, max_scanlines);
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
for (i = 1, curptr = &poly->pts[0]; i < poly_npts; i++)
|
|
|
|
{
|
|
|
|
xs = (gint) curptr->x;
|
|
|
|
ys = (gint) curptr->y;
|
|
|
|
curptr++;
|
|
|
|
xe = (gint) curptr->x;
|
|
|
|
ye = (gint) curptr->y;
|
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
xs *= SUPERSAMPLE;
|
|
|
|
ys *= SUPERSAMPLE;
|
|
|
|
xe *= SUPERSAMPLE;
|
|
|
|
ye *= SUPERSAMPLE;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
convert_segment (xs, ys, xe, ye, min_y * SUPERSAMPLE,
|
2000-01-13 23:39:26 +08:00
|
|
|
min_scanlines, max_scanlines);
|
|
|
|
}
|
1998-10-12 12:33:20 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable, 0, 0,
|
2000-01-13 23:39:26 +08:00
|
|
|
drawable->width, drawable->height, TRUE, TRUE);
|
|
|
|
|
|
|
|
vals = g_new (gint, size_x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-10-12 12:33:20 +08:00
|
|
|
for (i = 0; i < size_y; i++, min_scanlines_iter++, max_scanlines_iter++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
if (! (i % SUPERSAMPLE))
|
2000-01-13 23:39:26 +08:00
|
|
|
{
|
|
|
|
memset (vals, 0, sizeof (gint) * size_x);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
yy = (gdouble)i / (gdouble)SUPERSAMPLE + min_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-10-12 12:33:20 +08:00
|
|
|
for (j = *min_scanlines_iter; j < *max_scanlines_iter; j++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
x = j - min_x * SUPERSAMPLE;
|
1997-11-25 06:05:25 +08:00
|
|
|
vals[x] += 255;
|
|
|
|
}
|
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
if (! ((i + 1) % SUPERSAMPLE))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
y = (i / SUPERSAMPLE) + min_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (y >= y1 && y < y2)
|
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
for (j = 0; j < size_x; j += SUPERSAMPLE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
x = (j / SUPERSAMPLE) + min_x;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (x >= x1 && x < x2)
|
|
|
|
{
|
1998-10-12 12:33:20 +08:00
|
|
|
for (val = 0, vals_iter = &vals[j],
|
2000-08-23 02:44:59 +08:00
|
|
|
vals_end = &vals_iter[SUPERSAMPLE];
|
1998-10-12 12:33:20 +08:00
|
|
|
vals_iter < vals_end;
|
|
|
|
vals_iter++)
|
|
|
|
val += *vals_iter;
|
|
|
|
|
2000-08-23 02:44:59 +08:00
|
|
|
val /= SQR(SUPERSAMPLE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (val > 0)
|
|
|
|
{
|
2000-08-23 02:44:59 +08:00
|
|
|
xx = (gdouble) j / (gdouble) SUPERSAMPLE + min_x;
|
1998-10-12 12:33:20 +08:00
|
|
|
alpha = (gint) (val * calc_alpha_blend (vec, one_over_dist, xx - sx, yy - sy));
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_pixel_rgn_get_pixel (&src_rgn, buf, x, y);
|
|
|
|
|
1998-10-12 12:33:20 +08:00
|
|
|
#ifndef USE_READABLE_BUT_SLOW_CODE
|
|
|
|
{
|
|
|
|
guchar *buf_iter = buf,
|
|
|
|
*col_iter = col,
|
|
|
|
*buf_end = buf+bytes;
|
|
|
|
|
|
|
|
for(; buf_iter < buf_end; buf_iter++, col_iter++)
|
|
|
|
*buf_iter = ((guint)(*col_iter * alpha)
|
|
|
|
+ (((guint)*buf_iter)
|
|
|
|
* (256 - alpha))) >> 8;
|
|
|
|
}
|
|
|
|
#else /* original, pre-ECL code */
|
1997-11-25 06:05:25 +08:00
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
buf[b] = ((col[b] * alpha) + (buf[b] * (255 - alpha))) / 255;
|
|
|
|
|
1998-10-12 12:33:20 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_pixel_rgn_set_pixel (&src_rgn, buf, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
g_free (vals);
|
|
|
|
g_free (min_scanlines);
|
|
|
|
g_free (max_scanlines);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
convert_segment (gint x1,
|
|
|
|
gint y1,
|
|
|
|
gint x2,
|
|
|
|
gint y2,
|
|
|
|
gint offset,
|
|
|
|
gint *min,
|
|
|
|
gint *max)
|
|
|
|
{
|
|
|
|
gint ydiff, y, tmp;
|
|
|
|
gdouble xinc, xstart;
|
|
|
|
|
|
|
|
if (y1 > y2)
|
2000-01-13 23:39:26 +08:00
|
|
|
{
|
|
|
|
tmp = y2; y2 = y1; y1 = tmp;
|
|
|
|
tmp = x2; x2 = x1; x1 = tmp;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
ydiff = (y2 - y1);
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
if (ydiff)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
xinc = (gdouble) (x2 - x1) / (gdouble) ydiff;
|
|
|
|
xstart = x1 + 0.5 * xinc;
|
|
|
|
for (y = y1 ; y < y2; y++)
|
|
|
|
{
|
|
|
|
if (xstart < min[y - offset])
|
|
|
|
min[y-offset] = xstart;
|
|
|
|
if (xstart > max[y - offset])
|
|
|
|
max[y-offset] = xstart;
|
|
|
|
|
|
|
|
xstart += xinc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
randomize_indices (gint count,
|
|
|
|
gint *indices)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gint index1, index2;
|
|
|
|
gint tmp;
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
GRand *gr;
|
|
|
|
|
|
|
|
gr = g_rand_new();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count * RANDOMNESS; i++)
|
|
|
|
{
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
index1 = g_rand_int_range (gr, 0, count);
|
|
|
|
index2 = g_rand_int_range (gr, 0, count);
|
1997-11-25 06:05:25 +08:00
|
|
|
tmp = indices[index1];
|
|
|
|
indices[index1] = indices[index2];
|
|
|
|
indices[index2] = tmp;
|
|
|
|
}
|
|
|
|
|
configure.in app/core/gimpbrushpipe.c app/gui/about-dialog.c
2002-11-20 Dave Neary <bolsh@gimp.org>
* configure.in
* app/core/gimpbrushpipe.c
* app/gui/about-dialog.c
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.c
* libgimpmath/gimpmath.h
* libgimpwidgets/gimpwidgets.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/blur.c
* plug-ins/common/cubism.c
* plug-ins/common/gee.c
* plug-ins/common/gee_zoom.c
* plug-ins/common/gqbist.c
* plug-ins/common/jigsaw.c
* plug-ins/common/lic.c
* plug-ins/common/noisify.c
* plug-ins/common/nova.c
* plug-ins/common/papertile.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sample_colorize.c
* plug-ins/common/scatter_hsv.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/smooth_palette.c
* plug-ins/common/snoise.c
* plug-ins/common/sparkle.c
* plug-ins/common/spheredesigner.c
* plug-ins/common/spread.c
* plug-ins/common/warp.c
* plug-ins/common/wind.c
* plug-ins/flame/cmap.c
* plug-ins/flame/flame.c
* plug-ins/flame/libifs.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/gimpressionist/gimpressionist.h
* plug-ins/gimpressionist/plasma.c
* plug-ins/gimpressionist/repaint.c
* plug-ins/ifscompose/ifscompose_utils.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/mosaic/mosaic.c: Change all occurrences of RAND_MAX,
G_MAXRAND, rand(), srand(), lrand48(), srand48(), random(),
srandom(), RAND_FUNC and SRAND_FUNC to the appropriate g_rand*
equivalent. Programs which require seed setting for reproducible
results, and anything in the core, gets a dedicated GRand * for
the lifetime required. Programs which only ever used random
numbers for tossing a coin, rolling a dice, etc use g_random
functions. For the rest, judgement was used. Where it was easy, a
GRand * object was used and g_rand_* functions were
preferred. This fixes bug #67386 in HEAD.
2002-11-20 17:27:48 +08:00
|
|
|
g_rand_free (gr);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
polygon_add_point (Polygon *poly,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
if (poly->npts < 12)
|
|
|
|
{
|
|
|
|
poly->pts[poly->npts].x = x;
|
|
|
|
poly->pts[poly->npts].y = y;
|
|
|
|
poly->npts++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_print ("Unable to add additional point.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
polygon_rotate (Polygon *poly,
|
|
|
|
gdouble theta)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gdouble ct, st;
|
|
|
|
gdouble ox, oy;
|
|
|
|
|
|
|
|
ct = cos (theta);
|
|
|
|
st = sin (theta);
|
|
|
|
|
|
|
|
for (i = 0; i < poly->npts; i++)
|
|
|
|
{
|
|
|
|
ox = poly->pts[i].x;
|
|
|
|
oy = poly->pts[i].y;
|
|
|
|
poly->pts[i].x = ct * ox - st * oy;
|
|
|
|
poly->pts[i].y = st * ox + ct * oy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
polygon_translate (Polygon *poly,
|
|
|
|
gdouble tx,
|
|
|
|
gdouble ty)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < poly->npts; i++)
|
|
|
|
{
|
|
|
|
poly->pts[i].x += tx;
|
|
|
|
poly->pts[i].y += ty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
polygon_extents (Polygon *poly,
|
|
|
|
gdouble *x1,
|
|
|
|
gdouble *y1,
|
|
|
|
gdouble *x2,
|
|
|
|
gdouble *y2)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (!poly->npts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*x1 = *x2 = poly->pts[0].x;
|
|
|
|
*y1 = *y2 = poly->pts[0].y;
|
|
|
|
|
|
|
|
for (i = 1; i < poly->npts; i++)
|
|
|
|
{
|
|
|
|
if (poly->pts[i].x < *x1)
|
|
|
|
*x1 = poly->pts[i].x;
|
|
|
|
if (poly->pts[i].x > *x2)
|
|
|
|
*x2 = poly->pts[i].x;
|
|
|
|
if (poly->pts[i].y < *y1)
|
|
|
|
*y1 = poly->pts[i].y;
|
|
|
|
if (poly->pts[i].y > *y2)
|
|
|
|
*y2 = poly->pts[i].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
polygon_reset (Polygon *poly)
|
|
|
|
{
|
|
|
|
poly->npts = 0;
|
|
|
|
}
|