app: add new multiply op

This commit is contained in:
Øyvind Kolås 2017-01-09 02:03:52 +01:00
parent 735887286a
commit c2583faa5a
15 changed files with 457 additions and 233 deletions

View File

@ -318,6 +318,8 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_LCH_COLOR, "GIMP_LAYER_MODE_LCH_COLOR", "lch-color" },
{ GIMP_LAYER_MODE_LCH_LIGHTNESS, "GIMP_LAYER_MODE_LCH_LIGHTNESS", "lch-lightness" },
{ GIMP_LAYER_MODE_NORMAL, "GIMP_LAYER_MODE_NORMAL", "normal" },
{ GIMP_LAYER_MODE_MULTIPLY, "GIMP_LAYER_MODE_MULTIPLY", "multiply" },
{ GIMP_LAYER_MODE_MULTIPLY_LINEAR, "GIMP_LAYER_MODE_MULTIPLY_LINEAR", "multiply-linear" },
{ GIMP_LAYER_MODE_ERASE, "GIMP_LAYER_MODE_ERASE", "erase" },
{ GIMP_LAYER_MODE_REPLACE, "GIMP_LAYER_MODE_REPLACE", "replace" },
{ GIMP_LAYER_MODE_ANTI_ERASE, "GIMP_LAYER_MODE_ANTI_ERASE", "anti-erase" },
@ -329,7 +331,7 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_NORMAL_NON_LINEAR, NC_("layer-mode", "Normal (non-linear)"), NULL },
{ GIMP_LAYER_MODE_DISSOLVE, NC_("layer-mode", "Dissolve"), NULL },
{ GIMP_LAYER_MODE_BEHIND, NC_("layer-mode", "Behind"), NULL },
{ GIMP_LAYER_MODE_MULTIPLY_LEGACY, NC_("layer-mode", "Multiply"), NULL },
{ GIMP_LAYER_MODE_MULTIPLY_LEGACY, NC_("layer-mode", "Multiply (legacy)"), NULL },
{ GIMP_LAYER_MODE_SCREEN_LEGACY, NC_("layer-mode", "Screen"), NULL },
{ GIMP_LAYER_MODE_OVERLAY_LEGACY, NC_("layer-mode", "Old broken Overlay"), NULL },
{ GIMP_LAYER_MODE_DIFFERENCE_LEGACY, NC_("layer-mode", "Difference"), NULL },
@ -355,6 +357,8 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_LCH_COLOR, NC_("layer-mode", "Color (LCH)"), NULL },
{ GIMP_LAYER_MODE_LCH_LIGHTNESS, NC_("layer-mode", "Lightness (LCH)"), NULL },
{ GIMP_LAYER_MODE_NORMAL, NC_("layer-mode", "Normal"), NULL },
{ GIMP_LAYER_MODE_MULTIPLY, NC_("layer-mode", "Multiply"), NULL },
{ GIMP_LAYER_MODE_MULTIPLY_LINEAR, NC_("layer-mode", "Multiply (linear)"), NULL },
{ GIMP_LAYER_MODE_ERASE, NC_("layer-mode", "Erase"), NULL },
{ GIMP_LAYER_MODE_REPLACE, NC_("layer-mode", "Replace"), NULL },
{ GIMP_LAYER_MODE_ANTI_ERASE, NC_("layer-mode", "Anti erase"), NULL },

View File

