version number bump to 1.1.6

* configure.in: version number bump to 1.1.6

* added unsharp plug-in

* app/indicator_area.c
* app/main.c
* app/menus.c
* app/paint_core.c: minor cleanups

* plug-ins/wmf/wmf.c: s/memmove/g_memmove/

* tools/pdbgen/lib.pl: formatting changes, still unfinished

-Yosh
This commit is contained in:
Manish Singh 1999-06-05 02:11:16 +00:00
parent 022333d337
commit db54371de7
22 changed files with 2172 additions and 83 deletions

View File

@ -1,3 +1,18 @@
Fri Jun 4 19:00:12 PDT 1999 Manish Singh <yosh@gimp.org>
* configure.in: version number bump to 1.1.6
* added unsharp plug-in
* app/indicator_area.c
* app/main.c
* app/menus.c
* app/paint_core.c: minor cleanups
* plug-ins/wmf/wmf.c: s/memmove/g_memmove/
* tools/pdbgen/lib.pl: formatting changes, still unfinished
Sat Jun 5 02:17:02 MEST 1999 Sven Neumann <sven@gimp.org>
* plug-ins/screenshot/screenshot.c: I still don't know why this guy

View File

@ -270,7 +270,7 @@ pattern_area_update()
*b++ = *s++;
*b++ = *s++;
}
gtk_preview_draw_row (pattern_preview,
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview),
buffer,
offset_x, i, width);

View File

@ -404,7 +404,7 @@ menus_destroy (char *path)
}
void
menus_quit ()
menus_quit (void)
{
gchar *filename;
@ -437,7 +437,7 @@ menus_last_opened_cmd_callback (GtkWidget *widget,
}
void
menus_last_opened_update_labels ()
menus_last_opened_update_labels (void)
{
GSList *filename_slist;
GString *entry_filename, *path;
@ -560,7 +560,7 @@ menus_init_mru (void)
}
void
menus_init_toolbox ()
menus_init_toolbox (void)
{
GtkItemFactoryEntry *translated_entries;

View File

@ -270,7 +270,7 @@ pattern_area_update()
*b++ = *s++;
*b++ = *s++;
}
gtk_preview_draw_row (pattern_preview,
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview),
buffer,
offset_x, i, width);

View File

