1997-12-09 13:57:33 +08:00
|
|
|
/*
|
2000-05-23 03:40:06 +08:00
|
|
|
* This is the Glass Tile plug-in for the GIMP 1.2
|
|
|
|
* 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
|
|
|
|
* the image is refracted.
|
|
|
|
*
|
|
|
|
* The alpha-channel is left unchanged.
|
|
|
|
*
|
|
|
|
* 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 :(
|
2000-05-26 07:28:20 +08:00
|
|
|
*
|
|
|
|
* May 2000 alt@gimp.org Made preview work and removed some boundary
|
|
|
|
* conditions that caused "streaks" to appear when using some tile spaces.
|
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
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-10-01 04:13:06 +08:00
|
|
|
#include <string.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
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
|
|
|
|
|
|
|
/* --- Typedefs --- */
|
2000-01-16 23:38:38 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-12-09 13:57:33 +08:00
|
|
|
gint xblock;
|
|
|
|
gint yblock;
|
|
|
|
} GlassValues;
|
2000-01-16 23:38:38 +08:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
1997-12-09 13:57:33 +08:00
|
|
|
gint run;
|
|
|
|
} GlassInterface;
|
|
|
|
|
|
|
|
/* --- Declare local functions --- */
|
|
|
|
static void query (void);
|
2001-12-29 21:26:29 +08:00
|
|
|
static void run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2001-12-29 21:26:29 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals);
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
static gint glass_dialog (GimpDrawable *drawable);
|
2000-05-23 03:40:06 +08:00
|
|
|
static void glass_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
static void glasstile (GimpDrawable *drawable,
|
2000-05-23 03:40:06 +08:00
|
|
|
gboolean preview_mode);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* --- Variables --- */
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
|
|
|
static GlassValues gtvals =
|
|
|
|
{
|
|
|
|
20, /* tile width */
|
|
|
|
20 /* tile height */
|
|
|
|
};
|
|
|
|
static GlassInterface gt_int =
|
|
|
|
{
|
|
|
|
FALSE /* run */
|
|
|
|
};
|
|
|
|
|
2002-12-02 04:56:01 +08:00
|
|
|
static GimpFixMePreview *preview;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* --- Functions --- */
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
|
|
|
query (void)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (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
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
gimp_install_procedure ("plug_in_glasstile",
|
2000-01-31 10:32:30 +08:00
|
|
|
"Divide the image into square glassblocks",
|
2002-02-21 22:50:24 +08:00
|
|
|
"Divide the image into square glassblocks in "
|
|
|
|
"which the image is refracted.",
|
1997-12-09 13:57:33 +08:00
|
|
|
"Karl-Johan Andersson", /* Author */
|
|
|
|
"Karl-Johan Andersson", /* Copyright */
|
2000-05-23 03:40:06 +08:00
|
|
|
"May 2000",
|
1999-12-26 05:49:51 +08:00
|
|
|
N_("<Image>/Filters/Glass Effects/Glass Tile..."),
|
1997-12-09 13:57:33 +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-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
2001-12-29 21:26:29 +08:00
|
|
|
run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2001-12-29 21:26:29 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2001-12-29 21:26:29 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2001-12-29 21:26:29 +08:00
|
|
|
*return_vals = values;
|
1997-12-09 13:57:33 +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);
|
|
|
|
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1999-12-26 05:49:51 +08:00
|
|
|
INIT_I18N_UI();
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data ("plug_in_glasstile", >vals);
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (! glass_dialog (drawable))
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1999-12-26 05:49:51 +08:00
|
|
|
INIT_I18N();
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 5)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
gtvals.xblock = (gint) param[3].data.d_int32;
|
|
|
|
gtvals.yblock = (gint) param[4].data.d_int32;
|
|
|
|
}
|
|
|
|
if (gtvals.xblock < 10 || gtvals.xblock > 50)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1997-12-09 13:57:33 +08:00
|
|
|
if (gtvals.yblock < 10 || gtvals.yblock > 50)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1997-12-09 13:57:33 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
1999-12-26 05:49:51 +08:00
|
|
|
INIT_I18N();
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data ("plug_in_glasstile", >vals);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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) ||
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id))
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
1999-12-26 05:49:51 +08:00
|
|
|
gimp_progress_init ( _("Glass Tile..."));
|
2002-02-21 22:50:24 +08:00
|
|
|
gimp_tile_cache_ntiles (2 *
|
|
|
|
(drawable->width / gimp_tile_width () + 1));
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2002-02-21 22:50:24 +08:00
|
|
|
glasstile (drawable, FALSE);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
1997-12-09 13:57:33 +08:00
|
|
|
gimp_displays_flush ();
|
|
|
|
/* Store data */
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
|
|
|
gimp_set_data ("plug_in_glasstile", >vals,
|
|
|
|
sizeof (GlassValues));
|
2002-12-02 04:56:01 +08:00
|
|
|
gimp_fixme_preview_free (preview);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static gint
|
2000-08-22 09:26:57 +08:00
|
|
|
glass_dialog (GimpDrawable *drawable)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dlg;
|
2000-05-23 03:40:06 +08:00
|
|
|
GtkWidget *main_vbox;
|
1997-12-09 13:57:33 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *table;
|
2000-05-23 03:40:06 +08:00
|
|
|
GtkWidget *abox;
|
2000-01-16 23:38:38 +08:00
|
|
|
GtkObject *adj;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
gimp_ui_init ("glasstile", TRUE);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
dlg = gimp_dialog_new (_("Glass Tile"), "glasstile",
|
2000-05-23 01:10:28 +08:00
|
|
|
gimp_standard_help_func, "filters/glasstile.html",
|
2000-01-07 06:26:10 +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 06:26:10 +08:00
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
2001-11-29 21:23:44 +08:00
|
|
|
GTK_STOCK_OK, glass_ok_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
2000-01-07 06:26:10 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2001-12-29 21:26:29 +08:00
|
|
|
g_signal_connect (G_OBJECT (dlg), "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit),
|
|
|
|
NULL);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2002-09-07 04:44:47 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
|
2002-02-21 22:50:24 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
|
|
|
|
main_vbox, TRUE, TRUE, 0);
|
2000-05-23 03:40:06 +08:00
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (_("Preview"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2002-09-07 04:44:47 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (abox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), abox);
|
|
|
|
gtk_widget_show (abox);
|
2002-09-07 04:44:47 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), frame);
|
|
|
|
gtk_widget_show (frame);
|
2002-09-07 04:44:47 +08:00
|
|
|
|
2002-12-02 04:56:01 +08:00
|
|
|
preview = gimp_fixme_preview_new (drawable);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview->widget);
|
2000-05-23 03:40:06 +08:00
|
|
|
glasstile (drawable, TRUE); /* filter routine, initial pass */
|
2002-12-02 04:56:01 +08:00
|
|
|
gtk_widget_show (preview->widget);
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Parameter settings */
|
2000-01-07 06:26:10 +08:00
|
|
|
frame = gtk_frame_new (_("Parameter Settings"));
|
1997-12-09 13:57:33 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
2000-05-23 03:40:06 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0);
|
2002-09-07 04:44:47 +08:00
|
|
|
gtk_widget_show (frame);
|
2000-01-09 04:00:10 +08:00
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
table = gtk_table_new (2, 3, FALSE);
|
2002-09-07 04:44:47 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
2000-01-09 04:00:10 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
1997-12-09 13:57:33 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
2002-09-07 04:44:47 +08:00
|
|
|
gtk_widget_show (table);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* Horizontal scale - Width */
|
2000-01-16 23:38:38 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2002-05-08 08:30:26 +08:00
|
|
|
_("Tile _Width:"), 150, 0,
|
2000-05-23 03:40:06 +08:00
|
|
|
gtvals.xblock, 10, 50, 2, 10, 0,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-16 23:38:38 +08:00
|
|
|
NULL, NULL);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (adj), "value_changed",
|
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
>vals.xblock);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (adj), "value_changed",
|
|
|
|
G_CALLBACK (glasstile),
|
|
|
|
drawable);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
/* Horizontal scale - Height */
|
2000-01-16 23:38:38 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-05-08 08:30:26 +08:00
|
|
|
_("Tile _Height:"), 150, 0,
|
2000-05-23 03:40:06 +08:00
|
|
|
gtvals.yblock, 10, 50, 2, 10, 0,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-16 23:38:38 +08:00
|
|
|
NULL, NULL);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (adj), "drawable", drawable);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (adj), "value_changed",
|
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
>vals.yblock);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (adj), "value_changed",
|
|
|
|
G_CALLBACK (glasstile),
|
|
|
|
drawable);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
gdk_flush ();
|
|
|
|
|
|
|
|
return gt_int.run;
|
|
|
|
}
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static void
|
|
|
|
glass_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
gt_int.run = TRUE;
|
|
|
|
|
2000-01-16 23:38:38 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
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
|
2000-08-22 09:26:57 +08:00
|
|
|
glasstile (GimpDrawable *drawable,
|
2002-02-21 22:50:24 +08:00
|
|
|
gboolean preview_mode)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn srcPR, destPR;
|
2002-02-21 22:50:24 +08:00
|
|
|
gint width, height;
|
|
|
|
gint bytes;
|
2000-05-26 07:28:20 +08:00
|
|
|
guchar *dest, *d;
|
1997-12-09 13:57:33 +08:00
|
|
|
guchar *cur_row;
|
2002-02-21 22:50:24 +08:00
|
|
|
gint row, col, i, iwidth;
|
|
|
|
gint x1, y1, x2, y2;
|
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;
|
|
|
|
gint cbytes;
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
|
|
|
{
|
2002-12-02 04:56:01 +08:00
|
|
|
width = preview->width;
|
|
|
|
height = preview->height;
|
|
|
|
bytes = preview->bpp;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
|
|
|
x1 = y1 = 0;
|
|
|
|
x2 = width;
|
|
|
|
y2 = height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
2000-05-23 03:40:06 +08:00
|
|
|
width = drawable->width;
|
|
|
|
height = drawable->height;
|
|
|
|
bytes = drawable->bpp;
|
|
|
|
}
|
1997-12-09 13:57:33 +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
|
|
|
|
|
|
|
/* initialize the pixel regions */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
|
|
|
{
|
2002-12-02 04:56:01 +08:00
|
|
|
rutbredd = gtvals.xblock * preview->scale_x;
|
|
|
|
ruthojd = gtvals.yblock * preview->scale_y;
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2000-05-23 03:40:06 +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
|
|
|
cbytes = bytes;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
2002-02-21 22:50:24 +08:00
|
|
|
if (! (cbytes & 1))
|
2000-05-23 03:40:06 +08:00
|
|
|
cbytes--;
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
iwidth = width - x1;
|
|
|
|
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;
|
2000-05-23 03:40:06 +08:00
|
|
|
ypixel2 = ymitt + yoffs * 2;
|
|
|
|
|
2002-02-21 22:50:24 +08:00
|
|
|
if (ypixel2 < 0)
|
2000-05-26 07:28:20 +08:00
|
|
|
ypixel2 = 0;
|
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
|
|
|
{
|
|
|
|
if (ypixel2 < height)
|
2000-05-24 02:52:14 +08:00
|
|
|
memcpy (cur_row,
|
2002-12-02 04:56:01 +08:00
|
|
|
preview->cache + (ypixel2 * preview->rowstride),
|
|
|
|
preview->rowstride);
|
2000-05-23 03:40:06 +08:00
|
|
|
else
|
2000-05-24 02:52:14 +08:00
|
|
|
memcpy (cur_row,
|
2002-12-02 04:56:01 +08:00
|
|
|
preview->cache + ((y2 - 1) * preview->rowstride),
|
|
|
|
preview->rowstride);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
else
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
|
|
|
if (ypixel2 < height)
|
|
|
|
gimp_pixel_rgn_get_row (&srcPR, cur_row, x1, ypixel2, iwidth);
|
|
|
|
else
|
|
|
|
gimp_pixel_rgn_get_row (&srcPR, cur_row, x1, y2 - 1, iwidth);
|
|
|
|
}
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
yoffs++;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
|
|
|
if (yoffs == yhalv)
|
|
|
|
{
|
|
|
|
ymitt += ruthojd;
|
2002-02-21 22:50:24 +08:00
|
|
|
yoffs = - (yhalv + yplus);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
xmitt = 0;
|
|
|
|
xoffs = 0;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
for (col = 0; col < (x2 - x1); col++) /* one pixel */
|
|
|
|
{
|
|
|
|
xpixel1 = (xmitt + xoffs) * bytes;
|
|
|
|
xpixel2 = (xmitt + xoffs * 2) * bytes;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
|
|
|
if (xpixel2 < ((x2 - x1) * bytes))
|
|
|
|
{
|
2000-05-26 07:28:20 +08:00
|
|
|
if(xpixel2 < 0)
|
|
|
|
xpixel2 = 0;
|
|
|
|
for (i = 0; i < bytes; i++)
|
2000-05-23 03:40:06 +08:00
|
|
|
d[xpixel1 + i] = cur_row[xpixel2 + i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-05-26 07:28:20 +08:00
|
|
|
for (i = 0; i < bytes; i++)
|
2002-02-21 22:50:24 +08:00
|
|
|
d[xpixel1 + i] = cur_row[xpixel1 + i];
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
xoffs++;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
|
|
|
if (xoffs == xhalv)
|
|
|
|
{
|
|
|
|
xmitt += rutbredd;
|
2002-02-21 22:50:24 +08:00
|
|
|
xoffs = - (xhalv + xplus);
|
2000-05-23 03:40:06 +08:00
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
2000-05-23 03:40:06 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* Store the dest */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
2002-02-21 22:50:24 +08:00
|
|
|
{
|
2002-12-02 04:56:01 +08:00
|
|
|
gimp_fixme_preview_do_row (preview, row, width, dest);
|
2002-02-21 22:50:24 +08:00
|
|
|
}
|
2000-05-23 03:40:06 +08:00
|
|
|
else
|
2002-02-21 22:50:24 +08:00
|
|
|
{
|
|
|
|
gimp_pixel_rgn_set_row (&destPR, dest, x1, row, iwidth);
|
|
|
|
|
|
|
|
if ((row % 5) == 0)
|
|
|
|
gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update region */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
|
|
|
{
|
2002-12-02 04:56:01 +08:00
|
|
|
gtk_widget_queue_draw (preview->widget);
|
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);
|
2002-02-21 22:50:24 +08:00
|
|
|
gimp_drawable_update (drawable->drawable_id,
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1));
|
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
|
|
|
}
|
2000-05-24 02:52:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|