@ -157,7 +157,7 @@ typedef enum
GIMP_LAYER_MODE_NORMAL_NON_LINEAR, /*< desc="Normal (non-linear)" >*/
GIMP_LAYER_MODE_DISSOLVE, /*< desc="Dissolve" >*/
GIMP_LAYER_MODE_BEHIND, /*< desc="Behind" >*/
GIMP_LAYER_MODE_MULTIPLY_LEGACY, /*< desc="Multiply" >*/
GIMP_LAYER_MODE_MULTIPLY_LEGACY, /*< desc="Multiply (legacy)" >*/
GIMP_LAYER_MODE_SCREEN_LEGACY, /*< desc="Screen" >*/
GIMP_LAYER_MODE_OVERLAY_LEGACY, /*< desc="Old broken Overlay" >*/
GIMP_LAYER_MODE_DIFFERENCE_LEGACY, /*< desc="Difference" >*/
@ -183,6 +183,8 @@ typedef enum
GIMP_LAYER_MODE_LCH_COLOR, /*< desc="Color (LCH)" >*/
GIMP_LAYER_MODE_LCH_LIGHTNESS, /*< desc="Lightness (LCH)" >*/
GIMP_LAYER_MODE_NORMAL, /*< desc="Normal" >*/
GIMP_LAYER_MODE_MULTIPLY, /*< desc="Multiply" >*/
GIMP_LAYER_MODE_MULTIPLY_LINEAR, /*< desc="Multiply (linear)" >*/
/* internal modes, not available to the PDB */
GIMP_LAYER_MODE_ERASE = 1000, /*< pdb-skip, desc="Erase" >*/

View File

