Commit 993089b8 authored by Manish Singh's avatar Manish Singh

moved a bunch of PDB stuff here

* app/color_cmds.c: moved a bunch of PDB stuff here

* app/color_balance.[ch]: removed PDB proc, exported TransferMode
enum, ColorBalanceDialog, color_balance_create_lookup_tables, and
color_balance

* app/curves.[ch]: removed PDB procs, exported SMOOTH and GFREE
#defines, CurvesDialog, curves_lut_func and curves_calculate_curve

* app/desaturate.[ch]: removed PDB proc, exported desaturate

* app/equalize.[ch]: removed PDB proc, exported equalize

* app/histogram_tool.[ch]: removed PDB proc, exported HISTOGRAM_WIDTH
and HISTOGRAM_HEIGHT #defines, HistogramToolDialog,
histogram_tool_histogram_range

* app/hue_saturation.[ch]: removed PDB proc, exported HueRange enum,
HueSaturationDialog, hue_saturation_calculate_transfers,
hue_saturation

* app/invert.[ch]: remove PDB proc, export invert

* app/threshold.[ch]: remove PDB proc, export ThresholdDialog and
threshold_2

* internal_procs.c: changes for pdbgen

* app/gimprc.c: removed leftover declaration

* app/image_map.h: add #include "gimpdrawableF.h"

* app/lut_funcs.h: add ALPHA_LUT to ChannelLutType

