Commit 413a516f authored by Daniel Sabo's avatar Daniel Sabo

Extract layer mode blend functions

Extract layer mode blend functions form their operations so
they can be used directly by paintcore.
parent 91b51117
......@@ -141,6 +141,9 @@ libappoperations_a_sources = \
gimpoperationreplacemode.c \
gimpoperationreplacemode.h \
gimpoperationantierasemode.c \
gimpoperationantierasemode.h
gimpoperationantierasemode.h \
\
gimplayermodefunctions.c \
gimplayermodefunctions.h
libappoperations_a_SOURCES = $(libappoperations_a_sources)
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimplayermodefunctions.c
* Copyright (C) 2013 Daniel Sabo <DanielSabo@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.h>
#include <gegl-plugin.h>
#include "operations-types.h"
#include "gimplayermodefunctions.h"
#include "gimpoperationpointlayermode.h"
#include "gimpoperationnormalmode.h"
#include "gimpoperationdissolvemode.h"
#include "gimpoperationbehindmode.h"
#include "gimpoperationmultiplymode.h"
#include "gimpoperationscreenmode.h"
#include "gimpoperationoverlaymode.h"
#include "gimpoperationdifferencemode.h"
#include "gimpoperationadditionmode.h"
#include "gimpoperationsubtractmode.h"
#include "gimpoperationdarkenonlymode.h"
#include "gimpoperationlightenonlymode.h"
#include "gimpoperationhuemode.h"
#include "gimpoperationsaturationmode.h"
#include "gimpoperationcolormode.h"
#include "gimpoperationvaluemode.h"
#include "gimpoperationdividemode.h"
#include "gimpoperationdodgemode.h"
#include "gimpoperationburnmode.h"
#include "gimpoperationhardlightmode.h"
#include "gimpoperationsoftlightmode.h"
#include "gimpoperationgrainextractmode.h"
#include "gimpoperationgrainmergemode.h"
#include "gimpoperationcolorerasemode.h"
#include "gimpoperationerasemode.h"
#include "gimpoperationreplacemode.h"
#include "gimpoperationantierasemode.h"
GimpLayerModeFunction
get_layer_mode_function (GimpLayerModeEffects paint_mode)
{
GimpLayerModeFunction func = gimp_operation_normal_mode_process_pixels;
switch (paint_mode)
{
case GIMP_NORMAL_MODE: func = gimp_operation_normal_mode_process_pixels; break;
case GIMP_DISSOLVE_MODE: func = gimp_operation_dissolve_mode_process_pixels; break;
case GIMP_BEHIND_MODE: func = gimp_operation_behind_mode_process_pixels; break;
case GIMP_MULTIPLY_MODE: func = gimp_operation_multiply_mode_process_pixels; break;
case GIMP_SCREEN_MODE: func = gimp_operation_screen_mode_process_pixels; break;
case GIMP_OVERLAY_MODE: func = gimp_operation_overlay_mode_process_pixels; break;
case GIMP_DIFFERENCE_MODE: func = gimp_operation_difference_mode_process_pixels; break;
case GIMP_ADDITION_MODE: func = gimp_operation_addition_mode_process_pixels; break;
case GIMP_SUBTRACT_MODE: func = gimp_operation_subtract_mode_process_pixels; break;
case GIMP_DARKEN_ONLY_MODE: func = gimp_operation_darken_only_mode_process_pixels; break;
case GIMP_LIGHTEN_ONLY_MODE: func = gimp_operation_lighten_only_mode_process_pixels; break;
case GIMP_HUE_MODE: func = gimp_operation_hue_mode_process_pixels; break;
case GIMP_SATURATION_MODE: func = gimp_operation_saturation_mode_process_pixels; break;
case GIMP_COLOR_MODE: func = gimp_operation_color_mode_process_pixels; break;
case GIMP_VALUE_MODE: func = gimp_operation_value_mode_process_pixels; break;
case GIMP_DIVIDE_MODE: func = gimp_operation_divide_mode_process_pixels; break;
case GIMP_DODGE_MODE: func = gimp_operation_dodge_mode_process_pixels; break;
case GIMP_BURN_MODE: func = gimp_operation_burn_mode_process_pixels; break;
case GIMP_HARDLIGHT_MODE: func = gimp_operation_hardlight_mode_process_pixels; break;
case GIMP_SOFTLIGHT_MODE: func = gimp_operation_softlight_mode_process_pixels; break;
case GIMP_GRAIN_EXTRACT_MODE: func = gimp_operation_grain_extract_mode_process_pixels; break;
case GIMP_GRAIN_MERGE_MODE: func = gimp_operation_grain_merge_mode_process_pixels; break;
case GIMP_COLOR_ERASE_MODE: func = gimp_operation_color_erase_mode_process_pixels; break;
case GIMP_ERASE_MODE: func = gimp_operation_erase_mode_process_pixels; break;
case GIMP_REPLACE_MODE: func = gimp_operation_replace_mode_process_pixels; break;
case GIMP_ANTI_ERASE_MODE: func = gimp_operation_anti_erase_mode_process_pixels; break;
default:
g_warning ("No direct function for layer mode (%d), using gimp:normal-mode", paint_mode);
func = gimp_operation_normal_mode_process_pixels;
break;
}
return func;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimplayermodefunctions.h
* Copyright (C) 2013 Daniel Sabo <DanielSabo@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/>.
*/
#ifndef __GIMP_LAYER_MODE_FUNCTIONS_H__
#define __GIMP_LAYER_MODE_FUNCTIONS_H__
GimpLayerModeFunction get_layer_mode_function (GimpLayerModeEffects paint_mode);
#endif /* __GIMP_LAYER_MODE_FUNCTIONS_H__ */
......@@ -76,10 +76,20 @@ gimp_operation_addition_mode_process (GeglOperation *operation,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
return gimp_operation_addition_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_addition_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......
......@@ -50,5 +50,13 @@ struct _GimpOperationAdditionModeClass
GType gimp_operation_addition_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_addition_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_ADDITION_MODE_H__ */
......@@ -88,12 +88,22 @@ gimp_operation_anti_erase_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
const gboolean has_mask = mask != NULL;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_anti_erase_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_anti_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
......
......@@ -51,4 +51,13 @@ struct _GimpOperationAntiEraseModeClass
GType gimp_operation_anti_erase_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_anti_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_ANTI_ERASE_MODE_H__ */
......@@ -75,13 +75,22 @@ gimp_operation_behind_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
GimpOperationPointLayerMode *point = GIMP_OPERATION_POINT_LAYER_MODE (operation);
gdouble opacity = point->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
const gboolean has_mask = mask != NULL;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_behind_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_behind_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
......
......@@ -50,5 +50,13 @@ struct _GimpOperationBehindModeClass
GType gimp_operation_behind_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_behind_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_BEHIND_MODE_H__ */
......@@ -75,11 +75,21 @@ gimp_operation_burn_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_burn_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_burn_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......@@ -126,4 +136,4 @@ gimp_operation_burn_mode_process (GeglOperation *operation,
}
return TRUE;
}
}
\ No newline at end of file
......@@ -50,5 +50,13 @@ struct _GimpOperationBurnModeClass
GType gimp_operation_burn_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_burn_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_BURN_MODE_H__ */
......@@ -79,12 +79,22 @@ gimp_operation_color_erase_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
const gboolean has_mask = mask != NULL;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_color_erase_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_color_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
......
......@@ -50,5 +50,13 @@ struct _GimpOperationColorEraseModeClass
GType gimp_operation_color_erase_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_color_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_COLOR_ERASE_MODE_H__ */
......@@ -79,11 +79,21 @@ gimp_operation_color_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_color_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_color_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......
......@@ -50,5 +50,13 @@ struct _GimpOperationColorModeClass
GType gimp_operation_color_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_color_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_COLOR_MODE_H__ */
......@@ -75,11 +75,21 @@ gimp_operation_darken_only_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_darken_only_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_darken_only_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......@@ -125,4 +135,4 @@ gimp_operation_darken_only_mode_process (GeglOperation *operation,
}
return TRUE;
}
}
\ No newline at end of file
......@@ -50,5 +50,13 @@ struct _GimpOperationDarkenOnlyModeClass
GType gimp_operation_darken_only_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_darken_only_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_DARKEN_ONLY_MODE_H__ */
......@@ -75,11 +75,21 @@ gimp_operation_difference_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_difference_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_difference_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......
......@@ -51,4 +51,13 @@ struct _GimpOperationDifferenceModeClass
GType gimp_operation_difference_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_difference_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_DIFFERENCE_MODE_H__ */
......@@ -91,13 +91,23 @@ gimp_operation_dissolve_mode_process (GeglOperation *operation,
const GeglRectangle *result,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *out = out_buf;
gfloat *aux = aux_buf;
gfloat *mask = aux2_buf;
const gboolean has_mask = mask != NULL;
gint x, y;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_dissolve_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, result, level);
}
gboolean
gimp_operation_dissolve_mode_process_pixels (gfloat *in,
gfloat *aux,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *result,
gint level)
{
const gboolean has_mask = mask != NULL;
gint x, y;
for (y = result->y; y < result->y + result->height; y++)
{
......@@ -140,4 +150,4 @@ gimp_operation_dissolve_mode_process (GeglOperation *operation,
}
return TRUE;
}
}
\ No newline at end of file
......@@ -50,5 +50,13 @@ struct _GimpOperationDissolveMode
GType gimp_operation_dissolve_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_dissolve_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *result,
gint level);
#endif /* __GIMP_OPERATION_DISSOLVE_MODE_H__ */
......@@ -75,11 +75,21 @@ gimp_operation_divide_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_divide_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_divide_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......@@ -126,4 +136,4 @@ gimp_operation_divide_mode_process (GeglOperation *operation,
}
return TRUE;
}
}
\ No newline at end of file
......@@ -50,5 +50,13 @@ struct _GimpOperationDivideModeClass
GType gimp_operation_divide_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_divide_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_DIVIDE_MODE_H__ */
......@@ -75,11 +75,21 @@ gimp_operation_dodge_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_dodge_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_dodge_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
......@@ -126,4 +136,4 @@ gimp_operation_dodge_mode_process (GeglOperation *operation,
}
return TRUE;
}
}
\ No newline at end of file
......@@ -50,5 +50,13 @@ struct _GimpOperationDodgeModeClass
GType gimp_operation_dodge_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_dodge_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);
#endif /* __GIMP_OPERATION_DODGE_MODE_H__ */
......@@ -88,13 +88,22 @@ gimp_operation_erase_mode_process (GeglOperation *operation,
const GeglRectangle *roi,
gint level)
{
GimpOperationPointLayerMode *point = GIMP_OPERATION_POINT_LAYER_MODE (operation);
gdouble opacity = point->opacity;
gfloat *in = in_buf;
gfloat *layer = aux_buf;
gfloat *mask = aux2_buf;
gfloat *out = out_buf;
const gboolean has_mask = mask != NULL;
gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity;
return gimp_operation_erase_mode_process_pixels (in_buf, aux_buf, aux2_buf, out_buf, opacity, samples, roi, level);
}
gboolean
gimp_operation_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level)
{
const gboolean has_mask = mask != NULL;
while (samples--)
{
......
......@@ -50,5 +50,13 @@ struct _GimpOperationEraseModeClass
GType gimp_operation_erase_mode_get_type (void) G_GNUC_CONST;
gboolean gimp_operation_erase_mode_process_pixels (gfloat *in,
gfloat *layer,
gfloat *mask,
gfloat *out,
gdouble opacity,
glong samples,
const GeglRectangle *roi,
gint level);