libgimp: add gimp_layer_new_from_surface()

and to enable that, make libgimp depend on Cairo.
This commit is contained in:
Michael Natterer 2011-04-20 23:58:00 +02:00
parent bdc08aae83
commit 374dd50c43
12 changed files with 198 additions and 4 deletions

View File

@ -117,11 +117,13 @@ AC_SUBST(GIMP_FULL_NAME)
# These are used in the .pc files
GLIB_REQUIRED_VERSION=glib_required_version
GTK_REQUIRED_VERSION=gtk_required_version
GDK_PIXBUF_REQUIRED_VERSION=gdk_pixbuf_required_version
GTK_REQUIRED_VERSION=gtk_required_version
CAIRO_REQUIRED_VERSION=cairo_required_version
AC_SUBST(GLIB_REQUIRED_VERSION)
AC_SUBST(GTK_REQUIRED_VERSION)
AC_SUBST(GDK_PIXBUF_REQUIRED_VERSION)
AC_SUBST(GTK_REQUIRED_VERSION)
AC_SUBST(CAIRO_REQUIRED_VERSION)
# The symbol GIMP_UNSTABLE is defined above for substitution in
# Makefiles and conditionally defined here as a preprocessor symbol

View File

@ -696,6 +696,7 @@ gimp_layer_new
gimp_layer_new_from_drawable
gimp_layer_new_from_visible
gimp_layer_new_from_pixbuf
gimp_layer_new_from_surface
gimp_layer_group_new
gimp_layer_copy
gimp_layer_scale

View File

@ -12,6 +12,6 @@ gimplocaledir=@gimplocaledir@
Name: GIMP
Description: GIMP Library
Version: @GIMP_REAL_VERSION@
Requires: gdk-pixbuf-2.0 >= @GDK_PIXBUF_REQUIRED_VERSION@
Requires: gdk-pixbuf-2.0 >= @GDK_PIXBUF_REQUIRED_VERSION@ cairo >= @CAIRO_REQUIRED_VERSION@
Libs: -L${libdir} -lgimp-@GIMP_API_VERSION@ -lgimpmath-@GIMP_API_VERSION@ -lgimpconfig-@GIMP_API_VERSION@ -lgimpcolor-@GIMP_API_VERSION@ -lgimpbase-@GIMP_API_VERSION@ @RT_LIBS@
Cflags: -I${includedir}/gimp-@GIMP_API_VERSION@

View File

@ -364,6 +364,7 @@ libgimp_2_0_la_LIBADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS)

View File

@ -516,6 +516,7 @@ EXPORTS
gimp_layer_new
gimp_layer_new_from_drawable
gimp_layer_new_from_pixbuf
gimp_layer_new_from_surface
gimp_layer_new_from_visible
gimp_layer_remove_mask
gimp_layer_resize

View File

@ -21,6 +21,7 @@
#ifndef __GIMP_H__
#define __GIMP_H__
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libgimpbase/gimpbase.h>

View File

@ -27,6 +27,9 @@
#undef __GIMP_LAYER_H__
#include "gimplayer.h"
#include "libgimpwidgets/gimpcairo-utils.h" /* eek */
/**
* gimp_layer_new:
* @image_ID: The image to which to add the layer.
@ -198,6 +201,160 @@ gimp_layer_new_from_pixbuf (gint32 image_ID,
return layer;
}
/**
* gimp_layer_new_from_surface:
* @image_ID: The RGB image to which to add the layer.
* @name: The layer name.
* @cairo_surface_t: A Cairo image surface.
* @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 #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.
*
* Returns: The newly created layer.
*
* Since: GIMP 2.8
*/
gint32
gimp_layer_new_from_surface (gint32 image_ID,
const gchar *name,
cairo_surface_t *surface,
gdouble opacity,
GimpLayerModeEffects mode,
gdouble progress_start,
gdouble progress_end)
{
GimpDrawable *drawable;
GimpPixelRgn rgn;
const guchar *pixels;
gpointer pr;
gint32 layer;
cairo_format_t format;
gint width;
gint height;
gint rowstride;
gdouble range = progress_end - progress_start;
guint count = 0;
guint done = 0;
g_return_val_if_fail (surface != NULL, -1);
g_return_val_if_fail (cairo_surface_get_type (surface) ==
CAIRO_SURFACE_TYPE_IMAGE, -1);
if (gimp_image_base_type (image_ID) != GIMP_RGB)
{
g_warning ("gimp_layer_new_from_surface() needs an RGB image");
return -1;
}
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");
return -1;
}
layer = gimp_layer_new (image_ID, name, width, height,
format == CAIRO_FORMAT_RGB24 ?
GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
opacity, mode);
if (layer == -1)
return -1;
drawable = gimp_drawable_get (layer);
gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
rowstride = cairo_image_surface_get_stride (surface);
pixels = cairo_image_surface_get_data (surface);
for (pr = gimp_pixel_rgns_register (1, &rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
const guchar *src = pixels + rgn.y * rowstride + rgn.x * 4;
guchar *dest = rgn.data;
gint y;
switch (format)
{
case CAIRO_FORMAT_RGB24:
for (y = 0; y < rgn.h; y++)
{
const guchar *s = src;
guchar *d = dest;
gint w = rgn.w;
while (w--)
{
GIMP_CAIRO_RGB24_GET_PIXEL (s, d[0], d[1], d[2]);
s += 4;
d += 3;
}
src += rowstride;
dest += rgn.rowstride;
}
break;
case CAIRO_FORMAT_ARGB32:
for (y = 0; y < rgn.h; y++)
{
const guchar *s = src;
guchar *d = dest;
gint w = rgn.w;
while (w--)
{
GIMP_CAIRO_ARGB32_GET_PIXEL (s, d[0], d[1], d[2], d[3]);
s += 4;
d += 4;
}
src += rowstride;
dest += rgn.rowstride;
}
break;
default:
break;
}
if (range > 0.0)
{
done += rgn.h * rgn.w;
if (count++ % 32 == 0)
gimp_progress_update (progress_start +
(gdouble) done / (width * height) * range);
}
}
if (range > 0.0)
gimp_progress_update (progress_end);
gimp_drawable_detach (drawable);
return layer;
}
/**
* gimp_layer_get_preserve_trans:
* @layer_ID: The layer.

View File

@ -42,6 +42,13 @@ gint32 gimp_layer_new_from_pixbuf (gint32 image_ID,
GimpLayerModeEffects mode,
gdouble progress_start,
gdouble progress_end);
gint32 gimp_layer_new_from_surface (gint32 image_ID,
const gchar *name,
cairo_surface_t *surface,
gdouble opacity,
GimpLayerModeEffects mode,
gdouble progress_start,
gdouble progress_end);
#ifndef GIMP_DISABLE_DEPRECATED

View File

@ -264,6 +264,7 @@ animation_optimize_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -295,6 +296,7 @@ antialias_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -343,6 +345,7 @@ blur_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -631,6 +634,7 @@ contrast_normalize_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -662,6 +666,7 @@ contrast_stretch_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -676,6 +681,7 @@ contrast_stretch_hsv_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -707,6 +713,7 @@ crop_auto_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -721,6 +728,7 @@ crop_zealous_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -922,6 +930,7 @@ edge_laplace_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1039,6 +1048,7 @@ file_compressor_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1070,6 +1080,7 @@ file_desktop_link_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1120,6 +1131,7 @@ file_gif_load_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1168,6 +1180,7 @@ file_glob_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1216,6 +1229,7 @@ file_jp2_load_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(JP2_LIBS) \
$(RT_LIBS) \
@ -1660,6 +1674,7 @@ gradient_map_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -1691,6 +1706,7 @@ guillotine_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -2201,6 +2217,7 @@ rotate_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -2252,6 +2269,7 @@ semi_flatten_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -2453,6 +2471,7 @@ tile_seamless_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
@ -2518,6 +2537,7 @@ value_invert_LDADD = \
$(libgimpconfig) \
$(libgimpcolor) \
$(libgimpbase) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \

View File

@ -139,7 +139,7 @@ foreach (sort keys %plugins) {
if (exists $plugins{$_}->{ui}) {
$glib = "\$(GTK_LIBS)\t\t\\"
} else {
$glib = "\$(GDK_PIXBUF_LIBS)\t\\"
$glib = "\$(CAIRO_LIBS)\t\t\\\n\t\$(GDK_PIXBUF_LIBS)\t\\"
}
my $optlib = "";

View File

@ -30,6 +30,7 @@ file_faxg3_SOURCES = \
INCLUDES = \
-I$(top_srcdir) \
$(CAIRO_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
-I$(includedir)
@ -39,6 +40,7 @@ LDADD = \
$(libgimpcolor) \
$(libgimpbase) \
$(libgimpmath) \
$(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \

View File

@ -44,6 +44,7 @@ help_SOURCES = help.c
INCLUDES = \
-I$(top_srcdir) \
$(CAIRO_CFLAGS) \
$(GIO_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
-I$(includedir)
@ -55,6 +56,7 @@ LDADD = \
$(libgimpcolor) \
$(libgimpbase) \
$(libgimpmath) \
$(CAIRO_LIBS) \
$(GIO_LIBS) \
$(GDK_PIXBUF_LIBS) \
$(RT_LIBS) \