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
|
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
|
|
|
|
|
|
|
#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
|
|
|
|
2003-12-12 02:16:47 +08:00
|
|
|
#include "gimpoldpreview.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
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* --- Declare local functions --- */
|
2004-05-19 23:28:01 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2000-01-16 23:38:38 +08:00
|
|
|
|
2004-05-19 23:28:01 +08:00
|
|
|
static gboolean glass_dialog (GimpDrawable *drawable);
|
|
|
|
static void glasstile (GimpDrawable *drawable,
|
|
|
|
gboolean preview_mode);
|
2000-05-23 03:40:06 +08:00
|
|
|
|
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 */
|
|
|
|
};
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
static GlassValues gtvals =
|
|
|
|
{
|
|
|
|
20, /* tile width */
|
|
|
|
20 /* tile height */
|
|
|
|
};
|
|
|
|
|
2003-12-11 06:50:26 +08:00
|
|
|
static GimpOldPreview *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
|
2003-11-06 23:27:05 +08:00
|
|
|
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
|
|
|
{
|
2004-05-07 21:15:52 +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",
|
2003-12-11 06:50:26 +08:00
|
|
|
"Divide the image into square glassblocks",
|
|
|
|
"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
|
|
|
|
|
|
|
gimp_plugin_menu_register ("plug_in_glasstile",
|
|
|
|
N_("<Image>/Filters/Glass Effects"));
|
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];
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
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);
|
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 */
|
|
|
|
gimp_get_data ("plug_in_glasstile", >vals);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-12-09 13:57:33 +08:00
|
|
|
/* First acquire information with a dialog */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (! glass_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 */
|
|
|
|
gimp_get_data ("plug_in_glasstile", >vals);
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
gimp_progress_init (_("Glass Tile..."));
|
|
|
|
gimp_tile_cache_ntiles (2 *
|
2002-02-21 22:50:24 +08:00
|
|
|
(drawable->width / gimp_tile_width () + 1));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-12-11 06:50:26 +08:00
|
|
|
glasstile (drawable, FALSE);
|
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)
|
|
|
|
{
|
|
|
|
gimp_set_data ("plug_in_glasstile", >vals,
|
|
|
|
sizeof (GlassValues));
|
|
|
|
gimp_old_preview_free (preview);
|
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
|
2000-08-22 09:26:57 +08:00
|
|
|
glass_dialog (GimpDrawable *drawable)
|
1997-12-09 13:57:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dlg;
|
2004-05-19 01:06:06 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
1997-12-09 13:57:33 +08:00
|
|
|
GtkWidget *table;
|
2000-01-16 23:38:38 +08:00
|
|
|
GtkObject *adj;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
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",
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2004-01-21 01:10:16 +08:00
|
|
|
gimp_standard_help_func, "plug-in-glasstile",
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2003-12-11 06:50:26 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2003-12-11 06:50:26 +08:00
|
|
|
NULL);
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2004-05-19 01:06:06 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
|
2004-05-19 01:06:06 +08:00
|
|
|
vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
2000-05-23 03:40:06 +08:00
|
|
|
|
2004-05-19 01:06:06 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
preview = gimp_old_preview_new (drawable);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), preview->frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (preview->frame);
|
2002-12-20 06:23:37 +08:00
|
|
|
glasstile (drawable, TRUE); /* filter routine, initial pass */
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-12-11 05:13:29 +08:00
|
|
|
/* Parameter settings */
|
|
|
|
table = gtk_table_new (2, 3, 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);
|
|
|
|
gtk_box_pack_start (GTK_BOX (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 */
|
2000-01-16 23:38:38 +08:00
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2004-05-28 03:00:49 +08:00
|
|
|
_("Tile _width:"), 150, 0,
|
2003-12-11 06:50:26 +08:00
|
|
|
gtvals.xblock, 10, 50, 2, 10, 0,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
>vals.xblock);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect_swapped (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
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,
|
2004-05-28 03:00:49 +08:00
|
|
|
_("Tile _height:"), 150, 0,
|
2003-12-11 06:50:26 +08:00
|
|
|
gtvals.yblock, 10, 50, 2, 10, 0,
|
|
|
|
TRUE, 0, 0,
|
|
|
|
NULL, NULL);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (adj), "drawable", drawable);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
>vals.yblock);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect_swapped (adj, "value_changed",
|
2001-12-29 21:26:29 +08:00
|
|
|
G_CALLBACK (glasstile),
|
|
|
|
drawable);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
|
1997-12-09 13:57:33 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (dlg);
|
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
|
|
|
}
|
|
|
|
|
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,
|
2003-12-11 06:50:26 +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
|
|
|
|
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;
|
|
|
|
gint cbytes;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
if (preview_mode)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
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;
|
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);
|
2000-05-23 03:40:06 +08:00
|
|
|
width = drawable->width;
|
|
|
|
height = drawable->height;
|
|
|
|
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 */
|
2003-11-06 23:27:05 +08:00
|
|
|
if (preview_mode)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
2002-12-02 04:56:01 +08:00
|
|
|
rutbredd = gtvals.xblock * preview->scale_x;
|
|
|
|
ruthojd = gtvals.yblock * preview->scale_y;
|
2003-10-13 03:55:43 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
/* Algorithm depends on grid height/width being at least 2
|
|
|
|
* or you'll get extremely bad previews (1/2 size).
|
2003-10-13 03:55:43 +08:00
|
|
|
*
|
|
|
|
* Preview isn't really terribly useful for larger images.
|
2003-11-06 23:27:05 +08:00
|
|
|
* Might be more useful as full-size window scroll-around type.
|
2003-10-13 03:55:43 +08:00
|
|
|
*/
|
|
|
|
rutbredd = MAX(rutbredd, 2);
|
|
|
|
ruthojd = MAX(ruthojd, 2);
|
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
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (! (cbytes & 1))
|
|
|
|
cbytes--;
|
2000-05-23 03:40:06 +08:00
|
|
|
|
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;
|
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
|
|
|
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
memcpy (cur_row, preview->cache + ypixel2 * preview->rowstride,
|
|
|
|
preview->rowstride);
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
else
|
2003-12-11 06:50:26 +08:00
|
|
|
{
|
|
|
|
gimp_pixel_rgn_get_row (&srcPR, cur_row, x1, ypixel2, iwidth);
|
|
|
|
}
|
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 */
|
2000-05-23 03:40:06 +08:00
|
|
|
if (preview_mode)
|
2002-02-21 22:50:24 +08:00
|
|
|
{
|
2003-12-11 06:50:26 +08:00
|
|
|
gimp_old_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);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2002-02-21 22:50:24 +08:00
|
|
|
if ((row % 5) == 0)
|
|
|
|
gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
|
|
|
|
}
|
1997-12-09 13:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update region */
|
2003-11-06 23:27:05 +08:00
|
|
|
if (preview_mode)
|
2000-05-23 03:40:06 +08:00
|
|
|
{
|
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);
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_drawable_update (drawable->drawable_id,
|
2004-05-28 03:00:49 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|