2000-06-01 14:59:22 +00:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimplayer.c
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2000-06-01 14:59:22 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-17 22:28:01 +00:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-06-01 14:59:22 +00:00
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-17 22:28:01 +00:00
|
|
|
* License along with this library. If not, see
|
2018-07-11 23:27:07 +02:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2000-06-01 14:59:22 +00:00
|
|
|
*/
|
|
|
|
|
2002-05-13 23:30:23 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-04-20 20:04:35 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-06-01 14:59:22 +00:00
|
|
|
#include "gimp.h"
|
2002-05-13 23:30:23 +00:00
|
|
|
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-08-27 16:47:17 +02:00
|
|
|
struct _GimpLayerPrivate
|
|
|
|
{
|
|
|
|
gpointer unused;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpLayer, gimp_layer, GIMP_TYPE_DRAWABLE)
|
2019-08-13 13:59:33 +02:00
|
|
|
|
|
|
|
#define parent_class gimp_layer_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_class_init (GimpLayerClass *klass)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_init (GimpLayer *layer)
|
|
|
|
{
|
2019-08-27 16:47:17 +02:00
|
|
|
layer->priv = gimp_layer_get_instance_private (layer);
|
2019-08-13 13:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Public API. */
|
|
|
|
|
2000-08-25 00:37:35 +00:00
|
|
|
/**
|
|
|
|
* gimp_layer_new:
|
2019-08-11 17:12:20 +02:00
|
|
|
* @image: The image to which to add the layer.
|
|
|
|
* @name: The layer name.
|
|
|
|
* @width: The layer width.
|
|
|
|
* @height: The layer height.
|
|
|
|
* @type: The layer type.
|
2000-08-25 00:37:35 +00:00
|
|
|
* @opacity: The layer opacity.
|
2019-08-11 17:12:20 +02:00
|
|
|
* @mode: The layer combination mode.
|
2000-08-25 00:37:35 +00:00
|
|
|
*
|
|
|
|
* Create a new layer.
|
|
|
|
*
|
|
|
|
* This procedure creates a new layer with the specified width, height,
|
|
|
|
* and type. Name, opacity, and mode are also supplied parameters. The
|
|
|
|
* new layer still needs to be added to the image, as this is not
|
2010-09-06 00:03:29 +02:00
|
|
|
* automatic. Add the new layer with the gimp_image_insert_layer()
|
2000-08-25 00:37:35 +00:00
|
|
|
* command. Other attributes such as layer mask modes, and offsets
|
|
|
|
* should be set with explicit procedure calls.
|
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: (transfer none): The newly created layer.
|
|
|
|
* The object belongs to libgimp and you should not free it.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2000-08-25 00:37:35 +00:00
|
|
|
*/
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *
|
2019-08-11 17:12:20 +02:00
|
|
|
gimp_layer_new (GimpImage *image,
|
2017-01-08 23:00:19 +01:00
|
|
|
const gchar *name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerMode mode)
|
2000-06-01 14:59:22 +00:00
|
|
|
{
|
2019-08-11 17:12:20 +02:00
|
|
|
return _gimp_layer_new (image,
|
2006-04-12 10:53:28 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
type,
|
|
|
|
name,
|
|
|
|
opacity,
|
|
|
|
mode);
|
2000-06-01 14:59:22 +00:00
|
|
|
}
|
|
|
|
|
2000-08-25 00:37:35 +00:00
|
|
|
/**
|
|
|
|
* gimp_layer_copy:
|
2019-08-13 16:16:08 +02:00
|
|
|
* @layer: The layer to copy.
|
2000-08-25 00:37:35 +00:00
|
|
|
*
|
|
|
|
* Copy a layer.
|
|
|
|
*
|
|
|
|
* This procedure copies the specified layer and returns the copy. The
|
|
|
|
* newly copied layer is for use within the original layer's image. It
|
2007-10-16 06:02:18 +00:00
|
|
|
* should not be subsequently added to any other image.
|
2000-08-25 00:37:35 +00:00
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: (transfer none): The newly copied layer.
|
|
|
|
* The object belongs to libgimp and you should not free it.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2000-08-25 00:37:35 +00:00
|
|
|
*/
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *
|
|
|
|
gimp_layer_copy (GimpLayer *layer)
|
2000-06-01 14:59:22 +00:00
|
|
|
{
|
2019-08-13 16:16:08 +02:00
|
|
|
return _gimp_layer_copy (layer, FALSE);
|
2000-06-01 14:59:22 +00:00
|
|
|
}
|
2005-07-10 21:17:22 +00:00
|
|
|
|
2011-04-20 20:04:35 +02:00
|
|
|
/**
|
|
|
|
* gimp_layer_new_from_pixbuf:
|
2019-08-11 17:12:20 +02:00
|
|
|
* @image: The RGB image to which to add the layer.
|
2011-04-20 20:04:35 +02:00
|
|
|
* @name: The layer name.
|
|
|
|
* @pixbuf: A GdkPixbuf.
|
|
|
|
* @opacity: The layer opacity.
|
|
|
|
* @mode: The layer combination mode.
|
|
|
|
* @progress_start: start of progress
|
|
|
|
* @progress_end: end of progress
|
|
|
|
*
|
|
|
|
* Create a new layer from a %GdkPixbuf.
|
|
|
|
*
|
|
|
|
* This procedure creates a new layer from the given %GdkPixbuf. The
|
|
|
|
* image has to be an RGB image and just like with gimp_layer_new()
|
|
|
|
* you will still need to add the layer to it.
|
|
|
|
*
|
|
|
|
* If you pass @progress_end > @progress_start to this function,
|
|
|
|
* gimp_progress_update() will be called for. You have to call
|
|
|
|
* gimp_progress_init() beforehand then.
|
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: (transfer none): The newly created layer.
|
|
|
|
* The object belongs to libgimp and you should not free it.
|
2011-04-20 20:04:35 +02:00
|
|
|
*
|
2019-08-30 18:44:56 +02:00
|
|
|
* Since: 2.2
|
2011-04-20 20:04:35 +02:00
|
|
|
*/
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *
|
2019-08-11 17:12:20 +02:00
|
|
|
gimp_layer_new_from_pixbuf (GimpImage *image,
|
2017-01-08 23:00:19 +01:00
|
|
|
const gchar *name,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerMode mode,
|
|
|
|
gdouble progress_start,
|
|
|
|
gdouble progress_end)
|
2011-04-20 20:04:35 +02:00
|
|
|
{
|
2019-07-19 19:08:31 +02:00
|
|
|
GeglBuffer *dest_buffer;
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *layer;
|
2019-07-19 19:08:31 +02:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bpp;
|
|
|
|
gdouble range = progress_end - progress_start;
|
2011-04-20 20:04:35 +02:00
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
2011-04-20 20:04:35 +02:00
|
|
|
|
2019-08-11 17:12:20 +02:00
|
|
|
if (gimp_image_base_type (image) != GIMP_RGB)
|
2011-04-20 20:04:35 +02:00
|
|
|
{
|
|
|
|
g_warning ("gimp_layer_new_from_pixbuf() needs an RGB image");
|
2019-08-13 16:16:08 +02:00
|
|
|
return NULL;
|
2011-04-20 20:04:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB)
|
|
|
|
{
|
|
|
|
g_warning ("gimp_layer_new_from_pixbuf() assumes that GdkPixbuf is RGB");
|
2019-08-13 16:16:08 +02:00
|
|
|
return NULL;
|
2011-04-20 20:04:35 +02:00
|
|
|
}
|
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
bpp = gdk_pixbuf_get_n_channels (pixbuf);
|
2011-04-20 20:04:35 +02:00
|
|
|
|
2019-08-11 17:12:20 +02:00
|
|
|
layer = gimp_layer_new (image, name, width, height,
|
2011-04-20 20:04:35 +02:00
|
|
|
bpp == 3 ? GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
|
|
|
|
opacity, mode);
|
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
2011-04-20 20:04:35 +02:00
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
dest_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
2012-05-03 03:48:49 +02:00
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
|
|
|
|
gimp_pixbuf_get_format (pixbuf),
|
|
|
|
gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf));
|
2011-04-20 20:04:35 +02:00
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
g_object_unref (dest_buffer);
|
2011-04-20 23:58:00 +02:00
|
|
|
|
|
|
|
if (range > 0.0)
|
|
|
|
gimp_progress_update (progress_end);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_layer_new_from_surface:
|
2019-08-11 17:12:20 +02:00
|
|
|
* @image: The RGB image to which to add the layer.
|
2011-04-20 23:58:00 +02:00
|
|
|
* @name: The layer name.
|
2011-04-27 20:35:56 +05:30
|
|
|
* @surface: A Cairo image surface.
|
2011-04-20 23:58:00 +02:00
|
|
|
* @progress_start: start of progress
|
|
|
|
* @progress_end: end of progress
|
|
|
|
*
|
|
|
|
* Create a new layer from a #cairo_surface_t.
|
|
|
|
*
|
|
|
|
* This procedure creates a new layer from the given
|
|
|
|
* #cairo_surface_t. The image has to be an RGB image and just like
|
|
|
|
* with gimp_layer_new() you will still need to add the layer to it.
|
|
|
|
*
|
|
|
|
* If you pass @progress_end > @progress_start to this function,
|
|
|
|
* gimp_progress_update() will be called for. You have to call
|
|
|
|
* gimp_progress_init() beforehand then.
|
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: (transfer none): The newly created layer.
|
|
|
|
* The object belongs to libgimp and you should not free it.
|
2011-04-20 23:58:00 +02:00
|
|
|
*
|
2019-08-30 18:44:56 +02:00
|
|
|
* Since: 2.8
|
2011-04-20 23:58:00 +02:00
|
|
|
*/
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *
|
2019-08-30 18:44:56 +02:00
|
|
|
gimp_layer_new_from_surface (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
gdouble progress_start,
|
|
|
|
gdouble progress_end)
|
2011-04-20 23:58:00 +02:00
|
|
|
{
|
2019-07-19 19:08:31 +02:00
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
GeglBuffer *dest_buffer;
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *layer;
|
2012-05-03 04:13:39 +02:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
cairo_format_t format;
|
|
|
|
gdouble range = progress_end - progress_start;
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
g_return_val_if_fail (surface != NULL, NULL);
|
2011-04-20 23:58:00 +02:00
|
|
|
g_return_val_if_fail (cairo_surface_get_type (surface) ==
|
2019-08-13 16:16:08 +02:00
|
|
|
CAIRO_SURFACE_TYPE_IMAGE, NULL);
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-08-11 17:12:20 +02:00
|
|
|
if (gimp_image_base_type (image) != GIMP_RGB)
|
2011-04-20 23:58:00 +02:00
|
|
|
{
|
|
|
|
g_warning ("gimp_layer_new_from_surface() needs an RGB image");
|
2019-08-13 16:16:08 +02:00
|
|
|
return NULL;
|
2011-04-20 23:58:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
width = cairo_image_surface_get_width (surface);
|
|
|
|
height = cairo_image_surface_get_height (surface);
|
|
|
|
format = cairo_image_surface_get_format (surface);
|
|
|
|
|
|
|
|
if (format != CAIRO_FORMAT_ARGB32 &&
|
|
|
|
format != CAIRO_FORMAT_RGB24)
|
|
|
|
{
|
|
|
|
g_warning ("gimp_layer_new_from_surface() assumes that surface is RGB");
|
2019-08-13 16:16:08 +02:00
|
|
|
return NULL;
|
2011-04-20 23:58:00 +02:00
|
|
|
}
|
|
|
|
|
2019-08-11 17:12:20 +02:00
|
|
|
layer = gimp_layer_new (image, name, width, height,
|
2011-04-20 23:58:00 +02:00
|
|
|
format == CAIRO_FORMAT_RGB24 ?
|
|
|
|
GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
|
2018-04-24 13:55:50 +02:00
|
|
|
100.0,
|
2019-08-11 17:12:20 +02:00
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
if (layer == NULL)
|
|
|
|
return NULL;
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
src_buffer = gimp_cairo_surface_create_buffer (surface);
|
2019-08-13 16:16:08 +02:00
|
|
|
dest_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
2011-04-20 23:58:00 +02:00
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE,
|
|
|
|
dest_buffer, NULL);
|
2012-05-03 04:13:39 +02:00
|
|
|
|
2019-07-19 19:08:31 +02:00
|
|
|
g_object_unref (src_buffer);
|
|
|
|
g_object_unref (dest_buffer);
|
2011-04-20 20:04:35 +02:00
|
|
|
|
|
|
|
if (range > 0.0)
|
|
|
|
gimp_progress_update (progress_end);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
2019-08-13 00:42:10 +02:00
|
|
|
|
|
|
|
|
2019-08-30 18:44:56 +02:00
|
|
|
/* Deprecate API. */
|
2019-08-13 00:42:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_layer_new_deprecated: (skip)
|
|
|
|
* @image_id: The image to which to add the layer.
|
|
|
|
* @name: The layer name.
|
|
|
|
* @width: The layer width.
|
|
|
|
* @height: The layer height.
|
|
|
|
* @type: The layer type.
|
|
|
|
* @opacity: The layer opacity.
|
|
|
|
* @mode: The layer combination mode.
|
|
|
|
*
|
|
|
|
* Create a new layer.
|
|
|
|
*
|
|
|
|
* This procedure creates a new layer with the specified width, height,
|
|
|
|
* and type. Name, opacity, and mode are also supplied parameters. The
|
|
|
|
* new layer still needs to be added to the image, as this is not
|
|
|
|
* automatic. Add the new layer with the gimp_image_insert_layer()
|
|
|
|
* command. Other attributes such as layer mask modes, and offsets
|
|
|
|
* should be set with explicit procedure calls.
|
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: The newly created layer ID.
|
2019-08-13 00:42:10 +02:00
|
|
|
*/
|
|
|
|
gint32
|
|
|
|
gimp_layer_new_deprecated (gint32 image_id,
|
|
|
|
const gchar *name,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerMode mode)
|
|
|
|
{
|
2019-08-13 16:16:08 +02:00
|
|
|
GimpLayer *layer;
|
2019-08-13 00:42:10 +02:00
|
|
|
|
2019-08-15 10:01:08 +02:00
|
|
|
layer = gimp_layer_new (gimp_image_get_by_id (image_id),
|
|
|
|
name, width, height,
|
2019-08-13 16:16:08 +02:00
|
|
|
type, opacity, mode);
|
2019-08-13 00:42:10 +02:00
|
|
|
|
2019-08-15 12:12:25 +02:00
|
|
|
return gimp_item_get_id (GIMP_ITEM (layer));
|
2019-08-13 00:42:10 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 16:16:08 +02:00
|
|
|
/**
|
|
|
|
* gimp_layer_copy_deprecated: (skip)
|
|
|
|
* @layer_ID: The layer to copy.
|
|
|
|
*
|
|
|
|
* Copy a layer.
|
|
|
|
*
|
|
|
|
* This procedure copies the specified layer and returns the copy. The
|
|
|
|
* newly copied layer is for use within the original layer's image. It
|
|
|
|
* should not be subsequently added to any other image.
|
|
|
|
*
|
2019-08-15 12:12:25 +02:00
|
|
|
* Returns: The newly copied layer ID.
|
2019-08-13 16:16:08 +02:00
|
|
|
*/
|
|
|
|
gint32
|
|
|
|
gimp_layer_copy_deprecated (gint32 layer_ID)
|
|
|
|
{
|
|
|
|
GimpLayer *copy;
|
|
|
|
|
2019-08-15 12:12:25 +02:00
|
|
|
copy = gimp_layer_copy (GIMP_LAYER (gimp_item_get_by_id (layer_ID)));
|
2019-08-13 16:16:08 +02:00
|
|
|
|
2019-08-15 12:12:25 +02:00
|
|
|
return gimp_item_get_id (GIMP_ITEM (copy));
|
2019-08-13 16:16:08 +02:00
|
|
|
}
|