1998-04-24 10:18:52 +08:00
|
|
|
/*
|
|
|
|
* "$Id$"
|
|
|
|
*
|
|
|
|
* Sharpen filters for The GIMP -- an image manipulation program
|
|
|
|
*
|
|
|
|
* Copyright 1997-1998 Michael Sweet (mike@easysw.com)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Contents:
|
|
|
|
*
|
2000-05-02 04:22:55 +08:00
|
|
|
* main() - Main entry - just call gimp_main()...
|
|
|
|
* query() - Respond to a plug-in query...
|
|
|
|
* run() - Run the filter...
|
|
|
|
* sharpen() - Sharpen an image using a median filter.
|
|
|
|
* sharpen_dialog() - Popup a dialog window for the filter box size...
|
|
|
|
* preview_init() - Initialize the preview window...
|
|
|
|
* preview_scroll_callback() - Update the preview when a scrollbar is moved.
|
|
|
|
* preview_update() - Update the preview window.
|
|
|
|
* preview_exit() - Free all memory used by the preview window...
|
|
|
|
* dialog_iscale_update() - Update the value field using the scale.
|
|
|
|
* dialog_ok_callback() - Start the filter...
|
|
|
|
* gray_filter() - Sharpen grayscale pixels.
|
|
|
|
* graya_filter() - Sharpen grayscale+alpha pixels.
|
|
|
|
* rgb_filter() - Sharpen RGB pixels.
|
|
|
|
* rgba_filter() - Sharpen RGBA pixels.
|
1998-04-24 10:18:52 +08:00
|
|
|
*
|
|
|
|
* Revision History:
|
|
|
|
*
|
2000-01-28 21:12:50 +08:00
|
|
|
* See ChangeLog
|
1998-04-24 10:18:52 +08:00
|
|
|
*/
|
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
|
2000-01-08 01:18:44 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
/*
|
|
|
|
* Constants...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PLUG_IN_NAME "plug_in_sharpen"
|
1998-06-07 07:22:22 +08:00
|
|
|
#define PLUG_IN_VERSION "1.4.2 - 3 June 1998"
|
1998-04-24 10:18:52 +08:00
|
|
|
#define PREVIEW_SIZE 128
|
2000-01-15 23:32:28 +08:00
|
|
|
#define SCALE_WIDTH 100
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local functions...
|
|
|
|
*/
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2000-01-15 23:32:28 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **returm_vals);
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
static void compute_luts (void);
|
|
|
|
static void sharpen (void);
|
|
|
|
|
|
|
|
static gint sharpen_dialog (void);
|
|
|
|
|
|
|
|
static void dialog_iscale_update (GtkAdjustment *, gint *);
|
|
|
|
static void dialog_ok_callback (GtkWidget *, gpointer);
|
|
|
|
|
|
|
|
static void preview_init (void);
|
|
|
|
static void preview_exit (void);
|
|
|
|
static void preview_update (void);
|
|
|
|
static void preview_scroll_callback (void);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
1999-03-16 06:38:36 +08:00
|
|
|
typedef gint32 intneg;
|
|
|
|
typedef gint32 intpos;
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
static void gray_filter (int width, guchar *src, guchar *dst, intneg *neg0,
|
|
|
|
intneg *neg1, intneg *neg2);
|
|
|
|
static void graya_filter (int width, guchar *src, guchar *dst, intneg *neg0,
|
|
|
|
intneg *neg1, intneg *neg2);
|
|
|
|
static void rgb_filter (int width, guchar *src, guchar *dst, intneg *neg0,
|
|
|
|
intneg *neg1, intneg *neg2);
|
|
|
|
static void rgba_filter (int width, guchar *src, guchar *dst, intneg *neg0,
|
|
|
|
intneg *neg1, intneg *neg2);
|
1998-04-28 06:01:01 +08:00
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Globals...
|
|
|
|
*/
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run /* run_proc */
|
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
static GtkWidget *preview; /* Preview widget */
|
|
|
|
static gint preview_width; /* Width of preview widget */
|
|
|
|
static gint preview_height; /* Height of preview widget */
|
|
|
|
static gint preview_x1; /* Upper-left X of preview */
|
|
|
|
static gint preview_y1; /* Upper-left Y of preview */
|
|
|
|
static gint preview_x2; /* Lower-right X of preview */
|
|
|
|
static gint preview_y2; /* Lower-right Y of preview */
|
|
|
|
static guchar *preview_src; /* Source pixel image */
|
|
|
|
static intneg *preview_neg; /* Negative coefficient pixels */
|
|
|
|
static guchar *preview_dst; /* Destination pixel image */
|
|
|
|
static guchar *preview_image; /* Preview RGB image */
|
|
|
|
static GtkObject *hscroll_data; /* Horizontal scrollbar data */
|
|
|
|
static GtkObject *vscroll_data; /* Vertical scrollbar data */
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpDrawable *drawable = NULL; /* Current image */
|
2000-05-02 04:22:55 +08:00
|
|
|
static gint sel_x1; /* Selection bounds */
|
|
|
|
static gint sel_y1;
|
|
|
|
static gint sel_x2;
|
|
|
|
static gint sel_y2;
|
|
|
|
static gint sel_width; /* Selection width */
|
|
|
|
static gint sel_height; /* Selection height */
|
|
|
|
static gint img_bpp; /* Bytes-per-pixel in image */
|
|
|
|
static gint sharpen_percent = 10; /* Percent of sharpening */
|
|
|
|
static gint run_filter = FALSE; /* True if we should run the filter */
|
|
|
|
|
|
|
|
static intneg neg_lut[256]; /* Negative coefficient LUT */
|
|
|
|
static intpos pos_lut[256]; /* Positive coefficient LUT */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
MAIN ()
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
query (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
static GimpParamDef args[] =
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
|
|
|
{ GIMP_PDB_INT32, "percent", "Percent sharpening (default = 10)" }
|
1998-04-24 10:18:52 +08:00
|
|
|
};
|
2000-02-04 23:12:17 +08:00
|
|
|
static gint nargs = sizeof (args) / sizeof (args[0]);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_NAME,
|
2000-05-02 04:22:55 +08:00
|
|
|
"Sharpen filter, typically used to 'sharpen' a photographic image.",
|
2000-03-08 21:53:54 +08:00
|
|
|
"This plug-in selectively performs a convolution filter on an image.",
|
2000-01-15 23:32:28 +08:00
|
|
|
"Michael Sweet <mike@easysw.com>",
|
|
|
|
"Copyright 1997-1998 by Michael Sweet",
|
|
|
|
PLUG_IN_VERSION,
|
|
|
|
N_("<Image>/Filters/Enhance/Sharpen..."),
|
|
|
|
"RGB*, GRAY*",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2000-02-04 23:12:17 +08:00
|
|
|
nargs, 0,
|
|
|
|
args, NULL);
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
run (gchar *name,
|
|
|
|
gint nparams,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam *param,
|
2000-01-15 23:32:28 +08:00
|
|
|
gint *nreturn_vals,
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpParam **return_vals)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpRunModeType run_mode; /* Current run mode */
|
|
|
|
GimpPDBStatusType status; /* Return status */
|
|
|
|
GimpParam *values; /* Return values */
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Initialize parameter data...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_SUCCESS;
|
1998-04-24 10:18:52 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values = g_new (GimpParam, 1);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1998-04-24 10:18:52 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Get drawable information...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable->id, &sel_x1, &sel_y1, &sel_x2, &sel_y2);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
sel_width = sel_x2 - sel_x1;
|
|
|
|
sel_height = sel_y2 - sel_y1;
|
2000-05-02 04:22:55 +08:00
|
|
|
img_bpp = gimp_drawable_bpp (drawable->id);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* See how we will run
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
switch (run_mode)
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2000-01-08 01:18:44 +08:00
|
|
|
INIT_I18N_UI();
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Possibly retrieve data...
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_get_data (PLUG_IN_NAME, &sharpen_percent);
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get information from the dialog...
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
if (!sharpen_dialog ())
|
2000-01-15 23:32:28 +08:00
|
|
|
return;
|
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2000-01-08 01:18:44 +08:00
|
|
|
INIT_I18N();
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Make sure all the arguments are present...
|
|
|
|
*/
|
|
|
|
if (nparams != 4)
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-15 23:32:28 +08:00
|
|
|
else
|
|
|
|
sharpen_percent = param[3].data.d_int32;
|
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2000-01-08 01:18:44 +08:00
|
|
|
INIT_I18N();
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Possibly retrieve data...
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_get_data (PLUG_IN_NAME, &sharpen_percent);
|
2000-01-15 23:32:28 +08:00
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
default:
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-15 23:32:28 +08:00
|
|
|
break;;
|
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Sharpen the image...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
if ((gimp_drawable_is_rgb (drawable->id) ||
|
|
|
|
gimp_drawable_is_gray (drawable->id)))
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set the tile cache size...
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->width + gimp_tile_width() - 1) /
|
|
|
|
gimp_tile_width() + 1);
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Run!
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
sharpen ();
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If run mode is interactive, flush displays...
|
|
|
|
*/
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_displays_flush ();
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Store data...
|
|
|
|
*/
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2000-01-15 23:32:28 +08:00
|
|
|
gimp_set_data (PLUG_IN_NAME,
|
|
|
|
&sharpen_percent, sizeof (sharpen_percent));
|
|
|
|
}
|
|
|
|
else
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Reset the current run status...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Detach from the drawable...
|
|
|
|
*/
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-28 06:01:01 +08:00
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
compute_luts (void)
|
1998-04-28 06:01:01 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
gint i; /* Looping var */
|
|
|
|
gint fact; /* 1 - sharpness */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
fact = 100 - sharpen_percent;
|
|
|
|
if (fact < 1)
|
|
|
|
fact = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i ++)
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
|
|
|
pos_lut[i] = 800 * i / fact;
|
|
|
|
neg_lut[i] = (4 + pos_lut[i] - (i << 3)) >> 3;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
}
|
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
/*
|
|
|
|
* 'sharpen()' - Sharpen an image using a convolution filter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
sharpen (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn src_rgn, /* Source image region */
|
1998-04-24 10:18:52 +08:00
|
|
|
dst_rgn; /* Destination image region */
|
|
|
|
guchar *src_rows[4], /* Source pixel rows */
|
1998-04-28 06:01:01 +08:00
|
|
|
*src_ptr, /* Current source pixel */
|
1999-03-16 06:38:36 +08:00
|
|
|
*dst_row; /* Destination pixel row */
|
|
|
|
intneg *neg_rows[4], /* Negative coefficient rows */
|
1998-04-28 06:01:01 +08:00
|
|
|
*neg_ptr; /* Current negative coefficient */
|
2000-05-02 04:22:55 +08:00
|
|
|
gint i, /* Looping vars */
|
1998-04-28 06:01:01 +08:00
|
|
|
y, /* Current location in image */
|
1998-04-24 10:18:52 +08:00
|
|
|
row, /* Current row in src_rows */
|
|
|
|
count, /* Current number of filled src_rows */
|
|
|
|
width; /* Byte width of the image */
|
1999-03-16 06:38:36 +08:00
|
|
|
void (*filter)(int, guchar *, guchar *, intneg *, intneg *, intneg *);
|
1998-04-28 06:01:01 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
filter = NULL;
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Let the user know what we're doing...
|
|
|
|
*/
|
2000-01-08 01:18:44 +08:00
|
|
|
gimp_progress_init( _("Sharpening..."));
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Setup for filter...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE);
|
|
|
|
gimp_pixel_rgn_init (&dst_rgn, drawable,
|
|
|
|
sel_x1, sel_y1, sel_width, sel_height, TRUE, TRUE);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
compute_luts ();
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
width = sel_width * img_bpp;
|
|
|
|
|
|
|
|
for (row = 0; row < 4; row ++)
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
src_rows[row] = g_new (guchar, width);
|
|
|
|
neg_rows[row] = g_new (intneg, width);
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
dst_row = g_new (guchar, width);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Pre-load the first row for the filter...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_pixel_rgn_get_row (&src_rgn, src_rows[0], sel_x1, sel_y1, sel_width);
|
1998-04-28 06:01:01 +08:00
|
|
|
for (i = width, src_ptr = src_rows[0], neg_ptr = neg_rows[0];
|
|
|
|
i > 0;
|
|
|
|
i --, src_ptr ++, neg_ptr ++)
|
|
|
|
*neg_ptr = neg_lut[*src_ptr];
|
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
row = 1;
|
|
|
|
count = 1;
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Select the filter...
|
|
|
|
*/
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
switch (img_bpp)
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
1998-04-28 06:01:01 +08:00
|
|
|
case 1 :
|
2000-01-15 23:32:28 +08:00
|
|
|
filter = gray_filter;
|
|
|
|
break;
|
1998-04-28 06:01:01 +08:00
|
|
|
case 2 :
|
2000-01-15 23:32:28 +08:00
|
|
|
filter = graya_filter;
|
|
|
|
break;
|
1998-04-28 06:01:01 +08:00
|
|
|
case 3 :
|
2000-01-15 23:32:28 +08:00
|
|
|
filter = rgb_filter;
|
|
|
|
break;
|
1998-04-28 06:01:01 +08:00
|
|
|
case 4 :
|
2000-01-15 23:32:28 +08:00
|
|
|
filter = rgba_filter;
|
|
|
|
break;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Sharpen...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
for (y = sel_y1; y < sel_y2; y ++)
|
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Load the next pixel row...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
if ((y + 1) < sel_y2)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check to see if our src_rows[] array is overflowing yet...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (count >= 3)
|
|
|
|
count --;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the next row...
|
|
|
|
*/
|
|
|
|
|
|
|
|
gimp_pixel_rgn_get_row (&src_rgn, src_rows[row],
|
|
|
|
sel_x1, y + 1, sel_width);
|
|
|
|
for (i = width, src_ptr = src_rows[row], neg_ptr = neg_rows[row];
|
|
|
|
i > 0;
|
|
|
|
i --, src_ptr ++, neg_ptr ++)
|
|
|
|
*neg_ptr = neg_lut[*src_ptr];
|
|
|
|
|
|
|
|
count ++;
|
|
|
|
row = (row + 1) & 3;
|
|
|
|
}
|
1998-06-07 07:22:22 +08:00
|
|
|
else
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No more pixels at the bottom... Drop the oldest samples...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
count --;
|
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Now sharpen pixels and save the results...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (count == 3)
|
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
(* filter) (sel_width, src_rows[(row + 2) & 3], dst_row,
|
|
|
|
neg_rows[(row + 1) & 3] + img_bpp,
|
|
|
|
neg_rows[(row + 2) & 3] + img_bpp,
|
|
|
|
neg_rows[(row + 3) & 3] + img_bpp);
|
2000-01-15 23:32:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the row...
|
|
|
|
*/
|
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_pixel_rgn_set_row (&dst_rgn, dst_row, sel_x1, y, sel_width);
|
2000-01-15 23:32:28 +08:00
|
|
|
}
|
|
|
|
else if (count == 2)
|
|
|
|
{
|
2001-01-14 23:18:37 +08:00
|
|
|
if (y == sel_y1) /* first row */
|
|
|
|
gimp_pixel_rgn_set_row (&dst_rgn, src_rows[0],
|
|
|
|
sel_x1, y, sel_width);
|
|
|
|
else /* last row */
|
|
|
|
gimp_pixel_rgn_set_row (&dst_rgn, src_rows[(sel_height - 1) & 3],
|
|
|
|
sel_x1, y, sel_width);
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if ((y & 15) == 0)
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_progress_update ((gdouble) (y - sel_y1) / (gdouble) sel_height);
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we're done. Free all memory used...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
for (row = 0; row < 4; row ++)
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
g_free (src_rows[row]);
|
|
|
|
g_free (neg_rows[row]);
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
g_free (dst_row);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Update the screen...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable->id, TRUE);
|
|
|
|
gimp_drawable_update (drawable->id, sel_x1, sel_y1, sel_width, sel_height);
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'sharpen_dialog()' - Popup a dialog window for the filter box size...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gint
|
2000-01-08 23:23:28 +08:00
|
|
|
sharpen_dialog (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
GtkWidget *dialog;
|
2000-02-04 23:12:17 +08:00
|
|
|
GtkWidget *vbox;
|
2000-01-15 23:32:28 +08:00
|
|
|
GtkWidget *table;
|
2000-02-04 23:12:17 +08:00
|
|
|
GtkWidget *abox;
|
2000-01-15 23:32:28 +08:00
|
|
|
GtkWidget *ptable;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *scrollbar;
|
|
|
|
GtkObject *adj;
|
2000-05-02 04:22:55 +08:00
|
|
|
gchar *title;
|
2000-01-15 23:32:28 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_ui_init ("sharpen", TRUE);
|
2000-01-08 23:23:28 +08:00
|
|
|
|
|
|
|
title = g_strdup_printf (_("Sharpen - %s"), PLUG_IN_VERSION);
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
dialog = gimp_dialog_new (title, "sharpen",
|
2000-05-23 01:10:28 +08:00
|
|
|
gimp_standard_help_func, "filters/sharpen.html",
|
2000-01-08 23:23:28 +08:00
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, TRUE, FALSE,
|
|
|
|
|
|
|
|
_("OK"), dialog_ok_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
|
|
|
_("Cancel"), gtk_widget_destroy,
|
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
g_free (title);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT(dialog), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_main_quit),
|
|
|
|
NULL);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Top-level table for dialog...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-02-04 23:12:17 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
/*
|
|
|
|
* Preview window...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-02-04 23:12:17 +08:00
|
|
|
frame = gtk_frame_new (_("Preview"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
ptable = gtk_table_new (2, 2, FALSE);
|
2000-02-04 23:12:17 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (abox), ptable);
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_show (ptable);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_table_attach (GTK_TABLE (ptable), frame, 0, 1, 0, 1, 0, 0, 0, 0);
|
|
|
|
gtk_widget_show (frame);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
preview_width = MIN (sel_width, PREVIEW_SIZE);
|
|
|
|
preview_height = MIN (sel_height, PREVIEW_SIZE);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (preview), preview_width, preview_height);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
|
|
|
gtk_widget_show (preview);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
hscroll_data = gtk_adjustment_new (0, 0, sel_width - 1, 1.0,
|
|
|
|
MIN (preview_width, sel_width),
|
|
|
|
MIN (preview_width, sel_width));
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_signal_connect (hscroll_data, "value_changed",
|
|
|
|
(GtkSignalFunc) preview_scroll_callback,
|
|
|
|
NULL);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (hscroll_data));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
|
|
|
|
gtk_table_attach (GTK_TABLE (ptable), scrollbar, 0, 1, 1, 2,
|
|
|
|
GTK_FILL, 0, 0, 0);
|
|
|
|
gtk_widget_show (scrollbar);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
vscroll_data = gtk_adjustment_new (0, 0, sel_height - 1, 1.0,
|
|
|
|
MIN (preview_height, sel_height),
|
|
|
|
MIN (preview_height, sel_height));
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_signal_connect (vscroll_data, "value_changed",
|
2000-05-02 04:22:55 +08:00
|
|
|
GTK_SIGNAL_FUNC (preview_scroll_callback),
|
2000-01-08 23:23:28 +08:00
|
|
|
NULL);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
scrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (vscroll_data));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
|
|
|
|
gtk_table_attach (GTK_TABLE (ptable), scrollbar, 1, 2, 0, 1,
|
|
|
|
0, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (scrollbar);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
preview_init ();
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
/*
|
|
|
|
* Sharpness control...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-02-04 23:12:17 +08:00
|
|
|
frame = gtk_frame_new (_("Parameter Settings"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
table = gtk_table_new (1, 3, FALSE);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2000-01-15 23:32:28 +08:00
|
|
|
_("Sharpness:"), SCALE_WIDTH, 0,
|
|
|
|
sharpen_percent, 1, 99, 1, 10, 0,
|
2000-02-04 23:12:17 +08:00
|
|
|
TRUE, 0, 0,
|
2000-01-15 23:32:28 +08:00
|
|
|
NULL, NULL);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
|
|
|
GTK_SIGNAL_FUNC (dialog_iscale_update),
|
|
|
|
&sharpen_percent);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_show (dialog);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
preview_update ();
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_main ();
|
|
|
|
gdk_flush ();
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
preview_exit ();
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
return run_filter;
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/* preview functions */
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
static void
|
2000-02-04 23:12:17 +08:00
|
|
|
preview_init (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
gint width; /* Byte width of the image */
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/*
|
|
|
|
* Setup for preview filter...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
1998-04-28 06:01:01 +08:00
|
|
|
compute_luts();
|
|
|
|
|
1998-04-24 10:18:52 +08:00
|
|
|
width = preview_width * img_bpp;
|
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
preview_src = g_new (guchar, width * preview_height);
|
|
|
|
preview_neg = g_new (intneg, width * preview_height);
|
|
|
|
preview_dst = g_new (guchar, width * preview_height);
|
|
|
|
preview_image = g_new (guchar, preview_width * preview_height * 3);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
preview_x1 = sel_x1;
|
|
|
|
preview_y1 = sel_y1;
|
|
|
|
preview_x2 = preview_x1 + preview_width;
|
|
|
|
preview_y2 = preview_y1 + preview_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
preview_scroll_callback (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-05-02 04:22:55 +08:00
|
|
|
preview_x1 = sel_x1 + GTK_ADJUSTMENT (hscroll_data)->value;
|
|
|
|
preview_y1 = sel_y1 + GTK_ADJUSTMENT (vscroll_data)->value;
|
|
|
|
preview_x2 = preview_x1 + MIN (preview_width, sel_width);
|
|
|
|
preview_y2 = preview_y1 + MIN (preview_height, sel_height);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
preview_update ();
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
preview_update (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPixelRgn src_rgn; /* Source image region */
|
1998-04-24 10:18:52 +08:00
|
|
|
guchar *src_ptr, /* Current source pixel */
|
|
|
|
*dst_ptr, /* Current destination pixel */
|
1999-03-16 06:38:36 +08:00
|
|
|
*image_ptr; /* Current image pixel */
|
|
|
|
intneg *neg_ptr; /* Current negative pixel */
|
1998-04-24 10:18:52 +08:00
|
|
|
guchar check; /* Current check mark pixel */
|
2000-05-02 04:22:55 +08:00
|
|
|
gint i, /* Looping var */
|
1998-04-24 10:18:52 +08:00
|
|
|
x, y, /* Current location in image */
|
1998-04-28 06:01:01 +08:00
|
|
|
width; /* Byte width of the image */
|
1999-03-16 06:38:36 +08:00
|
|
|
void (*filter)(int, guchar *, guchar *, intneg *, intneg *, intneg *);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
filter = NULL;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Setup for filter...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
|
|
|
preview_x1, preview_y1, preview_width, preview_height,
|
|
|
|
FALSE, FALSE);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
width = preview_width * img_bpp;
|
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Load the preview area...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_pixel_rgn_get_rect (&src_rgn, preview_src, preview_x1, preview_y1,
|
|
|
|
preview_width, preview_height);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
1998-04-28 06:01:01 +08:00
|
|
|
for (i = width * preview_height, src_ptr = preview_src, neg_ptr = preview_neg;
|
|
|
|
i > 0;
|
|
|
|
i --)
|
|
|
|
*neg_ptr++ = neg_lut[*src_ptr++];
|
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Select the filter...
|
|
|
|
*/
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
switch (img_bpp)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
filter = gray_filter;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
filter = graya_filter;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
filter = rgb_filter;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
filter = rgba_filter;
|
|
|
|
break;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Sharpen...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
memcpy (preview_dst, preview_src, width);
|
|
|
|
memcpy (preview_dst + width * (preview_height - 1),
|
|
|
|
preview_src + width * (preview_height - 1),
|
|
|
|
width);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
1998-04-28 06:01:01 +08:00
|
|
|
for (y = preview_height - 2, src_ptr = preview_src + width,
|
|
|
|
neg_ptr = preview_neg + width + img_bpp,
|
|
|
|
dst_ptr = preview_dst + width;
|
|
|
|
y > 0;
|
|
|
|
y --, src_ptr += width, neg_ptr += width, dst_ptr += width)
|
|
|
|
(*filter)(preview_width, src_ptr, dst_ptr, neg_ptr - width,
|
|
|
|
neg_ptr, neg_ptr + width);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Fill the preview image buffer...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
switch (img_bpp)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
for (x = preview_width * preview_height, dst_ptr = preview_dst,
|
|
|
|
image_ptr = preview_image;
|
|
|
|
x > 0;
|
|
|
|
x --, dst_ptr ++, image_ptr += 3)
|
|
|
|
image_ptr[0] = image_ptr[1] = image_ptr[2] = *dst_ptr;
|
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
case 2:
|
|
|
|
for (y = preview_height, dst_ptr = preview_dst,
|
|
|
|
image_ptr = preview_image;
|
|
|
|
y > 0;
|
|
|
|
y --)
|
|
|
|
for (x = preview_width;
|
|
|
|
x > 0;
|
|
|
|
x --, dst_ptr += 2, image_ptr += 3)
|
|
|
|
if (dst_ptr[1] == 255)
|
|
|
|
image_ptr[0] = image_ptr[1] = image_ptr[2] = *dst_ptr;
|
|
|
|
else
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
if ((y & GIMP_CHECK_SIZE) ^ (x & GIMP_CHECK_SIZE))
|
|
|
|
check = GIMP_CHECK_LIGHT * 255;
|
1998-04-24 10:18:52 +08:00
|
|
|
else
|
2000-01-15 23:32:28 +08:00
|
|
|
check = GIMP_CHECK_DARK * 255;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
if (dst_ptr[1] == 0)
|
|
|
|
image_ptr[0] = image_ptr[1] = image_ptr[2] = check;
|
|
|
|
else
|
|
|
|
image_ptr[0] = image_ptr[1] = image_ptr[2] =
|
2000-05-02 04:22:55 +08:00
|
|
|
check + ((dst_ptr[0] - check) * dst_ptr[1]) / 255;
|
1998-06-07 07:22:22 +08:00
|
|
|
};
|
2000-05-02 04:22:55 +08:00
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
case 3:
|
|
|
|
memcpy (preview_image, preview_dst, preview_width * preview_height * 3);
|
|
|
|
break;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
case 4:
|
|
|
|
for (y = preview_height, dst_ptr = preview_dst,
|
|
|
|
image_ptr = preview_image;
|
|
|
|
y > 0;
|
|
|
|
y --)
|
|
|
|
for (x = preview_width;
|
|
|
|
x > 0;
|
|
|
|
x --, dst_ptr += 4, image_ptr += 3)
|
|
|
|
if (dst_ptr[3] == 255)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
|
|
|
image_ptr[0] = dst_ptr[0];
|
|
|
|
image_ptr[1] = dst_ptr[1];
|
|
|
|
image_ptr[2] = dst_ptr[2];
|
|
|
|
}
|
2000-05-02 04:22:55 +08:00
|
|
|
else
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
if ((y & GIMP_CHECK_SIZE) ^ (x & GIMP_CHECK_SIZE))
|
|
|
|
check = GIMP_CHECK_LIGHT * 255;
|
1998-04-24 10:18:52 +08:00
|
|
|
else
|
2000-01-15 23:32:28 +08:00
|
|
|
check = GIMP_CHECK_DARK * 255;
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
if (dst_ptr[3] == 0)
|
|
|
|
image_ptr[0] = image_ptr[1] = image_ptr[2] = check;
|
|
|
|
else
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
image_ptr[0] =
|
|
|
|
check + ((dst_ptr[0] - check) * dst_ptr[3]) / 255;
|
|
|
|
image_ptr[1] =
|
|
|
|
check + ((dst_ptr[1] - check) * dst_ptr[3]) / 255;
|
|
|
|
image_ptr[2] =
|
|
|
|
check + ((dst_ptr[2] - check) * dst_ptr[3]) / 255;
|
|
|
|
};
|
1998-06-07 07:22:22 +08:00
|
|
|
};
|
2000-05-02 04:22:55 +08:00
|
|
|
break;
|
|
|
|
};
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
/*
|
|
|
|
* Draw the preview image on the screen...
|
|
|
|
*/
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
for (y = 0, image_ptr = preview_image;
|
|
|
|
y < preview_height;
|
|
|
|
y ++, image_ptr += preview_width * 3)
|
2000-05-02 04:22:55 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (preview), image_ptr, 0, y,
|
|
|
|
preview_width);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gtk_widget_draw (preview, NULL);
|
|
|
|
gdk_flush ();
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
preview_exit (void)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
g_free (preview_src);
|
|
|
|
g_free (preview_neg);
|
|
|
|
g_free (preview_dst);
|
|
|
|
g_free (preview_image);
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
/* dialog callbacks */
|
1998-04-24 10:18:52 +08:00
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
dialog_iscale_update (GtkAdjustment *adjustment,
|
|
|
|
gint *value)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
2000-01-15 23:32:28 +08:00
|
|
|
gimp_int_adjustment_update (adjustment, value);
|
1998-04-24 10:18:52 +08:00
|
|
|
|
2000-01-15 23:32:28 +08:00
|
|
|
compute_luts ();
|
|
|
|
preview_update ();
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
dialog_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-04-24 10:18:52 +08:00
|
|
|
{
|
|
|
|
run_filter = TRUE;
|
|
|
|
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
1998-04-24 10:18:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-28 06:01:01 +08:00
|
|
|
/*
|
|
|
|
* 'gray_filter()' - Sharpen grayscale pixels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-01-15 23:32:28 +08:00
|
|
|
gray_filter (gint width, /* I - Width of line in pixels */
|
|
|
|
guchar *src, /* I - Source line */
|
|
|
|
guchar *dst, /* O - Destination line */
|
|
|
|
intneg *neg0, /* I - Top negative coefficient line */
|
|
|
|
intneg *neg1, /* I - Middle negative coefficient line */
|
|
|
|
intneg *neg2) /* I - Bottom negative coefficient line */
|
1998-04-28 06:01:01 +08:00
|
|
|
{
|
1999-03-16 06:38:36 +08:00
|
|
|
intpos pixel; /* New pixel value */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
width -= 2;
|
|
|
|
|
|
|
|
while (width > 0)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-1] - neg0[0] - neg0[1] -
|
|
|
|
neg1[-1] - neg1[1] -
|
|
|
|
neg2[-1] - neg2[0] - neg2[1]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
neg0 ++;
|
|
|
|
neg1 ++;
|
|
|
|
neg2 ++;
|
|
|
|
width --;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'graya_filter()' - Sharpen grayscale+alpha pixels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-05-02 04:22:55 +08:00
|
|
|
graya_filter (gint width, /* I - Width of line in pixels */
|
|
|
|
guchar *src, /* I - Source line */
|
|
|
|
guchar *dst, /* O - Destination line */
|
|
|
|
intneg *neg0, /* I - Top negative coefficient line */
|
|
|
|
intneg *neg1, /* I - Middle negative coefficient line */
|
|
|
|
intneg *neg2) /* I - Bottom negative coefficient line */
|
1998-04-28 06:01:01 +08:00
|
|
|
{
|
1999-03-16 06:38:36 +08:00
|
|
|
intpos pixel; /* New pixel value */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
width -= 2;
|
|
|
|
|
|
|
|
while (width > 0)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-2] - neg0[0] - neg0[2] -
|
|
|
|
neg1[-2] - neg1[2] -
|
|
|
|
neg2[-2] - neg2[0] - neg2[2]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
neg0 += 2;
|
|
|
|
neg1 += 2;
|
|
|
|
neg2 += 2;
|
|
|
|
width --;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'rgb_filter()' - Sharpen RGB pixels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-05-02 04:22:55 +08:00
|
|
|
rgb_filter (gint width, /* I - Width of line in pixels */
|
|
|
|
guchar *src, /* I - Source line */
|
|
|
|
guchar *dst, /* O - Destination line */
|
|
|
|
intneg *neg0, /* I - Top negative coefficient line */
|
|
|
|
intneg *neg1, /* I - Middle negative coefficient line */
|
|
|
|
intneg *neg2) /* I - Bottom negative coefficient line */
|
1998-04-28 06:01:01 +08:00
|
|
|
{
|
1999-03-16 06:38:36 +08:00
|
|
|
intpos pixel; /* New pixel value */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
width -= 2;
|
|
|
|
|
|
|
|
while (width > 0)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-3] - neg0[0] - neg0[3] -
|
|
|
|
neg1[-3] - neg1[3] -
|
|
|
|
neg2[-3] - neg2[0] - neg2[3]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-2] - neg0[1] - neg0[4] -
|
|
|
|
neg1[-2] - neg1[4] -
|
|
|
|
neg2[-2] - neg2[1] - neg2[4]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-1] - neg0[2] - neg0[5] -
|
|
|
|
neg1[-1] - neg1[5] -
|
|
|
|
neg2[-1] - neg2[2] - neg2[5]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
neg0 += 3;
|
|
|
|
neg1 += 3;
|
|
|
|
neg2 += 3;
|
|
|
|
width --;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'rgba_filter()' - Sharpen RGBA pixels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-05-02 04:22:55 +08:00
|
|
|
rgba_filter (gint width, /* I - Width of line in pixels */
|
|
|
|
guchar *src, /* I - Source line */
|
|
|
|
guchar *dst, /* O - Destination line */
|
|
|
|
intneg *neg0, /* I - Top negative coefficient line */
|
|
|
|
intneg *neg1, /* I - Middle negative coefficient line */
|
|
|
|
intneg *neg2) /* I - Bottom negative coefficient line */
|
1998-04-28 06:01:01 +08:00
|
|
|
{
|
1999-03-16 06:38:36 +08:00
|
|
|
intpos pixel; /* New pixel value */
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
width -= 2;
|
|
|
|
|
|
|
|
while (width > 0)
|
2000-05-02 04:22:55 +08:00
|
|
|
{
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-4] - neg0[0] - neg0[4] -
|
|
|
|
neg1[-4] - neg1[4] -
|
|
|
|
neg2[-4] - neg2[0] - neg2[4]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-3] - neg0[1] - neg0[5] -
|
|
|
|
neg1[-3] - neg1[5] -
|
|
|
|
neg2[-3] - neg2[1] - neg2[5]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
pixel = (pos_lut[*src++] - neg0[-2] - neg0[2] - neg0[6] -
|
|
|
|
neg1[-2] - neg1[6] -
|
|
|
|
neg2[-2] - neg2[2] - neg2[6]);
|
|
|
|
pixel = (pixel + 4) >> 3;
|
|
|
|
if (pixel < 0)
|
|
|
|
*dst++ = 0;
|
|
|
|
else if (pixel < 255)
|
|
|
|
*dst++ = pixel;
|
|
|
|
else
|
|
|
|
*dst++ = 255;
|
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
|
|
|
|
neg0 += 4;
|
|
|
|
neg1 += 4;
|
|
|
|
neg2 += 4;
|
|
|
|
width --;
|
|
|
|
};
|
1998-04-28 06:01:01 +08:00
|
|
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|