Commit 4c330841 authored by Sven Neumann's avatar Sven Neumann

Added the rcm plugin.


--Sven
parent 24ffa60f
Mon Apr 5 22:28:01 MEST 1999 Sven Neumann <sven@gimp.org>
* configure.in
* plug-ins/Makefile.am
* plug-ins/rcm: Added RotateColorMap plug-in. This is a rewrite
of the original plug-in by Pavel Grinfeld done by Sven Anders
(anderss@fmi.uni-passau.de)
1999-04-05 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/action_area.h: #include <gtk/gtk.h>.
......
......@@ -783,6 +783,7 @@ plug-ins/print/Makefile
plug-ins/ps/Makefile
plug-ins/psd/Makefile
plug-ins/randomize/Makefile
plug-ins/rcm/Makefile
plug-ins/ripple/Makefile
plug-ins/rotate/Makefile
plug-ins/rotators/Makefile
......
......@@ -111,6 +111,7 @@ SUBDIRS = \
ps \
psd \
randomize \
rcm \
ripple \
rotate \
rotators \
......
Makefile.in
Makefile
.deps
_libs
.libs
rcm
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = rcm
rcm_SOURCES = \
rcm.c \
rcm_dialog.c \
rcm_callback.c \
rcm_gdk.c \
rcm_misc.c
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimp.la \
$(GTK_LIBS)
DEPS = \
$(top_builddir)/libgimp/libgimp.la
rcm_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
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Colormap-Rotation plug-in. Exchanges two color ranges.
*
* Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
* Based on code from Pavel Grinfeld (pavel@ml.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.
*/
/*-----------------------------------------------------------------------------------
* Change log:
*
* Version 2.0, 04 April 1999.
* Nearly complete rewrite, made plug-in stable.
* (Works with GIMP 1.1 and GTK+ 1.2)
*
* Version 1.0, 27 March 1997.
* Initial (unstable) release by Pavel Grinfeld
*
*-----------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpintl.h>
#include "rcm.h"
#include "rcm_misc.h"
#include "rcm_dialog.h"
#include "rcm_callback.h"
/*-----------------------------------------------------------------------------------*/
/* Forward declarations */
/*-----------------------------------------------------------------------------------*/
void query(void);
void run(char *name, int nparams, GParam *param, int *nreturn_vals, GParam **return_vals);
/*-----------------------------------------------------------------------------------*/
/* Global variables */
/*-----------------------------------------------------------------------------------*/
RcmParams Current =
{
SELECTION, /* SELECTION ONLY */
TRUE, /* REAL TIME */
FALSE, /* SUCCESS */
RADIANS_OVER_PI, /* START IN RADIANS OVER PI */
GRAY_TO
};
/*-----------------------------------------------------------------------------------*/
/* Local variables */
/*-----------------------------------------------------------------------------------*/
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
/*-----------------------------------------------------------------------------------*/
/* Dummy function */
/*-----------------------------------------------------------------------------------*/
MAIN();
/*-----------------------------------------------------------------------------------*/
/* Query plug-in */
/*-----------------------------------------------------------------------------------*/
void query(void)
{
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 ("Colormap rotation plug-in",
"Colormap rotation as in xv",
"Exchanges two color ranges. "\
"Based on code from Pavel Grinfeld (pavel@ml.com). "\
"This version written by Sven Anders (anderss@fmi.uni-passau.de).",
"Sven Anders (anderss@fmi.uni-passau.de) and Pavel Grinfeld (pavel@ml.com)",
"Sven Anders (anderss@fmi.uni-passau.de)",
"04th April 1999",
"<Image>/Filters/Darkroom/Colormap Rotation",
"RGB*",
PROC_PLUG_IN,
nargs, nreturn_vals,
args, return_vals);
}
/*-----------------------------------------------------------------------------------*/
/* Rotate colormap of a single row */
/*-----------------------------------------------------------------------------------*/
void rcm_row(const guchar *src_row, guchar *dest_row,
gint row, gint row_width, gint bytes)
{
gint col, bytenum, skip;
hsv H,S,V,R,G,B;
for (col=0; col < row_width; col++)
{
skip = 0;
R = (float)src_row[col*bytes + 0]/255.0;
G = (float)src_row[col*bytes + 1]/255.0;
B = (float)src_row[col*bytes + 2]/255.0;
rgb_to_hsv(R,G,B, &H,&S,&V);
if (rcm_is_gray(S))
{
if (Current.Gray_to_from == GRAY_FROM)
{
if (rcm_angle_inside_slice(Current.Gray->hue,Current.From->angle) <= 1)
{
H = Current.Gray->hue / TP;
S = Current.Gray->satur;
}
else
{
skip = 1;
}
}
else
{
skip = 1;
hsv_to_rgb(Current.Gray->hue/TP, Current.Gray->satur, V, &R, &G, &B);
}
}
if (!skip)
{
H = rcm_linear(rcm_left_end(Current.From->angle),
rcm_right_end(Current.From->angle),
rcm_left_end(Current.To->angle),
rcm_right_end(Current.To->angle),
H*TP);
H = angle_mod_2PI(H) / TP;
hsv_to_rgb(H,S,V, &R,&G,&B);
}
dest_row[col*bytes +0] = R * 255;
dest_row[col*bytes +1] = G * 255;
dest_row[col*bytes +2] = B * 255;
if (bytes > 3)
{
for (bytenum=3; bytenum<bytes; bytenum++)
dest_row[col*bytes+bytenum] = src_row[col*bytes+bytenum];
}
}
}
/*-----------------------------------------------------------------------------------*/
/* Rotate colormap row by row ... */
/*-----------------------------------------------------------------------------------*/
void rcm(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));
rcm_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);
}
/*-----------------------------------------------------------------------------------*/
/* 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;
Current.drawable = gimp_drawable_get(param[2].data.d_drawable);
Current.mask = gimp_drawable_get(gimp_image_get_selection(param[1].data.d_image));
/* works not on INDEXED images */
if (gimp_drawable_indexed (Current.drawable->id) ||
gimp_drawable_gray (Current.drawable->id) )
{
status = STATUS_EXECUTION_ERROR;
}
else
{
/* call dialog and rotate the colormap */
if (gimp_drawable_color(Current.drawable->id) && rcm_dialog())
{
gimp_progress_init(_("Rotating the colormap..."));
gimp_tile_cache_ntiles(2 * (Current.drawable->width / gimp_tile_width() + 1));
rcm(Current.drawable);
gimp_displays_flush();
}
else
status = STATUS_EXECUTION_ERROR;
}
values[0].data.d_status = status;
if (status == STATUS_SUCCESS)
gimp_drawable_detach(Current.drawable);
}
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Colormap-Rotation plug-in. Exchanges two color ranges.
*
* Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
* Based on code from Pavel Grinfeld (pavel@ml.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.
*/
/*-----------------------------------------------------------------------------------
* Change log:
*
* Version 2.0, 04 April 1999.
* Nearly complete rewrite, made plug-in stable.
* (Works with GIMP 1.1 and GTK+ 1.2)
*
* Version 1.0, 27 March 1997.
* Initial (unstable) release by Pavel Grinfeld
*
*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Global defines */
/*-----------------------------------------------------------------------------------*/
#ifndef PI
#define PI 3.14159265358979323846
#endif
#define TP (2*PI)
/*-----------------------------------------------------------------------------------*/
/* Typedefs */
/*-----------------------------------------------------------------------------------*/
enum { ENTIRE_IMAGE, SELECTION, SELECTION_IN_CONTEXT, PREVIEW_OPTIONS };
enum { EACH, BOTH, DEGREES, RADIANS, RADIANS_OVER_PI,
GRAY_FROM, GRAY_TO, CURRENT, ORIGINAL };
typedef enum { VIRGIN, DRAG_START, DRAGING, DO_NOTHING } RcmOp;
typedef double hsv;
typedef struct
{
float alpha;
float beta;
int cw_ccw;
} RcmAngle;
typedef struct
{
gint width;
gint height;
guchar *rgb;
hsv *hsv;
guchar *mask;
} ReducedImage;
typedef struct
{
GtkWidget *preview;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *cw_ccw_button;
GtkWidget *cw_ccw_box;
GtkWidget *cw_ccw_label;
GtkWidget *cw_ccw_pixmap;
GtkWidget *a_b_button;
GtkWidget *a_b_box;
GtkWidget *a_b_pixmap;
GtkWidget *f360_button;
GtkWidget *f360_box;
GtkWidget *f360_pixmap;
GtkWidget *alpha_entry;
GtkWidget *alpha_units_label;
GtkWidget *beta_entry;
GtkWidget *beta_units_label;
gfloat *target;
gint mode;
RcmAngle *angle;
RcmOp action_flag;
gfloat prev_clicked;
} RcmCircle;
typedef struct
{
GtkWidget *dlg;
GtkWidget *bna_frame;
GtkWidget *before;
GtkWidget *after;
} RcmBna;
typedef struct
{
GtkWidget *preview;
GtkWidget *frame;
float gray_sat;
float hue;
float satur;
GtkWidget *gray_sat_entry;
GtkWidget *hue_entry;
GtkWidget *hue_units_label;
GtkWidget *satur_entry;
RcmOp action_flag;
} RcmGray;
typedef struct
{
gint Slctn;
gint RealTime;
gint Success;
gint Units;
gint Gray_to_from;
GDrawable *drawable;
GDrawable *mask;
ReducedImage *reduced;
RcmCircle *To;
RcmCircle *From;
RcmGray *Gray;
RcmBna *Bna;
} RcmParams;
/*-----------------------------------------------------------------------------------*/
/* Global variables */
/*-----------------------------------------------------------------------------------*/
extern RcmParams Current;
/*-----------------------------------------------------------------------------------*/
This diff is collapsed.
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Colormap-Rotation plug-in. Exchanges two color ranges.
*
* Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
* Based on code from Pavel Grinfeld (pavel@ml.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.
*/
/*-----------------------------------------------------------------------------------
* Change log:
*
* Version 2.0, 04 April 1999.
* Nearly complete rewrite, made plug-in stable.
* (Works with GIMP 1.1 and GTK+ 1.2)
*
* Version 1.0, 27 March 1997.
* Initial (unstable) release by Pavel Grinfeld
*
*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Misc functions */
/*-----------------------------------------------------------------------------------*/
float rcm_units_factor(gint units);
gchar *rcm_units_string(gint units);
void rcm_set_pixmap(GtkWidget **widget, GtkWidget *parent,
GtkWidget *label_box, char **pixmap_data);
/*-----------------------------------------------------------------------------------*/
/* Ok/Cancel Buttons */
/*-----------------------------------------------------------------------------------*/
void rcm_close_callback(GtkWidget *widget, gpointer data);
void rcm_ok_callback(GtkWidget *widget, gpointer data);
/*-----------------------------------------------------------------------------------*/
/* Circle buttons */
/*-----------------------------------------------------------------------------------*/
void rcm_360_degrees(GtkWidget *button, RcmCircle *circle);
void rcm_cw_ccw(GtkWidget *button, RcmCircle *circle);
void rcm_a_to_b(GtkWidget *button, RcmCircle *circle);
/*-----------------------------------------------------------------------------------*/
/* Misc: units buttons */
/*-----------------------------------------------------------------------------------*/
void rcm_switch_to_degrees(GtkWidget *button, gpointer *value);
void rcm_switch_to_radians(GtkWidget *button, gpointer *value);
void rcm_switch_to_radians_over_PI(GtkWidget *button, gpointer *value);
/*-----------------------------------------------------------------------------------*/
/* Misc: Gray: mode buttons */
/*-----------------------------------------------------------------------------------*/
void rcm_switch_to_gray_to(GtkWidget *button, gpointer *value);
void rcm_switch_to_gray_from(GtkWidget *button, gpointer *value);
/*-----------------------------------------------------------------------------------*/
/* Misc: Preview buttons */
/*-----------------------------------------------------------------------------------*/
void rcm_preview_as_you_drag(GtkWidget *button, gpointer *value);
void rcm_selection_in_context(GtkWidget *button, gpointer *value);
void rcm_selection(GtkWidget *button, gpointer *value);
void rcm_entire_image(GtkWidget *button, gpointer *value);
/*-----------------------------------------------------------------------------------*/
/* Circle events */
/*-----------------------------------------------------------------------------------*/
gint rcm_expose_event(GtkWidget *widget, GdkEvent *event, RcmCircle *circle);
gint rcm_button_press_event(GtkWidget *widget, GdkEvent *event, RcmCircle *circle);
gint rcm_release_event(GtkWidget *widget, GdkEvent *event, RcmCircle *circle);
gint rcm_motion_notify_event(GtkWidget *widget, GdkEvent *event, RcmCircle *circle);
/*-----------------------------------------------------------------------------------*/
/* Gray circle events */
/*-----------------------------------------------------------------------------------*/
gint rcm_gray_expose_event(GtkWidget *widget, GdkEvent *event, RcmGray *circle);
gint rcm_gray_button_press_event(GtkWidget *widget, GdkEvent *event, RcmGray *circle);
gint rcm_gray_release_event(GtkWidget *widget, GdkEvent *event, RcmGray *circle);
gint rcm_gray_motion_notify_event(GtkWidget *widget, GdkEvent *event, RcmGray *circle);
/*-----------------------------------------------------------------------------------*/
/* Spinbuttons */
/*-----------------------------------------------------------------------------------*/
void rcm_set_alpha(GtkWidget *entry, gpointer data);
void rcm_set_beta(GtkWidget *entry, gpointer data);
void rcm_set_hue(GtkWidget *entry, gpointer data);
void rcm_set_satur(GtkWidget *entry, gpointer data);
void rcm_set_gray_sat(GtkWidget *entry, gpointer data);
/*-----------------------------------------------------------------------------------*/
This diff is collapsed.
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Colormap-Rotation plug-in. Exchanges two color ranges.
*
* Copyright (C) 1999 Sven Anders (anderss@fmi.uni-passau.de)
* Based on code from Pavel Grinfeld (pavel@ml.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.
*/
/*-----------------------------------------------------------------------------------
* Change log:
*
* Version 2.0, 04 April 1999.
* Nearly complete rewrite, made plug-in stable.
* (Works with GIMP 1.1 and GTK+ 1.2)
*
* Version 1.0, 27 March 1997.
* Initial (unstable) release by Pavel Grinfeld
*
*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Global defines */
/*-----------------------------------------------------------------------------------*/
#define MAX_PREVIEW_SIZE 150
/*-----------------------------------------------------------------------------------*/
/* Procedures */
/*-----------------------------------------------------------------------------------*/
gint rcm_dialog();
/*-----------------------------------------------------------------------------------*/
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*