@ -166,6 +166,11 @@ gimp_gegl_mode_node_set_mode (GeglNode *node,
operation = "gimp:multiply-mode";
break;
case GIMP_LAYER_MODE_MULTIPLY:
case GIMP_LAYER_MODE_MULTIPLY_LINEAR:
operation = "gimp:multiply";
break;
case GIMP_LAYER_MODE_SCREEN_LEGACY:
operation = "gimp:screen-mode";
break;
@ -293,17 +298,19 @@ gimp_gegl_mode_node_set_mode (GeglNode *node,
{
case GIMP_LAYER_MODE_NORMAL:
case GIMP_LAYER_MODE_DISSOLVE:
case GIMP_LAYER_MODE_MULTIPLY_LINEAR:
gegl_node_set (node,
"linear", TRUE,
NULL);
break;
case GIMP_LAYER_MODE_BEHIND:
case GIMP_LAYER_MODE_MULTIPLY:
case GIMP_LAYER_MODE_MULTIPLY_LEGACY:
case GIMP_LAYER_MODE_SCREEN_LEGACY:
case GIMP_LAYER_MODE_ADDITION_LEGACY:
case GIMP_LAYER_MODE_SUBTRACT_LEGACY:
case GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY:
case GIMP_LAYER_MODE_LIGHTEN_ONLY_LEGACY:
gegl_node_set (node,
"linear", TRUE,
NULL);
break;
case GIMP_LAYER_MODE_NORMAL_NON_LINEAR:
case GIMP_LAYER_MODE_OVERLAY_LEGACY:
case GIMP_LAYER_MODE_DIFFERENCE_LEGACY:

View File

@ -102,8 +102,10 @@ libappoperations_generic_a_sources = \
gimpoperationdissolvemode.h \
gimpoperationbehindmode.c \
gimpoperationbehindmode.h \
gimpoperationmultiplymode.c \
gimpoperationmultiplymode.h \
gimpoperationmultiply.c \
gimpoperationmultiply.h \
gimpoperationmultiplylegacy.c \
gimpoperationmultiplylegacy.h \
gimpoperationscreenmode.c \
gimpoperationscreenmode.h \
gimpoperationoverlaymode.c \

View File

@ -69,7 +69,8 @@
#include "gimpoperationnormalmode.h"
#include "gimpoperationdissolvemode.h"
#include "gimpoperationbehindmode.h"
#include "gimpoperationmultiplymode.h"
#include "gimpoperationmultiply.h"
#include "gimpoperationmultiplylegacy.h"
#include "gimpoperationscreenmode.h"
#include "gimpoperationoverlaymode.h"
#include "gimpoperationdifferencemode.h"
@ -133,7 +134,8 @@ gimp_operations_init (void)
g_type_class_ref (GIMP_TYPE_OPERATION_NORMAL_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_DISSOLVE_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_BEHIND_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_MULTIPLY_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_MULTIPLY);
g_type_class_ref (GIMP_TYPE_OPERATION_MULTIPLY_LEGACY);
g_type_class_ref (GIMP_TYPE_OPERATION_SCREEN_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_OVERLAY_MODE);
g_type_class_ref (GIMP_TYPE_OPERATION_DIFFERENCE_MODE);

View File

@ -29,7 +29,8 @@
#include "gimpoperationnormalmode.h"
#include "gimpoperationdissolvemode.h"
#include "gimpoperationbehindmode.h"
#include "gimpoperationmultiplymode.h"
#include "gimpoperationmultiply.h"
#include "gimpoperationmultiplylegacy.h"
#include "gimpoperationscreenmode.h"
#include "gimpoperationoverlaymode.h"
#include "gimpoperationdifferencemode.h"
@ -79,7 +80,11 @@ get_layer_mode_function (GimpLayerMode paint_mode,
break;
case GIMP_LAYER_MODE_MULTIPLY_LEGACY:
func = gimp_operation_multiply_mode_process_pixels;
func = gimp_operation_multiply_legacy_process_pixels;
break;
case GIMP_LAYER_MODE_MULTIPLY:
func = gimp_operation_multiply_process_pixels;
break;
case GIMP_LAYER_MODE_SCREEN_LEGACY:

View File

@ -0,0 +1,135 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiply.c
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
* 2012 Ville Sokk <ville.sokk@gmail.com>
* 2017 Øyvind Kolås <pippin@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl-plugin.h>
#include "operations-types.h"
#include "gimpoperationmultiply.h"
static gboolean gimp_operation_multiply_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level);
G_DEFINE_TYPE (GimpOperationMultiply, gimp_operation_multiply,
GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
static void
gimp_operation_multiply_class_init (GimpOperationMultiplyClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationPointComposer3Class *point_class;
operation_class = GEGL_OPERATION_CLASS (klass);
point_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);
gegl_operation_class_set_keys (operation_class,
"name", "gimp:multiply-mode",
"description", "GIMP multiply mode operation",
NULL);
point_class->process = gimp_operation_multiply_process;
}
static void
gimp_operation_multiply_init (GimpOperationMultiply *self)
{
}
static gboolean
gimp_operation_multiply_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level)
{
gfloat opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_multiply_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_multiply_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
gfloat comp_alpha;
comp_alpha = layer[ALPHA] * opacity;
if (has_mask)
comp_alpha *= *mask;
if (comp_alpha != 0.0f)
{
gint b;
for (b = RED; b < ALPHA; b++)
{
gfloat comp = layer[b] * in[b];
out[b] = comp * comp_alpha + in[b] * (1.0 - comp_alpha);
out[b] = CLAMP (out[b], 0.0, 1.0);
}
}
else
{
gint b;
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
}
out[ALPHA] = in[ALPHA];
in += 4;
layer += 4;
out += 4;
if (has_mask)
mask++;
}
return TRUE;
}

View File

@ -0,0 +1,60 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiply.h
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
* 2017 Øyvind Kolås <pippin@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_OPERATION_MULTIPLY_H__
#define __GIMP_OPERATION_MULTIPLY_H__
#include "gimpoperationpointlayermode.h"
#define GIMP_TYPE_OPERATION_MULTIPLY (gimp_operation_multiply_get_type ())
#define GIMP_OPERATION_MULTIPLY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_MULTIPLY, GimpOperationMultiply))
#define GIMP_OPERATION_MULTIPLY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_MULTIPLY, GimpOperationMultiplyClass))
#define GIMP_IS_OPERATION_MULTIPLY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_MULTIPLY))
#define GIMP_IS_OPERATION_MULTIPLY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OPERATION_MULTIPLY))
#define GIMP_OPERATION_MULTIPLY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_MULTIPLY, GimpOperationMultiplyClass))
typedef struct _GimpOperationMultiply GimpOperationMultiply;
typedef struct _GimpOperationMultiplyClass GimpOperationMultiplyClass;
struct _GimpOperationMultiply
{
GimpOperationPointLayerMode parent_instance;
};
struct _GimpOperationMultiplyClass
{
GimpOperationPointLayerModeClass parent_class;
};
GType gimp_operation_multiply_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_multiply_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_MULTIPLY_H__ */

View File

@ -0,0 +1,137 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiplylegacy.c
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
* 2012 Ville Sokk <ville.sokk@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl-plugin.h>
#include "operations-types.h"
#include "gimpoperationmultiplylegacy.h"
static gboolean gimp_operation_multiply_legacy_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level);
G_DEFINE_TYPE (GimpOperationMultiplyLegacy, gimp_operation_multiply_legacy,
GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
static void
gimp_operation_multiply_legacy_class_init (GimpOperationMultiplyLegacyClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationPointComposer3Class *point_class;
operation_class = GEGL_OPERATION_CLASS (klass);
point_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);
gegl_operation_class_set_keys (operation_class,
"name", "gimp:multiply-legacy",
"description", "GIMP multiply legacy operation",
NULL);
point_class->process = gimp_operation_multiply_legacy_process;
}
static void
gimp_operation_multiply_legacy_init (GimpOperationMultiplyLegacy *self)
{
}
static gboolean
gimp_operation_multiply_legacy_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level)
{
gfloat opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_multiply_legacy_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_multiply_legacy_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
gfloat comp_alpha, new_alpha;
comp_alpha = MIN (in[ALPHA], layer[ALPHA]) * opacity;
if (has_mask)
comp_alpha *= *mask;
new_alpha = in[ALPHA] + (1.0 - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
{
gfloat ratio = comp_alpha / new_alpha;
gint b;
for (b = RED; b < ALPHA; b++)
{
gfloat comp = layer[b] * in[b];
out[b] = comp * ratio + in[b] * (1.0 - ratio);
out[b] = CLAMP (out[b], 0.0, 1.0);
}
}
else
{
gint b;
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
}
out[ALPHA] = in[ALPHA];
in += 4;
layer += 4;
out += 4;
if (has_mask)
mask++;
}
return TRUE;
}

