Commit 5f54518a authored by Debarshi Ray's avatar Debarshi Ray

gegl: Add photos_gegl_pixbuf_new_from_buffer

This is part of a new set of APIs for GeglBuffer that don't require the
creation of a graph. These will allow decoding and encoding image file
formats to and from a GeglBuffer through asynchronous and cancellable
methods with error handling. These will follow GIO idioms and be
similar to the codec APIs for GdkPixbuf. There will be a compatibility
layer to convert a GeglBuffer to and from GdkPixbuf for legacy reasons.

These APIs will address the current lack of cancellation and error
handling in gegl:load, and make it easier to port existing code away
from GdkPixbuf.

Bump minimum GdkPixbuf version to 2.36.8.
parent 7128f1df
......@@ -41,7 +41,7 @@ GLIB_GSETTINGS
CAIRO_MIN_VERSION=1.14.0
DAZZLE_MIN_VERSION=3.26.0
GDATA_MIN_VERSION=0.15.2
GDK_PIXBUF_MIN_VERSION=2.32
GDK_PIXBUF_MIN_VERSION=2.36.8
GEGL_MIN_VERSION=0.4.0
GEXIV2_MIN_VERSION=0.10.8
GFBGRAPH_MIN_VERSION=0.2.1
......
......@@ -150,7 +150,7 @@ libgd_dep = libgd.get_variable('libgd_dep')
babl_dep = dependency('babl')
cairo_dep = dependency('cairo', version: '>= 1.14.0')
gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.32')
gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.36.8')
gegl_dep = dependency('gegl-0.4', version: '>= 0.4.0')
geocode_glib_dep = dependency('geocode-glib-1.0')
gexiv_dep = dependency('gexiv2', version: '>= 0.10.8')
......
......@@ -652,6 +652,46 @@ photos_gegl_init_fishes (void)
}
GdkPixbuf *
photos_gegl_pixbuf_new_from_buffer (GeglBuffer *buffer)
{
const Babl *format_buffer;
const Babl *format_pixbuf;
g_autoptr (GBytes) bytes = NULL;
GdkPixbuf *pixbuf = NULL;
GeglRectangle bbox;
gboolean has_alpha;
gint stride;
gpointer buf = NULL;
gsize size;
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
bbox = *gegl_buffer_get_extent (buffer);
format_buffer = gegl_buffer_get_format (buffer);
has_alpha = babl_format_has_alpha (format_buffer);
if (has_alpha)
format_pixbuf = babl_format ("R'G'B'A u8");
else
format_pixbuf = babl_format ("R'G'B' u8");
stride = gdk_pixbuf_calculate_rowstride (GDK_COLORSPACE_RGB, has_alpha, 8, bbox.width, bbox.height);
if (stride == -1)
goto out;
buf = g_malloc0_n ((gsize) bbox.height, (gsize) stride);
gegl_buffer_get (buffer, &bbox, 1.0, format_pixbuf, buf, stride, GEGL_ABYSS_NONE);
size = (gsize) bbox.height * (gsize) stride;
bytes = g_bytes_new_take (buf, size);
pixbuf = gdk_pixbuf_new_from_bytes (bytes, GDK_COLORSPACE_RGB, has_alpha, 8, bbox.width, bbox.height, stride);
out:
return pixbuf;
}
static gboolean
photos_gegl_processor_process_idle (gpointer user_data)
{
......
......@@ -51,6 +51,8 @@ void photos_gegl_init (void);
void photos_gegl_init_fishes (void);
GdkPixbuf *photos_gegl_pixbuf_new_from_buffer (GeglBuffer *buffer);
void photos_gegl_processor_process_async (GeglProcessor *processor,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......
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