@ -118,8 +118,8 @@ main (int argc, char **argv)
/* Initialize Gtk toolkit */
gtk_set_locale ();
setlocale(LC_NUMERIC, "C"); /* must use dot, not comma, as decimal separator */
/* Initialize i18n support */
/* Initialize i18n support */
#ifdef HAVE_LC_MESSAGES
setlocale(LC_MESSAGES, "");
#endif
@ -128,10 +128,6 @@ main (int argc, char **argv)
gtk_init (&argc, &argv);
#ifdef HAVE_LIBGLE
gle_init (&argc, &argv);
#endif /* !HAVE_LIBGLE */
#ifdef HAVE_PUTENV
display_name = gdk_get_display ();
display_env = g_new (gchar, strlen (display_name) + 9);
@ -145,18 +141,20 @@ main (int argc, char **argv)
no_data = FALSE;
no_splash = FALSE;
no_splash_image = FALSE;
#if defined (HAVE_SHM_H) || defined (NATIVE_WIN32)
use_shm = TRUE;
#else
use_shm = FALSE;
#endif
use_debug_handler = FALSE;
restore_session = FALSE;
console_messages = FALSE;
message_handler = CONSOLE;
batch_cmds = g_new (char*, argc);
batch_cmds = g_new (char *, argc);
batch_cmds[0] = NULL;
alternate_gimprc = NULL;
@ -165,7 +163,7 @@ main (int argc, char **argv)
show_version = FALSE;
show_help = FALSE;
test_gserialize();
test_gserialize ();
for (i = 1; i < argc; i++)
{
@ -341,10 +339,8 @@ main (int argc, char **argv)
signal (SIGCHLD, on_sig_child);
#endif
g_log_set_handler(NULL,
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
on_error,
NULL);
g_log_set_handler (NULL, G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
on_error, NULL);
/* Keep the command line arguments--for use in gimp_init */
gimp_argc = argc - 1;
@ -379,7 +375,7 @@ WinMain (int hInstance, int hPrevInstance, char *lpszCmdLine, int nCmdShow)
#endif
static void
init ()
init (void)
{
/* Continue initializing */
gimp_init (gimp_argc, gimp_argv);
@ -387,13 +383,13 @@ init ()
static void
on_error (const gchar* domain,
GLogLevelFlags flags,
const gchar* msg,
gpointer user_data){
fprintf(stderr, "%s: fatal error: %s\n",
prog_name, msg);
g_on_error_query(prog_name);
on_error (const gchar *domain,
GLogLevelFlags flags,
const gchar *msg,
gpointer user_data)
{
fprintf(stderr, "%s: fatal error: %s\n", prog_name, msg);
g_on_error_query(prog_name);
}
static int caught_fatal_sig = 0;
@ -487,13 +483,14 @@ typedef struct
guint16 *test_array;
} test_struct;
static void test_gserialize()
static void
test_gserialize (void)
{
GSerialDescription *test_struct_descript;
test_struct *ts, *to;
char ser_1[] = {3, 1, 2, 3, 4, 4, 64, 83, 51, 51, 101, 0, 0, 0, 4, 102, 111, 111, 0, 103, 0, 0, 0, 2, 5, 6, 7, 8 };
ts = g_malloc(sizeof(test_struct));
to = g_malloc(sizeof(test_struct));
ts = g_new (test_struct, 1);
to = g_new (test_struct, 1);
test_struct_descript
= g_new_serial_description("test_struct",
g_serial_item(GSERIAL_INT32,
@ -516,11 +513,11 @@ static void test_gserialize()
ts->test_float = 3.3f;
ts->test_string = "foo";
ts->test_length = 2;
ts->test_array = g_malloc(sizeof(short) *2);
ts->test_array = g_new (guint16, 2);
ts->test_array[0] = 0x0506;
ts->test_array[1] = 0x0708;
g_deserialize(test_struct_descript, (char *)(void*)to, ser_1);
g_deserialize (test_struct_descript, (char *)(void*)to, ser_1);
#define EPSILON .0001

View File

@ -404,7 +404,7 @@ menus_destroy (char *path)
}
void
menus_quit ()
menus_quit (void)
{
gchar *filename;
@ -437,7 +437,7 @@ menus_last_opened_cmd_callback (GtkWidget *widget,
}
void
menus_last_opened_update_labels ()
menus_last_opened_update_labels (void)
{
GSList *filename_slist;
GString *entry_filename, *path;
@ -560,7 +560,7 @@ menus_init_mru (void)
}
void
menus_init_toolbox ()
menus_init_toolbox (void)
{
GtkItemFactoryEntry *translated_entries;

View File

@ -404,7 +404,7 @@ menus_destroy (char *path)
}
void
menus_quit ()
menus_quit (void)
{
gchar *filename;
@ -437,7 +437,7 @@ menus_last_opened_cmd_callback (GtkWidget *widget,
}
void
menus_last_opened_update_labels ()
menus_last_opened_update_labels (void)
{
GSList *filename_slist;
GString *entry_filename, *path;
@ -560,7 +560,7 @@ menus_init_mru (void)
}
void
menus_init_toolbox ()
menus_init_toolbox (void)
{
GtkItemFactoryEntry *translated_entries;

View File

@ -342,7 +342,7 @@ paint_core_cursor_update (Tool *tool,
gdisplay_untransform_coords (gdisp, (double) mevent->x, (double) mevent->y,
&x, &y, TRUE, FALSE);
if (layer = gimage_get_active_layer (gdisp->gimage))
if ((layer = gimage_get_active_layer (gdisp->gimage)))
{
/* If Ctrl or Mod1 is pressed, pick colors */
if (paint_core->pick_colors

View File

@ -342,7 +342,7 @@ paint_core_cursor_update (Tool *tool,
gdisplay_untransform_coords (gdisp, (double) mevent->x, (double) mevent->y,
&x, &y, TRUE, FALSE);
if (layer = gimage_get_active_layer (gdisp->gimage))
if ((layer = gimage_get_active_layer (gdisp->gimage)))
{
/* If Ctrl or Mod1 is pressed, pick colors */
if (paint_core->pick_colors

View File

@ -404,7 +404,7 @@ menus_destroy (char *path)
}
void
menus_quit ()
menus_quit (void)
{
gchar *filename;
@ -437,7 +437,7 @@ menus_last_opened_cmd_callback (GtkWidget *widget,
}
void
menus_last_opened_update_labels ()
menus_last_opened_update_labels (void)
{
GSList *filename_slist;
GString *entry_filename, *path;
@ -560,7 +560,7 @@ menus_init_mru (void)
}
void
menus_init_toolbox ()
menus_init_toolbox (void)
{
GtkItemFactoryEntry *translated_entries;

View File

@ -270,7 +270,7 @@ pattern_area_update()
*b++ = *s++;
*b++ = *s++;
}
gtk_preview_draw_row (pattern_preview,
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview),
buffer,
offset_x, i, width);

View File

@ -4,7 +4,7 @@ AC_INIT(gimprc.in)
dnl Initialize automake stuff
GIMP_MAJOR_VERSION=1
GIMP_MINOR_VERSION=1
GIMP_MICRO_VERSION=5
GIMP_MICRO_VERSION=6
GIMP_INTERFACE_AGE=0
GIMP_BINARY_AGE=0
GIMP_VERSION=$GIMP_MAJOR_VERSION.$GIMP_MINOR_VERSION.$GIMP_MICRO_VERSION
@ -794,6 +794,7 @@ plug-ins/threshold_alpha/Makefile
plug-ins/tile/Makefile
plug-ins/tileit/Makefile
plug-ins/tiler/Makefile
plug-ins/unsharp/Makefile
plug-ins/url/Makefile
plug-ins/video/Makefile
plug-ins/vinvert/Makefile

View File

@ -135,6 +135,7 @@ SUBDIRS = \
tile \
tileit \
tiler \
unsharp \
url \
video \
vinvert \

895
plug-ins/common/unsharp.c Normal file
View File

@ -0,0 +1,895 @@
/*
* unsharp.c 0.5 -- This is a plug-in for the GIMP 1.0
* http://www.steppe.com/~winston/gimp/unsharp.html
*
* Copyright (C) 1999 Winston Chang
* <wchang3@students.wisc.edu>
* <winston@steppe.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.
*/
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "libgimp/gimp.h"
#include "gtk/gtk.h"
#include "dialog_f.h"
#define PLUG_IN_VERSION "0.5 - 1999/6/2"
/* to show both pretty unoptimized code and ugly optimized code blocks
There's really no reason to define this, unless you want to see how
much pointer aritmetic can speed things up. I find that it is about
45% faster with the optimized code. */
/* #define READABLE_CODE */
/* uncomment this line to get a rough feel of how long the
plug-in takes to run */
/* #define TIMER */
#ifdef TIMER
# include <sys/time.h>
# include <unistd.h>
static void timerstart();
static void timerstop();
static struct timeval time_start,time_stop;
#endif
typedef struct {
gdouble radius;
gdouble amount;
gdouble threshold;
} UnsharpMaskParams;
typedef struct {
gint run;
} UnsharpMaskInterface;
/* local function prototypes */
static inline void blur_line(gdouble* ctable, gdouble* cmatrix, gint cmatrix_length,
guchar* cur_col, guchar* dest_col,
gint y, glong bytes);
static int gen_convolve_matrix(double std_dev, double** cmatrix);
static gdouble* gen_lookup_table(gdouble* cmatrix, gint cmatrix_length);
static inline gint round(gdouble i);
static void unsharp_region (GPixelRgn srcPTR, GPixelRgn dstPTR,
gint width, gint height, gint bytes,
gdouble radius, gdouble amount,
gint x1, gint x2, gint y1, gint y2);
static void query(void);
static void run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals);
static void unsharp_mask(GDrawable *drawable, gint radius, gdouble amount);
static void unsharp_cancel_callback (GtkWidget *widget, gpointer data);
static void unsharp_ok_callback (GtkWidget *widget, gpointer data);
static gint unsharp_mask_dialog();
/* preview shit -- not finished yet */
#undef PREVIEW
#ifdef PREVIEW
static void preview_scroll_callback(void);
static void preview_init(void);
static void preview_exit(void);
static void preview_update(void);
static void dialog_create_ivalue(char *title, /* I - Label for control */
GtkTable *table, /* I - Table container to use */
int row, /* I - Row # for container */
gint *value, /* I - Value holder */
int left, /* I - Minimum value for slider */
int right); /* I - Maximum value for slider */
static GtkWidget* preview;
static int preview_width; /* Width of preview widget */
static int preview_height; /* Height of preview widget */
static int preview_x1; /* Upper-left X of preview */
static int preview_y1; /* Upper-left Y of preview */
static int preview_x2; /* Lower-right X of preview */
static int preview_y2; /* Lower-right Y of preview */
static int sel_width; /* Selection width */
static int sel_height; /* Selection height */
static GtkObject *hscroll_data; /* Horizontal scrollbar data */
static GtkObject *vscroll_data; /* Vertical scrollbar data */
#endif
static gint run_filter = FALSE;
/* create a few globals, set default values */
static UnsharpMaskParams unsharp_params =
{
5.0, /* default radius = 5 */
0.5, /* default amount = .5 */
0.0 /* default threshold = 0.0 */
};
/* static UnsharpMaskInterface umint = { FALSE }; */
/* Setting PLUG_IN_INFO */
GPlugInInfo PLUG_IN_INFO = {
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN()
static void query () {
static GParamDef args[] = {
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "(unused)" },
{ PARAM_DRAWABLE, "drawable", "Drawable to draw on" },
{ PARAM_FLOAT, "radius", "Radius of gaussian blur (in pixels > 1.0)" },
{ PARAM_FLOAT, "amount", "Strength of effect." }
};
static gint nargs = sizeof(args) / sizeof(args[0]);
/* for return vals */
static GParamDef *return_vals = NULL;
static int nreturn_vals = 0;
/* Install a procedure in the procedure database. */
gimp_install_procedure ("plug_in_unsharp_mask",
"An unsharp mask filter",
"Long description / help",
"Winston Chang <wchang3@students.wisc.edu>",
"Winston Chang",
"1999",
"<Image>/Filters/Enhance/Unsharp Mask",
"GRAY*, RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
/* this is the actual function */
static void run(char *name, int nparams, GParam *param, int *nreturn_vals,
GParam **return_vals) {
static GParam values[1];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
#ifdef TIMER
timerstart();
#endif
run_mode = param[0].data.d_int32;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
*return_vals = values;
*nreturn_vals = 1;
switch (run_mode) {
case RUN_INTERACTIVE:
gimp_get_data ("plug_in_unsharp_mask", &unsharp_params);
if (! unsharp_mask_dialog ()) return;
break;
case RUN_NONINTERACTIVE:
if (nparams != 4) status = STATUS_CALLING_ERROR;
/* get the parameters */
else if (status == STATUS_SUCCESS) {
unsharp_params.radius = param[3].data.d_float;
unsharp_params.amount = param[4].data.d_float;
}
/* make sure there are legal values */
if (status == STATUS_SUCCESS &&
( (unsharp_params.radius < 0) || (unsharp_params.amount<0) ) )
status = STATUS_CALLING_ERROR;
break;
case RUN_WITH_LAST_VALS:
gimp_get_data ("plug_in_unsharp_mask", &unsharp_params);
break;
default:
break;
}
if (status == STATUS_SUCCESS) {
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_tile_cache_ntiles(2 * (drawable->width / gimp_tile_width() + 1));
/* here we go */
unsharp_mask(drawable, unsharp_params.radius, unsharp_params.amount);
/* values[0].data.d_status = status; */
gimp_displays_flush ();
/* set data for next use of filter */
gimp_set_data ("plug_in_unsharp_mask", &unsharp_params,
sizeof (UnsharpMaskParams));
/*fprintf(stderr, "%f %f\n", unsharp_params.radius, unsharp_params.amount);*/
gimp_drawable_detach(drawable);
values[0].data.d_status = status;
}
#ifdef TIMER
timerstop();
#endif
}
/* -------------------------- Unsharp Mask ------------------------- */
static void unsharp_mask(GDrawable *drawable, gint radius, gdouble amount) {
GPixelRgn srcPR, destPR;
glong width, height;
glong bytes;
gint x1, y1, x2, y2;
gdouble* cmatrix = NULL;
gint cmatrix_length;
gdouble* ctable;
/* Get the input */
gimp_drawable_mask_bounds(drawable->id, &x1, &y1, &x2, &y2);
gimp_progress_init("Blurring...");
/* generate convolution matrix */
cmatrix_length = gen_convolve_matrix(radius, &cmatrix);
/* generate lookup table */
ctable = gen_lookup_table(cmatrix, cmatrix_length);
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
/* initialize pixel regions */
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
unsharp_region (srcPR, destPR, width, height, bytes, radius, amount,
x1, x2, y1, y2);
#ifdef PIMPDADDY
/* allocate row, col buffers */
cur_row = (guchar *) g_malloc ((x2 - x1) * bytes);
dest_row = (guchar *) g_malloc ((x2 - x1) * bytes);
cur_col = (guchar *) g_malloc ((y2 - y1) * bytes);
dest_col = (guchar *) g_malloc ((y2 - y1) * bytes);
/* set height and width */
x = x2-x1;
y = y2-y1;
/* blank out a region of the destination memory area, I think */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, (x2-x1));
memset(dest_row, 0, x*bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, (x2-x1));
}
/* blur the rows */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
blur_line(ctable, cmatrix, cmatrix_length, cur_row, dest_row, x, bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y));
}
/* blur the cols */
for (col = 0; col < x; col++) {
gimp_pixel_rgn_get_col(&destPR, cur_col, x1+col, y1, y);
gimp_pixel_rgn_get_col(&destPR, dest_col, x1+col, y1, y);
blur_line(ctable, cmatrix, cmatrix_length, cur_col, dest_col, y, bytes);
gimp_pixel_rgn_set_col(&destPR, dest_col, x1+col, y1, y);
if (col%5 == 0) gimp_progress_update((gdouble)col/(3*x) + 0.33);
}
gimp_progress_init("Merging...");
for (row = 0; row < y; row++) {
int value = 0;
int u,v;
/* get source row */
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
/* get dest row */
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
/* combine the two */
for (u=0;u<x;u++) {
for (v=0; v<bytes; v++) {
value = cur_row[u*bytes+v] +
amount * (cur_row[u*bytes+v] - dest_row[u*bytes+v]);
if (value < 0) dest_row[u*bytes+v] =0;
else if (value > 255) dest_row[u*bytes+v] = 255;
else dest_row[u*bytes+v] = value;
}
}
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y) + 0.67);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
}
/* free the memory we took */
g_free(cur_row);
g_free(dest_row);
g_free(cur_col);
g_fre(dest_col);
#endif
gimp_drawable_flush(drawable);
gimp_drawable_merge_shadow(drawable->id, TRUE);
gimp_drawable_update(drawable->id, x1, y1, (x2-x1), (y2-y1));
}
/* perform an unsharp mask on the region, given a source region, dest.
region, width and height of the regions, and corner coordinates of
a subregion to act upon. Everything outside the subregion is unaffected.
*/
static void unsharp_region (GPixelRgn srcPR, GPixelRgn destPR,
gint width, gint height, gint bytes,
gdouble radius, gdouble amount,
gint x1, gint x2, gint y1, gint y2) {
guchar* cur_col;
guchar* dest_col;
guchar* cur_row;
guchar* dest_row;
gint x;
gint y;
gdouble* cmatrix = NULL;
gint cmatrix_length;
gdouble* ctable;
gint row, col; /* these are counters for loops */
/* these are used for the merging step */
gint threshold;
gint diff;
gint value;
gint u,v;
/* generate convolution matrix */
cmatrix_length = gen_convolve_matrix(radius, &cmatrix);
/* generate lookup table */
ctable = gen_lookup_table(cmatrix, cmatrix_length);
/* allocate row, col buffers */
cur_row = (guchar *) g_malloc ((x2 - x1) * bytes);
dest_row = (guchar *) g_malloc ((x2 - x1) * bytes);
/* find height and width of subregion to act on */
x = x2-x1;
y = y2-y1;
/* blank out a region of the destination memory area, I think */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, (x2-x1));
memset(dest_row, 0, x*bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, (x2-x1));
}
/* blur the rows */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
blur_line(ctable, cmatrix, cmatrix_length, cur_row, dest_row, x, bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y));
}
/* allocate column buffers */
cur_col = (guchar *) g_malloc ((y2 - y1) * bytes);
dest_col = (guchar *) g_malloc ((y2 - y1) * bytes);
/* blur the cols */
for (col = 0; col < x; col++) {
gimp_pixel_rgn_get_col(&destPR, cur_col, x1+col, y1, y);
gimp_pixel_rgn_get_col(&destPR, dest_col, x1+col, y1, y);
blur_line(ctable, cmatrix, cmatrix_length, cur_col, dest_col, y, bytes);
gimp_pixel_rgn_set_col(&destPR, dest_col, x1+col, y1, y);
if (col%5 == 0) gimp_progress_update((gdouble)col/(3*x) + 0.33);
}
gimp_progress_init("Merging...");
/* find integer value of threshold */
threshold = round( unsharp_params.threshold * 255.0 );
/* merge the source and destination images */
for (row = 0; row < y; row++) {
value = 0;
/* get source row */
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
/* get dest row */
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
/* combine the two */
for (u=0;u<x;u++) {
for (v=0; v<bytes; v++) {
diff = (cur_row[u*bytes+v] - dest_row[u*bytes+v]);
/* do tresholding */
if (diff > threshold) diff = diff - threshold;
else if (diff < -threshold) diff = diff + threshold;
else diff = 0;
value = cur_row[u*bytes+v] + amount * diff;
if (value < 0) dest_row[u*bytes+v] =0;
else if (value > 255) dest_row[u*bytes+v] = 255;
else dest_row[u*bytes+v] = value;
}
}
/* update progress bar every five rows */
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y) + 0.67);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
}
/* free the memory we took */
g_free(cur_row);
g_free(dest_row);
g_free(cur_col);
g_free(dest_col);
}
/* this function is written as if it is blurring a column at a time,
even though it can operate on rows, too. There is no difference
in the processing of the lines, at least to the blur_line function. */
static inline void blur_line(gdouble* ctable, gdouble* cmatrix,
gint cmatrix_length,
guchar* cur_col, guchar* dest_col,
gint y, glong bytes) {
#ifdef READABLE_CODE
/* ------------- semi-readable code ------------------- */
gdouble scale;
gdouble sum;
gint i,j;
gint row;
/* for the edge condition, we only use available info, and scale to one */
for (row = 0; row < cmatrix_length/2; row++) {
/* find scale factor */
scale=0;
for (j = cmatrix_length/2 - row; j<cmatrix_length; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = cmatrix_length/2 - row; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
/* go through each pixel in each col */
for ( ; row < y-cmatrix_length/2; row++) {
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum);
}
}
/* for the edge condition , we only use available info, and scale to one */
for ( ; row < y; row++) {
/* find scale factor */
scale=0;
for (j = 0; j< y-row + cmatrix_length/2; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<y-row + cmatrix_length/2; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
#endif
#ifndef READABLE_CODE
/* --------------- optimized, unreadable code -------------------*/
gdouble scale;
gdouble sum;
gint i=0, j=0;
gint row;
gint cmatrix_middle = cmatrix_length/2;
gdouble *cmatrix_p;
guchar *cur_col_p;
guchar *cur_col_p1;
guchar *dest_col_p;
gdouble *ctable_p;
/* for the edge condition, we only use available info and scale to one */
for (row = 0; row < cmatrix_middle; row++) {
/* find scale factor */
scale=0;
for (j = cmatrix_middle - row; j<cmatrix_length; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = cmatrix_middle - row; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_middle)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
/* go through each pixel in each col */
dest_col_p = dest_col + row*bytes;
for ( ; row < y-cmatrix_middle; row++) {
cur_col_p = (row - cmatrix_middle) * bytes + cur_col;
for (i = 0; i<bytes; i++) {
sum = 0;
cmatrix_p = cmatrix;
cur_col_p1 = cur_col_p;
ctable_p = ctable;
for (j = cmatrix_length; j>0; j--) {
sum += *(ctable_p + *cur_col_p1);
cur_col_p1 += bytes;
ctable_p += 256; /* * sizeof(gdouble); */
}
cur_col_p++;
*(dest_col_p++) = round(sum);
}
}
/* for the edge condition , we only use available info, and scale to one */
for ( ; row < y; row++) {
/* find scale factor */
scale=0;
for (j = 0; j< y-row + cmatrix_middle; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<y-row + cmatrix_middle; j++) {
sum += cur_col[(row + j-cmatrix_middle)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
#endif
}
static inline gint round(gdouble i) {
return (gint)(i + 0.5);
}
/* generates a 1-D convolution matrix to be used for each pass of
* a two-pass gaussian blur. Returns the length of the matrix.
*/
static gint gen_convolve_matrix(gdouble radius, gdouble** cmatrix_p) {
gint matrix_length;
gint matrix_midpoint;
gdouble* cmatrix;
gint i,j;
gdouble std_dev;
gdouble sum;
/* we want to generate a matrix that goes out a certain radius
* from the center, so we have to go out ceil(rad-0.5) pixels,
* inlcuding the center pixel. Of course, that's only in one direction,
* so we have to go the same amount in the other direction, but not count
* the center pixel again. So we double the previous result and subtract
* one.
* I lifted the formula for getting std_dev from radius from the gauss_rle
* plug-in. No, I don't understand why it is what it is.
*/
radius = fabs(radius) + 1.0;
std_dev = sqrt (-(radius * radius) / (2 * log (1.0 / 255.0)));
/* go out 'radius' in each direction */
matrix_length = 2 * ceil(radius-0.5) + 1;
if (matrix_length <= 0) matrix_length = 1;
matrix_midpoint = matrix_length/2 + 1;
*cmatrix_p = (gdouble*)(malloc(matrix_length * sizeof(gdouble)));
cmatrix = *cmatrix_p;
/* Now we fill the matrix by doing a numeric integration approximation
* from -2*std_dev to 2*std_dev, sampling 50 points per pixel.
* We do the bottom half, mirror it to the top half, then compute the
* center point. Otherwise asymmetric quantization errors will occur.
* The formula to integrate is e^-(x^2/2s^2).
*/
for (i=matrix_length/2 + 1; i<matrix_length; i++) {
double base_x = i - floor(matrix_length/2) - 0.5;
sum = 0;
for (j=1; j<=50; j++) {
if ( base_x+0.02*j <= radius )
sum += exp( -(base_x+0.02*j)*(base_x+0.02*j) /
(2*std_dev*std_dev) );
}
cmatrix[i] = sum/50;
}
/* mirror the thing to the bottom half */
for (i=0; i<=matrix_length/2; i++) {
cmatrix[i] = cmatrix[matrix_length-1-i];
}
/* find center val -- calculate an odd number of quanta to make it symmetric,
* even if the center point is weighted slightly higher than others. */
sum = 0;
for (j=0; j<=50; j++) {
sum += exp( -(0.5+0.02*j)*(0.5+0.02*j) /
(2*std_dev*std_dev) );
}
cmatrix[matrix_length/2] = sum/51;
/* normalize the distribution by scaling the total sum to one */
sum=0;
for (i=0; i<matrix_length; i++) sum += cmatrix[i];
for (i=0; i<matrix_length; i++) cmatrix[i] = cmatrix[i] / sum;
return matrix_length;
}
/* ----------------------- gen_lookup_table ----------------------- */
/* generates a lookup table for every possible product of 0-255 and
each value in the convolution matrix */
static gdouble* gen_lookup_table(gdouble* cmatrix, gint cmatrix_length) {
int i, j;
gdouble* lookup_table = malloc(cmatrix_length * 256 * sizeof(gdouble));
#ifdef READABLE_CODE
for (i=0; i<cmatrix_length; i++) {
for (j=0; j<256; j++) {
lookup_table[i*256 + j] = cmatrix[i] * (gdouble)j;
}
}
#endif
#ifndef READABLE_CODE
gdouble* lookup_table_p = lookup_table;
gdouble* cmatrix_p = cmatrix;
for (i=0; i<cmatrix_length; i++) {
for (j=0; j<256; j++) {
*(lookup_table_p++) = *cmatrix_p * (gdouble)j;
}
cmatrix_p++;
}
#endif
return lookup_table;
}
/* ------------------------ unsharp_mask_dialog ----------------------- */
static gint unsharp_mask_dialog() {
GtkWidget *window;
GtkWidget *mainbox;
GtkWidget *table;
/* GtkWidget *label; */
/* GtkWidget *textentry; */
GtkWidget *button;
/* radius = 0; */
/* amount = 0; */
/* threshold = 0; */
gint argc = 1;
gchar** argv = g_new(gchar*, 1);
argv[0] = g_strdup("unsharp mask");
/* initialize */
gtk_init(&argc, &argv);
gtk_rc_parse(gimp_gtkrc());
gdk_set_use_xshm(gimp_use_xshm());
gtk_preview_set_gamma(gimp_gamma());
gtk_preview_set_install_cmap(gimp_install_cmap());
/* create a new window */
window = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_window_set_title(GTK_WINDOW(window), "Unsharp Mask");
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (unsharp_cancel_callback), NULL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (unsharp_cancel_callback), NULL);
mainbox = gtk_vbox_new(FALSE, 4); /* create main container box */
gtk_container_add(GTK_CONTAINER(window), mainbox);
table = gtk_table_new(3, 3, FALSE); /* Make a 3x3 table in mainbox */
gtk_box_pack_start(GTK_BOX(mainbox), table, FALSE, FALSE, 0);
/* create each of the inputs */
dialog_create_value_f("Radius", GTK_TABLE(table), 1, &unsharp_params.radius,
0.1, 1, 1.0, 20.0);
dialog_create_value_f("Amount", GTK_TABLE(table), 2, &unsharp_params.amount,
0.01, 2, 0.01, 1.0);
dialog_create_value_f("Threshold", GTK_TABLE(table), 3, &unsharp_params.threshold,
0.01, 2, 0.01, 1.0);
/* show table */
gtk_widget_show(table);
table = gtk_table_new(1, 2, TRUE); /* Make a 2x1 table in mainbox for OK, Cancel */
gtk_box_pack_start(GTK_BOX(mainbox), table, FALSE, FALSE, 0);
/* Make OK button */
button = gtk_button_new_with_label("OK");
gtk_table_attach_defaults( GTK_TABLE(table), button, 0, 1, 0, 1);
gtk_signal_connect( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(unsharp_ok_callback), window);
gtk_widget_show(button);
/* Make Cancel button */
button = gtk_button_new_with_label("Cancel");
gtk_table_attach_defaults( GTK_TABLE(table), button, 1, 2, 0, 1);
gtk_signal_connect ( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(unsharp_cancel_callback), NULL);
gtk_widget_show(button);
gtk_widget_show(table);
/* show the main container */
gtk_widget_show(mainbox);
/* and the window */
gtk_widget_show (window);
gtk_main ();
gdk_flush();
/* return ok or cancel */
return(run_filter);
}
#ifdef PREVIEW
/* 'preview_init()' - Initialize the preview window... */
static void
preview_init(void)
{
int width; /* Byte width of the image */
/*
* Setup for preview filter...
*/
width = preview_width * img_bpp;
preview_src = g_malloc(width * preview_height * sizeof(guchar));
preview_neg = g_malloc(width * preview_height * sizeof(guchar));
preview_dst = g_malloc(width * preview_height * sizeof(guchar));
preview_image = g_malloc(preview_width * preview_height * 3 * sizeof(guchar));
preview_x1 = sel_x1;
preview_y1 = sel_y1;
preview_x2 = preview_x1 + preview_width;
preview_y2 = preview_y1 + preview_height;
}
/*
* 'preview_scroll_callback()' - Update the preview when a scrollbar is moved.
*/
static void
preview_scroll_callback(void)
{
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);
preview_update();
}
/*
* 'preview_update()' - Update the preview window.
*/
static void
preview_update(void) {
}
#endif
static void unsharp_cancel_callback (GtkWidget *widget, gpointer data) {
gtk_main_quit ();
}
static void unsharp_ok_callback (GtkWidget *widget, gpointer data) {
run_filter = TRUE;
gtk_widget_destroy (GTK_WIDGET (data));
}
/* delete_event */
gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) {
return FALSE;
}
/* Destroy callback */
void destroy( GtkWidget *widget, gpointer data ) {
gtk_main_quit();
}
#ifdef TIMER
static void timerstart() {
gettimeofday(&time_start,NULL);
}
static void timerstop() {
long sec, usec;
gettimeofday(&time_stop,NULL);
sec = time_stop.tv_sec - time_start.tv_sec;
usec = time_stop.tv_usec - time_start.tv_usec;
if (usec < 0) {
sec--;
usec += 1000000;
}
fprintf(stderr, "%ld.%ld seconds\n", sec, usec);
}
#endif

View File

@ -1331,7 +1331,7 @@ load_image (char *filename)
return -1;
}
memmove (&apm_head.Key, buffer, 4);
g_memmove (&apm_head.Key, buffer, 4);
if (GUINT32_FROM_LE (apm_head.Key) == 0x9ac6cdd7)
{
@ -1341,11 +1341,11 @@ load_image (char *filename)
g_message ("WMF: Failed to read placeable metafile header");
return -1;
}
memmove (&apm_head.Left, buffer + 6, 2);
memmove (&apm_head.Top, buffer + 8, 2);
memmove (&apm_head.Right, buffer + 10, 2);
memmove (&apm_head.Bottom, buffer + 12, 2);
memmove (&apm_head.Inch, buffer + 14, 2);
g_memmove (&apm_head.Left, buffer + 6, 2);
g_memmove (&apm_head.Top, buffer + 8, 2);
g_memmove (&apm_head.Right, buffer + 10, 2);
g_memmove (&apm_head.Bottom, buffer + 12, 2);
g_memmove (&apm_head.Inch, buffer + 14, 2);
bbox.x = GINT16_FROM_LE (apm_head.Left);
bbox.y = GINT16_FROM_LE (apm_head.Top);
bbox.width = GUINT16_FROM_LE (apm_head.Right) - bbox.x;
@ -1374,9 +1374,9 @@ load_image (char *filename)
pixs_per_in = 72;
#endif
memmove (&wmf_head.Version, buffer + 4, 2);
memmove (&wmf_head.FileSize, buffer + 6, 4);
memmove (&wmf_head.NumOfObjects, buffer + 10, 2);
g_memmove (&wmf_head.Version, buffer + 4, 2);
g_memmove (&wmf_head.FileSize, buffer + 6, 4);
g_memmove (&wmf_head.NumOfObjects, buffer + 10, 2);
if (GUINT16_FROM_LE (wmf_head.Version) != 0x0300)
{
@ -1397,8 +1397,8 @@ load_image (char *filename)
g_message ("WMF: Failed to read metafile record");
return -1;
}
memmove (&record.Size, buffer, 4);
memmove (&record.Function, buffer + 4, 2);
g_memmove (&record.Size, buffer, 4);
g_memmove (&record.Function, buffer + 4, 2);
record_counter++;
#if 0
g_print ("%#x %d\n", GUINT16_FROM_LE (record.Function), GUINT32_FROM_LE (record.Size));

View File

@ -0,0 +1,6 @@
Makefile.in
Makefile
.deps
_libs
.libs
unsharp

View File

@ -0,0 +1,37 @@
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = unsharp
unsharp_SOURCES = \
dialog_f.h \
dialog_f.c \
unsharp.c
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS)
DEPS = \
$(top_builddir)/libgimp/libgimp.la
unsharp_DEPENDENCIES = $(DEPS)
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done
@for subdir in $(SUBDIRS); do \
files=`cd $$subdir; $(MAKE) files | grep -v "make\[[1-9]\]"`; \
for file in $$files; do \
echo $$subdir/$$file; \
done; \
done

218
plug-ins/unsharp/dialog_f.c Normal file
View File

@ -0,0 +1,218 @@
/*
* dialog_f.c -- functions for creating a GTK gdouble slider/value input.
*
* Copyright (C) 1999 Winston Chang
* <wchang3@students.wisc.edu>
* <winston@steppe.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.
*/
#include <gtk/gtk.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dialog_f.h"
/*
* 'dialog_create_value_f()' - Create an gdouble value control...
*/
void
dialog_create_value_f(char *title, /* Label for control */
GtkTable *table, /* Table container to use */
int row, /* Row # for container */
gdouble *value, /* Value holder */
gdouble increment,/* Size of mouse-click and
keyboard increment */
gint precision,/* Number of digits after decimal point */
int left, /* Minimum value for slider */
int right) /* Maximum value for slider */
{
GtkWidget *label; /* Control label */
GtkWidget *scale; /* Scale widget */
GtkWidget *entry; /* Text widget */
GtkObject *scale_data; /* Scale data */
char buf[256]; /* String buffer */
/* Create label... */
label = gtk_label_new(title);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 1.0);
gtk_table_attach(table, label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 4, 0);
gtk_widget_show(label);
/*
* Scale...
*/
/* the "right+increment" is necessary to make it stop on 5.0 instead
of 4.9. I think this is a shortcoming of GTK's adjustments */
scale_data = gtk_adjustment_new(*value, left, right+increment,
increment, increment, increment);
gtk_signal_connect(GTK_OBJECT(scale_data), "value_changed",
(GtkSignalFunc) dialog_fscale_update, value);
scale = gtk_hscale_new(GTK_ADJUSTMENT(scale_data));
gtk_scale_set_digits( GTK_SCALE(scale), precision);
gtk_widget_set_usize(scale, SCALE_WIDTH, 0);
gtk_table_attach( table, scale, 1, 2, row, row + 1,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
gtk_scale_set_draw_value( GTK_SCALE(scale), FALSE);
gtk_range_set_update_policy( GTK_RANGE(scale), GTK_UPDATE_CONTINUOUS);
gtk_widget_show(scale);
/*
* Text entry...
*/
entry = gtk_entry_new();
gtk_object_set_user_data(GTK_OBJECT(entry), scale_data);
gtk_object_set_user_data(scale_data, entry);
gtk_widget_set_usize(entry, ENTRY_WIDTH, 0);
sprintf(buf, "%g", *value);
gtk_entry_set_text(GTK_ENTRY(entry), buf);
gtk_signal_connect(GTK_OBJECT(entry), "changed",
(GtkSignalFunc) dialog_fentry_update,
value);
gtk_table_attach( GTK_TABLE(table), entry, 2, 3, row, row + 1,
GTK_FILL, GTK_FILL, 4, 0);
gtk_widget_show(entry);
}
/*
* 'dialog_fscale_update()' - Update the value field using the scale.
*/
void
dialog_fscale_update(GtkAdjustment *adjustment, /* I - New value */
gdouble *value) /* I - Current value */
{
GtkWidget *entry; /* Text entry widget */
char buf[256]; /* Text buffer */
if (*value != adjustment->value)
{
*value = adjustment->value;
entry = gtk_object_get_user_data(GTK_OBJECT(adjustment));
/* use precision of 5 */
sprintf(buf, "%.5g", *value);
/* This is to round the number to a reasonable value. For some
some reason it wants to increment by about 0.1000000105 instead
of 0.1. That annoys me. */
*value = atof(buf);
/* assign the text value to the entry */
gtk_signal_handler_block_by_data(GTK_OBJECT(entry), value);
gtk_entry_set_text(GTK_ENTRY(entry), buf);
gtk_signal_handler_unblock_by_data(GTK_OBJECT(entry), value);
/* assign the rounded value back the adjustment */
adjustment->value = *value;
}
}
/*
* 'dialog_fentry_update()' - Update the value field using the text entry.
*/
void
dialog_fentry_update(GtkWidget *widget, /* I - Entry widget */
gdouble *value) /* I - Current value */
{
GtkAdjustment *adjustment;
gdouble new_value;
/* these three are for the string cleaner */
gint shift;
gboolean periodfound;
gint digits_after_period;
gchar* textvalue;
gchar newtextvalue[MAX_ENTRY_LENGTH+1];
gint oldtextlength;
gint i;
/* new_value = atod(gtk_entry_get_text(GTK_ENTRY(widget))); */
textvalue = gtk_entry_get_text( GTK_ENTRY(widget));
strncpy(newtextvalue, textvalue, MAX_ENTRY_LENGTH);
/* clean up new value so that it only has one digit after decimal
and no weird chars */
newtextvalue[MAX_ENTRY_LENGTH] ='\0';
oldtextlength = strlen(newtextvalue);
/* this stuff cleans up non-numeric chars */
shift=0;
periodfound = FALSE;
digits_after_period = 0;
for (i=0; i+shift < oldtextlength; i++) {
if (newtextvalue[i] == '.') {
if (periodfound) shift++; /* if not first period, ignore */
else periodfound = TRUE; /* if first period, mark periodfound */
}
else if (newtextvalue[i]>='0' && newtextvalue[i]<='9') {
if (periodfound) {
digits_after_period++;
/* this is to ignore a certain number of digits after period */
if (digits_after_period > ENTRY_PRECISION) shift++;
}
}
else shift++; /* ignore non-numeric chars */
/* copy shifted value back, making sure we don't run off end */
if (i+shift >= MAX_ENTRY_LENGTH) newtextvalue[i] = '\0';
else newtextvalue[i] = newtextvalue[i+shift];
}
newtextvalue[i]='\0';
/* write the cleaned-up value into the entry box */
/* block the signal handler so we don't go into an infinite recursion */
gtk_signal_handler_block_by_data(GTK_OBJECT(widget), value);
/* update the entry text */
gtk_entry_set_text( GTK_ENTRY(widget), newtextvalue);
/* gtk_entry_set_position( GTK_ENTRY(widget), i); */ /* doesn't seem to work */
/* unblock signal handler */
gtk_signal_handler_unblock_by_data(GTK_OBJECT(widget), value);
/* g_print(newtextvalue); */
/* g_print("\n"); */
/* set the adjustment thingy */
new_value = atof(newtextvalue);
/* g_print("%e.", new_value); */
/* set the new value */
if (*value != new_value) {
adjustment = gtk_object_get_user_data(GTK_OBJECT(widget));
if ((new_value >= adjustment->lower) &&
(new_value <= adjustment->upper)) {
*value = new_value;
adjustment->value = new_value;
gtk_signal_emit_by_name(GTK_OBJECT(adjustment), "value_changed");
}
}
}

View File

@ -0,0 +1,18 @@
#ifndef __DIALOG_F_H__
#define __DIALOG_F_H__
#define MAX_ENTRY_LENGTH 5
#define ENTRY_WIDTH 40
#define SCALE_WIDTH 100
#define ENTRY_PRECISION 1
void dialog_create_value_f(char *title, GtkTable *table, int row,
gdouble *value,
gdouble increment, int precision,
int left, int right);
void dialog_fscale_update(GtkAdjustment *adjustment, gdouble *value);
void dialog_fentry_update(GtkWidget *widget, gdouble *value);
#endif /* __DIALOG_F_H__ */

895
plug-ins/unsharp/unsharp.c Normal file
View File

@ -0,0 +1,895 @@
/*
* unsharp.c 0.5 -- This is a plug-in for the GIMP 1.0
* http://www.steppe.com/~winston/gimp/unsharp.html
*
* Copyright (C) 1999 Winston Chang
* <wchang3@students.wisc.edu>
* <winston@steppe.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.
*/
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "libgimp/gimp.h"
#include "gtk/gtk.h"
#include "dialog_f.h"
#define PLUG_IN_VERSION "0.5 - 1999/6/2"
/* to show both pretty unoptimized code and ugly optimized code blocks
There's really no reason to define this, unless you want to see how
much pointer aritmetic can speed things up. I find that it is about
45% faster with the optimized code. */
/* #define READABLE_CODE */
/* uncomment this line to get a rough feel of how long the
plug-in takes to run */
/* #define TIMER */
#ifdef TIMER
# include <sys/time.h>
# include <unistd.h>
static void timerstart();
static void timerstop();
static struct timeval time_start,time_stop;
#endif
typedef struct {
gdouble radius;
gdouble amount;
gdouble threshold;
} UnsharpMaskParams;
typedef struct {
gint run;
} UnsharpMaskInterface;
/* local function prototypes */
static inline void blur_line(gdouble* ctable, gdouble* cmatrix, gint cmatrix_length,
guchar* cur_col, guchar* dest_col,
gint y, glong bytes);
static int gen_convolve_matrix(double std_dev, double** cmatrix);
static gdouble* gen_lookup_table(gdouble* cmatrix, gint cmatrix_length);
static inline gint round(gdouble i);
static void unsharp_region (GPixelRgn srcPTR, GPixelRgn dstPTR,
gint width, gint height, gint bytes,
gdouble radius, gdouble amount,
gint x1, gint x2, gint y1, gint y2);
static void query(void);
static void run (gchar *name,
gint nparams,
GParam *param,
gint *nreturn_vals,
GParam **return_vals);
static void unsharp_mask(GDrawable *drawable, gint radius, gdouble amount);
static void unsharp_cancel_callback (GtkWidget *widget, gpointer data);
static void unsharp_ok_callback (GtkWidget *widget, gpointer data);
static gint unsharp_mask_dialog();
/* preview shit -- not finished yet */
#undef PREVIEW
#ifdef PREVIEW
static void preview_scroll_callback(void);
static void preview_init(void);
static void preview_exit(void);
static void preview_update(void);
static void dialog_create_ivalue(char *title, /* I - Label for control */
GtkTable *table, /* I - Table container to use */
int row, /* I - Row # for container */
gint *value, /* I - Value holder */
int left, /* I - Minimum value for slider */
int right); /* I - Maximum value for slider */
static GtkWidget* preview;
static int preview_width; /* Width of preview widget */
static int preview_height; /* Height of preview widget */
static int preview_x1; /* Upper-left X of preview */
static int preview_y1; /* Upper-left Y of preview */
static int preview_x2; /* Lower-right X of preview */
static int preview_y2; /* Lower-right Y of preview */
static int sel_width; /* Selection width */
static int sel_height; /* Selection height */
static GtkObject *hscroll_data; /* Horizontal scrollbar data */
static GtkObject *vscroll_data; /* Vertical scrollbar data */
#endif
static gint run_filter = FALSE;
/* create a few globals, set default values */
static UnsharpMaskParams unsharp_params =
{
5.0, /* default radius = 5 */
0.5, /* default amount = .5 */
0.0 /* default threshold = 0.0 */
};
/* static UnsharpMaskInterface umint = { FALSE }; */
/* Setting PLUG_IN_INFO */
GPlugInInfo PLUG_IN_INFO = {
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN()
static void query () {
static GParamDef args[] = {
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "(unused)" },
{ PARAM_DRAWABLE, "drawable", "Drawable to draw on" },
{ PARAM_FLOAT, "radius", "Radius of gaussian blur (in pixels > 1.0)" },
{ PARAM_FLOAT, "amount", "Strength of effect." }
};
static gint nargs = sizeof(args) / sizeof(args[0]);
/* for return vals */
static GParamDef *return_vals = NULL;
static int nreturn_vals = 0;
/* Install a procedure in the procedure database. */
gimp_install_procedure ("plug_in_unsharp_mask",
"An unsharp mask filter",
"Long description / help",
"Winston Chang <wchang3@students.wisc.edu>",
"Winston Chang",
"1999",
"<Image>/Filters/Enhance/Unsharp Mask",
"GRAY*, RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
/* this is the actual function */
static void run(char *name, int nparams, GParam *param, int *nreturn_vals,
GParam **return_vals) {
static GParam values[1];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
#ifdef TIMER
timerstart();
#endif
run_mode = param[0].data.d_int32;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
*return_vals = values;
*nreturn_vals = 1;
switch (run_mode) {
case RUN_INTERACTIVE:
gimp_get_data ("plug_in_unsharp_mask", &unsharp_params);
if (! unsharp_mask_dialog ()) return;
break;
case RUN_NONINTERACTIVE:
if (nparams != 4) status = STATUS_CALLING_ERROR;
/* get the parameters */
else if (status == STATUS_SUCCESS) {
unsharp_params.radius = param[3].data.d_float;
unsharp_params.amount = param[4].data.d_float;
}
/* make sure there are legal values */
if (status == STATUS_SUCCESS &&
( (unsharp_params.radius < 0) || (unsharp_params.amount<0) ) )
status = STATUS_CALLING_ERROR;
break;
case RUN_WITH_LAST_VALS:
gimp_get_data ("plug_in_unsharp_mask", &unsharp_params);
break;
default:
break;
}
if (status == STATUS_SUCCESS) {
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_tile_cache_ntiles(2 * (drawable->width / gimp_tile_width() + 1));
/* here we go */
unsharp_mask(drawable, unsharp_params.radius, unsharp_params.amount);
/* values[0].data.d_status = status; */
gimp_displays_flush ();
/* set data for next use of filter */
gimp_set_data ("plug_in_unsharp_mask", &unsharp_params,
sizeof (UnsharpMaskParams));
/*fprintf(stderr, "%f %f\n", unsharp_params.radius, unsharp_params.amount);*/
gimp_drawable_detach(drawable);
values[0].data.d_status = status;
}
#ifdef TIMER
timerstop();
#endif
}
/* -------------------------- Unsharp Mask ------------------------- */
static void unsharp_mask(GDrawable *drawable, gint radius, gdouble amount) {
GPixelRgn srcPR, destPR;
glong width, height;
glong bytes;
gint x1, y1, x2, y2;
gdouble* cmatrix = NULL;
gint cmatrix_length;
gdouble* ctable;
/* Get the input */
gimp_drawable_mask_bounds(drawable->id, &x1, &y1, &x2, &y2);
gimp_progress_init("Blurring...");
/* generate convolution matrix */
cmatrix_length = gen_convolve_matrix(radius, &cmatrix);
/* generate lookup table */
ctable = gen_lookup_table(cmatrix, cmatrix_length);
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
/* initialize pixel regions */
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
unsharp_region (srcPR, destPR, width, height, bytes, radius, amount,
x1, x2, y1, y2);
#ifdef PIMPDADDY
/* allocate row, col buffers */
cur_row = (guchar *) g_malloc ((x2 - x1) * bytes);
dest_row = (guchar *) g_malloc ((x2 - x1) * bytes);
cur_col = (guchar *) g_malloc ((y2 - y1) * bytes);
dest_col = (guchar *) g_malloc ((y2 - y1) * bytes);
/* set height and width */
x = x2-x1;
y = y2-y1;
/* blank out a region of the destination memory area, I think */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, (x2-x1));
memset(dest_row, 0, x*bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, (x2-x1));
}
/* blur the rows */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
blur_line(ctable, cmatrix, cmatrix_length, cur_row, dest_row, x, bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y));
}
/* blur the cols */
for (col = 0; col < x; col++) {
gimp_pixel_rgn_get_col(&destPR, cur_col, x1+col, y1, y);
gimp_pixel_rgn_get_col(&destPR, dest_col, x1+col, y1, y);
blur_line(ctable, cmatrix, cmatrix_length, cur_col, dest_col, y, bytes);
gimp_pixel_rgn_set_col(&destPR, dest_col, x1+col, y1, y);
if (col%5 == 0) gimp_progress_update((gdouble)col/(3*x) + 0.33);
}
gimp_progress_init("Merging...");
for (row = 0; row < y; row++) {
int value = 0;
int u,v;
/* get source row */
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
/* get dest row */
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
/* combine the two */
for (u=0;u<x;u++) {
for (v=0; v<bytes; v++) {
value = cur_row[u*bytes+v] +
amount * (cur_row[u*bytes+v] - dest_row[u*bytes+v]);
if (value < 0) dest_row[u*bytes+v] =0;
else if (value > 255) dest_row[u*bytes+v] = 255;
else dest_row[u*bytes+v] = value;
}
}
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y) + 0.67);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
}
/* free the memory we took */
g_free(cur_row);
g_free(dest_row);
g_free(cur_col);
g_fre(dest_col);
#endif
gimp_drawable_flush(drawable);
gimp_drawable_merge_shadow(drawable->id, TRUE);
gimp_drawable_update(drawable->id, x1, y1, (x2-x1), (y2-y1));
}
/* perform an unsharp mask on the region, given a source region, dest.
region, width and height of the regions, and corner coordinates of
a subregion to act upon. Everything outside the subregion is unaffected.
*/
static void unsharp_region (GPixelRgn srcPR, GPixelRgn destPR,
gint width, gint height, gint bytes,
gdouble radius, gdouble amount,
gint x1, gint x2, gint y1, gint y2) {
guchar* cur_col;
guchar* dest_col;
guchar* cur_row;
guchar* dest_row;
gint x;
gint y;
gdouble* cmatrix = NULL;
gint cmatrix_length;
gdouble* ctable;
gint row, col; /* these are counters for loops */
/* these are used for the merging step */
gint threshold;
gint diff;
gint value;
gint u,v;
/* generate convolution matrix */
cmatrix_length = gen_convolve_matrix(radius, &cmatrix);
/* generate lookup table */
ctable = gen_lookup_table(cmatrix, cmatrix_length);
/* allocate row, col buffers */
cur_row = (guchar *) g_malloc ((x2 - x1) * bytes);
dest_row = (guchar *) g_malloc ((x2 - x1) * bytes);
/* find height and width of subregion to act on */
x = x2-x1;
y = y2-y1;
/* blank out a region of the destination memory area, I think */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, (x2-x1));
memset(dest_row, 0, x*bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, (x2-x1));
}
/* blur the rows */
for (row = 0; row < y; row++) {
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
blur_line(ctable, cmatrix, cmatrix_length, cur_row, dest_row, x, bytes);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y));
}
/* allocate column buffers */
cur_col = (guchar *) g_malloc ((y2 - y1) * bytes);
dest_col = (guchar *) g_malloc ((y2 - y1) * bytes);
/* blur the cols */
for (col = 0; col < x; col++) {
gimp_pixel_rgn_get_col(&destPR, cur_col, x1+col, y1, y);
gimp_pixel_rgn_get_col(&destPR, dest_col, x1+col, y1, y);
blur_line(ctable, cmatrix, cmatrix_length, cur_col, dest_col, y, bytes);
gimp_pixel_rgn_set_col(&destPR, dest_col, x1+col, y1, y);
if (col%5 == 0) gimp_progress_update((gdouble)col/(3*x) + 0.33);
}
gimp_progress_init("Merging...");
/* find integer value of threshold */
threshold = round( unsharp_params.threshold * 255.0 );
/* merge the source and destination images */
for (row = 0; row < y; row++) {
value = 0;
/* get source row */
gimp_pixel_rgn_get_row(&srcPR, cur_row, x1, y1+row, x);
/* get dest row */
gimp_pixel_rgn_get_row(&destPR, dest_row, x1, y1+row, x);
/* combine the two */
for (u=0;u<x;u++) {
for (v=0; v<bytes; v++) {
diff = (cur_row[u*bytes+v] - dest_row[u*bytes+v]);
/* do tresholding */
if (diff > threshold) diff = diff - threshold;
else if (diff < -threshold) diff = diff + threshold;
else diff = 0;
value = cur_row[u*bytes+v] + amount * diff;
if (value < 0) dest_row[u*bytes+v] =0;
else if (value > 255) dest_row[u*bytes+v] = 255;
else dest_row[u*bytes+v] = value;
}
}
/* update progress bar every five rows */
if (row%5 == 0) gimp_progress_update((gdouble)row/(3*y) + 0.67);
gimp_pixel_rgn_set_row(&destPR, dest_row, x1, y1+row, x);
}
/* free the memory we took */
g_free(cur_row);
g_free(dest_row);
g_free(cur_col);
g_free(dest_col);
}
/* this function is written as if it is blurring a column at a time,
even though it can operate on rows, too. There is no difference
in the processing of the lines, at least to the blur_line function. */
static inline void blur_line(gdouble* ctable, gdouble* cmatrix,
gint cmatrix_length,
guchar* cur_col, guchar* dest_col,
gint y, glong bytes) {
#ifdef READABLE_CODE
/* ------------- semi-readable code ------------------- */
gdouble scale;
gdouble sum;
gint i,j;
gint row;
/* for the edge condition, we only use available info, and scale to one */
for (row = 0; row < cmatrix_length/2; row++) {
/* find scale factor */
scale=0;
for (j = cmatrix_length/2 - row; j<cmatrix_length; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = cmatrix_length/2 - row; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
/* go through each pixel in each col */
for ( ; row < y-cmatrix_length/2; row++) {
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum);
}
}
/* for the edge condition , we only use available info, and scale to one */
for ( ; row < y; row++) {
/* find scale factor */
scale=0;
for (j = 0; j< y-row + cmatrix_length/2; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<y-row + cmatrix_length/2; j++) {
sum += cur_col[(row + j-cmatrix_length/2)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
#endif
#ifndef READABLE_CODE
/* --------------- optimized, unreadable code -------------------*/
gdouble scale;
gdouble sum;
gint i=0, j=0;
gint row;
gint cmatrix_middle = cmatrix_length/2;
gdouble *cmatrix_p;
guchar *cur_col_p;
guchar *cur_col_p1;
guchar *dest_col_p;
gdouble *ctable_p;
/* for the edge condition, we only use available info and scale to one */
for (row = 0; row < cmatrix_middle; row++) {
/* find scale factor */
scale=0;
for (j = cmatrix_middle - row; j<cmatrix_length; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = cmatrix_middle - row; j<cmatrix_length; j++) {
sum += cur_col[(row + j-cmatrix_middle)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
/* go through each pixel in each col */
dest_col_p = dest_col + row*bytes;
for ( ; row < y-cmatrix_middle; row++) {
cur_col_p = (row - cmatrix_middle) * bytes + cur_col;
for (i = 0; i<bytes; i++) {
sum = 0;
cmatrix_p = cmatrix;
cur_col_p1 = cur_col_p;
ctable_p = ctable;
for (j = cmatrix_length; j>0; j--) {
sum += *(ctable_p + *cur_col_p1);
cur_col_p1 += bytes;
ctable_p += 256; /* * sizeof(gdouble); */
}
cur_col_p++;
*(dest_col_p++) = round(sum);
}
}
/* for the edge condition , we only use available info, and scale to one */
for ( ; row < y; row++) {
/* find scale factor */
scale=0;
for (j = 0; j< y-row + cmatrix_middle; j++)
scale += cmatrix[j];
for (i = 0; i<bytes; i++) {
sum = 0;
for (j = 0; j<y-row + cmatrix_middle; j++) {
sum += cur_col[(row + j-cmatrix_middle)*bytes + i] * cmatrix[j];
}
dest_col[row*bytes + i] = (guchar)round(sum / scale);
}
}
#endif
}
static inline gint round(gdouble i) {
return (gint)(i + 0.5);
}
/* generates a 1-D convolution matrix to be used for each pass of
* a two-pass gaussian blur. Returns the length of the matrix.
*/
static gint gen_convolve_matrix(gdouble radius, gdouble** cmatrix_p) {
gint matrix_length;
gint matrix_midpoint;
gdouble* cmatrix;
gint i,j;
gdouble std_dev;
gdouble sum;
/* we want to generate a matrix that goes out a certain radius
* from the center, so we have to go out ceil(rad-0.5) pixels,
* inlcuding the center pixel. Of course, that's only in one direction,
* so we have to go the same amount in the other direction, but not count
* the center pixel again. So we double the previous result and subtract
* one.
* I lifted the formula for getting std_dev from radius from the gauss_rle
* plug-in. No, I don't understand why it is what it is.
*/
radius = fabs(radius) + 1.0;
std_dev = sqrt (-(radius * radius) / (2 * log (1.0 / 255.0)));
/* go out 'radius' in each direction */
matrix_length = 2 * ceil(radius-0.5) + 1;
if (matrix_length <= 0) matrix_length = 1;
matrix_midpoint = matrix_length/2 + 1;
*cmatrix_p = (gdouble*)(malloc(matrix_length * sizeof(gdouble)));
cmatrix = *cmatrix_p;
/* Now we fill the matrix by doing a numeric integration approximation
* from -2*std_dev to 2*std_dev, sampling 50 points per pixel.
* We do the bottom half, mirror it to the top half, then compute the
* center point. Otherwise asymmetric quantization errors will occur.
* The formula to integrate is e^-(x^2/2s^2).
*/
for (i=matrix_length/2 + 1; i<matrix_length; i++) {
double base_x = i - floor(matrix_length/2) - 0.5;
sum = 0;
for (j=1; j<=50; j++) {
if ( base_x+0.02*j <= radius )
sum += exp( -(base_x+0.02*j)*(base_x+0.02*j) /
(2*std_dev*std_dev) );
}
cmatrix[i] = sum/50;
}
/* mirror the thing to the bottom half */
for (i=0; i<=matrix_length/2; i++) {
cmatrix[i] = cmatrix[matrix_length-1-i];
}
/* find center val -- calculate an odd number of quanta to make it symmetric,
* even if the center point is weighted slightly higher than others. */
sum = 0;
for (j=0; j<=50; j++) {
sum += exp( -(0.5+0.02*j)*(0.5+0.02*j) /
(2*std_dev*std_dev) );
}
cmatrix[matrix_length/2] = sum/51;
/* normalize the distribution by scaling the total sum to one */
sum=0;
for (i=0; i<matrix_length; i++) sum += cmatrix[i];
for (i=0; i<matrix_length; i++) cmatrix[i] = cmatrix[i] / sum;
return matrix_length;
}
/* ----------------------- gen_lookup_table ----------------------- */
/* generates a lookup table for every possible product of 0-255 and
each value in the convolution matrix */
static gdouble* gen_lookup_table(gdouble* cmatrix, gint cmatrix_length) {
int i, j;
gdouble* lookup_table = malloc(cmatrix_length * 256 * sizeof(gdouble));
#ifdef READABLE_CODE
for (i=0; i<cmatrix_length; i++) {
for (j=0; j<256; j++) {
lookup_table[i*256 + j] = cmatrix[i] * (gdouble)j;
}
}
#endif
#ifndef READABLE_CODE
gdouble* lookup_table_p = lookup_table;
gdouble* cmatrix_p = cmatrix;
for (i=0; i<cmatrix_length; i++) {
for (j=0; j<256; j++) {
*(lookup_table_p++) = *cmatrix_p * (gdouble)j;
}
cmatrix_p++;
}
#endif
return lookup_table;
}
/* ------------------------ unsharp_mask_dialog ----------------------- */
static gint unsharp_mask_dialog() {
GtkWidget *window;
GtkWidget *mainbox;
GtkWidget *table;
/* GtkWidget *label; */
/* GtkWidget *textentry; */
GtkWidget *button;
/* radius = 0; */
/* amount = 0; */
/* threshold = 0; */
gint argc = 1;
gchar** argv = g_new(gchar*, 1);
argv[0] = g_strdup("unsharp mask");
/* initialize */
gtk_init(&argc, &argv);
gtk_rc_parse(gimp_gtkrc());
gdk_set_use_xshm(gimp_use_xshm());
gtk_preview_set_gamma(gimp_gamma());
gtk_preview_set_install_cmap(gimp_install_cmap());
/* create a new window */
window = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_window_set_title(GTK_WINDOW(window), "Unsharp Mask");
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (unsharp_cancel_callback), NULL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (unsharp_cancel_callback), NULL);
mainbox = gtk_vbox_new(FALSE, 4); /* create main container box */
gtk_container_add(GTK_CONTAINER(window), mainbox);
table = gtk_table_new(3, 3, FALSE); /* Make a 3x3 table in mainbox */
gtk_box_pack_start(GTK_BOX(mainbox), table, FALSE, FALSE, 0);
/* create each of the inputs */
dialog_create_value_f("Radius", GTK_TABLE(table), 1, &unsharp_params.radius,
0.1, 1, 1.0, 20.0);
dialog_create_value_f("Amount", GTK_TABLE(table), 2, &unsharp_params.amount,
0.01, 2, 0.01, 1.0);
dialog_create_value_f("Threshold", GTK_TABLE(table), 3, &unsharp_params.threshold,
0.01, 2, 0.01, 1.0);
/* show table */
gtk_widget_show(table);
table = gtk_table_new(1, 2, TRUE); /* Make a 2x1 table in mainbox for OK, Cancel */
gtk_box_pack_start(GTK_BOX(mainbox), table, FALSE, FALSE, 0);
/* Make OK button */
button = gtk_button_new_with_label("OK");
gtk_table_attach_defaults( GTK_TABLE(table), button, 0, 1, 0, 1);
gtk_signal_connect( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(unsharp_ok_callback), window);
gtk_widget_show(button);
/* Make Cancel button */
button = gtk_button_new_with_label("Cancel");
gtk_table_attach_defaults( GTK_TABLE(table), button, 1, 2, 0, 1);
gtk_signal_connect ( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(unsharp_cancel_callback), NULL);
gtk_widget_show(button);
gtk_widget_show(table);
/* show the main container */
gtk_widget_show(mainbox);
/* and the window */
gtk_widget_show (window);
gtk_main ();
gdk_flush();
/* return ok or cancel */
return(run_filter);
}
#ifdef PREVIEW
/* 'preview_init()' - Initialize the preview window... */
static void
preview_init(void)
{
int width; /* Byte width of the image */
/*
* Setup for preview filter...
*/
width = preview_width * img_bpp;
preview_src = g_malloc(width * preview_height * sizeof(guchar));
preview_neg = g_malloc(width * preview_height * sizeof(guchar));
preview_dst = g_malloc(width * preview_height * sizeof(guchar));
preview_image = g_malloc(preview_width * preview_height * 3 * sizeof(guchar));
preview_x1 = sel_x1;
preview_y1 = sel_y1;
preview_x2 = preview_x1 + preview_width;
preview_y2 = preview_y1 + preview_height;
}
/*
* 'preview_scroll_callback()' - Update the preview when a scrollbar is moved.
*/
static void
preview_scroll_callback(void)
{
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);
preview_update();
}
/*
* 'preview_update()' - Update the preview window.
*/
static void
preview_update(void) {
}
#endif
static void unsharp_cancel_callback (GtkWidget *widget, gpointer data) {
gtk_main_quit ();
}
static void unsharp_ok_callback (GtkWidget *widget, gpointer data) {
run_filter = TRUE;
gtk_widget_destroy (GTK_WIDGET (data));
}
/* delete_event */
gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) {
return FALSE;
}
/* Destroy callback */
void destroy( GtkWidget *widget, gpointer data ) {
gtk_main_quit();
}
#ifdef TIMER
static void timerstart() {
gettimeofday(&time_start,NULL);
}
static void timerstop() {
long sec, usec;
gettimeofday(&time_stop,NULL);
sec = time_stop.tv_sec - time_start.tv_sec;
usec = time_stop.tv_usec - time_start.tv_usec;
if (usec < 0) {
sec--;
usec += 1000000;
}
fprintf(stderr, "%ld.%ld seconds\n", sec, usec);
}
#endif

View File

@ -1331,7 +1331,7 @@ load_image (char *filename)
return -1;
}
memmove (&apm_head.Key, buffer, 4);
g_memmove (&apm_head.Key, buffer, 4);
if (GUINT32_FROM_LE (apm_head.Key) == 0x9ac6cdd7)
{
@ -1341,11 +1341,11 @@ load_image (char *filename)
g_message ("WMF: Failed to read placeable metafile header");
return -1;
}
memmove (&apm_head.Left, buffer + 6, 2);
memmove (&apm_head.Top, buffer + 8, 2);
memmove (&apm_head.Right, buffer + 10, 2);
memmove (&apm_head.Bottom, buffer + 12, 2);
memmove (&apm_head.Inch, buffer + 14, 2);
g_memmove (&apm_head.Left, buffer + 6, 2);
g_memmove (&apm_head.Top, buffer + 8, 2);
g_memmove (&apm_head.Right, buffer + 10, 2);
g_memmove (&apm_head.Bottom, buffer + 12, 2);
g_memmove (&apm_head.Inch, buffer + 14, 2);
bbox.x = GINT16_FROM_LE (apm_head.Left);
bbox.y = GINT16_FROM_LE (apm_head.Top);
bbox.width = GUINT16_FROM_LE (apm_head.Right) - bbox.x;
@ -1374,9 +1374,9 @@ load_image (char *filename)
pixs_per_in = 72;
#endif
memmove (&wmf_head.Version, buffer + 4, 2);
memmove (&wmf_head.FileSize, buffer + 6, 4);
memmove (&wmf_head.NumOfObjects, buffer + 10, 2);
g_memmove (&wmf_head.Version, buffer + 4, 2);
g_memmove (&wmf_head.FileSize, buffer + 6, 4);
g_memmove (&wmf_head.NumOfObjects, buffer + 10, 2);
if (GUINT16_FROM_LE (wmf_head.Version) != 0x0300)
{
@ -1397,8 +1397,8 @@ load_image (char *filename)
g_message ("WMF: Failed to read metafile record");
return -1;
}
memmove (&record.Size, buffer, 4);
memmove (&record.Function, buffer + 4, 2);
g_memmove (&record.Size, buffer, 4);
g_memmove (&record.Function, buffer + 4, 2);
record_counter++;
#if 0
g_print ("%#x %d\n", GUINT16_FROM_LE (record.Function), GUINT32_FROM_LE (record.Size));

View File

@ -285,7 +285,9 @@ CODE
# Our function prototype for the headers
(my $hrettype = $rettype) =~ s/ //g;
push @{$out->{proto}}, "$hrettype gimp_$name ($arglist);\n";
my $proto = "$hrettype gimp_$name ($arglist);\n";
$proto =~ s/ +/ /g;
push @{$out->{proto}}, $proto;
my $clist = $arglist;
$clist =~ s/\t/' ' x (length("gimp_$name") + 2)/eg;
@ -343,43 +345,47 @@ LGPL
$extra = $main::grp{$group}->{extra}->{lib}
}
my ($longest1, $longest2, $longest3) = (0, 0, 0); my @arglist = ();
push @{$out->{proto}}, $extra->{protos} if exists $extra->{protos};
my @longest = (0, 0, 0); my @arglist = (); my $seen = 0;
foreach (@{$out->{proto}}) {
my $len; my $arglist = [ split(' ', $_, 3) ];
$len = length($arglist->[0]);
$longest1 = $len if $longest1 < $len;
for (0..1) {
$len = length($arglist->[$_]);
$longest[$_] = $len if $longest[$_] < $len;
}
$len = length($arglist->[1]);
$longest2 = $len if $longest2 < $len;
my @arg = split(' ', $arglist->[2]);
if ($#arg) {
$len = index($arglist->[2], $arg[1]);
$len -= scalar($arg[1] =~ /\*/g);
$longest3 = $len if $longest3 < $len;
my @arg = split(/,/, $arglist->[2]);
foreach (@arg) {
/(\w+) \S+/;
$len = length($1) + 1;
$seen++ if /\*/;
$longest[2] = $len if $longest[2] < $len;
}
push @arglist, $arglist;
}
$longest[2]++ if $seen;
@{$out->{proto}} = ();
foreach (@arglist) {
my ($type, $func, $arglist) = @$_;
my @args = split(/,/, $arglist); $arglist = "";
foreach (@args) {
my $len = $longest3 - scalar(/ /g);
$len -= scalar(/\*/g);
s/(\s*\w+)\s+/$1 . ' ' x $len/e;
my $len = $longest[2] - index($_, ' ') + 1;
$len-- if /\*/;
s/ /' ' x $len/e if $len > 1;
$arglist .= $_;
$arglist .= "," if !/;\n$/;
}
my $arg = $type;
$arg .= ' ' x ($longest1 - length($type) + 1) . $func;
$arg .= ' ' x ($longest2 - length($func) + 1) . $arglist;
$arg =~ s/\t/' ' x ($longest1 + $longest2 + 3)/eg;
$arg =~ s/ {8}/\t/g;
$arg .= ' ' x ($longest[0] - length($type) + 1) . $func;
$arg .= ' ' x ($longest[1] - length($func) + 1) . $arglist;
$arg =~ s/\t/' ' x ($longest[0] + $longest[1] + 3)/eg;
while ($arg =~ /^\t* {8}/m) { $arg =~ s/^(\t*) {8}/$1\t/mg }
push @{$out->{proto}}, $arg;
}