Commit d70a75c4 authored by Sven Neumann's avatar Sven Neumann

app/airbrush.c app/convolve.c app/dodgeburn.c app/paint_options.h

        * app/airbrush.c
        * app/convolve.c
        * app/dodgeburn.c
        * app/paint_options.h
        * app/paintbrush.c
        * app/pencil.c
        * app/smudge.c
        * app/tool_options.c: cleaned up pressure sensitivity for paint
        tools. I had to rename Pressure to Rate in a few tools to avoid
        confusion with the Pressure option that applies to the brush.

        * app/gimplut.c: indentation, no changes

--Sven
parent 03d1d522
Sat Nov 13 01:58:31 MET 1999 Sven Neumann <sven@gimp.org>
* app/airbrush.c
* app/convolve.c
* app/dodgeburn.c
* app/paint_options.h
* app/paintbrush.c
* app/pencil.c
* app/smudge.c
* app/tool_options.c: cleaned up pressure sensitivity for paint
tools. I had to rename Pressure to Rate in a few tools to avoid
confusion with the Pressure option that applies to the brush.
* app/gimplut.c: indentation, no changes
Fri Nov 12 17:23:05 1999 ape@gandalf.spacetec.no (Asbjorn Pettersen)
* app/unittest/gimpmodule.c : Unit test program for module_db.c and
......
......@@ -189,6 +189,7 @@ airbrush_paint_func (PaintCore *paint_core,
int state)
{
GimpBrushP brush;
gdouble rate;
if (!drawable)
return NULL;
......@@ -221,8 +222,10 @@ airbrush_paint_func (PaintCore *paint_core,
{
airbrush_timeout.paint_core = paint_core;
airbrush_timeout.drawable = drawable;
timer = gtk_timeout_add ((10000 / airbrush_options->rate),
airbrush_time_out, NULL);
rate = airbrush_options->paint_options.pressure_options->rate ?
(10000 / (airbrush_options->rate * 2.0 * paint_core->curpressure)) :
(10000 / airbrush_options->rate);
timer = gtk_timeout_add (rate, airbrush_time_out, NULL);
timer_state = ON;
}
break;
......@@ -266,7 +269,17 @@ airbrush_time_out (gpointer client_data)
/* restart the timer */
if (airbrush_options->rate != 0.0)
return TRUE;
{
if (airbrush_options->paint_options.pressure_options->rate)
{
/* set a new timer */
timer = gtk_timeout_add ((10000 / (airbrush_options->rate * 2.0 * airbrush_timeout.paint_core->curpressure)),
airbrush_time_out, NULL);
return FALSE;
}
else
return TRUE;
}
else
return FALSE;
}
......@@ -298,7 +311,22 @@ airbrush_motion (PaintCore *paint_core,
if (! (area = paint_core_get_paint_area (paint_core, drawable, scale)))
return;
if (GIMP_IS_BRUSH_PIXMAP (paint_core->brush))
/* color the pixels */
if (pressure_options->color)
{
gdouble r, g, b, a;
gradient_get_color_at (gimp_context_get_gradient (NULL),
paint_core->curpressure, &r, &g, &b, &a);
col[0] = r * 255.0;
col[1] = g * 255.0;
col[2] = b * 255.0;
col[3] = a * 255.0;
mode = INCREMENTAL;
color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes);
}
else if (GIMP_IS_BRUSH_PIXMAP (paint_core->brush))
{
mode = INCREMENTAL;
paint_core_color_area_with_pixmap (paint_core, gimage, drawable, area,
......@@ -306,24 +334,8 @@ airbrush_motion (PaintCore *paint_core,
}
else
{
/* color the pixels */
if (pressure_options->color)
{
gdouble r, g, b, a;
gradient_get_color_at (gimp_context_get_gradient (NULL),
paint_core->curpressure, &r, &g, &b, &a);
col[0] = r * 255.0;
col[1] = g * 255.0;
col[2] = b * 255.0;
col[3] = a * 255.0;
mode = INCREMENTAL;
}
else
{
gimage_get_foreground (gimage, drawable, col);
col[area->bytes - 1] = OPAQUE_OPACITY;
}
gimage_get_foreground (gimage, drawable, col);
col[area->bytes - 1] = OPAQUE_OPACITY;
color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes);
}
......
......@@ -23,7 +23,7 @@
#include <stdio.h>
GimpLut *
gimp_lut_new()
gimp_lut_new ()
{
GimpLut *lut;
lut = g_new(GimpLut, 1);
......@@ -33,7 +33,7 @@ gimp_lut_new()
}
void
gimp_lut_free(GimpLut *lut)
gimp_lut_free (GimpLut *lut)
{
int i;
for (i = 0; i < lut->nchannels; i++)
......@@ -43,8 +43,10 @@ gimp_lut_free(GimpLut *lut)
}
void
gimp_lut_setup (GimpLut *lut, GimpLutFunc func,
void *user_data, int nchannels)
gimp_lut_setup (GimpLut *lut,
GimpLutFunc func,
void *user_data,
int nchannels)
{
int i, v;
double val;
......@@ -73,8 +75,10 @@ gimp_lut_setup (GimpLut *lut, GimpLutFunc func,
}
void
gimp_lut_setup_exact (GimpLut *lut, GimpLutFunc func,
void *user_data, int nchannels)
gimp_lut_setup_exact (GimpLut *lut,
GimpLutFunc func,
void *user_data,
int nchannels)
{
gimp_lut_setup(lut, func, user_data, nchannels);
}
......
......@@ -40,8 +40,8 @@
#define MAX_SHARPEN -64
/* defaults */
#define DEFAULT_CONVOLVE_PRESSURE 50.0
#define DEFAULT_CONVOLVE_TYPE BLUR_CONVOLVE
#define DEFAULT_CONVOLVE_RATE 50.0
#define DEFAULT_CONVOLVE_TYPE BLUR_CONVOLVE
/* the convolve structures */
......@@ -54,9 +54,9 @@ struct _ConvolveOptions
ConvolveType type_d;
GtkWidget *type_w[2];
double pressure;
double pressure_d;
GtkObject *pressure_w;
double rate;
double rate_d;
GtkObject *rate_w;
};
......@@ -69,7 +69,7 @@ static int matrix_size;
static int matrix_divisor;
static ConvolveType non_gui_type;
static double non_gui_pressure;
static double non_gui_rate;
static float custom_matrix [25] =
{
......@@ -100,12 +100,13 @@ static float sharpen_matrix [25] =
/* forward function declarations */
static void calculate_matrix (ConvolveType, double, double);
static void calculate_matrix (ConvolveType, double);
static void integer_matrix (float *, int *, int);
static void copy_matrix (float *, float *, int);
static int sum_matrix (int *, int);
static void convolve_motion (PaintCore *, GimpDrawable *, PaintPressureOptions *,
static void convolve_motion (PaintCore *, GimpDrawable *,
PaintPressureOptions *,
ConvolveType, double);
/* functions */
......@@ -118,8 +119,7 @@ convolve_options_reset (void)
paint_options_reset ((PaintOptions *) options);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->pressure_w),
options->pressure_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->rate_w), options->rate_d);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
}
......@@ -141,30 +141,30 @@ convolve_options_new (void)
paint_options_init ((PaintOptions *) options,
CONVOLVE,
convolve_options_reset);
options->type = options->type_d = DEFAULT_CONVOLVE_TYPE;
options->pressure = options->pressure_d = DEFAULT_CONVOLVE_PRESSURE;
options->type = options->type_d = DEFAULT_CONVOLVE_TYPE;
options->rate = options->rate_d = DEFAULT_CONVOLVE_RATE;
/* the main vbox */
vbox = ((ToolOptions *) options)->main_vbox;
/* the pressure scale */
/* the rate scale */
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new (_("Pressure:"));
label = gtk_label_new (_("Rate:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
options->pressure_w =
gtk_adjustment_new (options->pressure_d, 0.0, 100.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->pressure_w));
options->rate_w =
gtk_adjustment_new (options->rate_d, 0.0, 100.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->rate_w));
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (options->pressure_w), "value_changed",
gtk_signal_connect (GTK_OBJECT (options->rate_w), "value_changed",
(GtkSignalFunc) tool_options_double_adjustment_update,
&options->pressure);
&options->rate);
gtk_widget_show (scale);
gtk_widget_show (hbox);
......@@ -191,7 +191,7 @@ convolve_paint_func (PaintCore *paint_core,
case MOTION_PAINT:
convolve_motion (paint_core, drawable,
convolve_options->paint_options.pressure_options,
convolve_options->type, convolve_options->pressure);
convolve_options->type, convolve_options->rate);
break;
}
......@@ -261,7 +261,7 @@ convolve_motion (PaintCore *paint_core,
GimpDrawable *drawable,
PaintPressureOptions *pressure_options,
ConvolveType type,
double pressure)
double rate)
{
GImage *gimage;
TempBuf * area;
......@@ -296,8 +296,10 @@ convolve_motion (PaintCore *paint_core,
destPR.rowstride = area->width * destPR.bytes;
destPR.data = temp_buf_data (area);
calculate_matrix (type, pressure,
paint_core->curpressure);
if (pressure_options->rate)
rate = rate * 2.0 * paint_core->curpressure;
calculate_matrix (type, rate);
/* convolve the source image with the convolve mask */
if (srcPR.w >= matrix_size && srcPR.h >= matrix_size)
......@@ -367,18 +369,18 @@ convolve_motion (PaintCore *paint_core,
/* paste the newly painted canvas to the gimage which is being worked on */
paint_core_replace_canvas (paint_core, drawable, OPAQUE_OPACITY,
(int) (gimp_context_get_opacity (NULL) * 255),
SOFT, scale, INCREMENTAL);
pressure_options->pressure ? PRESSURE : SOFT,
scale, INCREMENTAL);
}
static void
calculate_matrix (ConvolveType type,
double pressure,
double curpressure)
double rate)
{
float percent;
/* find percent of tool pressure */
percent = (pressure / 100.0) * curpressure;
percent = MIN (rate / 100.0, 1.0);
/* get the appropriate convolution matrix and size and divisor */
switch (type)
......@@ -452,7 +454,7 @@ convolve_non_gui_paint_func (PaintCore *paint_core,
int state)
{
convolve_motion (paint_core, drawable, &non_gui_pressure_options,
non_gui_type, non_gui_pressure);
non_gui_type, non_gui_rate);
return NULL;
}
......@@ -462,22 +464,22 @@ convolve_non_gui_default (GimpDrawable *drawable,
int num_strokes,
double *stroke_array)
{
double pressure = DEFAULT_CONVOLVE_PRESSURE;
double rate = DEFAULT_CONVOLVE_RATE;
ConvolveType type = DEFAULT_CONVOLVE_TYPE;
ConvolveOptions *options = convolve_options;
if(options)
if (options)
{
pressure = options->pressure;
rate = options->rate;
type = options->type;
}
return convolve_non_gui(drawable,pressure,type,num_strokes,stroke_array);
return convolve_non_gui (drawable, rate, type, num_strokes, stroke_array);
}
gboolean
convolve_non_gui (GimpDrawable *drawable,
double pressure,
double rate,
ConvolveType type,
int num_strokes,
double *stroke_array)
......@@ -491,7 +493,7 @@ convolve_non_gui (GimpDrawable *drawable,
non_gui_paint_core.paint_func = convolve_non_gui_paint_func;
non_gui_type = type;
non_gui_pressure = pressure;
non_gui_rate = rate;
non_gui_paint_core.startx = non_gui_paint_core.lastx = stroke_array[0];
non_gui_paint_core.starty = non_gui_paint_core.lasty = stroke_array[1];
......
......@@ -760,6 +760,8 @@ paint_pressure_options_new (ToolType tool_type)
pressure->opacity = pressure->opacity_d =TRUE;
pressure->pressure_w = NULL;
pressure->pressure = pressure->pressure_d = TRUE;
pressure->rate_w = NULL;
pressure->rate = pressure->rate_d = FALSE;
pressure->size_w = NULL;
pressure->size = pressure->size_d = FALSE;
pressure->color_w = NULL;
......@@ -767,14 +769,14 @@ paint_pressure_options_new (ToolType tool_type)
switch (tool_type)
{
case AIRBRUSH:
case CLONE:
case CONVOLVE:
case DODGEBURN:
case SMUDGE:
case AIRBRUSH:
case ERASER:
case PAINTBRUSH:
case PENCIL:
case SMUDGE:
frame = gtk_frame_new (_("Pressure sensitivity"));
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (frame), hbox);
......@@ -787,8 +789,8 @@ paint_pressure_options_new (ToolType tool_type)
/* the opacity toggle */
switch (tool_type)
{
case AIRBRUSH:
case CLONE:
case DODGEBURN:
case ERASER:
case PAINTBRUSH:
case PENCIL:
......@@ -806,16 +808,17 @@ paint_pressure_options_new (ToolType tool_type)
break;
}
/* the pressure toggle */
/* the pressure toggle */
switch (tool_type)
{
case AIRBRUSH:
case CLONE:
case CONVOLVE:
case DODGEBURN:
case SMUDGE:
case ERASER:
case PAINTBRUSH:
pressure->pressure_w =
gtk_check_button_new_with_label (_("Pressure"));
case SMUDGE:
pressure->pressure_w = gtk_check_button_new_with_label (_("Pressure"));
gtk_container_add (GTK_CONTAINER (hbox), pressure->pressure_w);
gtk_signal_connect (GTK_OBJECT (pressure->pressure_w), "toggled",
(GtkSignalFunc) tool_options_toggle_update,
......@@ -828,6 +831,26 @@ paint_pressure_options_new (ToolType tool_type)
break;
}
/* the rate toggle */
switch (tool_type)
{
case AIRBRUSH:
case CONVOLVE:
case SMUDGE:
pressure->rate_w =
gtk_check_button_new_with_label (_("Rate"));
gtk_container_add (GTK_CONTAINER (hbox), pressure->rate_w);
gtk_signal_connect (GTK_OBJECT (pressure->rate_w), "toggled",
(GtkSignalFunc) tool_options_toggle_update,
&pressure->rate);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->rate_w),
pressure->rate_d);
gtk_widget_show (pressure->rate_w);
break;
default:
break;
}
/* the size toggle */
switch (tool_type)
{
......@@ -871,6 +894,7 @@ paint_pressure_options_new (ToolType tool_type)
default:
break;
}
pressure->frame = frame;
return (pressure);
......@@ -889,6 +913,11 @@ paint_pressure_options_reset (PaintPressureOptions *pressure)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->pressure_w),
pressure->pressure_d);
}
if (pressure->rate_w)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->rate_w),
pressure->rate_d);
}
if (pressure->size_w)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pressure->size_w),
......
......@@ -50,7 +50,7 @@ struct _DodgeBurnOptions
DodgeBurnType type_d;
GtkWidget *type_w[2];
DodgeBurnMode mode; /*highlights,midtones,shadows*/
DodgeBurnMode mode; /*highlights, midtones, shadows*/
DodgeBurnMode mode_d;
GtkWidget *mode_w[3];
......@@ -70,9 +70,9 @@ static gfloat dodgeburn_midtones_lut_func (void *, int, int, gfloat);
static gfloat dodgeburn_shadows_lut_func (void *, int, int, gfloat);
/* The dodge burn lookup tables */
gfloat dodgeburn_highlights(void *, int, int, gfloat);
gfloat dodgeburn_midtones(void *, int, int, gfloat);
gfloat dodgeburn_shadows(void *, int, int, gfloat);
gfloat dodgeburn_highlights (void *, int, int, gfloat);
gfloat dodgeburn_midtones (void *, int, int, gfloat);
gfloat dodgeburn_shadows (void *, int, int, gfloat);
/* the dodgeburn tool options */
static DodgeBurnOptions * dodgeburn_options = NULL;
......@@ -216,8 +216,8 @@ dodgeburn_paint_func (PaintCore *paint_core,
}
static void
dodgeburn_finish ( PaintCore *paint_core,
GimpDrawable * drawable)
dodgeburn_finish (PaintCore *paint_core,
GimpDrawable *drawable)
{
/* Here we destroy the luts to do the painting with.*/
if (dodgeburn_options->lut)
......@@ -228,8 +228,8 @@ dodgeburn_finish ( PaintCore *paint_core,
}
static void
dodgeburn_init ( PaintCore *paint_core,
GimpDrawable * drawable)
dodgeburn_init (PaintCore *paint_core,
GimpDrawable *drawable)
{
/* Here we create the luts to do the painting with.*/
dodgeburn_options->lut = gimp_lut_new();
......@@ -242,18 +242,18 @@ dodgeburn_init ( PaintCore *paint_core,
}
static void
dodgeburn_make_luts ( PaintCore *paint_core,
double db_exposure,
DodgeBurnType type,
DodgeBurnMode mode,
GimpLut *lut,
GimpDrawable *drawable)
dodgeburn_make_luts (PaintCore *paint_core,
double db_exposure,
DodgeBurnType type,
DodgeBurnMode mode,
GimpLut *lut,
GimpDrawable *drawable)
{
GimpLutFunc lut_func;
int nchannels = gimp_drawable_bytes (drawable);
static gfloat exposure;
exposure = (db_exposure)/100.0;
exposure = (db_exposure) / 100.0;
/* make the exposure negative if burn for luts*/
if (type == BURN)
......@@ -353,7 +353,6 @@ dodgeburn_motion (PaintCore *paint_core,
TempBuf * orig;
PixelRegion srcPR, destPR, tempPR;
guchar *temp_data;
gfloat exposure;
gint opacity;
gdouble scale;
......@@ -408,9 +407,6 @@ dodgeburn_motion (PaintCore *paint_core,
temp_data = g_malloc (tempPR.h * tempPR.rowstride);
tempPR.data = temp_data;
/* Enable pressure sensitive exposure */
exposure = ((dodgeburn_exposure)/100.0 * (paint_core->curpressure)/0.5);
/* DodgeBurn the region */
gimp_lut_process (lut, &srcPR, &tempPR);
......@@ -427,13 +423,13 @@ dodgeburn_motion (PaintCore *paint_core,
if (!drawable_has_alpha (drawable))
add_alpha_region (&tempPR, &destPR);
else
copy_region(&tempPR, &destPR);
copy_region (&tempPR, &destPR);
opacity = 255 * gimp_context_get_opacity (NULL);
if (pressure_options->opacity)
opacity = opacity * 2.0 * paint_core->curpressure;
/*Replace the newly dodgedburned area (canvas_buf) to the gimage*/
/* Replace the newly dodgedburned area (canvas_buf) to the gimage*/
paint_core_replace_canvas (paint_core, drawable,
MIN (opacity, 255),
OPAQUE_OPACITY,
......@@ -444,9 +440,9 @@ dodgeburn_motion (PaintCore *paint_core,
}
static void *
dodgeburn_non_gui_paint_func (PaintCore *paint_core,
GimpDrawable *drawable,
int state)
dodgeburn_non_gui_paint_func (PaintCore *paint_core,
GimpDrawable *drawable,
int state)
{
dodgeburn_motion (paint_core, &non_gui_pressure_options,
non_gui_exposure, non_gui_lut, drawable);
......@@ -475,12 +471,12 @@ dodgeburn_non_gui_default (GimpDrawable *drawable,
}
gboolean
dodgeburn_non_gui (GimpDrawable *drawable,
double exposure,
DodgeBurnType type,
DodgeBurnMode mode,
int num_strokes,
double *stroke_array)
dodgeburn_non_gui (GimpDrawable *drawable,
double exposure,
DodgeBurnType type,
DodgeBurnMode mode,
int num_strokes,
double *stroke_array)
{
int i;
......@@ -530,10 +526,10 @@ dodgeburn_non_gui (GimpDrawable *drawable,
}
static gfloat
dodgeburn_highlights_lut_func(void * user_data,
int nchannels,
int channel,
gfloat value)
dodgeburn_highlights_lut_func (void *user_data,
int nchannels,
int channel,
gfloat value)
{
gfloat * exposure_ptr = (gfloat *)user_data;
gfloat exposure = *exposure_ptr;
......@@ -547,10 +543,10 @@ dodgeburn_highlights_lut_func(void * user_data,
}
static gfloat
dodgeburn_midtones_lut_func(void * user_data,
int nchannels,
int channel,
gfloat value)
dodgeburn_midtones_lut_func (void *user_data,
int nchannels,
int channel,
gfloat value)
{
gfloat * exposure_ptr = (gfloat *)user_data;
gfloat exposure = *exposure_ptr;
......@@ -568,10 +564,10 @@ dodgeburn_midtones_lut_func(void * user_data,
}
static gfloat
dodgeburn_shadows_lut_func(void * user_data,
int nchannels,
int channel,
gfloat value)
dodgeburn_shadows_lut_func (void *user_data,
int nchannels,
int channel,
gfloat value)
{
gfloat * exposure_ptr = (gfloat *)user_data;
gfloat exposure = *exposure_ptr;
......@@ -597,3 +593,10 @@ dodgeburn_shadows_lut_func(void * user_data,
}
return new_value;
}
......@@ -23,7 +23,7 @@
#include <stdio.h>
GimpLut *
gimp_lut_new()
gimp_lut_new ()
{
GimpLut *lut;
lut = g_new(GimpLut, 1);
......@@ -33,7 +33,7 @@ gimp_lut_new()
}
void
gimp_lut_free(GimpLut *lut)
gimp_lut_free (GimpLut *lut)
{
int i;
for (i = 0; i < lut->nchannels; i++)
......@@ -43,8 +43,10 @@ gimp_lut_free(GimpLut *lut)
}
void
gimp_lut_setup (GimpLut *lut, GimpLutFunc func,
void *user_data, int nchannels)
gimp_lut_setup (GimpLut *lut,
GimpLutFunc func,
void *user_data,
int nchannels)
{
int i, v;
double val;
......@@ -73,8 +75,10 @@ gimp_lut_setup (GimpLut *lut, GimpLutFunc func,
}
void
gimp_lut_setup_exact (GimpLut *lut, GimpLutFunc func,
void *user_data, int nchannels)
gimp_lut_setup_exact (GimpLut *lut,
GimpLutFunc func,
void *user_data,
int nchannels)
{
gimp_lut_setup(lut, func, user_data, nchannels);
}
......
......@@ -189,6 +189,7 @@ airbrush_paint_func (PaintCore *paint_core,
int state)
{
GimpBrushP brush;
gdouble rate;
if (!drawable)
return NULL;
......@@ -221,8 +222,10 @@ airbrush_paint_func (PaintCore *paint_core,
{
airbrush_timeout.paint_core = paint_core;
airbrush_timeout.drawable = drawable;
timer = gtk_timeout_add ((10000 / airbrush_options->rate),
airbrush_time_out, NULL);
rate = airbrush_options->paint_options.pressure_options->rate ?
(10000 / (airbrush_options->rate * 2.0 * paint_core->curpressure)) :