1999-07-02 00:52:50 +08:00
|
|
|
/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-07-27 08:14:14 +08:00
|
|
|
#include "config.h"
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
#include <glib-object.h>
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "paint-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/gimplut.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "gimpdodgeburn.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimpdodgeburnoptions.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
static void gimp_dodge_burn_class_init (GimpDodgeBurnClass *klass);
|
|
|
|
static void gimp_dodge_burn_init (GimpDodgeBurn *dodgeburn);
|
|
|
|
|
|
|
|
static void gimp_dodge_burn_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2004-05-27 00:13:53 +08:00
|
|
|
GimpPaintCoreState paint_state,
|
|
|
|
guint32 time);
|
2004-05-26 04:41:09 +08:00
|
|
|
static void gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
|
|
|
|
|
|
|
static void gimp_dodge_burn_make_luts (GimpDodgeBurn *dodgeburn,
|
|
|
|
gdouble db_exposure,
|
|
|
|
GimpDodgeBurnType type,
|
|
|
|
GimpTransferMode mode,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
|
|
|
|
static gfloat gimp_dodge_burn_highlights_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value);
|
|
|
|
static gfloat gimp_dodge_burn_midtones_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value);
|
|
|
|
static gfloat gimp_dodge_burn_shadows_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value);
|
|
|
|
|
|
|
|
|
|
|
|
static GimpBrushCoreClass *parent_class = NULL;
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2001-03-31 23:45:05 +08:00
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
2002-02-27 21:57:49 +08:00
|
|
|
{
|
2003-02-14 22:14:29 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_DODGE_BURN,
|
|
|
|
GIMP_TYPE_DODGE_BURN_OPTIONS,
|
|
|
|
_("Dodge/Burn"));
|
2002-02-27 21:57:49 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_get_type (void)
|
2001-03-31 23:45:05 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static GType type = 0;
|
2001-03-31 23:45:05 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (! type)
|
2001-03-31 23:45:05 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static const GTypeInfo info =
|
2001-08-14 22:53:55 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
sizeof (GimpDodgeBurnClass),
|
2004-05-26 04:41:09 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_dodge_burn_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpDodgeBurn),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_dodge_burn_init,
|
2001-08-14 22:53:55 +08:00
|
|
|
};
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
type = g_type_register_static (GIMP_TYPE_BRUSH_CORE,
|
2002-02-15 03:31:16 +08:00
|
|
|
"GimpDodgeBurn",
|
|
|
|
&info, 0);
|
2001-03-31 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
return type;
|
2001-03-31 23:45:05 +08:00
|
|
|
}
|
|
|
|
|
1999-07-02 00:52:50 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_class_init (GimpDodgeBurnClass *klass)
|
2001-03-24 10:27:16 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
2001-03-24 10:27:16 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-24 10:27:16 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
object_class->finalize = gimp_dodge_burn_finalize;
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
paint_core_class->paint = gimp_dodge_burn_paint;
|
2001-03-31 23:45:05 +08:00
|
|
|
}
|
2001-03-24 10:27:16 +08:00
|
|
|
|
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_init (GimpDodgeBurn *dodgeburn)
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (dodgeburn);
|
2001-03-24 10:27:16 +08:00
|
|
|
|
2002-02-16 01:44:05 +08:00
|
|
|
paint_core->flags |= CORE_HANDLES_CHANGING_BRUSH;
|
1999-07-02 00:52:50 +08:00
|
|
|
}
|
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_finalize (GObject *object)
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (object);
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
if (dodgeburn->lut)
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_lut_free (dodgeburn->lut);
|
|
|
|
dodgeburn->lut = NULL;
|
1999-07-02 00:52:50 +08:00
|
|
|
}
|
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
1999-07-02 00:52:50 +08:00
|
|
|
}
|
2001-03-31 23:45:05 +08:00
|
|
|
|
1999-07-02 00:52:50 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2004-05-27 00:13:53 +08:00
|
|
|
GimpPaintCoreState paint_state,
|
|
|
|
guint32 time)
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (paint_core);
|
|
|
|
GimpDodgeBurnOptions *options = GIMP_DODGE_BURN_OPTIONS (paint_options);
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
switch (paint_state)
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
|
|
|
case INIT_PAINT:
|
2002-06-09 21:56:09 +08:00
|
|
|
dodgeburn->lut = gimp_lut_new ();
|
2002-02-15 03:31:16 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_make_luts (dodgeburn,
|
|
|
|
options->exposure,
|
|
|
|
options->type,
|
|
|
|
options->mode,
|
|
|
|
drawable);
|
2001-04-07 19:01:22 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTION_PAINT:
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_motion (paint_core, drawable, paint_options);
|
2001-04-07 19:01:22 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FINISH_PAINT:
|
2002-06-09 21:56:09 +08:00
|
|
|
if (dodgeburn->lut)
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_lut_free (dodgeburn->lut);
|
|
|
|
dodgeburn->lut = NULL;
|
2001-04-07 19:01:22 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-02 00:52:50 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options)
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (paint_core);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
|
|
|
GimpPressureOptions *pressure_options = paint_options->pressure_options;
|
2002-02-15 03:31:16 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
TempBuf *area;
|
|
|
|
TempBuf *orig;
|
|
|
|
PixelRegion srcPR, destPR, tempPR;
|
|
|
|
guchar *temp_data;
|
2002-03-04 01:38:12 +08:00
|
|
|
gdouble opacity;
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
opacity = gimp_paint_options_get_fade (paint_options, gimage,
|
|
|
|
paint_core->pixel_dist);
|
|
|
|
if (opacity == 0.0)
|
1999-07-02 00:52:50 +08:00
|
|
|
return;
|
|
|
|
|
2004-05-26 17:32:03 +08:00
|
|
|
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
|
|
|
|
if (! area)
|
1999-07-02 00:52:50 +08:00
|
|
|
return;
|
|
|
|
|
2001-03-31 23:45:05 +08:00
|
|
|
/* Constant painting --get a copy of the orig drawable (with no
|
|
|
|
* paint from this stroke yet)
|
|
|
|
*/
|
1999-07-02 00:52:50 +08:00
|
|
|
{
|
2003-05-08 21:12:46 +08:00
|
|
|
GimpItem *item;
|
|
|
|
gint x1, y1, x2, y2;
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2003-05-08 21:12:46 +08:00
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
|
|
|
|
x1 = CLAMP (area->x, 0, gimp_item_width (item));
|
|
|
|
y1 = CLAMP (area->y, 0, gimp_item_height (item));
|
|
|
|
x2 = CLAMP (area->x + area->width, 0, gimp_item_width (item));
|
|
|
|
y2 = CLAMP (area->y + area->height, 0, gimp_item_height (item));
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
if (!(x2 - x1) || !(y2 - y1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get the original untouched image */
|
2002-02-15 03:31:16 +08:00
|
|
|
orig = gimp_paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
srcPR.bytes = orig->bytes;
|
2003-07-14 22:50:41 +08:00
|
|
|
srcPR.x = 0;
|
2002-02-15 03:31:16 +08:00
|
|
|
srcPR.y = 0;
|
|
|
|
srcPR.w = x2 - x1;
|
|
|
|
srcPR.h = y2 - y1;
|
2000-12-31 12:07:42 +08:00
|
|
|
srcPR.rowstride = srcPR.bytes * orig->width;
|
2002-02-15 03:31:16 +08:00
|
|
|
srcPR.data = temp_buf_data (orig);
|
2000-12-31 12:07:42 +08:00
|
|
|
}
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
/* tempPR will hold the dodgeburned region */
|
2002-02-15 03:31:16 +08:00
|
|
|
tempPR.bytes = srcPR.bytes;
|
2003-07-14 22:50:41 +08:00
|
|
|
tempPR.x = srcPR.x;
|
2002-02-15 03:31:16 +08:00
|
|
|
tempPR.y = srcPR.y;
|
|
|
|
tempPR.w = srcPR.w;
|
|
|
|
tempPR.h = srcPR.h;
|
1999-07-02 00:52:50 +08:00
|
|
|
tempPR.rowstride = tempPR.bytes * tempPR.w;
|
2002-02-15 03:31:16 +08:00
|
|
|
tempPR.data = g_malloc (tempPR.h * tempPR.rowstride);
|
|
|
|
|
|
|
|
temp_data = tempPR.data;
|
1999-07-02 00:52:50 +08:00
|
|
|
|
|
|
|
/* DodgeBurn the region */
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_lut_process (dodgeburn->lut, &srcPR, &tempPR);
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
/* The dest is the paint area we got above (= canvas_buf) */
|
2002-02-15 03:31:16 +08:00
|
|
|
destPR.bytes = area->bytes;
|
|
|
|
destPR.x = 0;
|
|
|
|
destPR.y = 0;
|
|
|
|
destPR.w = area->width;
|
|
|
|
destPR.h = area->height;
|
1999-07-02 00:52:50 +08:00
|
|
|
destPR.rowstride = area->width * destPR.bytes;
|
2002-02-15 03:31:16 +08:00
|
|
|
destPR.data = temp_buf_data (area);
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
/* Now add an alpha to the dodgeburned region
|
2003-07-16 19:25:37 +08:00
|
|
|
* and put this in area = canvas_buf
|
|
|
|
*/
|
2001-01-15 05:11:52 +08:00
|
|
|
if (! gimp_drawable_has_alpha (drawable))
|
1999-07-02 00:52:50 +08:00
|
|
|
add_alpha_region (&tempPR, &destPR);
|
|
|
|
else
|
1999-11-13 09:02:27 +08:00
|
|
|
copy_region (&tempPR, &destPR);
|
1999-07-02 00:52:50 +08:00
|
|
|
|
1999-09-09 09:47:54 +08:00
|
|
|
if (pressure_options->opacity)
|
2004-05-24 21:11:43 +08:00
|
|
|
opacity *= PRESSURE_SCALE * paint_core->cur_coords.pressure;
|
1999-09-09 09:47:54 +08:00
|
|
|
|
2003-07-16 19:25:37 +08:00
|
|
|
/* Replace the newly dodgedburned area (canvas_buf) to the gimage */
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
|
2002-03-04 01:38:12 +08:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
2003-07-16 19:25:37 +08:00
|
|
|
gimp_context_get_opacity (context),
|
2003-07-14 22:50:41 +08:00
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
2002-06-09 21:56:09 +08:00
|
|
|
GIMP_PAINT_CONSTANT);
|
2003-07-14 22:50:41 +08:00
|
|
|
|
1999-07-02 00:52:50 +08:00
|
|
|
g_free (temp_data);
|
|
|
|
}
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
static void
|
|
|
|
gimp_dodge_burn_make_luts (GimpDodgeBurn *dodgeburn,
|
|
|
|
gdouble db_exposure,
|
|
|
|
GimpDodgeBurnType type,
|
|
|
|
GimpTransferMode mode,
|
|
|
|
GimpDrawable *drawable)
|
2002-06-09 21:56:09 +08:00
|
|
|
{
|
|
|
|
GimpLutFunc lut_func;
|
|
|
|
gint nchannels = gimp_drawable_bytes (drawable);
|
|
|
|
static gfloat exposure;
|
|
|
|
|
|
|
|
exposure = db_exposure / 100.0;
|
|
|
|
|
|
|
|
/* make the exposure negative if burn for luts*/
|
|
|
|
if (type == GIMP_BURN)
|
|
|
|
exposure = -exposure;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case GIMP_HIGHLIGHTS:
|
2003-07-14 22:50:41 +08:00
|
|
|
lut_func = gimp_dodge_burn_highlights_lut_func;
|
2002-06-09 21:56:09 +08:00
|
|
|
break;
|
|
|
|
case GIMP_MIDTONES:
|
2003-07-14 22:50:41 +08:00
|
|
|
lut_func = gimp_dodge_burn_midtones_lut_func;
|
2002-06-09 21:56:09 +08:00
|
|
|
break;
|
|
|
|
case GIMP_SHADOWS:
|
2003-07-14 22:50:41 +08:00
|
|
|
lut_func = gimp_dodge_burn_shadows_lut_func;
|
2002-06-09 21:56:09 +08:00
|
|
|
break;
|
|
|
|
default:
|
2003-07-14 22:50:41 +08:00
|
|
|
lut_func = NULL;
|
2002-06-09 21:56:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_lut_setup_exact (dodgeburn->lut,
|
|
|
|
lut_func, (gpointer) &exposure,
|
|
|
|
nchannels);
|
|
|
|
}
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
static gfloat
|
2003-07-14 22:50:41 +08:00
|
|
|
gimp_dodge_burn_highlights_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
2003-02-05 22:39:40 +08:00
|
|
|
gfloat value)
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
|
|
|
gfloat *exposure_ptr = (gfloat *) user_data;
|
|
|
|
gfloat exposure = *exposure_ptr;
|
|
|
|
gfloat factor = 1.0 + exposure * (.333333);
|
|
|
|
|
|
|
|
if ((nchannels == 2 && channel == 1) ||
|
|
|
|
(nchannels == 4 && channel == 3))
|
|
|
|
return value;
|
|
|
|
|
|
|
|
return factor * value;
|
|
|
|
}
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
static gfloat
|
2003-07-14 22:50:41 +08:00
|
|
|
gimp_dodge_burn_midtones_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
2003-02-05 22:39:40 +08:00
|
|
|
gfloat value)
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
|
|
|
gfloat *exposure_ptr = (gfloat *) user_data;
|
|
|
|
gfloat exposure = *exposure_ptr;
|
|
|
|
gfloat factor;
|
|
|
|
|
|
|
|
if ((nchannels == 2 && channel == 1) ||
|
|
|
|
(nchannels == 4 && channel == 3))
|
|
|
|
return value;
|
|
|
|
|
|
|
|
if (exposure < 0)
|
|
|
|
factor = 1.0 - exposure * (.333333);
|
|
|
|
else
|
2002-03-04 01:38:12 +08:00
|
|
|
factor = 1 / (1.0 + exposure);
|
1999-07-02 00:52:50 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
return pow (value, factor);
|
2001-04-07 19:01:22 +08:00
|
|
|
}
|
2001-03-24 10:27:16 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
static gfloat
|
2003-07-14 22:50:41 +08:00
|
|
|
gimp_dodge_burn_shadows_lut_func (gpointer user_data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
2003-02-05 22:39:40 +08:00
|
|
|
gfloat value)
|
2001-03-31 23:45:05 +08:00
|
|
|
{
|
2001-04-07 19:01:22 +08:00
|
|
|
gfloat *exposure_ptr = (gfloat *) user_data;
|
|
|
|
gfloat exposure = *exposure_ptr;
|
|
|
|
gfloat new_value;
|
|
|
|
gfloat factor;
|
|
|
|
|
|
|
|
if ((nchannels == 2 && channel == 1) ||
|
|
|
|
(nchannels == 4 && channel == 3))
|
|
|
|
return value;
|
|
|
|
|
|
|
|
if (exposure >= 0)
|
|
|
|
{
|
|
|
|
factor = 0.333333 * exposure;
|
2003-07-14 22:50:41 +08:00
|
|
|
new_value = factor + value - factor * value;
|
2001-04-07 19:01:22 +08:00
|
|
|
}
|
2003-07-14 22:50:41 +08:00
|
|
|
else /* exposure < 0 */
|
2001-04-07 19:01:22 +08:00
|
|
|
{
|
|
|
|
factor = -0.333333 * exposure;
|
|
|
|
if (value < factor)
|
|
|
|
new_value = 0;
|
|
|
|
else /*factor <= value <=1*/
|
|
|
|
new_value = (value - factor)/(1 - factor);
|
|
|
|
}
|
2001-03-31 23:45:05 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
return new_value;
|
2001-03-31 23:45:05 +08:00
|
|
|
}
|