app: add a flatten meta-op and use it for layers and channels
This commit is contained in:
@ -37,6 +37,8 @@
|
||||
#include "paint/gimppaintcore-stroke.h"
|
||||
#include "paint/gimppaintoptions.h"
|
||||
|
||||
#include "gegl/gimp-gegl-nodes.h"
|
||||
|
||||
#include "gimp.h"
|
||||
#include "gimp-utils.h"
|
||||
#include "gimpcontainer.h"
|
||||
@ -456,27 +458,21 @@ gimp_channel_convert (GimpItem *item,
|
||||
|
||||
if (gimp_drawable_has_alpha (drawable))
|
||||
{
|
||||
GeglNode *flatten;
|
||||
TileManager *new_tiles;
|
||||
PixelRegion srcPR;
|
||||
PixelRegion destPR;
|
||||
guchar bg[1] = { 0 };
|
||||
GimpRGB background;
|
||||
|
||||
new_tiles = tile_manager_new (gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
GIMP_IMAGE_TYPE_BYTES (GIMP_GRAY_IMAGE));
|
||||
|
||||
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
|
||||
0, 0,
|
||||
gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
FALSE);
|
||||
pixel_region_init (&destPR, new_tiles,
|
||||
0, 0,
|
||||
gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
TRUE);
|
||||
gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
|
||||
flatten = gimp_gegl_create_flatten_node (&background);
|
||||
|
||||
flatten_region (&srcPR, &destPR, bg);
|
||||
gimp_drawable_apply_operation_to_tiles (drawable, NULL, NULL,
|
||||
flatten, TRUE, new_tiles);
|
||||
|
||||
g_object_unref (flatten);
|
||||
|
||||
gimp_drawable_set_tiles_full (drawable, FALSE, NULL,
|
||||
new_tiles, GIMP_GRAY_IMAGE,
|
||||
|
@ -34,12 +34,14 @@
|
||||
|
||||
#include "paint-funcs/paint-funcs.h"
|
||||
|
||||
#include "gegl/gimp-gegl-nodes.h"
|
||||
#include "gegl/gimp-gegl-utils.h"
|
||||
|
||||
#include "gimpchannel-select.h"
|
||||
#include "gimpcontext.h"
|
||||
#include "gimpcontainer.h"
|
||||
#include "gimpdrawable-convert.h"
|
||||
#include "gimpdrawable-operation.h"
|
||||
#include "gimperror.h"
|
||||
#include "gimpimage-undo-push.h"
|
||||
#include "gimpimage-undo.h"
|
||||
@ -1914,12 +1916,10 @@ void
|
||||
gimp_layer_flatten (GimpLayer *layer,
|
||||
GimpContext *context)
|
||||
{
|
||||
GimpItem *item;
|
||||
GimpDrawable *drawable;
|
||||
PixelRegion srcPR, destPR;
|
||||
GeglNode *flatten;
|
||||
TileManager *new_tiles;
|
||||
GimpImageType new_type;
|
||||
guchar bg[4];
|
||||
GimpRGB background;
|
||||
|
||||
g_return_if_fail (GIMP_IS_LAYER (layer));
|
||||
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
||||
@ -1927,36 +1927,20 @@ gimp_layer_flatten (GimpLayer *layer,
|
||||
if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
|
||||
return;
|
||||
|
||||
item = GIMP_ITEM (layer);
|
||||
drawable = GIMP_DRAWABLE (layer);
|
||||
new_type = gimp_drawable_type_without_alpha (GIMP_DRAWABLE (layer));
|
||||
|
||||
new_type = gimp_drawable_type_without_alpha (drawable);
|
||||
|
||||
gimp_image_get_background (gimp_item_get_image (item), context,
|
||||
gimp_drawable_type (drawable),
|
||||
bg);
|
||||
|
||||
/* Allocate the new tiles */
|
||||
new_tiles = tile_manager_new (gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
new_tiles = tile_manager_new (gimp_item_get_width (GIMP_ITEM (layer)),
|
||||
gimp_item_get_height (GIMP_ITEM (layer)),
|
||||
GIMP_IMAGE_TYPE_BYTES (new_type));
|
||||
|
||||
/* Configure the pixel regions */
|
||||
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
|
||||
0, 0,
|
||||
gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
FALSE);
|
||||
pixel_region_init (&destPR, new_tiles,
|
||||
0, 0,
|
||||
gimp_item_get_width (item),
|
||||
gimp_item_get_height (item),
|
||||
TRUE);
|
||||
gimp_context_get_background (context, &background);
|
||||
flatten = gimp_gegl_create_flatten_node (&background);
|
||||
|
||||
/* Remove alpha channel */
|
||||
flatten_region (&srcPR, &destPR, bg);
|
||||
gimp_drawable_apply_operation_to_tiles (GIMP_DRAWABLE (layer), NULL, NULL,
|
||||
flatten, TRUE, new_tiles);
|
||||
|
||||
g_object_unref (flatten);
|
||||
|
||||
/* Set the new tiles */
|
||||
gimp_drawable_set_tiles (GIMP_DRAWABLE (layer),
|
||||
gimp_item_is_attached (GIMP_ITEM (layer)),
|
||||
C_("undo-type", "Remove Alpha Channel"),
|
||||
|
@ -20,6 +20,8 @@ libappgegl_a_sources = \
|
||||
gimp-gegl-types.h \
|
||||
gimp-gegl.c \
|
||||
gimp-gegl.h \
|
||||
gimp-gegl-nodes.c \
|
||||
gimp-gegl-nodes.h \
|
||||
gimp-gegl-utils.c \
|
||||
gimp-gegl-utils.h \
|
||||
gimptilebackendtilemanager.c \
|
||||
|
69
app/gegl/gimp-gegl-nodes.c
Normal file
69
app/gegl/gimp-gegl-nodes.c
Normal file
@ -0,0 +1,69 @@
|
||||
/* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gegl.h>
|
||||
|
||||
#include "gimp-gegl-types.h"
|
||||
|
||||
#include "gimp-gegl-nodes.h"
|
||||
#include "gimp-gegl-utils.h"
|
||||
|
||||
|
||||
GeglNode *
|
||||
gimp_gegl_create_flatten_node (const GimpRGB *background)
|
||||
{
|
||||
GeglNode *node;
|
||||
GeglNode *input;
|
||||
GeglNode *output;
|
||||
GeglNode *color;
|
||||
GeglNode *over;
|
||||
GeglColor *c;
|
||||
|
||||
g_return_val_if_fail (background != NULL, NULL);
|
||||
|
||||
node = gegl_node_new ();
|
||||
|
||||
input = gegl_node_get_input_proxy (node, "input");
|
||||
output = gegl_node_get_output_proxy (node, "output");
|
||||
|
||||
c = gegl_color_new (NULL);
|
||||
gimp_gegl_color_set_rgba (c, background);
|
||||
|
||||
color = gegl_node_new_child (node,
|
||||
"operation", "gegl:color",
|
||||
"value", c,
|
||||
NULL);
|
||||
g_object_unref (c);
|
||||
|
||||
over = gegl_node_new_child (node,
|
||||
"operation", "gegl:over",
|
||||
NULL);
|
||||
|
||||
gegl_node_connect_to (input, "output",
|
||||
over, "aux");
|
||||
gegl_node_connect_to (color, "output",
|
||||
over, "input");
|
||||
gegl_node_connect_to (over, "output",
|
||||
output, "input");
|
||||
|
||||
return node;
|
||||
}
|
28
app/gegl/gimp-gegl-nodes.h
Normal file
28
app/gegl/gimp-gegl-nodes.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_GEGL_NODES_H__
|
||||
#define __GIMP_GEGL_NODES_H__
|
||||
|
||||
|
||||
GeglNode * gimp_gegl_create_flatten_node (const GimpRGB *background);
|
||||
|
||||
|
||||
#endif /* __GIMP_GEGL_NODES_H__ */
|
@ -178,3 +178,13 @@ gimp_gegl_buffer_refetch_tiles (GeglBuffer *buffer)
|
||||
|
||||
gegl_tile_source_reinit (GEGL_TILE_SOURCE (buffer));
|
||||
}
|
||||
|
||||
void
|
||||
gimp_gegl_color_set_rgba (GeglColor *color,
|
||||
const GimpRGB *rgb)
|
||||
{
|
||||
g_return_if_fail (GEGL_IS_COLOR (color));
|
||||
g_return_if_fail (rgb != NULL);
|
||||
|
||||
gegl_color_set_rgba (color, rgb->r, rgb->g, rgb->b, rgb->a);
|
||||
}
|
||||
|
@ -35,5 +35,8 @@ GeglBuffer * gimp_tile_manager_create_buffer (TileManager *tm,
|
||||
|
||||
void gimp_gegl_buffer_refetch_tiles (GeglBuffer *buffer);
|
||||
|
||||
void gimp_gegl_color_set_rgba (GeglColor *color,
|
||||
const GimpRGB *rgb);
|
||||
|
||||
|
||||
#endif /* __GIMP_GEGL_UTILS_H__ */
|
||||
|
Reference in New Issue
Block a user