1997-12-09 13:57:33 +08:00
|
|
|
/*
|
2007-06-06 16:44:52 +08:00
|
|
|
* This is the Glass Tile plug-in for GIMP 1.2
|
2000-05-23 03:40:06 +08:00
|
|
|
* Version 1.02
|
1997-12-09 13:57:33 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Karl-Johan Andersson (t96kja@student.tdb.uu.se)
|
|
|
|
*
|
|
|
|
* 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-12-09 13:57:33 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This filter divide the image into square "glass"-blocks in which
|
2003-11-06 23:27:05 +08:00
|
|
|
* the image is refracted.
|
|
|
|
*
|
1997-12-09 13:57:33 +08:00
|
|
|
* The alpha-channel is left unchanged.
|
2003-11-06 23:27:05 +08:00
|
|
|
*
|
1997-12-09 13:57:33 +08:00
|
|
|
* Please send any comments or suggestions to
|
|
|
|
* Karl-Johan Andersson (t96kja@student.tdb.uu.se)
|
2000-05-23 03:40:06 +08:00
|
|
|
*
|
|
|
|
* May 2000 - tim copperfield [timecop@japan.co.jp]
|
|
|
|
* Added preview mode.
|
|
|
|
* Noticed there is an issue with the algorithm if odd number of rows or
|
|
|
|
* columns is requested. Dunno why. I am not a graphics expert :(
|
2003-11-06 23:27:05 +08:00
|
|
|
*
|
|
|
|
* May 2000 alt@gimp.org Made preview work and removed some boundary
|
2000-05-26 07:28:20 +08:00
|
|
|
* conditions that caused "streaks" to appear when using some tile spaces.
|
2003-11-06 23:27:05 +08:00
|
|
|
*/
|
1997-12-09 13:57:33 +08:00
|
|
|
|
1999-12-26 05:49:51 +08:00
|
|
|
#include "config.h"
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2000-10-01 04:13:06 +08:00
|
|
|
#include <string.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
1999-12-26 05:49:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
|
|
|
|
#define PLUG_IN_PROC "plug-in-glasstile"
|
|
|
|
#define PLUG_IN_BINARY "glasstile"
|
|
|
|
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* --- Typedefs --- */
|
2000-01-16 23:38:38 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2004-10-17 22:37:45 +08:00
|
|
|
gint xblock;
|
|
|
|
gint yblock;
|
2004-10-30 07:05:24 +08:00
|
|
|
/* interface only */
|
|
|
|
gint constrain;
|
1997-12-09 13:57:33 +08:00
|
|
|
} GlassValues;
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2004-10-30 07:05:24 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GlassValues *gval;
|
|
|
|
GtkObject *xadj;
|
|
|
|
GtkObject *yadj;
|
|
|
|
} GlassChainedValues;
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* --- Declare local functions --- */
|
2004-10-30 07:05:24 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
|
|
|
static gboolean glasstile_dialog (GimpDrawable *drawable);
|
|
|
|
|
|
|
|
static void glasstile_size_changed (GtkObject *adj,
|
|
|
|
gpointer data);
|
|
|
|
static void glasstile_chain_toggled (GtkWidget *widget,
|
|
|
|
gboolean *value);
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2004-10-30 07:05:24 +08:00
|
|
|
static void glasstile (GimpDrawable *drawable,
|
|
|
|
GimpPreview *preview);
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* --- Variables --- */
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
static GlassValues gtvals =
|
|
|
|
{
|
2004-10-17 22:37:45 +08:00
|
|
|
20, /* tile width */
|
|
|
|
20, /* tile height */
|
2004-10-30 07:05:24 +08:00
|
|
|
/* interface only */
|
|
|
|
TRUE /* constrained */
|
1997-12-09 13:57:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --- Functions --- */
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
query (void)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef args[] =
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2005-08-14 06:52:41 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
|
2004-05-07 21:15:52 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
|
|
|
{ GIMP_PDB_INT32, "tilex", "Tile width (10 - 50)" },
|
|
|
|
{ GIMP_PDB_INT32, "tiley", "Tile height (10 - 50)" }
|
1997-12-09 13:57:33 +08:00
|
|
|
};
|
1999-12-26 05:49:51 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-17 17:29:48 +08:00
|
|
|
N_("Simulate distortion caused by square glass tiles"),
|
2003-12-11 06:50:26 +08:00
|
|
|
"Divide the image into square glassblocks in "
|
2002-02-21 22:50:24 +08:00
|
|
|
"which the image is refracted.",
|
2003-12-11 06:50:26 +08:00
|
|
|
"Karl-Johan Andersson", /* Author */
|
|
|
|
"Karl-Johan Andersson", /* Copyright */
|
|
|
|
"May 2000",
|
2004-05-07 21:15:52 +08:00
|
|
|
N_("_Glass Tile..."),
|
2003-12-11 06:50:26 +08:00
|
|
|
"RGB*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 21:15:52 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC,
|
2005-06-24 08:43:39 +08:00
|
|
|
"<Image>/Filters/Light and Shadow/Glass");
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
2003-07-02 19:07:41 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2001-12-29 21:26:29 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2004-10-17 22:37:45 +08:00
|
|
|
GimpDrawable *drawable;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
*nreturn_vals = 1;
|
2001-12-29 21:26:29 +08:00
|
|
|
*return_vals = values;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-12-09 13:57:33 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
/* Get the specified drawable */
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
2004-12-24 07:58:35 +08:00
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->ntile_cols));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, >vals);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* First acquire information with a dialog */
|
2004-10-17 22:37:45 +08:00
|
|
|
if (! glasstile_dialog (drawable))
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
return;
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
break;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 5)
|
2003-12-11 06:50:26 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
gtvals.xblock = (gint) param[3].data.d_int32;
|
|
|
|
gtvals.yblock = (gint) param[4].data.d_int32;
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
if (gtvals.xblock < 10 || gtvals.xblock > 50)
|
2003-12-11 06:50:26 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2003-11-06 23:27:05 +08:00
|
|
|
if (gtvals.yblock < 10 || gtvals.yblock > 50)
|
2003-12-11 06:50:26 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1997-12-09 13:57:33 +08:00
|
|
|
break;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Possibly retrieve data */
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, >vals);
|
1997-12-09 13:57:33 +08:00
|
|
|
break;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
/* Make sure that the drawable is gray or RGB color */
|
2001-06-15 04:07:38 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
2003-12-11 06:50:26 +08:00
|
|
|
gimp_drawable_is_gray (drawable->drawable_id))
|
|
|
|
{
|
2005-09-30 16:16:10 +08:00
|
|
|
gimp_progress_init (_("Glass Tile"));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-11-14 10:50:33 +08:00
|
|
|
glasstile (drawable, NULL);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-12-11 06:50:26 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
|
|
|
/* Store data */
|
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
{
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_set_data (PLUG_IN_PROC, >vals, sizeof (GlassValues));
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
2003-12-11 06:50:26 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
else
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
values[0].data.d_status = status;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
2004-05-19 23:28:01 +08:00
|
|
|
static gboolean
|
2004-10-17 22:37:45 +08:00
|
|
|
glasstile_dialog (GimpDrawable *drawable)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2004-10-30 07:05:24 +08:00
|
|
|
GlassChainedValues *gv;
|
2004-10-17 22:37:45 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *preview;
|
1997-12-09 13:57:33 +08:00
|
|
|
GtkWidget *table;
|
2004-10-30 07:05:24 +08:00
|
|
|
GtkWidget *chainbutton;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2004-10-30 07:05:24 +08:00
|
|
|
gv = g_new (GlassChainedValues, 1);
|
|
|
|
gv->gval = >vals;
|
|
|
|
gtvals.constrain = TRUE;
|
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, TRUE);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2005-08-14 06:52:41 +08:00
|
|
|
dialog = gimp_dialog_new (_("Glass Tile"), PLUG_IN_BINARY,
|
2004-10-17 22:37:45 +08:00
|
|
|
NULL, 0,
|
2005-08-14 06:52:41 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2004-10-17 22:37:45 +08:00
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-08-14 06:52:41 +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-17 22:37:45 +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);
|
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
preview = gimp_drawable_preview_new (drawable, NULL);
|
2004-10-17 22:37:45 +08:00
|
|
|
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
|
2004-08-07 04:52:44 +08:00
|
|
|
gtk_widget_show (preview);
|
2004-10-17 22:37:45 +08:00
|
|
|
g_signal_connect_swapped (preview, "invalidated",
|
|
|
|
G_CALLBACK (glasstile),
|
|
|
|
drawable);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-12-11 05:13:29 +08:00
|
|
|
/* Parameter settings */
|
2004-10-30 07:05:24 +08:00
|
|
|
table = gtk_table_new (2, 4, FALSE);
|
2004-05-19 01:06:06 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2004-10-30 07:05:24 +08:00
|
|
|
gtk_table_set_col_spacing (GTK_TABLE (table), 2, 2);
|
2004-10-17 22:37:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
2003-12-11 05:13:29 +08:00
|
|
|
gtk_widget_show (table);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* Horizontal scale - Width */
|
2004-10-30 07:05:24 +08:00
|
|
|
gv->xadj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Tile _width:"), 150, 0,
|
|
|
|
gtvals.xblock, 10, 50, 2, 10, 0,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (gv->xadj, "value-changed",
|
2004-10-30 07:05:24 +08:00
|
|
|
G_CALLBACK (glasstile_size_changed),
|
|
|
|
gv);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (gv->xadj, "value-changed",
|
2004-10-17 22:37:45 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* Horizontal scale - Height */
|
2004-10-30 07:05:24 +08:00
|
|
|
gv->yadj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
|
|
|
_("Tile _height:"), 150, 0,
|
|
|
|
gtvals.yblock, 10, 50, 2, 10, 0,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (gv->yadj, "value-changed",
|
2004-10-30 07:05:24 +08:00
|
|
|
G_CALLBACK (glasstile_size_changed),
|
|
|
|
gv);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect_swapped (gv->yadj, "value-changed",
|
2004-10-17 22:37:45 +08:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2004-10-30 07:05:24 +08:00
|
|
|
chainbutton = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
|
|
|
|
gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton),
|
|
|
|
gtvals.constrain);
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE(table), chainbutton, 3, 4, 0, 2);
|
2004-11-17 10:55:29 +08:00
|
|
|
g_signal_connect (chainbutton, "toggled",
|
2004-10-30 07:05:24 +08:00
|
|
|
G_CALLBACK (glasstile_chain_toggled),
|
|
|
|
>vals.constrain);
|
|
|
|
gtk_widget_show (chainbutton);
|
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
gtk_widget_show (dialog);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
2004-08-07 04:52:44 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
2004-10-30 07:05:24 +08:00
|
|
|
static void
|
|
|
|
glasstile_size_changed (GtkObject *adj,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GlassChainedValues *gv = data;
|
|
|
|
|
|
|
|
if (adj == gv->xadj)
|
|
|
|
{
|
|
|
|
gimp_int_adjustment_update(GTK_ADJUSTMENT (gv->xadj), &gv->gval->xblock);
|
|
|
|
if (gv->gval->constrain)
|
|
|
|
gtk_adjustment_set_value(GTK_ADJUSTMENT (gv->yadj),
|
|
|
|
(gdouble) gv->gval->xblock);
|
|
|
|
}
|
|
|
|
else if (adj == gv->yadj)
|
|
|
|
{
|
|
|
|
gimp_int_adjustment_update(GTK_ADJUSTMENT (gv->yadj), &gv->gval->yblock);
|
|
|
|
if (gv->gval->constrain)
|
|
|
|
gtk_adjustment_set_value(GTK_ADJUSTMENT (gv->xadj),
|
|
|
|
(gdouble) gv->gval->yblock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
glasstile_chain_toggled (GtkWidget *widget,
|
|
|
|
gboolean *value)
|
|
|
|
{
|
|
|
|
*value = gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (widget));
|
|
|
|
}
|
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
/* - Filter function - I wish all filter functions had a pmode :) */
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
glasstile (GimpDrawable *drawable,
|
2004-10-17 22:37:45 +08:00
|
|
|
GimpPreview *preview)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2004-10-17 22:37:45 +08:00
|
|
|
GimpPixelRgn srcPR, destPR;
|
|
|
|
gint width, height;
|
|
|
|
gint bytes;
|
|
|
|
guchar *dest, *d;
|
|
|
|
guchar *cur_row;
|
|
|
|
gint row, col, i;
|
|
|
|
gint x1, y1, x2, y2;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2003-10-13 03:55:43 +08:00
|
|
|
/* Translations of variable names from Maswan
|
|
|
|
* rutbredd = grid width
|
|
|
|
* ruthojd = grid height
|
|
|
|
* ymitt = y middle
|
|
|
|
* xmitt = x middle
|
|
|
|
*/
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
gint rutbredd, xpixel1, xpixel2;
|
|
|
|
gint ruthojd , ypixel2;
|
|
|
|
gint xhalv, xoffs, xmitt, xplus;
|
2000-05-26 07:28:20 +08:00
|
|
|
gint yhalv, yoffs, ymitt, yplus;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
if (preview)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
2004-10-17 22:37:45 +08:00
|
|
|
gimp_preview_get_position (preview, &x1, &y1);
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
|
|
|
x2 = x1 + width;
|
|
|
|
y2 = y1 + height;
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|
|
|
|
else
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
2004-10-17 22:37:45 +08:00
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
2004-10-17 22:37:45 +08:00
|
|
|
bytes = drawable->bpp;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
cur_row = g_new (guchar, width * bytes);
|
|
|
|
dest = g_new (guchar, width * bytes);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2003-10-13 03:55:43 +08:00
|
|
|
/* initialize the pixel regions, set grid height/width */
|
2004-10-17 22:37:45 +08:00
|
|
|
gimp_pixel_rgn_init (&srcPR, drawable,
|
|
|
|
x1, y1, width, height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&destPR, drawable,
|
|
|
|
x1, y1, width, height,
|
|
|
|
preview == NULL, TRUE);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
rutbredd = gtvals.xblock;
|
|
|
|
ruthojd = gtvals.yblock;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
xhalv = rutbredd / 2;
|
2000-05-23 03:40:06 +08:00
|
|
|
yhalv = ruthojd / 2;
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
xplus = rutbredd % 2;
|
2000-05-23 03:40:06 +08:00
|
|
|
yplus = ruthojd % 2;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
ymitt = y1;
|
|
|
|
yoffs = 0;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Loop through the rows */
|
|
|
|
for (row = y1; row < y2; row++)
|
|
|
|
{
|
|
|
|
d = dest;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
ypixel2 = ymitt + yoffs * 2;
|
2002-12-20 06:23:37 +08:00
|
|
|
ypixel2 = CLAMP (ypixel2, 0, y2 - 1);
|
2003-10-13 03:55:43 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
gimp_pixel_rgn_get_row (&srcPR, cur_row, x1, ypixel2, width);
|
1997-12-09 13:57:33 +08:00
|
|
|
yoffs++;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
2003-10-13 03:55:43 +08:00
|
|
|
/* if current offset = half, do a displacement next time around */
|
2003-11-06 23:27:05 +08:00
|
|
|
if (yoffs == yhalv)
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
ymitt += ruthojd;
|
|
|
|
yoffs = - (yhalv + yplus);
|
|
|
|
}
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
xmitt = 0;
|
|
|
|
xoffs = 0;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
2002-12-20 06:23:37 +08:00
|
|
|
for (col = 0; col < x2 - x1; col++) /* one pixel */
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
xpixel1 = (xmitt + xoffs) * bytes;
|
|
|
|
xpixel2 = (xmitt + xoffs * 2) * bytes;
|
|
|
|
|
2004-05-28 03:00:49 +08:00
|
|
|
if (xpixel2 < (x2 - x1) * bytes)
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
2004-05-28 03:00:49 +08:00
|
|
|
if (xpixel2 < 0)
|
2003-12-11 06:50:26 +08:00
|
|
|
xpixel2 = 0;
|
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
d[xpixel1 + i] = cur_row[xpixel2 + i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
d[xpixel1 + i] = cur_row[xpixel1 + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
xoffs++;
|
|
|
|
|
|
|
|
if (xoffs == xhalv)
|
|
|
|
{
|
|
|
|
xmitt += rutbredd;
|
|
|
|
xoffs = - (xhalv + xplus);
|
|
|
|
}
|
|
|
|
}
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Store the dest */
|
2004-10-17 22:37:45 +08:00
|
|
|
gimp_pixel_rgn_set_row (&destPR, dest, x1, row, width);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-10-17 22:37:45 +08:00
|
|
|
if (!preview && ((row % 5) == 0))
|
|
|
|
{
|
|
|
|
gimp_progress_update ((gdouble) row / (gdouble) height);
|
2002-02-21 22:50:24 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update region */
|
2004-10-17 22:37:45 +08:00
|
|
|
if (preview)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
2004-10-17 22:37:45 +08:00
|
|
|
gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview),
|
|
|
|
&destPR);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_drawable_flush (drawable);
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_drawable_update (drawable->drawable_id,
|
2004-10-17 22:37:45 +08:00
|
|
|
x1, y1, width, height);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
g_free (cur_row);
|
|
|
|
g_free (dest);
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|