View File

@ -0,0 +1,61 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiplylegacy.h
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_OPERATION_MULTIPLY_LEGACY_H__
#define __GIMP_OPERATION_MULTIPLY_LEGACY_H__
#include "gimpoperationpointlayermode.h"
#define GIMP_TYPE_OPERATION_MULTIPLY_LEGACY (gimp_operation_multiply_legacy_get_type ())
#define GIMP_OPERATION_MULTIPLY_LEGACY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_MULTIPLY_LEGACY, GimpOperationMultiplyLegacy))
#define GIMP_OPERATION_MULTIPLY_LEGACY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_MULTIPLY_LEGACY, GimpOperationMultiplyLegacyClass))
#define GIMP_IS_OPERATION_MULTIPLY_LEGACY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_MULTIPLY_LEGACY))
#define GIMP_IS_OPERATION_MULTIPLY_LEGACY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OPERATION_MULTIPLY_LEGACY))
#define GIMP_OPERATION_MULTIPLY_LEGACY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_MULTIPLY_LEGACY, GimpOperationMultiplyLegacyClass))
typedef struct _GimpOperationMultiplyLegacy GimpOperationMultiplyLegacy;
typedef struct _GimpOperationMultiplyLegacyClass GimpOperationMultiplyLegacyClass;
struct _GimpOperationMultiplyLegacy
{
GimpOperationPointLayerMode parent_instance;
};
struct _GimpOperationMultiplyLegacyClass
{
GimpOperationPointLayerModeClass parent_class;
};
GType gimp_operation_multiply_legacy_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_multiply_legacy_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_MULTIPLY_LEGACY_H__ */

View File

