Commit 8ca3cca5 authored by Manish Singh's avatar Manish Singh

fixed a buglet that caused an FP exception in PsychoBilly mode

* plug-ins/checkerboard/checkerboard.c: fixed a buglet that
caused an FP exception in PsychoBilly mode

* added borderaverage, wind, jigsaw, and newsprint plug-ins

-Yosh
parent 76d4ba71
Thu Oct 22 04:35:43 PDT 1998 Manish Singh <yosh@gimp.org>
* plug-ins/checkerboard/checkerboard.c: fixed a buglet that
caused an FP exception in PsychoBilly mode
* added borderaverage, wind, jigsaw, and newsprint plug-ins
Thu Oct 22 02:30:38 PDT 1998 Manish Singh <yosh@gimp.org>
* libgimp/Makefile.am
......
......@@ -543,6 +543,7 @@ plug-ins/autostretch_hsv/Makefile
plug-ins/blinds/Makefile
plug-ins/blur/Makefile
plug-ins/bmp/Makefile
plug-ins/borderaverage/Makefile
plug-ins/bumpmap/Makefile
plug-ins/bz2/Makefile
plug-ins/c_astretch/Makefile
......@@ -591,12 +592,14 @@ plug-ins/hrz/Makefile
plug-ins/ifscompose/Makefile
plug-ins/illusion/Makefile
plug-ins/iwarp/Makefile
plug-ins/jigsaw/Makefile
plug-ins/laplace/Makefile
plug-ins/mail/Makefile
plug-ins/max_rgb/Makefile
plug-ins/maze/Makefile
plug-ins/mblur/Makefile
plug-ins/mosaic/Makefile
plug-ins/newsprint/Makefile
plug-ins/nlfilt/Makefile
plug-ins/noisify/Makefile
plug-ins/normalize/Makefile
......@@ -646,6 +649,7 @@ plug-ins/vpropagate/Makefile
plug-ins/waterselect/Makefile
plug-ins/waves/Makefile
plug-ins/whirlpinch/Makefile
plug-ins/wind/Makefile
plug-ins/xwd/Makefile
plug-ins/zealouscrop/Makefile
app/Makefile
......
......@@ -28,6 +28,7 @@ SUBDIRS = \
blinds \
blur \
bmp \
borderaverage \
bumpmap \
bz2 \
c_astretch \
......@@ -75,12 +76,14 @@ SUBDIRS = \
ifscompose \
illusion \
iwarp \
jigsaw \
laplace \
mail \
max_rgb \
maze \
mblur \
mosaic \
newsprint \
nlfilt \
noisify \
normalize \
......@@ -130,6 +133,7 @@ SUBDIRS = \
waterselect \
waves \
whirlpinch \
wind \
xwd \
zealouscrop
......
......@@ -301,6 +301,10 @@ inblock( gint pos, gint size)
static gint *in = NULL; /* initialized first time */
gint i,j,k, len;
/* avoid a FP exception */
if (size == 1)
size = 2;
len = size*size;
/*
* Initialize the array; since we'll be called thousands of
......
/* borderaverage 0.01 - image processing plug-in for the Gimp 1.0 API
*
* Copyright (C) 1998 Philipp Klaus (webmaster@access.ch)
*
*
* 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 <libgimp/gimp.h>
#include <gtk/gtk.h>
#include <gck/gck.h>
#include <plug-ins/megawidget/megawidget.h>
/* Declare local functions.
*/
static void query (void);
static void run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals);
static void borderaverage(GDrawable *drawable, guchar *res_r, guchar *res_g, guchar *res_b);
static gint borderaverage_dialog(void);
static void add_new_color (gint bytes, guchar* buffer, gint* cube, gint bucket_expo);
void menu_callback(GtkWidget *widget, gpointer client_data);
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
static gint borderaverage_thickness = 3;
static gint borderaverage_bucket_exponent = 4;
struct borderaverage_data {
gint thickness;
gint bucket_exponent;
} borderaverage_data = { 3, 4 };
gchar * menu_labels[] =
{
"1 (nonsens?)", "2", "4", "8", "16", "32", "64", "128", "256 (nonsens?)"
};
MAIN ()
static void
query ()
{
static GParamDef args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image (unused)" },
{ PARAM_DRAWABLE, "drawable", "Input drawable" },
{ PARAM_INT32, "thickness", "Border size to take in count" },
{ PARAM_INT32, "bucket_exponent", "Bits for bucket size (default=4: 16 Levels)" },
};
static GParamDef return_vals[] =
{
{ PARAM_INT32, "num_channels", "Number of color channels returned (always 3)" },
{ PARAM_INT8ARRAY, "color_vals", "The average color of the specified border"},
};
static int nargs = sizeof (args) / sizeof (args[0]);
static int nreturn_vals = sizeof (return_vals) / sizeof (return_vals[0]);
gimp_install_procedure ("plug_in_borderaverage",
"Borderaverage",
"",
"Philipp Klaus",
"Internet Access AG",
"1998",
"<Image>/Filters/Colors/Border Average",
"RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
static void
run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals)
{
static GParam values[3];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
gint8 *result_color;
run_mode = param[0].data.d_int32;
/* get the return memory */
result_color = (gint8 *) g_new(gint8, 3);
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
switch (run_mode) {
case RUN_INTERACTIVE:
gimp_get_data("plug_in_borderaverage", &borderaverage_data);
borderaverage_thickness = borderaverage_data.thickness;
borderaverage_bucket_exponent = borderaverage_data.bucket_exponent;
if (! borderaverage_dialog())
status = STATUS_EXECUTION_ERROR;
break;
case RUN_NONINTERACTIVE:
if (nparams != 5)
status = STATUS_CALLING_ERROR;
if (status == STATUS_SUCCESS)
borderaverage_thickness = param[3].data.d_int32;
borderaverage_bucket_exponent = param[4].data.d_int32;
break;
case RUN_WITH_LAST_VALS:
gimp_get_data("plug_in_borderaverage", &borderaverage_data);
borderaverage_thickness = borderaverage_data.thickness;
borderaverage_bucket_exponent = borderaverage_data.bucket_exponent;
break;
default:
break;
}
if (status == STATUS_SUCCESS) {
/* Make sure that the drawable is RGB color */
if (gimp_drawable_color (drawable->id)) {
gimp_progress_init ("borderaverage");
borderaverage (drawable, &result_color[0], &result_color[1], &result_color[2]);
if (run_mode != RUN_NONINTERACTIVE) {
gimp_palette_set_foreground(result_color[0],result_color[1],result_color[2]);
gimp_displays_flush ();
}
if (run_mode == RUN_INTERACTIVE)
borderaverage_data.thickness = borderaverage_thickness;
borderaverage_data.bucket_exponent = borderaverage_bucket_exponent;
gimp_set_data("plug_in_borderaverage", &borderaverage_data, sizeof(borderaverage_data));
} else {
status = STATUS_EXECUTION_ERROR;
}
}
*nreturn_vals = 3;
*return_vals = values;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
values[1].type = PARAM_INT32;
values[1].data.d_int32 = 3;
values[2].type = PARAM_INT8ARRAY;
values[2].data.d_int8array = result_color;
gimp_drawable_detach (drawable);
}
static void
borderaverage (GDrawable *drawable, guchar *res_r, guchar *res_g, guchar *res_b) {
gint width;
gint height;
gint x1, x2, y1, y2;
gint bytes;
gint max;
guchar r, g, b;
guchar *buffer;
gint bucket_num, bucket_expo, bucket_rexpo;
gint* cube;
gint row, col, i,j,k; /* index variables */
GPixelRgn myPR;
/* allocate and clear the cube before */
bucket_expo = borderaverage_bucket_exponent;
bucket_rexpo = 8 - bucket_expo;
cube = (gint*) malloc( (1 << (bucket_rexpo * 3)) * sizeof(gint) );
bucket_num = 1 << bucket_rexpo;
for (i = 0; i < bucket_num; i++) {
for (j = 0; j < bucket_num; j++) {
for (k = 0; k < bucket_num; k++) {
cube[(i << (bucket_rexpo << 1)) + (j << bucket_rexpo) + k] = 0;
}
}
}
/* Get the input area. This is the bounding box of the selection in
* the image (or the entire image if there is no selection). Only
* operating on the input area is simply an optimization. It doesn't
* need to be done for correct operation. (It simply makes it go
* faster, since fewer pixels need to be operated on).
*/
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
/* Get the size of the input image. (This will/must be the same
* as the size of the output image.
*/
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
/* allocate row buffer */
buffer = (guchar *) malloc ((x2 - x1) * bytes);
/* initialize the pixel regions */
gimp_pixel_rgn_init (&myPR, drawable, 0, 0, width, height, FALSE, FALSE);
/* loop through the rows, performing our magic*/
for (row = y1; row < y2; row++) {
gimp_pixel_rgn_get_row (&myPR, buffer, x1, row, (x2-x1));
if (row < y1 + borderaverage_thickness ||
row >= y2 - borderaverage_thickness) {
/* add the whole row */
for (col = 0; col < ((x2 - x1) * bytes); col += bytes) {
add_new_color(bytes, &buffer[col], cube, bucket_expo);
}
} else {
/* add the left border */
for (col = 0; col < (borderaverage_thickness * bytes); col += bytes) {
add_new_color(bytes, &buffer[col], cube, bucket_expo);
}
/* add the right border */
for (col = ((x2 - x1 - borderaverage_thickness) * bytes);
col < ((x2 - x1) * bytes); col += bytes) {
add_new_color(bytes, &buffer[col], cube, bucket_expo);
}
}
if ((row % 5) == 0)
gimp_progress_update ((double) row / (double) (y2 - y1));
}
max = 0; r = 0; g = 0; b = 0;
/* get max of cube */
for (i = 0; i < bucket_num; i++) {
for (j = 0; j < bucket_num; j++) {
for (k = 0; k < bucket_num; k++) {
if (cube[(i << (bucket_rexpo << 1)) + (j << bucket_rexpo) + k] > max) {
max = cube[(i << (bucket_rexpo << 1)) + (j << bucket_rexpo) + k];
r = (i<<bucket_expo) + (1<<(bucket_expo - 1));
g = (j<<bucket_expo) + (1<<(bucket_expo - 1));
b = (k<<bucket_expo) + (1<<(bucket_expo - 1));
}
}
}
}
/* return the color */
*res_r = r;
*res_g = g;
*res_b = b;
free (buffer);
}
static void add_new_color(gint bytes, guchar* buffer, gint *cube, gint bucket_expo) {
guchar r,g,b;
gint bucket_rexpo;
bucket_rexpo = 8 - bucket_expo;
r = buffer[0] >>bucket_expo;
if (bytes > 1) {
g = buffer[1] >>bucket_expo;
} else {
g = 0;
}
if (bytes > 2) {
b = buffer[2] >>bucket_expo;
} else {
b = 0;
}
cube[(r << (bucket_rexpo << 1)) + (g << bucket_rexpo) + b]++;
}
static gint borderaverage_dialog() {
GtkWidget *dlg, *frame, *vbox2;
GtkWidget *vbox, *menu;
gint runp;
gchar **argv;
gint argc;
/* Set args */
argc = 1;
argv = g_new(gchar *, 1);
argv[0] = g_strdup("borderaverage");
gtk_init(&argc, &argv);
gtk_rc_parse(gimp_gtkrc());
dlg = mw_app_new("plug_in_borderaverage", "Borderaverage", &runp);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(vbox), 5);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), vbox, TRUE, TRUE, 0);
gtk_widget_show(vbox);
mw_ientry_new(vbox, "Border Size", "Thickness", &borderaverage_thickness);
frame=gck_frame_new("Number of colors",vbox,GTK_SHADOW_ETCHED_IN,FALSE,FALSE,0,2);
vbox2=gck_vbox_new(frame,FALSE,TRUE,TRUE,5,0,5);
menu=gck_option_menu_new("Bucket Size:",vbox2,TRUE,TRUE,0,
menu_labels,(GtkSignalFunc)menu_callback, NULL);
gtk_option_menu_set_history(GTK_OPTION_MENU(menu),borderaverage_bucket_exponent);
gtk_widget_show(menu);
gtk_widget_show(dlg);
gtk_main();
gdk_flush();
if (runp)
return 1;
else
return 0;
}
void menu_callback(GtkWidget *widget, gpointer client_data) {
borderaverage_bucket_exponent=(gint)gtk_object_get_data(GTK_OBJECT(widget),"_GckOptionMenuItemID");
}
......@@ -301,6 +301,10 @@ inblock( gint pos, gint size)
static gint *in = NULL; /* initialized first time */
gint i,j,k, len;
/* avoid a FP exception */
if (size == 1)
size = 2;
len = size*size;
/*
* Initialize the array; since we'll be called thousands of
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Makefile.in
Makefile
.deps
_libs
.libs
jigsaw
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = jigsaw
jigsaw_SOURCES = \
jigsaw.c
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS)
DEPS = \
$(top_builddir)/libgimp/libgimp.la
jigsaw_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
This diff is collapsed.
Makefile.in
Makefile
.deps
_libs
.libs
newsprint
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = newsprint
newsprint_SOURCES = \
newsprint.c
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS)
DEPS = \
$(top_builddir)/libgimp/libgimp.la
newsprint_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
This diff is collapsed.
Makefile.in
Makefile
.deps
_libs
.libs
wind
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = wind
wind_SOURCES = \
wind.c
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS)
DEPS = \
$(top_builddir)/libgimp/libgimp.la
wind_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
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment