2012-03-16 12:49:34 +01:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp-gegl-nodes.h
|
|
|
|
* Copyright (C) 2012 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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2012-03-16 12:49:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "gimp-gegl-types.h"
|
|
|
|
|
2017-02-05 15:59:29 +01:00
|
|
|
#include "operations/layer-modes/gimp-layer-modes.h"
|
2017-01-15 15:23:57 +01:00
|
|
|
|
2012-03-16 12:49:34 +01:00
|
|
|
#include "gimp-gegl-nodes.h"
|
|
|
|
#include "gimp-gegl-utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
GeglNode *
|
2023-12-22 15:47:36 +09:00
|
|
|
gimp_gegl_create_flatten_node (GeglColor *background,
|
2017-10-21 11:21:10 -04:00
|
|
|
GimpLayerColorSpace composite_space)
|
2012-03-16 12:49:34 +01:00
|
|
|
{
|
|
|
|
GeglNode *node;
|
|
|
|
GeglNode *input;
|
|
|
|
GeglNode *output;
|
|
|
|
GeglNode *color;
|
2017-10-21 11:32:07 -04:00
|
|
|
GeglNode *mode;
|
2012-03-16 12:49:34 +01:00
|
|
|
|
2023-12-22 15:47:36 +09:00
|
|
|
g_return_val_if_fail (GEGL_IS_COLOR (background), NULL);
|
2017-10-21 11:21:10 -04:00
|
|
|
g_return_val_if_fail (composite_space == GIMP_LAYER_COLOR_SPACE_RGB_LINEAR ||
|
2024-11-30 02:06:53 +01:00
|
|
|
composite_space == GIMP_LAYER_COLOR_SPACE_RGB_NON_LINEAR ||
|
2017-10-21 11:21:10 -04:00
|
|
|
composite_space == GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL,
|
|
|
|
NULL);
|
2012-03-16 12:49:34 +01:00
|
|
|
|
|
|
|
node = gegl_node_new ();
|
|
|
|
|
|
|
|
input = gegl_node_get_input_proxy (node, "input");
|
|
|
|
output = gegl_node_get_output_proxy (node, "output");
|
|
|
|
|
|
|
|
color = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:color",
|
2023-12-22 15:47:36 +09:00
|
|
|
"value", background,
|
2019-02-25 11:10:17 -05:00
|
|
|
"format", gimp_layer_mode_get_format (
|
|
|
|
GIMP_LAYER_MODE_NORMAL,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
2019-05-24 01:33:53 -04:00
|
|
|
composite_space,
|
|
|
|
GIMP_LAYER_COMPOSITE_AUTO,
|
2019-02-25 11:10:17 -05:00
|
|
|
NULL),
|
2012-03-16 12:49:34 +01:00
|
|
|
NULL);
|
|
|
|
|
2019-04-30 14:27:19 -04:00
|
|
|
gimp_gegl_node_set_underlying_operation (node, color);
|
|
|
|
|
2017-10-21 11:32:07 -04:00
|
|
|
mode = gegl_node_new_child (node,
|
|
|
|
"operation", "gimp:normal",
|
2012-03-16 12:49:34 +01:00
|
|
|
NULL);
|
2017-10-21 11:32:07 -04:00
|
|
|
gimp_gegl_mode_node_set_mode (mode,
|
|
|
|
GIMP_LAYER_MODE_NORMAL,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
composite_space,
|
|
|
|
GIMP_LAYER_COMPOSITE_AUTO);
|
2012-03-16 12:49:34 +01:00
|
|
|
|
2023-06-13 19:58:42 +02:00
|
|
|
gegl_node_connect (input, "output",
|
|
|
|
mode, "aux");
|
2023-06-13 17:05:02 +02:00
|
|
|
gegl_node_link_many (color, mode, output, NULL);
|
2012-03-16 12:49:34 +01:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
2012-03-16 17:29:28 +01:00
|
|
|
|
|
|
|
GeglNode *
|
|
|
|
gimp_gegl_create_apply_opacity_node (GeglBuffer *mask,
|
2012-03-19 02:30:18 +01:00
|
|
|
gint mask_offset_x,
|
2012-03-24 15:22:49 +01:00
|
|
|
gint mask_offset_y,
|
|
|
|
gdouble opacity)
|
2012-03-16 17:29:28 +01:00
|
|
|
{
|
|
|
|
GeglNode *node;
|
|
|
|
GeglNode *input;
|
|
|
|
GeglNode *output;
|
|
|
|
GeglNode *opacity_node;
|
|
|
|
GeglNode *mask_source;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GEGL_IS_BUFFER (mask), NULL);
|
|
|
|
|
|
|
|
node = gegl_node_new ();
|
|
|
|
|
|
|
|
input = gegl_node_get_input_proxy (node, "input");
|
|
|
|
output = gegl_node_get_output_proxy (node, "output");
|
|
|
|
|
|
|
|
opacity_node = gegl_node_new_child (node,
|
|
|
|
"operation", "gegl:opacity",
|
|
|
|
"value", opacity,
|
|
|
|
NULL);
|
2012-03-24 14:54:36 +01:00
|
|
|
|
2019-04-30 14:27:19 -04:00
|
|
|
gimp_gegl_node_set_underlying_operation (node, opacity_node);
|
|
|
|
|
2012-03-24 14:54:36 +01:00
|
|
|
mask_source = gimp_gegl_add_buffer_source (node, mask,
|
2012-03-24 15:22:49 +01:00
|
|
|
mask_offset_x,
|
|
|
|
mask_offset_y);
|
2012-03-16 17:29:28 +01:00
|
|
|
|
2023-06-13 17:05:02 +02:00
|
|
|
gegl_node_link_many (input, opacity_node, output, NULL);
|
2023-06-13 19:58:42 +02:00
|
|
|
gegl_node_connect (mask_source, "output",
|
|
|
|
opacity_node, "aux");
|
2012-03-24 14:54:36 +01:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2019-05-29 04:37:29 -04:00
|
|
|
GeglNode *
|
|
|
|
gimp_gegl_create_transform_node (const GimpMatrix3 *matrix)
|
|
|
|
{
|
|
|
|
GeglNode *node;
|
|
|
|
|
|
|
|
g_return_val_if_fail (matrix != NULL, NULL);
|
|
|
|
|
|
|
|
node = gegl_node_new_child (NULL,
|
|
|
|
"operation", "gegl:transform",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_gegl_node_set_matrix (node, matrix);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2012-03-24 14:54:36 +01:00
|
|
|
GeglNode *
|
|
|
|
gimp_gegl_add_buffer_source (GeglNode *parent,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
|
|
|
{
|
|
|
|
GeglNode *buffer_source;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GEGL_IS_NODE (parent), NULL);
|
|
|
|
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
|
|
|
|
|
|
|
|
buffer_source = gegl_node_new_child (parent,
|
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", buffer,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (offset_x != 0 || offset_y != 0)
|
|
|
|
{
|
|
|
|
GeglNode *translate =
|
|
|
|
gegl_node_new_child (parent,
|
|
|
|
"operation", "gegl:translate",
|
|
|
|
"x", (gdouble) offset_x,
|
|
|
|
"y", (gdouble) offset_y,
|
|
|
|
NULL);
|
|
|
|
|
2023-06-13 17:05:02 +02:00
|
|
|
gegl_node_link (buffer_source, translate);
|
2012-03-24 14:54:36 +01:00
|
|
|
|
|
|
|
buffer_source = translate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer_source;
|
|
|
|
}
|
2012-03-24 18:28:05 +01:00
|
|
|
|
|
|
|
void
|
2017-02-02 00:38:25 +01:00
|
|
|
gimp_gegl_mode_node_set_mode (GeglNode *node,
|
|
|
|
GimpLayerMode mode,
|
2017-02-12 23:49:26 +01:00
|
|
|
GimpLayerColorSpace blend_space,
|
|
|
|
GimpLayerColorSpace composite_space,
|
|
|
|
GimpLayerCompositeMode composite_mode)
|
2012-03-24 18:28:05 +01:00
|
|
|
{
|
2017-01-15 15:23:57 +01:00
|
|
|
gdouble opacity;
|
2012-03-24 18:28:05 +01:00
|
|
|
|
|
|
|
g_return_if_fail (GEGL_IS_NODE (node));
|
|
|
|
|
2017-02-12 23:49:26 +01:00
|
|
|
if (blend_space == GIMP_LAYER_COLOR_SPACE_AUTO)
|
|
|
|
blend_space = gimp_layer_mode_get_blend_space (mode);
|
|
|
|
|
|
|
|
if (composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
|
|
|
|
composite_space = gimp_layer_mode_get_composite_space (mode);
|
|
|
|
|
|
|
|
if (composite_mode == GIMP_LAYER_COMPOSITE_AUTO)
|
|
|
|
composite_mode = gimp_layer_mode_get_composite_mode (mode);
|
2017-02-02 00:38:25 +01:00
|
|
|
|
2013-06-12 22:13:01 +02:00
|
|
|
gegl_node_get (node,
|
|
|
|
"opacity", &opacity,
|
|
|
|
NULL);
|
|
|
|
|
2013-10-19 17:31:32 +02:00
|
|
|
/* setting the operation creates a new instance, so we have to set
|
|
|
|
* all its properties
|
|
|
|
*/
|
2012-03-24 18:28:05 +01:00
|
|
|
gegl_node_set (node,
|
2020-11-10 00:43:08 +01:00
|
|
|
"operation", gimp_layer_mode_get_operation_name (mode),
|
2017-01-22 17:14:44 +01:00
|
|
|
"layer-mode", mode,
|
|
|
|
"opacity", opacity,
|
2017-02-12 23:49:26 +01:00
|
|
|
"blend-space", blend_space,
|
|
|
|
"composite-space", composite_space,
|
|
|
|
"composite-mode", composite_mode,
|
2017-01-11 22:13:14 +01:00
|
|
|
NULL);
|
2012-03-24 18:28:05 +01:00
|
|
|
}
|
2012-03-31 16:18:13 +02:00
|
|
|
|
2013-04-27 08:23:58 +02:00
|
|
|
void
|
2013-04-22 22:53:07 +02:00
|
|
|
gimp_gegl_mode_node_set_opacity (GeglNode *node,
|
|
|
|
gdouble opacity)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GEGL_IS_NODE (node));
|
|
|
|
|
|
|
|
gegl_node_set (node,
|
|
|
|
"opacity", opacity,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2012-03-31 16:18:13 +02:00
|
|
|
void
|
|
|
|
gimp_gegl_node_set_matrix (GeglNode *node,
|
|
|
|
const GimpMatrix3 *matrix)
|
|
|
|
{
|
|
|
|
gchar *matrix_string;
|
|
|
|
|
|
|
|
g_return_if_fail (GEGL_IS_NODE (node));
|
|
|
|
g_return_if_fail (matrix != NULL);
|
|
|
|
|
|
|
|
matrix_string = gegl_matrix3_to_string ((GeglMatrix3 *) matrix);
|
|
|
|
|
|
|
|
gegl_node_set (node,
|
|
|
|
"transform", matrix_string,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (matrix_string);
|
|
|
|
}
|
2013-10-19 17:31:32 +02:00
|
|
|
|
|
|
|
void
|
2023-11-20 00:20:03 +01:00
|
|
|
gimp_gegl_node_set_color (GeglNode *node,
|
|
|
|
GeglColor *color)
|
2013-10-19 17:31:32 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (GEGL_IS_NODE (node));
|
2023-11-20 00:20:03 +01:00
|
|
|
g_return_if_fail (GEGL_IS_COLOR (color));
|
2013-10-19 17:31:32 +02:00
|
|
|
|
|
|
|
gegl_node_set (node,
|
2023-11-20 00:20:03 +01:00
|
|
|
"value", color,
|
2013-10-19 17:31:32 +02:00
|
|
|
NULL);
|
|
|
|
}
|