@ -1,137 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiplymode.c
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
* 2012 Ville Sokk <ville.sokk@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl-plugin.h>
#include "operations-types.h"
#include "gimpoperationmultiplymode.h"
static gboolean gimp_operation_multiply_mode_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level);
G_DEFINE_TYPE (GimpOperationMultiplyMode, gimp_operation_multiply_mode,
GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
static void
gimp_operation_multiply_mode_class_init (GimpOperationMultiplyModeClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationPointComposer3Class *point_class;
operation_class = GEGL_OPERATION_CLASS (klass);
point_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);
gegl_operation_class_set_keys (operation_class,
"name", "gimp:multiply-mode",
"description", "GIMP multiply mode operation",
NULL);
point_class->process = gimp_operation_multiply_mode_process;
}
static void
gimp_operation_multiply_mode_init (GimpOperationMultiplyMode *self)
{
}
static gboolean
gimp_operation_multiply_mode_process (GeglOperation *operation,
void *in_buf,
void *aux_buf,
void *aux2_buf,
void *out_buf,
glong samples,
const GeglRectangle *roi,
gint level)
{
gfloat opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_multiply_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_multiply_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
gfloat comp_alpha, new_alpha;
comp_alpha = MIN (in[ALPHA], layer[ALPHA]) * opacity;
if (has_mask)
comp_alpha *= *mask;
new_alpha = in[ALPHA] + (1.0 - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
{
gfloat ratio = comp_alpha / new_alpha;
gint b;
for (b = RED; b < ALPHA; b++)
{
gfloat comp = layer[b] * in[b];
out[b] = comp * ratio + in[b] * (1.0 - ratio);
out[b] = CLAMP (out[b], 0.0, 1.0);
}
}
else
{
gint b;
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
}
out[ALPHA] = in[ALPHA];
in += 4;
layer += 4;
out += 4;
if (has_mask)
mask++;
}
return TRUE;
}

View File

@ -1,61 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationmultiplymode.h
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_OPERATION_MULTIPLY_MODE_H__
#define __GIMP_OPERATION_MULTIPLY_MODE_H__
#include "gimpoperationpointlayermode.h"
#define GIMP_TYPE_OPERATION_MULTIPLY_MODE (gimp_operation_multiply_mode_get_type ())
#define GIMP_OPERATION_MULTIPLY_MODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_MULTIPLY_MODE, GimpOperationMultiplyMode))
#define GIMP_OPERATION_MULTIPLY_MODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_MULTIPLY_MODE, GimpOperationMultiplyModeClass))
#define GIMP_IS_OPERATION_MULTIPLY_MODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_MULTIPLY_MODE))
#define GIMP_IS_OPERATION_MULTIPLY_MODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OPERATION_MULTIPLY_MODE))
#define GIMP_OPERATION_MULTIPLY_MODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_OPERATION_MULTIPLY_MODE, GimpOperationMultiplyModeClass))
typedef struct _GimpOperationMultiplyMode GimpOperationMultiplyMode;
typedef struct _GimpOperationMultiplyModeClass GimpOperationMultiplyModeClass;
struct _GimpOperationMultiplyMode
{
GimpOperationPointLayerMode parent_instance;
};
struct _GimpOperationMultiplyModeClass
{
GimpOperationPointLayerModeClass parent_class;
};
GType gimp_operation_multiply_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_multiply_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gfloat opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_MULTIPLY_MODE_H__ */

View File

