Commit db09d0f3 authored by Michael Natterer's avatar Michael Natterer 😴

app: move functions to create layers to new files gimplayer-new.[ch]

parent fd86deb9
......@@ -32,6 +32,7 @@
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "core/gimppickable.h"
#include "core/gimpprojectable.h"
#include "core/gimpprojection.h"
......
......@@ -33,6 +33,7 @@
#include "core/gimpcontainer.h"
#include "core/gimpdrawable.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "core/gimpimage.h"
#include "core/gimpimage-new.h"
#include "core/gimpimage-undo.h"
......
......@@ -40,6 +40,7 @@
#include "core/gimpimage-undo-push.h"
#include "core/gimpitemundo.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimplayer-new.h"
#include "core/gimppickable.h"
#include "core/gimppickable-auto-shrink.h"
#include "core/gimptoolinfo.h"
......
......@@ -284,6 +284,8 @@ libappcore_a_sources = \
gimplayer.h \
gimplayer-floating-sel.c \
gimplayer-floating-sel.h \
gimplayer-new.c \
gimplayer-new.h \
gimplayermask.c \
gimplayermask.h \
gimplayermaskpropundo.c \
......
......@@ -41,6 +41,7 @@
#include "gimpimage-undo.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
#include "gimplayer-new.h"
#include "gimplist.h"
#include "gimppattern.h"
#include "gimppickable.h"
......
......@@ -751,6 +751,7 @@ gimp_file_is_executable (GFile *file)
#include "gegl/gimp-babl.h"
#include "gimpimage.h"
#include "gimplayer.h"
#include "gimplayer-new.h"
void
gimp_create_image_from_buffer (Gimp *gimp,
......
......@@ -43,6 +43,7 @@
#include "gimpimage-undo-push.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
#include "gimplayer-new.h"
#include "gimppickable.h"
#include "gimpprogress.h"
#include "gimpselection.h"
......
......@@ -43,6 +43,7 @@
#include "gimpimage-undo.h"
#include "gimpitemstack.h"
#include "gimplayer-floating-sel.h"
#include "gimplayer-new.h"
#include "gimplayermask.h"
#include "gimpmarshal.h"
#include "gimpparasitelist.h"
......
......@@ -41,6 +41,7 @@
#include "gimpimage-profile.h"
#include "gimpimage-undo.h"
#include "gimplayer.h"
#include "gimplayer-new.h"
#include "gimptemplate.h"
#include "gimp-intl.h"
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimpimage.h"
#include "gimplayer.h"
#include "gimplayer-new.h"
GimpLayer *
gimp_layer_new (GimpImage *image,
gint width,
gint height,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GimpLayer *layer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (format != NULL, NULL);
layer = GIMP_LAYER (gimp_drawable_new (GIMP_TYPE_LAYER,
image, name,
0, 0, width, height,
format));
opacity = CLAMP (opacity, GIMP_OPACITY_TRANSPARENT, GIMP_OPACITY_OPAQUE);
layer->opacity = opacity;
layer->mode = mode;
return layer;
}
/**
* gimp_layer_new_from_buffer:
* @buffer: The buffer to make the new layer from.
* @dest_image: The image the new layer will be added to.
* @format: The #Babl format of the new layer.
* @name: The new layer's name.
* @opacity: The new layer's opacity.
* @mode: The new layer's mode.
*
* Copies %buffer to a layer taking into consideration the
* possibility of transforming the contents to meet the requirements
* of the target image type
*
* Return value: The new layer.
**/
GimpLayer *
gimp_layer_new_from_buffer (GeglBuffer *buffer,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GimpLayer *layer;
GeglBuffer *dest;
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
g_return_val_if_fail (format != NULL, NULL);
/* do *not* use the buffer's format because this function gets
* buffers of any format passed, and converts them
*/
layer = gimp_layer_new (dest_image,
gegl_buffer_get_width (buffer),
gegl_buffer_get_height (buffer),
format,
name, opacity, mode);
dest = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_copy (buffer, NULL, GEGL_ABYSS_NONE, dest, NULL);
return layer;
}
/**
* gimp_layer_new_from_pixbuf:
* @pixbuf: The pixbuf to make the new layer from.
* @dest_image: The image the new layer will be added to.
* @format: The #Babl format of the new layer.
* @name: The new layer's name.
* @opacity: The new layer's opacity.
* @mode: The new layer's mode.
*
* Copies %pixbuf to a layer taking into consideration the
* possibility of transforming the contents to meet the requirements
* of the target image type
*
* Return value: The new layer.
**/
GimpLayer *
gimp_layer_new_from_pixbuf (GdkPixbuf *pixbuf,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GeglBuffer *buffer;
GimpLayer *layer;
gint width;
gint height;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
g_return_val_if_fail (format != NULL, NULL);
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
layer = gimp_layer_new (dest_image, width, height,
format, name, opacity, mode);
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
gimp_pixbuf_get_format (pixbuf),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf));
return layer;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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_LAYER_NEW_H__
#define __GIMP_LAYER_NEW_H__
GimpLayer * gimp_layer_new (GimpImage *image,
gint width,
gint height,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_new_from_buffer (GeglBuffer *buffer,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_new_from_pixbuf (GdkPixbuf *pixbuf,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
#endif /* __GIMP_LAYER_NEW_H__ */
......@@ -1191,128 +1191,6 @@ gimp_layer_layer_mask_update (GimpDrawable *drawable,
/* public functions */
GimpLayer *
gimp_layer_new (GimpImage *image,
gint width,
gint height,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GimpLayer *layer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (format != NULL, NULL);
layer = GIMP_LAYER (gimp_drawable_new (GIMP_TYPE_LAYER,
image, name,
0, 0, width, height,
format));
opacity = CLAMP (opacity, GIMP_OPACITY_TRANSPARENT, GIMP_OPACITY_OPAQUE);
layer->opacity = opacity;
layer->mode = mode;
return layer;
}
/**
* gimp_layer_new_from_buffer:
* @buffer: The buffer to make the new layer from.
* @dest_image: The image the new layer will be added to.
* @format: The #Babl format of the new layer.
* @name: The new layer's name.
* @opacity: The new layer's opacity.
* @mode: The new layer's mode.
*
* Copies %buffer to a layer taking into consideration the
* possibility of transforming the contents to meet the requirements
* of the target image type
*
* Return value: The new layer.
**/
GimpLayer *
gimp_layer_new_from_buffer (GeglBuffer *buffer,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GimpLayer *layer;
GeglBuffer *dest;
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
g_return_val_if_fail (format != NULL, NULL);
/* do *not* use the buffer's format because this function gets
* buffers of any format passed, and converts them
*/
layer = gimp_layer_new (dest_image,
gegl_buffer_get_width (buffer),
gegl_buffer_get_height (buffer),
format,
name, opacity, mode);
dest = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_copy (buffer, NULL, GEGL_ABYSS_NONE, dest, NULL);
return layer;
}
/**
* gimp_layer_new_from_pixbuf:
* @pixbuf: The pixbuf to make the new layer from.
* @dest_image: The image the new layer will be added to.
* @format: The #Babl format of the new layer.
* @name: The new layer's name.
* @opacity: The new layer's opacity.
* @mode: The new layer's mode.
*
* Copies %pixbuf to a layer taking into consideration the
* possibility of transforming the contents to meet the requirements
* of the target image type
*
* Return value: The new layer.
**/
GimpLayer *
gimp_layer_new_from_pixbuf (GdkPixbuf *pixbuf,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode)
{
GeglBuffer *buffer;
GimpLayer *layer;
gint width;
gint height;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
g_return_val_if_fail (format != NULL, NULL);
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
layer = gimp_layer_new (dest_image, width, height,
format, name, opacity, mode);
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
gimp_pixbuf_get_format (pixbuf),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf));
return layer;
}
GimpLayer *
gimp_layer_get_parent (GimpLayer *layer)
{
......
......@@ -76,27 +76,6 @@ struct _GimpLayerClass
GType gimp_layer_get_type (void) G_GNUC_CONST;
GimpLayer * gimp_layer_new (GimpImage *image,
gint width,
gint height,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_new_from_buffer (GeglBuffer *buffer,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_new_from_pixbuf (GdkPixbuf *pixbuf,
GimpImage *dest_image,
const Babl *format,
const gchar *name,
gdouble opacity,
GimpLayerModeEffects mode);
GimpLayer * gimp_layer_get_parent (GimpLayer *layer);
GimpLayerMask * gimp_layer_get_mask (const GimpLayer *layer);
......
......@@ -36,6 +36,7 @@
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimplayer.h"
#include "gimplayer-new.h"
#include "gimplayermask.h"
#include "gimplayer-floating-sel.h"
#include "gimppickable.h"
......
......@@ -37,6 +37,7 @@
#include "core/gimpimage-new.h"
#include "core/gimpimage-undo.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "core/gimplayermask.h"
#include "core/gimppattern.h"
#include "core/gimpprogress.h"
......
......@@ -35,6 +35,7 @@
#include "core/gimpimage-undo.h"
#include "core/gimpimage.h"
#include "core/gimpitem-linked.h"
#include "core/gimplayer-new.h"
#include "core/gimplayer.h"
#include "core/gimplayermask.h"
#include "core/gimpparamspecs.h"
......
......@@ -32,6 +32,7 @@
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "tests.h"
......
......@@ -37,6 +37,7 @@
#include "core/gimpimage.h"
#include "core/gimpitemundo.h"
#include "core/gimplayer.h"
#include "core/gimplayer-new.h"
#include "core/gimplayermask.h"
#include "core/gimptreehandler.h"
......
......@@ -48,6 +48,7 @@
#include "core/gimpimage-undo.h"
#include "core/gimpitemstack.h"
#include "core/gimplayer-floating-sel.h"
#include "core/gimplayer-new.h"
#include "core/gimplayermask.h"
#include "core/gimpparasitelist.h"
#include "core/gimpprogress.h"
......
......@@ -1199,6 +1199,7 @@ CODE
"core/gimpimage-undo.h"
"core/gimpitem-linked.h"
"core/gimpgrouplayer.h"
"core/gimplayer-new.h"
"core/gimppickable.h"
"core/gimpprogress.h"
"gimppdbcontext.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment