Commit 4607c5e5 authored by Manish Singh's avatar Manish Singh

Start of a stable/unstable plug-in split (these are going into

gimp-plugins-unstable)

-Yosh
parent 0e9f9891
......@@ -289,7 +289,6 @@ plug-ins/maze/Makefile
plug-ins/max_rgb/Makefile
plug-ins/mail/Makefile
plug-ins/magiceye/Makefile
plug-ins/lic/Makefile
plug-ins/laplace/Makefile
plug-ins/ifscompose/Makefile
plug-ins/iwarp/Makefile
......@@ -307,10 +306,8 @@ plug-ins/gfli/Makefile
plug-ins/gbr/Makefile
plug-ins/gauss_iir/Makefile
plug-ins/gauss_rle/Makefile
plug-ins/fp/Makefile
plug-ins/fits/Makefile
plug-ins/film/Makefile
plug-ins/figures/Makefile
plug-ins/faxg3/Makefile
plug-ins/exchange/Makefile
plug-ins/engrave/Makefile
......@@ -358,13 +355,10 @@ plug-ins/flame/Makefile
plug-ins/gimptcl/Makefile
plug-ins/gimptcl/scripts/Makefile
plug-ins/fuse/Makefile
plug-ins/mathmap/Makefile
plug-ins/rcm/Makefile
plug-ins/refract/Makefile
plug-ins/struc/Makefile
plug-ins/twist/Makefile
plug-ins/user_filter/Makefile
plug-ins/warp/Makefile
plug-ins/zealouscrop/Makefile
plug-ins/xwd/Makefile
plug-ins/whirlpinch/Makefile
......
......@@ -14,11 +14,9 @@ SUBDIRS = \
fuse \
gflare \
@GIMPTCL@ \
refract \
script-fu \
struc \
twist \
warp \
@TIFF@ \
@JPEG@ \
@PNG@ \
......@@ -57,12 +55,10 @@ SUBDIRS = \
engrave \
exchange \
faxg3 \
figures \
film \
fits \
flame \
flarefx \
fp \
fractaltrace \
gauss_iir \
gauss_rle \
......@@ -83,7 +79,6 @@ SUBDIRS = \
illusion \
iwarp \
laplace \
lic \
magiceye \
mail \
max_rgb \
......
#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"
#include "libgimp/gimp.h"
#include "fp.h"
#include "fp_hsv.h"
FP_Params Current =
{
1,
.25, /* Initial Roughness */
NULL,
.6, /* Initial Degree of Aliasing */
NULL,
60,
NULL,
MIDTONES, /* Initial Range */
BY_VAL, /* Initial God knows what */
TRUE, /* Selection Only */
TRUE, /* Real Time */
0, /* Offset */
HUE|VALUE,
{32,224,255},
{0,0,0}
};
GDrawable *drawable, *mask;
void query (void);
void run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals);
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN()
void
query ()
{
GParamDef args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image (used for indexed images)" },
{ PARAM_DRAWABLE, "drawable", "Input drawable" },
};
GParamDef *return_vals = NULL;
int nargs = sizeof (args) / sizeof (args[0]);
int nreturn_vals = 0;
gimp_install_procedure ("plug_in_filter_pack",
"Allows the user to change H, S, or C with many previews",
"Then something else here",
"Pavel Grinfeld (pavel@ml.com)",
"Pavel Grinfeld (pavel@ml.com)",
"27th March 1997",
"<Image>/Filters/Colors/Filter Pack",
"RGB*,INDEXED*,GRAY*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
/********************************STANDARD RUN*************************/
void
run (char *name,
int nparams,
GParam *param,
int *nreturn_vals,
GParam **return_vals)
{
GParam values[1];
GStatusType status = STATUS_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
initializeFilterPacks();
drawable = gimp_drawable_get (param[2].data.d_drawable);
mask=gimp_drawable_get(gimp_image_get_selection(param[1].data.d_image));
if (gimp_drawable_indexed (drawable->id) ||gimp_drawable_gray (drawable->id) ) {
ErrorMessage("Convert the image to RGB first!");
status = STATUS_EXECUTION_ERROR;
}
else if (gimp_drawable_color (drawable->id) && fp_dialog())
{
gimp_progress_init ("Applying the Filter Pack...");
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
fp (drawable);
gimp_displays_flush ();
}
else status = STATUS_EXECUTION_ERROR;
values[0].data.d_status = status;
if (status==STATUS_SUCCESS)
gimp_drawable_detach (drawable);
}
void
fp_row (const guchar *src_row,
guchar *dest_row,
gint row,
gint row_width,
gint bytes)
{
gint col, bytenum, k;
int JudgeBy, Intensity, P[3], backupP[3];
hsv H,S,V;
gint M, m, middle;
/* initialize */
Intensity = 0;
for (col = 0; col < row_width ; col++)
{
backupP[0] = P[0] = src_row[col*bytes+0];
backupP[0] = P[1] = src_row[col*bytes+1];
backupP[0] = P[2] = src_row[col*bytes+2];
rgb_to_hsv(P[0]/255.0, P[1]/255.0, P[2]/255.0, &H, &S, &V);
for (JudgeBy=BY_HUE; JudgeBy<JUDGE_BY; JudgeBy++) {
if (!Current.Touched[JudgeBy]) continue;
switch (JudgeBy) {
case BY_HUE:
Intensity=255*H;
break;
case BY_SAT:
Intensity=255*S;
break;
case BY_VAL:
Intensity=255*V;
break;
}
/* It's important to take care of Saturation first!!! */
m = MIN(MIN(P[0],P[1]),P[2]);
M = MAX(MAX(P[0],P[1]),P[2]);
middle=(M+m)/2;
for (k=0; k<3; k++)
if (P[k]!=m && P[k]!=M) middle=P[k];
for (k=0; k<3; k++)
if (M!=m)
if (P[k] == M)
P[k] = MAX(P[k]+Current.satAdj[JudgeBy][Intensity],middle);
else if (P[k] == m)
P[k] = MIN(P[k]-Current.satAdj[JudgeBy][Intensity],middle);
P[0] += Current.redAdj[JudgeBy][Intensity];
P[1] += Current.greenAdj[JudgeBy][Intensity];
P[2] += Current.blueAdj[JudgeBy][Intensity];
P[0] = MAX(0,MIN(255, P[0]));
P[1] = MAX(0,MIN(255, P[1]));
P[2] = MAX(0,MIN(255, P[2]));
}
dest_row[col*bytes + 0] = P[0];
dest_row[col*bytes + 1] = P[1];
dest_row[col*bytes + 2] = P[2];
if (bytes>3)
for (bytenum = 3; bytenum<bytes; bytenum++)
dest_row[col*bytes+bytenum] = src_row[col*bytes+bytenum];
}
}
void fp (GDrawable *drawable)
{
GPixelRgn srcPR, destPR;
gint width, height;
gint bytes;
guchar *src_row, *dest_row;
gint row;
gint x1, y1, x2, y2;
gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2);
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
src_row = (guchar *) malloc ((x2 - x1) * bytes);
dest_row = (guchar *) malloc ((x2 - x1) * bytes);
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
for (row = y1; row < y2; row++)
{
gimp_pixel_rgn_get_row (&srcPR, src_row, x1, row, (x2 - x1));
fp_row (src_row,
dest_row,
row,
(x2 - x1),
bytes
);
gimp_pixel_rgn_set_row (&destPR, dest_row, x1, row, (x2 - x1));
if ((row % 10) == 0)
gimp_progress_update ((double) row / (double) (y2 - y1));
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1));
free (src_row);
free (dest_row);
}
void
ErrorMessage(guchar *message)
{
GtkWidget *window, *label, *button,*table;
gchar **argv=g_new (gchar *, 1);
gint argc=1;
argv[0] = g_strdup ("fp");
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc ());
window=gtk_dialog_new();
gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
gtk_window_set_title(GTK_WINDOW(window),"Filter Pack Simulation Message");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
(GtkSignalFunc) fp_close_callback,
NULL);
button = gtk_button_new_with_label ("Got It!");
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) fp_ok_callback,
window);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);
table=gtk_table_new(2,2,FALSE);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox),table,TRUE,TRUE,0);
gtk_widget_show(table);
label=gtk_label_new("");
gtk_label_set(GTK_LABEL(label),message);
gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table),label,0,1,0,1,
GTK_FILL|GTK_EXPAND,GTK_FILL|GTK_EXPAND,15,15);
gtk_widget_show(window);
gtk_main ();
}
This diff is collapsed.
Makefile.in
Makefile
.deps
_libs
.libs
figures
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = figures
figures_SOURCES = \
figures.c
INCLUDES = \
$(X_CFLAGS) \
-I$(top_srcdir) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la \
$(X_LIBS) \
\
-lc
DEPS = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la
figures_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
/* The GIMP -- an image manipulation program * Copyright (C) 1995 Spencer
* Kimball and Peter Mattis * * 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., 675 Mass Ave, Cambridge, MA
* 02139, USA. */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "libgimp/gimp.h"
#include "gtk/gtk.h"
/* Declare local functions. */
static void query(void);
static void run(char *name,
int nparams,
GParam * param,
int *nreturn_vals,
GParam ** return_vals);
static gint dialog();
static void doit(GDrawable * drawable);
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
gint bytes;
gint sx1, sy1, sx2, sy2;
int run_flag = 0;
typedef struct {
gint min_width, max_width;
gint min_height, max_height;
float density;
} config;
config my_config =
{
10, 30, /* min_width, max_width */
10, 30, /* min_height, max_height */
4 /* density */
};
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_FLOAT, "density", "Density"},
{PARAM_INT32, "min_width", "Min. width"},
{PARAM_INT32, "max_width", "Max. width"},
{PARAM_INT32, "min_height", "Min. height"},
{PARAM_INT32, "max_height", "Max. height"},
};
static GParamDef *return_vals = NULL;
static int nargs = sizeof(args) / sizeof(args[0]);
static int nreturn_vals = 0;
gimp_install_procedure("plug_in_figures",
"Draws lots of rectangles.",
"Can be nice to use as \"textures\".",
"Tim Newsome",
"Tim Newsome",
"1997",
"<Image>/Filters/Render/Figures",
"RGB*, GRAY*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
static void run(char *name, int n_params, GParam * param, int *nreturn_vals,
GParam ** return_vals)
{
static GParam values[1];
GDrawable *drawable;
GRunModeType run_mode;
GStatusType status = STATUS_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
run_mode = param[0].data.d_int32;
if (run_mode == RUN_NONINTERACTIVE) {
if (n_params != 8) {
status = STATUS_CALLING_ERROR;
} else {
my_config.density = param[3].data.d_float;
my_config.min_width = param[4].data.d_int32;
my_config.max_width = param[5].data.d_int32;
my_config.min_height = param[6].data.d_int32;
my_config.max_height = param[7].data.d_int32;
}
} else {
/* Possibly retrieve data */
gimp_get_data("plug_in_figures", &my_config);
if (run_mode == RUN_INTERACTIVE) {
/* Oh boy. We get to do a dialog box, because we can't really expect the
* user to set us up with the right values using gdb.
*/
if (!dialog()) {
/* The dialog was closed, or something similarly evil happened. */
status = STATUS_EXECUTION_ERROR;
}
}
}
if (status == STATUS_SUCCESS) {
/* Get the specified drawable */
drawable = gimp_drawable_get(param[2].data.d_drawable);
/* Make sure that the drawable is gray or RGB color */
if (gimp_drawable_color(drawable->id) || gimp_drawable_gray(drawable->id)) {
gimp_progress_init("Drawing Figures...");
gimp_tile_cache_ntiles(2 * (drawable->width / gimp_tile_width() + 1));
srand(time(NULL));
doit(drawable);
if (run_mode != RUN_NONINTERACTIVE)
gimp_displays_flush();
if (run_mode == RUN_INTERACTIVE)
gimp_set_data("plug_in_figures", &my_config, sizeof(my_config));
} else {
status = STATUS_EXECUTION_ERROR;
}
gimp_drawable_detach(drawable);
}
values[0].type = PARAM_STATUS;
values[0].data.d_status = status;
}
/*
* Draws a rectangle in region, using tmp as tempspace, with center x, y,
* width w, height h, with color color, and opaqueness a.
*/
static void draw_rectangle(guchar * tmp, GPixelRgn * region, int x, int y,
int w, int h, guchar color[], float a)
{
int i, j, k;
int rx1, rx2, ry1, ry2;
rx1 = x - w / 2;
rx2 = rx1 + w;
ry1 = y - h / 2;
ry2 = ry1 + h;
rx1 = rx1 < sx1 ? sx1 : rx1;
ry1 = ry1 < sy1 ? sy1 : ry1;
rx2 = rx2 > sx2 ? sx2 : rx2;
ry2 = ry2 > sy2 ? sy2 : ry2;
gimp_pixel_rgn_get_rect(region, tmp, rx1, ry1, rx2 - rx1, ry2 - ry1);
for (j = 0; j < (rx2 - rx1); j++) {
for (k = 0; k < (ry2 - ry1); k++) {
for (i = 0; i < bytes; i++) {
tmp[(j + (rx2 - rx1) * k) * bytes + i] =
(float) tmp[(j + (rx2 - rx1) * k) * bytes + i] * (1 - a) +
(float) color[i] * a;
}
}
}
gimp_pixel_rgn_set_rect(region, tmp, rx1, ry1, rx2 - rx1, ry2 - ry1);
}
static void doit(GDrawable * drawable)
{
GPixelRgn srcPR, destPR;
gint width, height;
int x, y, w, h;
int i, j;
guchar *tmp, *copybuf;
guchar color[4];
int objects;
/* 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, &sx1, &sy1, &sx2, &sy2);
/* 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;
tmp = (guchar *) malloc(my_config.max_width * my_config.max_height * bytes);
if (tmp == NULL) {
return;
}
/* initialize the 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);
/* First off, copy the old one to the new one. */
copybuf = malloc(width * bytes);
for (i = sy1; i < sy2; i++) {
gimp_pixel_rgn_get_row(&srcPR, copybuf, sx1, i, width);
gimp_pixel_rgn_set_row(&destPR, copybuf, sx1, i, width);
}
free(copybuf);
objects = my_config.density * (float) (width * height) /
(float) (((my_config.min_width + my_config.max_width) / 2) *
((my_config.min_height + my_config.max_height)) / 2);
for (i =</