2008-10-13 04:26:27 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpoperationpointcomposer.c
|
|
|
|
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
|
2008-10-25 22:16:22 +08:00
|
|
|
* Copyright (C) 2008 Martin Nordholts <martinn@svn.gnome.org>
|
2008-10-13 04:26:27 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
#include <gegl-plugin.h>
|
2008-10-13 04:26:27 +08:00
|
|
|
|
|
|
|
#include "gegl-types.h"
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
#include "gimpoperationpointlayermode.h"
|
2008-10-13 04:26:27 +08:00
|
|
|
|
|
|
|
|
2008-10-26 22:39:08 +08:00
|
|
|
#define R RED
|
|
|
|
#define G GREEN
|
|
|
|
#define B BLUE
|
|
|
|
#define A ALPHA
|
|
|
|
#define inC in[c]
|
|
|
|
#define inA in[A]
|
|
|
|
#define layC lay[c]
|
|
|
|
#define layA lay[A]
|
|
|
|
#define outC out[c]
|
|
|
|
#define outA out[A]
|
|
|
|
|
2008-10-27 03:28:47 +08:00
|
|
|
#define BLEND(mode, expr) \
|
2008-10-27 01:43:46 +08:00
|
|
|
case (mode): \
|
|
|
|
for (c = RED; c < ALPHA; c++) \
|
|
|
|
{ \
|
|
|
|
expr; \
|
|
|
|
} \
|
2008-10-27 03:28:47 +08:00
|
|
|
break;
|
2008-10-26 06:44:19 +08:00
|
|
|
|
2008-10-25 21:29:55 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_BLEND_MODE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
struct _GimpOperationPointLayerModeClass
|
2008-10-25 21:29:55 +08:00
|
|
|
{
|
|
|
|
GeglOperationPointComposerClass parent_class;
|
|
|
|
};
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
struct _GimpOperationPointLayerMode
|
2008-10-25 21:29:55 +08:00
|
|
|
{
|
|
|
|
GeglOperationPointComposer parent_instance;
|
|
|
|
|
|
|
|
GimpLayerModeEffects blend_mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
static void gimp_operation_point_layer_mode_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_operation_point_layer_mode_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
static void gimp_operation_point_layer_mode_prepare (GeglOperation *operation);
|
|
|
|
static gboolean gimp_operation_point_layer_mode_process (GeglOperation *operation,
|
|
|
|
void *in_buf,
|
|
|
|
void *aux_buf,
|
|
|
|
void *out_buf,
|
|
|
|
glong samples,
|
|
|
|
const GeglRectangle *roi);
|
2008-10-13 04:26:27 +08:00
|
|
|
|
|
|
|
|
2008-10-25 22:16:22 +08:00
|
|
|
G_DEFINE_TYPE (GimpOperationPointLayerMode, gimp_operation_point_layer_mode,
|
2008-10-25 21:29:55 +08:00
|
|
|
GEGL_TYPE_OPERATION_POINT_COMPOSER)
|
2008-10-13 04:26:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_class_init (GimpOperationPointLayerModeClass *klass)
|
2008-10-13 04:26:27 +08:00
|
|
|
{
|
2008-10-25 21:29:55 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2008-10-13 04:26:27 +08:00
|
|
|
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
|
|
|
GeglOperationPointComposerClass *point_class = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass);
|
|
|
|
|
2008-10-26 05:02:46 +08:00
|
|
|
object_class->set_property = gimp_operation_point_layer_mode_set_property;
|
|
|
|
object_class->get_property = gimp_operation_point_layer_mode_get_property;
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-26 05:02:46 +08:00
|
|
|
operation_class->name = "gimp:point-layer-mode";
|
|
|
|
operation_class->description = "GIMP point layer mode operation";
|
2008-10-25 21:29:55 +08:00
|
|
|
operation_class->categories = "compositors";
|
2008-10-13 04:26:27 +08:00
|
|
|
|
2008-10-26 05:02:46 +08:00
|
|
|
operation_class->prepare = gimp_operation_point_layer_mode_prepare;
|
2008-10-25 17:47:09 +08:00
|
|
|
|
2008-10-26 05:02:46 +08:00
|
|
|
point_class->process = gimp_operation_point_layer_mode_process;
|
2008-10-25 21:29:55 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_BLEND_MODE,
|
|
|
|
g_param_spec_enum ("blend-mode", NULL, NULL,
|
|
|
|
GIMP_TYPE_LAYER_MODE_EFFECTS,
|
|
|
|
GIMP_NORMAL_MODE,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-10-13 04:26:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_init (GimpOperationPointLayerMode *self)
|
2008-10-13 04:26:27 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-25 21:29:55 +08:00
|
|
|
static void
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_set_property (GObject *object,
|
2008-10-26 05:02:46 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2008-10-25 21:29:55 +08:00
|
|
|
{
|
2008-10-25 22:16:22 +08:00
|
|
|
GimpOperationPointLayerMode *self = GIMP_OPERATION_POINT_LAYER_MODE (object);
|
2008-10-25 21:29:55 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BLEND_MODE:
|
|
|
|
self->blend_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_get_property (GObject *object,
|
2008-10-26 05:02:46 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2008-10-25 21:29:55 +08:00
|
|
|
{
|
2008-10-25 22:16:22 +08:00
|
|
|
GimpOperationPointLayerMode *self = GIMP_OPERATION_POINT_LAYER_MODE (object);
|
2008-10-25 21:29:55 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_BLEND_MODE:
|
|
|
|
g_value_set_enum (value, self->blend_mode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-25 17:47:09 +08:00
|
|
|
static void
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_prepare (GeglOperation *operation)
|
2008-10-25 17:47:09 +08:00
|
|
|
{
|
|
|
|
Babl *format = babl_format ("RaGaBaA float");
|
|
|
|
|
|
|
|
gegl_operation_set_format (operation, "input", format);
|
|
|
|
gegl_operation_set_format (operation, "output", format);
|
|
|
|
gegl_operation_set_format (operation, "aux", format);
|
|
|
|
}
|
|
|
|
|
2008-10-13 04:26:27 +08:00
|
|
|
static gboolean
|
2008-10-25 22:16:22 +08:00
|
|
|
gimp_operation_point_layer_mode_process (GeglOperation *operation,
|
2008-10-26 05:02:46 +08:00
|
|
|
void *in_buf,
|
|
|
|
void *aux_buf,
|
|
|
|
void *out_buf,
|
|
|
|
glong samples,
|
|
|
|
const GeglRectangle *roi)
|
2008-10-13 04:26:27 +08:00
|
|
|
{
|
2008-10-25 22:16:22 +08:00
|
|
|
GimpOperationPointLayerMode *self = GIMP_OPERATION_POINT_LAYER_MODE (operation);
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-26 06:44:19 +08:00
|
|
|
gfloat *in = in_buf; /* composite of layers below */
|
|
|
|
gfloat *lay = aux_buf; /* layer */
|
|
|
|
gfloat *out = out_buf; /* resulting composite */
|
2008-10-26 22:19:38 +08:00
|
|
|
gint c = 0;
|
2008-10-25 21:29:55 +08:00
|
|
|
|
|
|
|
while (samples--)
|
|
|
|
{
|
|
|
|
switch (self->blend_mode)
|
|
|
|
{
|
2008-10-26 06:44:19 +08:00
|
|
|
/* Porter-Duff A over B */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_NORMAL_MODE,
|
|
|
|
outC = layC + inC * (1 - layA));
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-26 06:44:19 +08:00
|
|
|
/* Porter-Duff B over A */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_BEHIND_MODE,
|
|
|
|
outC = inC + layC * (1 - inA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 multiply */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_MULTIPLY_MODE,
|
|
|
|
outC = layC * inC + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 screen */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_SCREEN_MODE,
|
|
|
|
outC = layC + inC - layC * inC);
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 difference */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_DIFFERENCE_MODE,
|
|
|
|
outC = inC + layC - 2 * MIN (layC * inA, inC * layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 darken */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_DARKEN_ONLY_MODE,
|
|
|
|
outC = MIN (layC * inA, inC * layA) + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 lighten */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_LIGHTEN_ONLY_MODE,
|
|
|
|
outC = MAX (layC * inA, inC * layA) + layC * (1 - inA) + inC * (1 - layA));
|
|
|
|
|
|
|
|
/* SVG 1.2 overlay */
|
|
|
|
BLEND (GIMP_OVERLAY_MODE,
|
|
|
|
if (2 * inC < inA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = 2 * layC * inC + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layA * inA - 2 * (inA - inC) * (layA - layC) + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
2008-10-26 21:48:19 +08:00
|
|
|
/* SVG 1.2 color-dodge */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_DODGE_MODE,
|
|
|
|
if (layC * inA + inC * layA >= layA * inA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layA * inA + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = inC * layA / (1 - layC / layA) + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-26 21:48:19 +08:00
|
|
|
/* SVG 1.2 color-burn */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_BURN_MODE,
|
|
|
|
if (layC * inA + inC * layA <= layA * inA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layA * (layC * inA + inC * layA - layA * inA) / layC + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 hard-light */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_HARDLIGHT_MODE,
|
|
|
|
if (2 * layC < layA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = 2 * layC * inC + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layA * inA - 2 * (inA - inC) * (layA - layC) + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
|
|
|
/* SVG 1.2 soft-light */
|
|
|
|
/* XXX: Why is the result so different from legacy Soft Light? */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_SOFTLIGHT_MODE,
|
|
|
|
if (2 * layC < layA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = inC * (layA - (1 - inC / inA) * (2 * layC - layA)) + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else if (8 * inC <= inA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = inC * (layA - (1 - inC / inA) * (2 * layC - layA) * (3 - 8 * inC / inA)) + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 01:43:46 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = (inC * layA + (sqrt (inC / inA) * inA - inC) * (2 * layC - layA)) + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
2008-10-27 03:28:47 +08:00
|
|
|
/* Custom SVG 1.2:
|
2008-10-25 21:29:55 +08:00
|
|
|
*
|
2008-10-27 03:28:47 +08:00
|
|
|
* if Dc + Sc >= 1
|
|
|
|
* f(Sc, Dc) = 1
|
|
|
|
* otherwise
|
|
|
|
* f(Sc, Dc) = Dc + Sc
|
2008-10-25 21:29:55 +08:00
|
|
|
*/
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_ADDITION_MODE,
|
2008-10-27 03:28:47 +08:00
|
|
|
if (layC * inA + inC * layA >= layA * inA)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layA * inA + layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 03:28:47 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = inC + layC);
|
2008-10-25 21:29:55 +08:00
|
|
|
|
2008-10-27 03:28:47 +08:00
|
|
|
/* Custom SVG 1.2:
|
|
|
|
*
|
|
|
|
* if Dc - Sc <= 0
|
|
|
|
* f(Sc, Dc) = 0
|
|
|
|
* otherwise
|
|
|
|
* f(Sc, Dc) = Dc - Sc
|
|
|
|
*/
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_SUBTRACT_MODE,
|
2008-10-27 03:28:47 +08:00
|
|
|
if (inC * layA - layC * inA <= 0)
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = layC * (1 - inA) + inC * (1 - layA);
|
2008-10-27 03:28:47 +08:00
|
|
|
else
|
2008-10-27 03:39:07 +08:00
|
|
|
outC = inC + layC - 2 * layC * inA);
|
2008-10-26 06:44:19 +08:00
|
|
|
|
2008-10-26 16:39:41 +08:00
|
|
|
/* Derieved from SVG 1.2 formulas, f(Sc, Dc) = Dc - Sc + 0.5 */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_GRAIN_EXTRACT_MODE,
|
|
|
|
outC = inC + layC - 2 * layC * inA + 0.5 * inA * layA);
|
2008-10-26 16:39:41 +08:00
|
|
|
|
|
|
|
/* Derieved from SVG 1.2 formulas, f(Sc, Dc) = Dc + Sc - 0.5 */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_GRAIN_MERGE_MODE,
|
|
|
|
outC = inC + layC - 0.5 * inA * layA);
|
2008-10-26 16:39:41 +08:00
|
|
|
|
|
|
|
/* Derieved from SVG 1.2 formulas, f(Sc, Dc) = Dc / Sc */
|
2008-10-27 01:43:46 +08:00
|
|
|
BLEND (GIMP_DIVIDE_MODE,
|
|
|
|
outC = inC * layA * layA / layC + layC * (1 - inA) + inC * (1 - layA));
|
2008-10-26 06:44:19 +08:00
|
|
|
|
2008-10-25 21:29:55 +08:00
|
|
|
case GIMP_HUE_MODE:
|
|
|
|
case GIMP_SATURATION_MODE:
|
|
|
|
case GIMP_COLOR_MODE:
|
|
|
|
case GIMP_VALUE_MODE:
|
2008-10-26 16:39:41 +08:00
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
2008-10-25 21:29:55 +08:00
|
|
|
case GIMP_ERASE_MODE:
|
|
|
|
case GIMP_ANTI_ERASE_MODE:
|
2008-10-26 16:39:41 +08:00
|
|
|
case GIMP_COLOR_ERASE_MODE:
|
|
|
|
case GIMP_REPLACE_MODE:
|
|
|
|
/* Icky eraser and paint modes */
|
2008-10-25 21:29:55 +08:00
|
|
|
break;
|
|
|
|
|
2008-10-26 06:44:19 +08:00
|
|
|
case GIMP_DISSOLVE_MODE:
|
|
|
|
/* Not a point filter and cannot be implemented here */
|
|
|
|
/* g_assert_not_reached (); */
|
|
|
|
break;
|
|
|
|
|
2008-10-25 21:29:55 +08:00
|
|
|
default:
|
|
|
|
g_error ("Unknown layer mode");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-26 16:39:41 +08:00
|
|
|
/* Alpha is treated the same */
|
2008-10-26 22:39:08 +08:00
|
|
|
outA = layA + inA - layA * inA;
|
2008-10-26 16:39:41 +08:00
|
|
|
|
2008-10-26 06:44:19 +08:00
|
|
|
in += 4;
|
|
|
|
lay += 4;
|
|
|
|
out += 4;
|
2008-10-25 21:29:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2008-10-13 04:26:27 +08:00
|
|
|
}
|