gimp/app/operations/layer-modes-legacy/gimpoperationdifferencelega...

127 lines
4.2 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpoperationdifferencemode.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 "gimpoperationdifferencelegacy.h"
app: layer mode code shuffling Commit 3635cf04ab69bafb76d7583da804f580f2d5fbf3 moved the special handling of bottom-layer compositing to GimpOperationLayerMode. This required giving the op more control over the process() function of its subclasses. As a temporary workaround, the commit bypassed the subclasses entirely, using "gimp:layer-mode" for all modes. This is the reckoning :) Add a process() virtual function to GimpOperationLayerMode, which its subclasses should override instead of GeglOperationPointComposer3's process() functions. Reinstate the subclasses (by returning the correct op in gimp_layer_mode_get_oepration()), and have them override this function. Improve the way gimp_operation_layer_mode_process() dispatches to the actual process function, to slightly lower its overhead and fix some thread-safety issues. Remove the "function" field of the layer-mode info array, and have gimp_layer_mode_get_function() return the GimpOperationLayerMode::process() function of the corresponding op's class (caching the result, to keep it cheap.) This reduces redundancy, allows us to make the ops' process() functions private, and simplifies SSE dispatching (only used by NORMAL mode, currently.) Move the blend and composite functions of the non-specialized layer modes to gimpoperationlayermode-{blend,composite}.[hc], respectively, to improve code organization. Move the SSE2 composite functions to a separate file, so that they can be built as part of libapplayermodes_sse2, allowing libapplayermodes to be built without SSE2 compiler flags. This allows building GIMP with SSE acceleration enabled, while running the resulting binary on a target with no SSE accelration. Add a "blend_function" field to the layer-mode info array, and use it to specify the blend function for the non-specialized modes. This replaces the separate switch() statement that we used previously. Remove the "affected_region" field of the layer-mode info array. We don't need it anymore, since we can go back to using GimpOperationLayerMode's virtual get_affected_region() function. Last but not least, a bunch of code cleanups and consistency adjustments.
2017-08-17 22:26:49 +08:00
static gboolean gimp_operation_difference_legacy_process (GeglOperation *op,
void *in,
void *layer,
void *mask,
void *out,
glong samples,
const GeglRectangle *roi,
gint level);
G_DEFINE_TYPE (GimpOperationDifferenceLegacy, gimp_operation_difference_legacy,
GIMP_TYPE_OPERATION_LAYER_MODE)
static void
gimp_operation_difference_legacy_class_init (GimpOperationDifferenceLegacyClass *klass)
{
app: layer mode code shuffling Commit 3635cf04ab69bafb76d7583da804f580f2d5fbf3 moved the special handling of bottom-layer compositing to GimpOperationLayerMode. This required giving the op more control over the process() function of its subclasses. As a temporary workaround, the commit bypassed the subclasses entirely, using "gimp:layer-mode" for all modes. This is the reckoning :) Add a process() virtual function to GimpOperationLayerMode, which its subclasses should override instead of GeglOperationPointComposer3's process() functions. Reinstate the subclasses (by returning the correct op in gimp_layer_mode_get_oepration()), and have them override this function. Improve the way gimp_operation_layer_mode_process() dispatches to the actual process function, to slightly lower its overhead and fix some thread-safety issues. Remove the "function" field of the layer-mode info array, and have gimp_layer_mode_get_function() return the GimpOperationLayerMode::process() function of the corresponding op's class (caching the result, to keep it cheap.) This reduces redundancy, allows us to make the ops' process() functions private, and simplifies SSE dispatching (only used by NORMAL mode, currently.) Move the blend and composite functions of the non-specialized layer modes to gimpoperationlayermode-{blend,composite}.[hc], respectively, to improve code organization. Move the SSE2 composite functions to a separate file, so that they can be built as part of libapplayermodes_sse2, allowing libapplayermodes to be built without SSE2 compiler flags. This allows building GIMP with SSE acceleration enabled, while running the resulting binary on a target with no SSE accelration. Add a "blend_function" field to the layer-mode info array, and use it to specify the blend function for the non-specialized modes. This replaces the separate switch() statement that we used previously. Remove the "affected_region" field of the layer-mode info array. We don't need it anymore, since we can go back to using GimpOperationLayerMode's virtual get_affected_region() function. Last but not least, a bunch of code cleanups and consistency adjustments.
2017-08-17 22:26:49 +08:00
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
GimpOperationLayerModeClass *layer_mode_class = GIMP_OPERATION_LAYER_MODE_CLASS (klass);
2012-03-30 02:22:22 +08:00
gegl_operation_class_set_keys (operation_class,
"name", "gimp:difference-legacy",
2012-04-21 06:46:48 +08:00
"description", "GIMP difference mode operation",
NULL);
app: layer mode code shuffling Commit 3635cf04ab69bafb76d7583da804f580f2d5fbf3 moved the special handling of bottom-layer compositing to GimpOperationLayerMode. This required giving the op more control over the process() function of its subclasses. As a temporary workaround, the commit bypassed the subclasses entirely, using "gimp:layer-mode" for all modes. This is the reckoning :) Add a process() virtual function to GimpOperationLayerMode, which its subclasses should override instead of GeglOperationPointComposer3's process() functions. Reinstate the subclasses (by returning the correct op in gimp_layer_mode_get_oepration()), and have them override this function. Improve the way gimp_operation_layer_mode_process() dispatches to the actual process function, to slightly lower its overhead and fix some thread-safety issues. Remove the "function" field of the layer-mode info array, and have gimp_layer_mode_get_function() return the GimpOperationLayerMode::process() function of the corresponding op's class (caching the result, to keep it cheap.) This reduces redundancy, allows us to make the ops' process() functions private, and simplifies SSE dispatching (only used by NORMAL mode, currently.) Move the blend and composite functions of the non-specialized layer modes to gimpoperationlayermode-{blend,composite}.[hc], respectively, to improve code organization. Move the SSE2 composite functions to a separate file, so that they can be built as part of libapplayermodes_sse2, allowing libapplayermodes to be built without SSE2 compiler flags. This allows building GIMP with SSE acceleration enabled, while running the resulting binary on a target with no SSE accelration. Add a "blend_function" field to the layer-mode info array, and use it to specify the blend function for the non-specialized modes. This replaces the separate switch() statement that we used previously. Remove the "affected_region" field of the layer-mode info array. We don't need it anymore, since we can go back to using GimpOperationLayerMode's virtual get_affected_region() function. Last but not least, a bunch of code cleanups and consistency adjustments.
2017-08-17 22:26:49 +08:00
layer_mode_class->process = gimp_operation_difference_legacy_process;
}
static void
gimp_operation_difference_legacy_init (GimpOperationDifferenceLegacy *self)
{
}
app: layer mode code shuffling Commit 3635cf04ab69bafb76d7583da804f580f2d5fbf3 moved the special handling of bottom-layer compositing to GimpOperationLayerMode. This required giving the op more control over the process() function of its subclasses. As a temporary workaround, the commit bypassed the subclasses entirely, using "gimp:layer-mode" for all modes. This is the reckoning :) Add a process() virtual function to GimpOperationLayerMode, which its subclasses should override instead of GeglOperationPointComposer3's process() functions. Reinstate the subclasses (by returning the correct op in gimp_layer_mode_get_oepration()), and have them override this function. Improve the way gimp_operation_layer_mode_process() dispatches to the actual process function, to slightly lower its overhead and fix some thread-safety issues. Remove the "function" field of the layer-mode info array, and have gimp_layer_mode_get_function() return the GimpOperationLayerMode::process() function of the corresponding op's class (caching the result, to keep it cheap.) This reduces redundancy, allows us to make the ops' process() functions private, and simplifies SSE dispatching (only used by NORMAL mode, currently.) Move the blend and composite functions of the non-specialized layer modes to gimpoperationlayermode-{blend,composite}.[hc], respectively, to improve code organization. Move the SSE2 composite functions to a separate file, so that they can be built as part of libapplayermodes_sse2, allowing libapplayermodes to be built without SSE2 compiler flags. This allows building GIMP with SSE acceleration enabled, while running the resulting binary on a target with no SSE accelration. Add a "blend_function" field to the layer-mode info array, and use it to specify the blend function for the non-specialized modes. This replaces the separate switch() statement that we used previously. Remove the "affected_region" field of the layer-mode info array. We don't need it anymore, since we can go back to using GimpOperationLayerMode's virtual get_affected_region() function. Last but not least, a bunch of code cleanups and consistency adjustments.
2017-08-17 22:26:49 +08:00
static gboolean
gimp_operation_difference_legacy_process (GeglOperation *op,
void *in_p,
void *layer_p,
void *mask_p,
void *out_p,
glong samples,
const GeglRectangle *roi,
gint level)
{
GimpOperationLayerMode *layer_mode = (gpointer) op;
gfloat *in = in_p;
gfloat *out = out_p;
gfloat *layer = layer_p;
gfloat *mask = mask_p;
gfloat opacity = layer_mode->opacity;
2012-06-01 03:06:31 +08:00
while (samples--)
{
2012-06-01 03:06:31 +08:00
gfloat comp_alpha, new_alpha;
2012-06-01 03:06:31 +08:00
comp_alpha = MIN (in[ALPHA], layer[ALPHA]) * opacity;
if (mask)
2012-06-01 03:06:31 +08:00
comp_alpha *= *mask;
new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
2012-06-01 03:06:31 +08:00
if (comp_alpha && new_alpha)
{
gfloat ratio = comp_alpha / new_alpha;
gint b;
2012-06-01 03:06:31 +08:00
for (b = RED; b < ALPHA; b++)
{
2012-06-01 03:06:31 +08:00
gfloat comp = in[b] - layer[b];
comp = (comp < 0.0f) ? -comp : comp;
out[b] = comp * ratio + in[b] * (1.0f - ratio);
}
}
2012-06-01 03:06:31 +08:00
else
{
2012-06-01 03:06:31 +08:00
gint b;
2012-06-01 03:06:31 +08:00
for (b = RED; b < ALPHA; b++)
{
2012-06-01 03:06:31 +08:00
out[b] = in[b];
}
2012-06-01 03:06:31 +08:00
}
2012-06-01 03:06:31 +08:00
out[ALPHA] = in[ALPHA];
2012-06-01 03:06:31 +08:00
in += 4;
layer += 4;
out += 4;
if (mask)
2012-06-01 03:06:31 +08:00
mask++;
}
return TRUE;
}