@ -104,7 +104,7 @@ gimp_paint_mode_menu_new (gboolean with_behind_mode,
GtkWidget *combo;
store = gimp_enum_store_new_with_values (GIMP_TYPE_LAYER_MODE,
26,
27,
GIMP_LAYER_MODE_NORMAL,
GIMP_LAYER_MODE_NORMAL_NON_LINEAR,
GIMP_LAYER_MODE_DISSOLVE,
@ -115,6 +115,8 @@ gimp_paint_mode_menu_new (gboolean with_behind_mode,
GIMP_LAYER_MODE_ADDITION_LEGACY,
GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY,
GIMP_LAYER_MODE_MULTIPLY,
GIMP_LAYER_MODE_MULTIPLY_LINEAR,
GIMP_LAYER_MODE_MULTIPLY_LEGACY,
GIMP_LAYER_MODE_BURN_LEGACY,

View File

@ -97,7 +97,9 @@ typedef enum
GIMP_LAYER_MODE_LCH_CHROMA,
GIMP_LAYER_MODE_LCH_COLOR,
GIMP_LAYER_MODE_LCH_LIGHTNESS,
GIMP_LAYER_MODE_NORMAL
GIMP_LAYER_MODE_NORMAL,
GIMP_LAYER_MODE_MULTIPLY,
GIMP_LAYER_MODE_MULTIPLY_LINEAR
} GimpLayerMode;

View File

@ -697,31 +697,32 @@ package Gimp::CodeGen::enums;
header => 'core/core-enums.h',
symbols => [ qw(GIMP_LAYER_MODE_NORMAL_NON_LINEAR
GIMP_LAYER_MODE_DISSOLVE GIMP_LAYER_MODE_BEHIND
GIMP_LAYER_MODE_MULTIPLY_BROKEN
GIMP_LAYER_MODE_SCREEN_BROKEN
GIMP_LAYER_MODE_OVERLAY_BROKEN
GIMP_LAYER_MODE_DIFFERENCE_BROKEN
GIMP_LAYER_MODE_ADDITION_BROKEN
GIMP_LAYER_MODE_SUBTRACT_BROKEN
GIMP_LAYER_MODE_DARKEN_ONLY_BROKEN
GIMP_LAYER_MODE_LIGHTEN_ONLY_BROKEN
GIMP_LAYER_MODE_HSV_HUE_BROKEN
GIMP_LAYER_MODE_HSV_SATURATION_BROKEN
GIMP_LAYER_MODE_HSV_COLOR_BROKEN
GIMP_LAYER_MODE_HSV_VALUE_BROKEN
GIMP_LAYER_MODE_DIVIDE_BROKEN
GIMP_LAYER_MODE_DODGE_BROKEN
GIMP_LAYER_MODE_BURN_BROKEN
GIMP_LAYER_MODE_HARDLIGHT_BROKEN
GIMP_LAYER_MODE_SOFTLIGHT_BROKEN
GIMP_LAYER_MODE_GRAIN_EXTRACT_BROKEN
GIMP_LAYER_MODE_GRAIN_MERGE_BROKEN
GIMP_LAYER_MODE_MULTIPLY_LEGACY
GIMP_LAYER_MODE_SCREEN_LEGACY
GIMP_LAYER_MODE_OVERLAY_LEGACY
GIMP_LAYER_MODE_DIFFERENCE_LEGACY
GIMP_LAYER_MODE_ADDITION_LEGACY
GIMP_LAYER_MODE_SUBTRACT_LEGACY
GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY
GIMP_LAYER_MODE_LIGHTEN_ONLY_LEGACY
GIMP_LAYER_MODE_HSV_HUE_LEGACY
GIMP_LAYER_MODE_HSV_SATURATION_LEGACY
GIMP_LAYER_MODE_HSV_COLOR_LEGACY
GIMP_LAYER_MODE_HSV_VALUE_LEGACY
GIMP_LAYER_MODE_DIVIDE_LEGACY
GIMP_LAYER_MODE_DODGE_LEGACY
GIMP_LAYER_MODE_BURN_LEGACY
GIMP_LAYER_MODE_HARDLIGHT_LEGACY
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY
GIMP_LAYER_MODE_COLOR_ERASE
GIMP_LAYER_MODE_OVERLAY GIMP_LAYER_MODE_LCH_HUE
GIMP_LAYER_MODE_LCH_CHROMA
GIMP_LAYER_MODE_LCH_COLOR
GIMP_LAYER_MODE_LCH_LIGHTNESS
GIMP_LAYER_MODE_NORMAL) ],
GIMP_LAYER_MODE_NORMAL GIMP_LAYER_MODE_MULTIPLY
GIMP_LAYER_MODE_MULTIPLY_LINEAR) ],
mapping => { GIMP_LAYER_MODE_NORMAL_NON_LINEAR => '0',
GIMP_LAYER_MODE_DISSOLVE => '1',
GIMP_LAYER_MODE_BEHIND => '2',
@ -750,7 +751,9 @@ package Gimp::CodeGen::enums;
GIMP_LAYER_MODE_LCH_CHROMA => '25',
GIMP_LAYER_MODE_LCH_COLOR => '26',
GIMP_LAYER_MODE_LCH_LIGHTNESS => '27',
GIMP_LAYER_MODE_NORMAL => '28' }
GIMP_LAYER_MODE_NORMAL => '28',
GIMP_LAYER_MODE_MULTIPLY => '29',
GIMP_LAYER_MODE_MULTIPLY_LINEAR => '30' }
},
GimpBrushApplicationMode =>
{ contig => 1,