-Yosh
parent 08d2c8f3
Tue Apr 20 21:53:01 PDT 1999 Manish Singh <yosh@gimp.org>
* app/color_cmds.c: moved a bunch of PDB stuff here
* app/color_balance.[ch]: removed PDB proc, exported TransferMode
enum, ColorBalanceDialog, color_balance_create_lookup_tables, and
color_balance
* app/curves.[ch]: removed PDB procs, exported SMOOTH and GFREE
#defines, CurvesDialog, curves_lut_func and curves_calculate_curve
* app/desaturate.[ch]: removed PDB proc, exported desaturate
* app/equalize.[ch]: removed PDB proc, exported equalize
* app/histogram_tool.[ch]: removed PDB proc, exported HISTOGRAM_WIDTH
and HISTOGRAM_HEIGHT #defines, HistogramToolDialog,
histogram_tool_histogram_range
* app/hue_saturation.[ch]: removed PDB proc, exported HueRange enum,
HueSaturationDialog, hue_saturation_calculate_transfers,
hue_saturation
* app/invert.[ch]: remove PDB proc, export invert
* app/threshold.[ch]: remove PDB proc, export ThresholdDialog and
threshold_2
* internal_procs.c: changes for pdbgen
* app/gimprc.c: removed leftover declaration
* app/image_map.h: add #include "gimpdrawableF.h"
* app/lut_funcs.h: add ALPHA_LUT to ChannelLutType
Wed Apr 21 01:21:55 MEST 1999 Sven Neumann <sven@gimp.org>
* app/crop.c: optimized the autocrop algorithm
......
......@@ -33,10 +33,6 @@
#define TEXT_WIDTH 55
#define SHADOWS 0
#define MIDTONES 1
#define HIGHLIGHTS 2
#define CR_SLIDER 0x1
#define MG_SLIDER 0x2
#define YB_SLIDER 0x4
......@@ -53,34 +49,6 @@ struct _ColorBalance
int x, y; /* coords for last mouse click */
};
typedef struct _ColorBalanceDialog ColorBalanceDialog;
struct _ColorBalanceDialog
{
GtkWidget *shell;
GtkWidget *cyan_red_text;
GtkWidget *magenta_green_text;
GtkWidget *yellow_blue_text;
GtkAdjustment *cyan_red_data;
GtkAdjustment *magenta_green_data;
GtkAdjustment *yellow_blue_data;
GimpDrawable *drawable;
ImageMap image_map;
double cyan_red[3];
double magenta_green[3];
double yellow_blue[3];
guchar r_lookup[256];
guchar g_lookup[256];
guchar b_lookup[256];
gint preserve_luminosity;
gint preview;
gint application_mode;
};
/* the color balance tool options */
static ToolOptions *color_balance_options = NULL;
......@@ -113,13 +81,10 @@ static void color_balance_cr_text_update (GtkWidget *, gpo
static void color_balance_mg_text_update (GtkWidget *, gpointer);
static void color_balance_yb_text_update (GtkWidget *, gpointer);
static void color_balance (PixelRegion *, PixelRegion *, void *);
static Argument * color_balance_invoker (Argument *);
/* color balance machinery */
static void
void
color_balance (PixelRegion *srcPR,
PixelRegion *destPR,
void *user_data)
......@@ -598,7 +563,7 @@ color_balance_update (ColorBalanceDialog *cbd,
}
}
static void
void
color_balance_create_lookup_tables (ColorBalanceDialog *cbd)
{
double *cyan_red_transfer[3];
......@@ -908,174 +873,3 @@ color_balance_yb_text_update (GtkWidget *w,
color_balance_preview (cbd);
}
}
/* The color_balance procedure definition */
ProcArg color_balance_args[] =
{
{ PDB_DRAWABLE,
"drawable",
"the drawable"
},
{ PDB_INT32,
"transfer_mode",
"Transfer mode: { SHADOWS (0), MIDTONES (1), HIGHLIGHTS (2) }"
},
{ PDB_INT32,
"preserve_lum",
"Preserve luminosity values at each pixel"
},
{ PDB_FLOAT,
"cyan_red",
"Cyan-Red color balance: (-100 <= cyan_red <= 100)"
},
{ PDB_FLOAT,
"magenta_green",
"Magenta-Green color balance: (-100 <= magenta_green <= 100)"
},
{ PDB_FLOAT,
"yellow_blue",
"Yellow-Blue color balance: (-100 <= yellow_blue <= 100)"
}
};
ProcRecord color_balance_proc =
{
"gimp_color_balance",
"Modify the color balance of the specified drawable",
"Modify the color balance of the specified drawable. There are three axis which can be modified: cyan-red, magenta-green, and yellow-blue. Negative values increase the amount of the former, positive values increase the amount of the latter. Color balance can be controlled with the 'transfer_mode' setting, which allows shadows, midtones, and highlights in an image to be affected differently. The 'preserve_lum' parameter, if non-zero, ensures that the luminosity of each pixel remains fixed.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1997",
PDB_INTERNAL,
/* Input arguments */
6,
color_balance_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { color_balance_invoker } },
};
static Argument *
color_balance_invoker (Argument *args)
{
PixelRegion srcPR, destPR;
int success = TRUE;
int int_value;
ColorBalanceDialog cbd;
GImage *gimage;
int transfer_mode;
int preserve_lum;
double cyan_red;
double magenta_green;
double yellow_blue;
double fp_value;
int x1, y1, x2, y2;
int i;
void *pr;
GimpDrawable *drawable;
drawable = NULL;
transfer_mode = MIDTONES;
cyan_red = 0;
magenta_green = 0;
yellow_blue = 0;
/* the drawable */
if (success)
{
int_value = args[0].value.pdb_int;
drawable = drawable_get_ID (int_value);
if (drawable == NULL)
success = FALSE;
else
gimage = drawable_gimage (drawable);
}
/* make sure the drawable is not indexed color */
if (success)
success = ! drawable_indexed (drawable);
/* transfer_mode */
if (success)
{
int_value = args[1].value.pdb_int;
switch (int_value)
{
case 0: transfer_mode = SHADOWS; break;
case 1: transfer_mode = MIDTONES; break;
case 2: transfer_mode = HIGHLIGHTS; break;
default: success = FALSE; break;
}
}
/* preserve_lum */
if (success)
{
int_value = args[2].value.pdb_int;
preserve_lum = (int_value) ? TRUE : FALSE;
}
/* cyan_red */
if (success)
{
fp_value = args[3].value.pdb_float;
if (fp_value >= -100 && fp_value <= 100)
cyan_red = fp_value;
else
success = FALSE;
}
/* magenta_green */
if (success)
{
fp_value = args[4].value.pdb_float;
if (fp_value >= -100 && fp_value <= 100)
magenta_green = fp_value;
else
success = FALSE;
}
/* yellow_blue */
if (success)
{
fp_value = args[5].value.pdb_float;
if (fp_value >= -100 && fp_value <= 100)
yellow_blue = fp_value;
else
success = FALSE;
}
/* arrange to modify the color balance */
if (success)
{
for (i = 0; i < 3; i++)
{
cbd.cyan_red[i] = 0.0;
cbd.magenta_green[i] = 0.0;
cbd.yellow_blue[i] = 0.0;
}
cbd.preserve_luminosity = preserve_lum;
cbd.cyan_red[transfer_mode] = cyan_red;
cbd.magenta_green[transfer_mode] = magenta_green;
cbd.yellow_blue[transfer_mode] = yellow_blue;
color_balance_create_lookup_tables (&cbd);
/* The application should occur only within selection bounds */
drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, drawable_shadow (drawable), x1, y1, (x2 - x1), (y2 - y1), TRUE);
for (pr = pixel_regions_register (2, &srcPR, &destPR); pr != NULL; pr = pixel_regions_process (pr))
color_balance (&srcPR, &destPR, (void *) &cbd);
drawable_merge_shadow (drawable, TRUE);
drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
}
return procedural_db_return_args (&color_balance_proc, success);
}
......@@ -18,16 +18,52 @@
#ifndef __COLOR_BALANCE_H__
#define __COLOR_BALANCE_H__
#include <gtk/gtk.h>
#include "gimpdrawableF.h"
#include "image_map.h"
#include "tools.h"
#include "procedural_db.h"
typedef enum
{
SHADOWS,
MIDTONES,
HIGHLIGHTS
} TransferMode;
typedef struct _ColorBalanceDialog ColorBalanceDialog;
struct _ColorBalanceDialog
{
GtkWidget *shell;
GtkWidget *cyan_red_text;
GtkWidget *magenta_green_text;
GtkWidget *yellow_blue_text;
GtkAdjustment *cyan_red_data;
GtkAdjustment *magenta_green_data;
GtkAdjustment *yellow_blue_data;
GimpDrawable *drawable;
ImageMap image_map;
double cyan_red[3];
double magenta_green[3];
double yellow_blue[3];
guchar r_lookup[256];
guchar g_lookup[256];
guchar b_lookup[256];
gint preserve_luminosity;
gint preview;
gint application_mode;
};
/* by_color select functions */
Tool * tools_new_color_balance (void);
void tools_free_color_balance (Tool *);
Tool * tools_new_color_balance (void);
void tools_free_color_balance (Tool *);
void color_balance_initialize (GDisplay *);
void color_balance_initialize (GDisplay *);
void color_balance (PixelRegion *, PixelRegion *, void *);
/* Procedure definition and marshalling function */
extern ProcRecord color_balance_proc;
void color_balance_create_lookup_tables (ColorBalanceDialog *);
#endif /* __COLOR_BALANCE_H__ */
......@@ -27,7 +27,6 @@
#include "general.h"
#include "gdisplay.h"
#include "gimphistogram.h"
#include "image_map.h"
#include "interface.h"
#include "curves.h"
#include "gimplut.h"
......@@ -52,9 +51,6 @@
#define RADIUS 3
#define MIN_DISTANCE 8
#define SMOOTH 0
#define GFREE 1
#define RANGE_MASK GDK_EXPOSURE_MASK | \
GDK_ENTER_NOTIFY_MASK
......@@ -74,34 +70,6 @@ struct _Curves
int x, y; /* coords for last mouse click */
};
typedef struct _CurvesDialog CurvesDialog;
struct _CurvesDialog
{
GtkWidget * shell;
GtkWidget * channel_menu;
GtkWidget * xrange;
GtkWidget * yrange;
GtkWidget * graph;
GdkPixmap * pixmap;
GimpDrawable * drawable;
ImageMap image_map;
int color;
int channel;
gint preview;
int grab_point;
int last;
int leftmost;
int rightmost;
int curve_type;
int points[5][17][2];
unsigned char curve[5][256];
int col_value[5];
GimpLut *lut;
};
typedef double CRMatrix[4][4];
......@@ -130,7 +98,6 @@ static void curves_control (Tool *, int, gpointer);
static CurvesDialog * curves_new_dialog (void);
static void curves_update (CurvesDialog *, int);
static void curves_plot_curve (CurvesDialog *, int, int, int, int);
static void curves_calculate_curve (CurvesDialog *);
static void curves_preview (CurvesDialog *);
static void curves_value_callback (GtkWidget *, gpointer);
static void curves_red_callback (GtkWidget *, gpointer);
......@@ -149,15 +116,12 @@ static gint curves_yrange_events (GtkWidget *, GdkEvent *,
static gint curves_graph_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static void curves_CR_compose (CRMatrix, CRMatrix, CRMatrix);
static Argument * curves_spline_invoker (Argument *);
static Argument * curves_explicit_invoker (Argument *);
/* curves machinery */
static float
curves_lut_func(CurvesDialog *cd,
int nchannels, int channel, float value)
float
curves_lut_func (CurvesDialog *cd,
int nchannels, int channel, float value)
{
float f;
int index;
......@@ -169,7 +133,7 @@ curves_lut_func(CurvesDialog *cd,
else
j = channel + 1;
inten = value;
/* For color images this runs through the loop with j = channel +1
/* For color images this runs through the loop with j = channel +1
the first time and j = 0 the second time */
/* For bw images this runs through the loop with j = 0 the first and
only time */
......@@ -868,7 +832,7 @@ curves_plot_curve (CurvesDialog *cd,
}
}
static void
void
curves_calculate_curve (CurvesDialog *cd)
{
int i;
......@@ -1397,300 +1361,3 @@ curves_CR_compose (CRMatrix a,
}
}
}
/*
* The curves procedure definitions
*/
/* Procedure for defining the curve with a spline */
ProcArg curves_spline_args[] =
{
{ PDB_DRAWABLE,
"drawable",
"the drawable"
},
{ PDB_INT32,
"channel",
"the channel to modify: { VALUE (0), RED (1), GREEN (2), BLUE (3), ALPHA (4), GRAY (0) }"
},
{ PDB_INT32,
"num_points",
"the number of values in the control point array ( 3 < num_points <= 32 )"
},
{ PDB_INT8ARRAY,
"control_pts",
"the spline control points: { cp1.x, cp1.y, cp2.x, cp2.y, ... }"
}
};
ProcRecord curves_spline_proc =
{
"gimp_curves_spline",
"Modifies the intensity curve(s) for specified drawable",
"Modifies the intensity mapping for one channel in the specified drawable. The drawable must be either grayscale or RGB, and the channel can be either an intensity component, or the value. The 'control_pts' parameter is an array of integers which define a set of control points which describe a Catmull Rom spline which yields the final intensity curve. Use the 'gimp_curves_explicit' function to explicitly modify intensity levels.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
PDB_INTERNAL,
/* Input arguments */
4,
curves_spline_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { curves_spline_invoker } },
};
static Argument *
curves_spline_invoker (Argument *args)
{
PixelRegion srcPR, destPR;
int success = TRUE;
int int_value;
CurvesDialog cd;
GImage *gimage;
int channel;
int num_cp;
unsigned char *control_pts;
int x1, y1, x2, y2;
int i, j;
GimpDrawable *drawable;
/* the drawable */
if (success)
{
int_value = args[0].value.pdb_int;
drawable = drawable_get_ID (int_value);
cd.drawable = drawable;
if (drawable == NULL)
success = FALSE;
else
gimage = drawable_gimage (drawable);
}
/* make sure the drawable is not indexed color */
if (success)
success = ! drawable_indexed (drawable);
/* channel */
if (success)
{
int_value = args[1].value.pdb_int;
if (success)
{
if (drawable_gray (drawable))
{
if (int_value != 0)
success = FALSE;
}
else if (drawable_color (drawable))
{
if (int_value < 0 || int_value > 3)
success = FALSE;
}
else
success = FALSE;
}
channel = int_value;
}
if (success)
{
num_cp = args[2].value.pdb_int;
if (num_cp < 4 || num_cp > 32 || (num_cp & 0x1))
success = FALSE;
}
/* control points */
if (success)
{
control_pts = (unsigned char *) args[3].value.pdb_pointer;
}
/* arrange to modify the curves */
if (success)
{
cd.lut = gimp_lut_new();
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
cd.curve[i][j] = j;
for (i = 0; i < 5; i++)
for (j = 0; j < 17; j++)
{
cd.points[i][j][0] = -1;
cd.points[i][j][1] = -1;
}
cd.channel = channel;
cd.color = drawable_color (drawable);
cd.curve_type = SMOOTH;
for (j = 0; j < num_cp / 2; j++)
{
cd.points[cd.channel][j][0] = control_pts[j * 2];
cd.points[cd.channel][j][1] = control_pts[j * 2 + 1];
}
curves_calculate_curve (&cd);
/* The application should occur only within selection bounds */
drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE);
pixel_region_init (&destPR, drawable_shadow (drawable), x1, y1, (x2 - x1), (y2 - y1), TRUE);
pixel_regions_process_parallel((p_func)gimp_lut_process, cd.lut,
2, &srcPR, &destPR);
gimp_lut_free(cd.lut);
drawable_merge_shadow (drawable, TRUE);
drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
}
return procedural_db_return_args (&curves_spline_proc, success);
}
/* Procedure for explicitly defining the curve */
ProcArg curves_explicit_args[] =
{
{ PDB_DRAWABLE,
"drawable",
"the drawable"
},
{ PDB_INT32,
"channel",
"the channel to modify: { VALUE (0), RED (1), GREEN (2), BLUE (3), GRAY (0) }"
},
{ PDB_INT32,
"num_bytes",
"the number of bytes in the new curve (always 256)"
},
{ PDB_INT8ARRAY,
"curve",
"the explicit curve"
}
};
ProcRecord curves_explicit_proc =
{
"gimp_curves_explicit",
"Modifies the intensity curve(s) for specified drawable",
"Modifies the intensity mapping for one channel in the specified drawable. The drawable must be either grayscale or RGB, and the channel can be either an intensity component, or the value. The 'curve' parameter is an array of bytes which explicitly defines how each pixel value in the drawable will be modified. Use the 'gimp_curves_spline' function to modify intensity levels with Catmull Rom splines.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
PDB_INTERNAL,
/* Input arguments */
4,
curves_explicit_args,
/* Output arguments */
0,
NULL,
/* Exec method */
{ { curves_explicit_invoker } },
};
static Argument *
curves_explicit_invoker (Argument *args)
{
PixelRegion srcPR, destPR;
int success = TRUE;
int int_value;
CurvesDialog cd;
GImage *gimage;
int channel;
unsigned char *curve;
int x1, y1, x2, y2;
int i, j;
GimpDrawable *drawable;
/* the drawable */
if (success)
{
int_value = args[0].value.pdb_int;
drawable = drawable_get_ID (int_value);
cd.drawable = drawable;
if (drawable == NULL)
success = FALSE;
else
gimage = drawable_gimage (drawable);
}
/* make sure the drawable is not indexed color */
if (success)
success = ! drawable_indexed (drawable);
/* channel */
if (success)
{
int_value = args[1].value.pdb_int;
if (success)
{
if (drawable_gray (drawable))
{
if (int_value != 0)
success = FALSE;
}
else if (drawable_color (drawable))
{
if (int_value < 0 || int_value > 3)
success = FALSE;
}
else
success = FALSE;
}
channel = int_value;
}
/* the number of bytes */
if (success)
{
int_value = args[2].value.pdb_int;
if (int_value != 256)
success = FALSE;
}
/* the curve */
if (success)
{
curve = (unsigned char *) args[3].value.pdb_pointer;
}
/* arrange to modify the curves */
if (success)
{
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
cd.curve[i][j] = j;
cd.channel = channel;
cd.color = drawable_color (drawable);
for (j = 0; j < 256; j++)
cd.curve[cd.channel][j] = curve[j];
cd.lut = gimp_lut_new();
gimp_lut_setup(cd.lut, (GimpLutFunc) curves_lut_func,
(void *) &cd, gimp_drawable_bytes(drawable));
/* The application should occur only within selection bounds */
drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2