app: use gimp_gegl_dodgeburn() in GimpDodgeBurn
This commit is contained in:
@ -24,10 +24,7 @@
|
|||||||
|
|
||||||
#include "paint-types.h"
|
#include "paint-types.h"
|
||||||
|
|
||||||
#include "base/gimplut.h"
|
#include "gegl/gimp-gegl-loops.h"
|
||||||
#include "base/pixel-region.h"
|
|
||||||
#include "base/temp-buf.h"
|
|
||||||
|
|
||||||
#include "gegl/gimp-gegl-utils.h"
|
#include "gegl/gimp-gegl-utils.h"
|
||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
@ -42,8 +39,6 @@
|
|||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
|
|
||||||
static void gimp_dodge_burn_finalize (GObject *object);
|
|
||||||
|
|
||||||
static void gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
static void gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
GimpPaintOptions *paint_options,
|
GimpPaintOptions *paint_options,
|
||||||
@ -55,25 +50,6 @@ static void gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|||||||
GimpPaintOptions *paint_options,
|
GimpPaintOptions *paint_options,
|
||||||
const GimpCoords *coords);
|
const GimpCoords *coords);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpDodgeBurn, gimp_dodge_burn, GIMP_TYPE_BRUSH_CORE)
|
G_DEFINE_TYPE (GimpDodgeBurn, gimp_dodge_burn, GIMP_TYPE_BRUSH_CORE)
|
||||||
|
|
||||||
@ -95,12 +71,9 @@ gimp_dodge_burn_register (Gimp *gimp,
|
|||||||
static void
|
static void
|
||||||
gimp_dodge_burn_class_init (GimpDodgeBurnClass *klass)
|
gimp_dodge_burn_class_init (GimpDodgeBurnClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
||||||
GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_CLASS (klass);
|
GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_CLASS (klass);
|
||||||
|
|
||||||
object_class->finalize = gimp_dodge_burn_finalize;
|
|
||||||
|
|
||||||
paint_core_class->paint = gimp_dodge_burn_paint;
|
paint_core_class->paint = gimp_dodge_burn_paint;
|
||||||
|
|
||||||
brush_core_class->handles_changing_brush = TRUE;
|
brush_core_class->handles_changing_brush = TRUE;
|
||||||
@ -111,20 +84,6 @@ gimp_dodge_burn_init (GimpDodgeBurn *dodgeburn)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_dodge_burn_finalize (GObject *object)
|
|
||||||
{
|
|
||||||
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (object);
|
|
||||||
|
|
||||||
if (dodgeburn->lut)
|
|
||||||
{
|
|
||||||
gimp_lut_free (dodgeburn->lut);
|
|
||||||
dodgeburn->lut = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
@ -133,19 +92,9 @@ gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
|||||||
GimpPaintState paint_state,
|
GimpPaintState paint_state,
|
||||||
guint32 time)
|
guint32 time)
|
||||||
{
|
{
|
||||||
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (paint_core);
|
|
||||||
GimpDodgeBurnOptions *options = GIMP_DODGE_BURN_OPTIONS (paint_options);
|
|
||||||
|
|
||||||
switch (paint_state)
|
switch (paint_state)
|
||||||
{
|
{
|
||||||
case GIMP_PAINT_STATE_INIT:
|
case GIMP_PAINT_STATE_INIT:
|
||||||
dodgeburn->lut = gimp_lut_new ();
|
|
||||||
|
|
||||||
gimp_dodge_burn_make_luts (dodgeburn,
|
|
||||||
options->exposure,
|
|
||||||
options->type,
|
|
||||||
options->mode,
|
|
||||||
drawable);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_PAINT_STATE_MOTION:
|
case GIMP_PAINT_STATE_MOTION:
|
||||||
@ -153,11 +102,6 @@ gimp_dodge_burn_paint (GimpPaintCore *paint_core,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_PAINT_STATE_FINISH:
|
case GIMP_PAINT_STATE_FINISH:
|
||||||
if (dodgeburn->lut)
|
|
||||||
{
|
|
||||||
gimp_lut_free (dodgeburn->lut);
|
|
||||||
dodgeburn->lut = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,7 +112,7 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|||||||
GimpPaintOptions *paint_options,
|
GimpPaintOptions *paint_options,
|
||||||
const GimpCoords *coords)
|
const GimpCoords *coords)
|
||||||
{
|
{
|
||||||
GimpDodgeBurn *dodgeburn = GIMP_DODGE_BURN (paint_core);
|
GimpDodgeBurnOptions *options = GIMP_DODGE_BURN_OPTIONS (paint_options);
|
||||||
GimpContext *context = GIMP_CONTEXT (paint_options);
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
||||||
GimpDynamics *dynamics = GIMP_BRUSH_CORE (paint_core)->dynamics;
|
GimpDynamics *dynamics = GIMP_BRUSH_CORE (paint_core)->dynamics;
|
||||||
GimpDynamicsOutput *opacity_output;
|
GimpDynamicsOutput *opacity_output;
|
||||||
@ -177,13 +121,6 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|||||||
GeglBuffer *paint_buffer;
|
GeglBuffer *paint_buffer;
|
||||||
gint paint_buffer_x;
|
gint paint_buffer_x;
|
||||||
gint paint_buffer_y;
|
gint paint_buffer_y;
|
||||||
const Babl *orig_format;
|
|
||||||
TempBuf *orig_temp;
|
|
||||||
GeglBuffer *orig_buffer;
|
|
||||||
GeglRectangle orig_rect;
|
|
||||||
PixelRegion srcPR, tempPR;
|
|
||||||
TempBuf *db_temp;
|
|
||||||
GeglBuffer *db_buffer;
|
|
||||||
gdouble fade_point;
|
gdouble fade_point;
|
||||||
gdouble opacity;
|
gdouble opacity;
|
||||||
gdouble hardness;
|
gdouble hardness;
|
||||||
@ -213,57 +150,17 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|||||||
if (! paint_buffer)
|
if (! paint_buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Constant painting --get a copy of the orig drawable (with no
|
/* DodgeBurn the region */
|
||||||
* paint from this stroke yet)
|
gimp_gegl_dodgeburn (gimp_paint_core_get_orig_image (paint_core),
|
||||||
*/
|
GEGL_RECTANGLE (paint_buffer_x,
|
||||||
if (! gimp_rectangle_intersect (paint_buffer_x,
|
|
||||||
paint_buffer_y,
|
paint_buffer_y,
|
||||||
gegl_buffer_get_width (paint_buffer),
|
gegl_buffer_get_width (paint_buffer),
|
||||||
gegl_buffer_get_height (paint_buffer),
|
gegl_buffer_get_height (paint_buffer)),
|
||||||
0, 0,
|
paint_buffer,
|
||||||
gimp_item_get_width (GIMP_ITEM (drawable)),
|
GEGL_RECTANGLE (0, 0, 0, 0),
|
||||||
gimp_item_get_height (GIMP_ITEM (drawable)),
|
options->exposure / 100.0,
|
||||||
&orig_rect.x,
|
options->type,
|
||||||
&orig_rect.y,
|
options->mode);
|
||||||
&orig_rect.width,
|
|
||||||
&orig_rect.height))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the original untouched image */
|
|
||||||
orig_format = gimp_drawable_get_format (drawable);
|
|
||||||
|
|
||||||
orig_temp = temp_buf_new (orig_rect.width, orig_rect.height,
|
|
||||||
babl_format_get_bytes_per_pixel (orig_format),
|
|
||||||
0, 0, NULL);
|
|
||||||
|
|
||||||
orig_buffer = gimp_temp_buf_create_buffer (orig_temp, orig_format, TRUE);
|
|
||||||
|
|
||||||
gegl_buffer_copy (gimp_paint_core_get_orig_image (paint_core),
|
|
||||||
&orig_rect,
|
|
||||||
orig_buffer,
|
|
||||||
GEGL_RECTANGLE (0, 0, 0, 0));
|
|
||||||
|
|
||||||
pixel_region_init_temp_buf (&srcPR, orig_temp,
|
|
||||||
0, 0, orig_rect.width, orig_rect.height);
|
|
||||||
|
|
||||||
/* tempPR will hold the dodgeburned region */
|
|
||||||
db_temp = temp_buf_new (orig_rect.width, orig_rect.height,
|
|
||||||
babl_format_get_bytes_per_pixel (orig_format),
|
|
||||||
0, 0, NULL);
|
|
||||||
db_buffer = gimp_temp_buf_create_buffer (db_temp, orig_format, TRUE);
|
|
||||||
|
|
||||||
pixel_region_init_temp_buf (&tempPR, db_temp,
|
|
||||||
0, 0, db_temp->width, db_temp->height);
|
|
||||||
|
|
||||||
/* DodgeBurn the region */
|
|
||||||
gimp_lut_process (dodgeburn->lut, &srcPR, &tempPR);
|
|
||||||
|
|
||||||
g_object_unref (orig_buffer);
|
|
||||||
|
|
||||||
gegl_buffer_copy (db_buffer, NULL, paint_buffer, NULL);
|
|
||||||
g_object_unref (db_buffer);
|
|
||||||
|
|
||||||
hardness_output = gimp_dynamics_get_output (dynamics,
|
hardness_output = gimp_dynamics_get_output (dynamics,
|
||||||
GIMP_DYNAMICS_OUTPUT_HARDNESS);
|
GIMP_DYNAMICS_OUTPUT_HARDNESS);
|
||||||
@ -282,112 +179,3 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
|
|||||||
hardness,
|
hardness,
|
||||||
GIMP_PAINT_CONSTANT);
|
GIMP_PAINT_CONSTANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_dodge_burn_make_luts (GimpDodgeBurn *dodgeburn,
|
|
||||||
gdouble db_exposure,
|
|
||||||
GimpDodgeBurnType type,
|
|
||||||
GimpTransferMode mode,
|
|
||||||
GimpDrawable *drawable)
|
|
||||||
{
|
|
||||||
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:
|
|
||||||
lut_func = gimp_dodge_burn_highlights_lut_func;
|
|
||||||
break;
|
|
||||||
case GIMP_MIDTONES:
|
|
||||||
lut_func = gimp_dodge_burn_midtones_lut_func;
|
|
||||||
break;
|
|
||||||
case GIMP_SHADOWS:
|
|
||||||
lut_func = gimp_dodge_burn_shadows_lut_func;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
lut_func = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
gimp_lut_setup_exact (dodgeburn->lut,
|
|
||||||
lut_func, (gpointer) &exposure,
|
|
||||||
nchannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
gimp_dodge_burn_highlights_lut_func (gpointer user_data,
|
|
||||||
gint nchannels,
|
|
||||||
gint channel,
|
|
||||||
gfloat value)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
gimp_dodge_burn_midtones_lut_func (gpointer user_data,
|
|
||||||
gint nchannels,
|
|
||||||
gint channel,
|
|
||||||
gfloat value)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
factor = 1 / (1.0 + exposure);
|
|
||||||
|
|
||||||
return pow (value, factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
gimp_dodge_burn_shadows_lut_func (gpointer user_data,
|
|
||||||
gint nchannels,
|
|
||||||
gint channel,
|
|
||||||
gfloat value)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
new_value = factor + value - factor * value;
|
|
||||||
}
|
|
||||||
else /* exposure < 0 */
|
|
||||||
{
|
|
||||||
factor = -0.333333 * exposure;
|
|
||||||
if (value < factor)
|
|
||||||
new_value = 0;
|
|
||||||
else /*factor <= value <=1*/
|
|
||||||
new_value = (value - factor)/(1 - factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_value;
|
|
||||||
}
|
|
||||||
|
@ -34,8 +34,6 @@ typedef struct _GimpDodgeBurnClass GimpDodgeBurnClass;
|
|||||||
struct _GimpDodgeBurn
|
struct _GimpDodgeBurn
|
||||||
{
|
{
|
||||||
GimpBrushCore parent_instance;
|
GimpBrushCore parent_instance;
|
||||||
|
|
||||||
GimpLut *lut;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpDodgeBurnClass
|
struct _GimpDodgeBurnClass
|
||||||
|
Reference in New Issue
Block a user