app: implement the different composite modes for anti-erase mode

This commit is contained in:
Ell
2017-02-17 15:25:51 -05:00
parent 15f5d5780e
commit 60466dce3e

View File

@ -28,6 +28,9 @@
#include "gimpoperationantierase.h"
static GimpLayerModeAffectMask gimp_operation_anti_erase_get_affect_mask (GimpOperationLayerMode *layer_mode);
G_DEFINE_TYPE (GimpOperationAntiErase, gimp_operation_anti_erase,
GIMP_TYPE_OPERATION_LAYER_MODE)
@ -37,9 +40,11 @@ gimp_operation_anti_erase_class_init (GimpOperationAntiEraseClass *klass)
{
GeglOperationClass *operation_class;
GeglOperationPointComposer3Class *point_class;
GimpOperationLayerModeClass *layer_mode_class;
operation_class = GEGL_OPERATION_CLASS (klass);
point_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);
layer_mode_class = GIMP_OPERATION_LAYER_MODE_CLASS (klass);
gegl_operation_class_set_keys (operation_class,
"name", "gimp:anti-erase",
@ -47,6 +52,8 @@ gimp_operation_anti_erase_class_init (GimpOperationAntiEraseClass *klass)
NULL);
point_class->process = gimp_operation_anti_erase_process;
layer_mode_class->get_affect_mask = gimp_operation_anti_erase_get_affect_mask;
}
static void
@ -72,6 +79,10 @@ gimp_operation_anti_erase_process (GeglOperation *op,
gfloat opacity = layer_mode->opacity;
const gboolean has_mask = mask != NULL;
switch (layer_mode->composite_mode)
{
case GIMP_LAYER_COMPOSITE_SRC_OVER:
case GIMP_LAYER_COMPOSITE_AUTO:
while (samples--)
{
gfloat value = opacity;
@ -94,6 +105,81 @@ gimp_operation_anti_erase_process (GeglOperation *op,
if (has_mask)
mask++;
}
break;
case GIMP_LAYER_COMPOSITE_SRC_ATOP:
while (samples--)
{
gint b;
out[ALPHA] = in[ALPHA];
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
in += 4;
out += 4;
}
break;
case GIMP_LAYER_COMPOSITE_DST_ATOP:
while (samples--)
{
gfloat value = opacity;
gint b;
if (has_mask)
value *= *mask;
out[ALPHA] = layer[ALPHA] * value;
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
in += 4;
layer += 4;
out += 4;
if (has_mask)
mask++;
}
break;
case GIMP_LAYER_COMPOSITE_SRC_IN:
while (samples--)
{
gfloat value = opacity;
gint b;
if (has_mask)
value *= *mask;
out[ALPHA] = in[ALPHA] * layer[ALPHA] * value;
for (b = RED; b < ALPHA; b++)
{
out[b] = in[b];
}
in += 4;
layer += 4;
out += 4;
if (has_mask)
mask++;
}
break;
}
return TRUE;
}
static GimpLayerModeAffectMask
gimp_operation_anti_erase_get_affect_mask (GimpOperationLayerMode *layer_mode)
{
return GIMP_LAYER_MODE_AFFECT_SRC;
}