[gegl/soc-2013-opecl-ops] operations: Add gegl:webp-load
- From: Carlos Zubieta <czubieta src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2013-opecl-ops] operations: Add gegl:webp-load
- Date: Wed, 31 Jul 2013 16:48:13 +0000 (UTC)
commit 50505e82a5683d2ffa77f58328d637ce652ccee6
Author: Michael Henning <drawoc darkrefraction com>
Date: Wed Jul 24 14:04:07 2013 -0400
operations: Add gegl:webp-load
configure.ac | 20 ++++++
operations/external/Makefile.am | 7 ++
operations/external/webp-load.c | 141 +++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
4 files changed, 169 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ad0934e..3a50958 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,7 @@ m4_define([pango_required_version], [0.0.0])
m4_define([pangocairo_required_version], [0.0.0])
m4_define([png_required_version], [0.0.0])
m4_define([sdl_required_version], [0.0.0])
+m4_define([webp_required_version], [0.0.0])
m4_define([poly2tri-c_required_version], [0.0.0])
AC_INIT(gegl, gegl_major_version.gegl_minor_version.gegl_micro_version)
@@ -1007,6 +1008,24 @@ AM_CONDITIONAL(HAVE_UMFPACK, test "x$have_umfpack" = "xyes")
AC_SUBST(UMFPACK_CFLAGS)
AC_SUBST(UMFPACK_LIBS)
+################
+# Check for webp
+################
+
+AC_ARG_WITH(webp, [ --without-webp build without webp support])
+
+have_webp="no"
+if test "x$with_webp" != "xno"; then
+ PKG_CHECK_MODULES(WEBP, libwebp >= webp_required_version,
+ have_webp="yes",
+ have_webp="no (webp library not found)")
+fi
+
+AM_CONDITIONAL(HAVE_WEBP, test "$have_webp" = "yes")
+
+AC_SUBST(WEBP_CFLAGS)
+AC_SUBST(WEBP_LIBS)
+
######################
# Check for poly2tri-c
######################
@@ -1177,5 +1196,6 @@ Optional dependencies:
spiro: $spiro_ok
EXIV: $have_exiv2
umfpack: $have_umfpack
+ webp: $have_webp
poly2tri-c: $have_p2tc
]);
diff --git a/operations/external/Makefile.am b/operations/external/Makefile.am
index b9e7ba2..de8c2ed 100644
--- a/operations/external/Makefile.am
+++ b/operations/external/Makefile.am
@@ -125,6 +125,13 @@ lcms_from_profile_la_LIBADD = $(op_libs) $(LCMS_LIBS)
lcms_from_profile_la_CFLAGS = $(AM_CFLAGS)
endif
+if HAVE_WEBP
+ops += webp-load.la
+webp_load_la_SOURCES = webp-load.c
+webp_load_la_LIBADD = $(op_libs) $(WEBP_LIBS)
+webp_load_la_CFLAGS = $(AM_CFLAGS) $(WEBP_CFLAGS)
+endif
+
# No dependencies
ops += ppm-load.la ppm-save.la
ppm_load_la_SOURCES = ppm-load.c
diff --git a/operations/external/webp-load.c b/operations/external/webp-load.c
new file mode 100644
index 0000000..e3cec8e
--- /dev/null
+++ b/operations/external/webp-load.c
@@ -0,0 +1,141 @@
+/* This file is an image processing operation for GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL 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
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 Michael Henning <drawoc darkrefraction com>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+
+#ifdef GEGL_CHANT_PROPERTIES
+
+gegl_chant_file_path (path, _("File"), "", _("Path of file to load."))
+
+#else
+
+#define GEGL_CHANT_TYPE_SOURCE
+#define GEGL_CHANT_C_FILE "webp-load.c"
+
+#include "gegl-chant.h"
+#include <webp/decode.h>
+
+/*XXX: leaks on failure */
+static gboolean
+read_webp (const gchar *path, GeglBuffer *buf, GeglRectangle *bounds_out, const Babl **format_out)
+{
+ GMappedFile *map = g_mapped_file_new (path, FALSE, NULL);
+
+ const gpointer data = g_mapped_file_get_contents (map);
+ gsize data_size = g_mapped_file_get_length (map);
+
+ const Babl* format;
+ GeglRectangle bounds = {0, };
+
+ WebPDecoderConfig config;
+ g_return_val_if_fail (WebPInitDecoderConfig (&config), FALSE);
+
+ g_return_val_if_fail (WebPGetFeatures (data, data_size, &config.input) == VP8_STATUS_OK, FALSE);
+
+ bounds.width = config.input.width;
+ bounds.height = config.input.height;
+
+ if (config.input.has_alpha)
+ {
+ config.output.colorspace = MODE_RGBA;
+ format = babl_format ("R'G'B'A u8");
+ }
+ else
+ {
+ config.output.colorspace = MODE_RGB;
+ format = babl_format ("R'G'B' u8");
+ }
+
+ if (buf)
+ {
+ g_return_val_if_fail (WebPDecode (data, data_size, &config) == VP8_STATUS_OK, FALSE);
+
+ gegl_buffer_set (buf, &bounds, 1, format, config.output.u.RGBA.rgba,
+ config.output.u.RGBA.stride);
+
+ WebPFreeDecBuffer (&config.output);
+ }
+
+ if (bounds_out)
+ *bounds_out = bounds;
+
+ if (format_out)
+ *format_out = format;
+
+ g_mapped_file_unref (map);
+
+ return TRUE;
+}
+
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ GeglRectangle result = {0,0,0,0};
+ const Babl *format = NULL;
+
+ read_webp (o->path, NULL, &result, &format);
+
+ if (format)
+ gegl_operation_set_format (operation, "output", format);
+
+ return result;
+}
+
+static gboolean
+process (GeglOperation *operation,
+ GeglBuffer *output,
+ const GeglRectangle *result,
+ gint level)
+{
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ return read_webp (o->path, output, NULL, NULL);
+}
+
+static GeglRectangle
+get_cached_region (GeglOperation *operation,
+ const GeglRectangle *roi)
+{
+ return get_bounding_box (operation);
+}
+
+static void
+gegl_chant_class_init (GeglChantClass *klass)
+{
+ GeglOperationClass *operation_class;
+ GeglOperationSourceClass *source_class;
+
+ operation_class = GEGL_OPERATION_CLASS (klass);
+ source_class = GEGL_OPERATION_SOURCE_CLASS (klass);
+
+ source_class->process = process;
+ operation_class->get_bounding_box = get_bounding_box;
+ operation_class->get_cached_region = get_cached_region;
+
+ gegl_operation_class_set_keys (operation_class,
+ "name" , "gegl:webp-load",
+ "categories" , "hidden",
+ "description" , _("WebP image loader."),
+ NULL);
+
+ gegl_extension_handler_register (".webp", "gegl:webp-load");
+}
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1fd6050..6a45ea7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -128,6 +128,7 @@ operations/external/text.c
operations/external/v4l.c
operations/external/vector-fill.c
operations/external/vector-stroke.c
+operations/external/webp-load.c
operations/generated/add.c
operations/generated/clear.c
operations/generated/color-burn.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]