[gegl] convert-format: change parameter to Babl*, allow passthrough
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] convert-format: change parameter to Babl*, allow passthrough
- Date: Fri, 6 Dec 2013 03:28:22 +0000 (UTC)
commit e4bbcb01962f09069266a0bf4e0f548dd772de46
Author: Daniel Sabo <DanielSabo gmail com>
Date: Wed Dec 4 13:32:33 2013 -0800
convert-format: change parameter to Babl*, allow passthrough
operations/core/convert-format.c | 70 ++++++++++---------
tests/simple/.gitignore | 1 +
tests/simple/Makefile.am | 1 +
tests/simple/test-convert-format.c | 132 ++++++++++++++++++++++++++++++++++++
4 files changed, 172 insertions(+), 32 deletions(-)
---
diff --git a/operations/core/convert-format.c b/operations/core/convert-format.c
index e792dcf..66ad45a 100644
--- a/operations/core/convert-format.c
+++ b/operations/core/convert-format.c
@@ -15,65 +15,71 @@
*
* Copyright 2007 Étienne Bersac <bersace03 laposte net>
* Copyright 2006 Øyvind Kolås <pippin gimp org>
+ * Copyright 2013 Daniel Sabo
*
- * This operation is just a forked grey op with format parameters.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
-
#ifdef GEGL_CHANT_PROPERTIES
-gegl_chant_string(format, _("Output format"), "RGBA float",
- _("Babl output format string"))
+gegl_chant_format (format, _("Output Format"),
+ _("The babl format of the output"))
#else
-#define GEGL_CHANT_TYPE_POINT_FILTER
-#define GEGL_CHANT_C_FILE "convert-format.c"
+#define GEGL_CHANT_TYPE_FILTER
+#define GEGL_CHANT_C_FILE "convert-format.c"
#include "gegl-chant.h"
-static void prepare (GeglOperation *operation)
+static void
+prepare (GeglOperation *self)
{
- GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
- const Babl *format;
-
- g_assert (o->format);
-
- format = babl_format (o->format);
- /* check format ? */
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (self);
- gegl_operation_set_format (operation, "input", format);
- gegl_operation_set_format (operation, "output", format);
+ if (o->format)
+ gegl_operation_set_format (self, "output", o->format);
+ else
+ gegl_operation_set_format (self, "output", gegl_operation_get_source_format (self, "input"));
}
static gboolean
-process (GeglOperation *op,
- void *in_buf,
- void *out_buf,
- glong samples,
- const GeglRectangle *roi,
- gint level)
+process (GeglOperation *operation,
+ GeglOperationContext *context,
+ const gchar *output_prop,
+ const GeglRectangle *roi,
+ gint level)
{
- int bpp = babl_format_get_bytes_per_pixel (gegl_operation_get_format (op, "output"));
- memcpy(out_buf, in_buf, samples * bpp);
+ GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+ GeglBuffer *input;
+ GeglBuffer *output;
+
+ input = gegl_operation_context_get_source (context, "input");
+
+ if (gegl_buffer_get_format (input) != o->format)
+ {
+ output = gegl_operation_context_get_target (context, "output");
+ gegl_buffer_copy (input, roi, output, roi);
+ g_object_unref (input);
+ }
+ else
+ {
+ gegl_operation_context_take_object (context, "output", G_OBJECT (input));
+ }
+
return TRUE;
}
-
static void
gegl_chant_class_init (GeglChantClass *klass)
{
- GeglOperationClass *operation_class;
- GeglOperationPointFilterClass *point_filter_class;
-
- operation_class = GEGL_OPERATION_CLASS (klass);
- point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
- point_filter_class->process = process;
- operation_class->prepare = prepare;
+ operation_class->prepare = prepare;
+ operation_class->process = process;
+ operation_class->no_cache = FALSE;
gegl_operation_class_set_keys (operation_class,
"name", "gegl:convert-format",
diff --git a/tests/simple/.gitignore b/tests/simple/.gitignore
index 1f7aca5..dada946 100644
--- a/tests/simple/.gitignore
+++ b/tests/simple/.gitignore
@@ -7,6 +7,7 @@
/Makefile.in
/test-change-processor-rect
/test-color-op
+/test-convert-format
/test-exp-combine.sh
/test-gegl-rectangle
/test-gegl-tile
diff --git a/tests/simple/Makefile.am b/tests/simple/Makefile.am
index 80ac95f..b8885ff 100644
--- a/tests/simple/Makefile.am
+++ b/tests/simple/Makefile.am
@@ -5,6 +5,7 @@ noinst_PROGRAMS = \
test-buffer-extract \
test-buffer-tile-voiding \
test-change-processor-rect \
+ test-convert-format \
test-color-op \
test-format-sensing \
test-gegl-rectangle \
diff --git a/tests/simple/test-convert-format.c b/tests/simple/test-convert-format.c
new file mode 100644
index 0000000..152851b
--- /dev/null
+++ b/tests/simple/test-convert-format.c
@@ -0,0 +1,132 @@
+/*
+ * 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/>.
+ *
+ * Copyright (C) 2013 Daniel Sabo
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include "gegl.h"
+
+#define SUCCESS 0
+#define FAILURE -1
+
+static gboolean
+test_convert_common (const Babl *in_format,
+ const Babl *out_format)
+{
+ /* Validate that gegl:convert-format produces out_format when given in_format */
+ gboolean result = TRUE;
+
+ GeglNode *ptn, *src, *convert, *sink;
+ GeglBuffer *src_buffer;
+ GeglBuffer *sink_buffer = NULL;
+
+ src_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 10, 10), in_format);
+
+ ptn = gegl_node_new ();
+
+ src = gegl_node_new_child (ptn,
+ "operation", "gegl:buffer-source",
+ "buffer", src_buffer,
+ NULL);
+
+ convert = gegl_node_new_child (ptn,
+ "operation", "gegl:convert-format",
+ "format", out_format,
+ NULL);
+
+ sink = gegl_node_new_child (ptn,
+ "operation", "gegl:buffer-sink",
+ "buffer", &sink_buffer,
+ "format", NULL,
+ NULL);
+
+ gegl_node_link_many (src, convert, sink, NULL);
+
+ gegl_node_blit_buffer (sink, NULL, NULL);
+
+ if (out_format != gegl_buffer_get_format (sink_buffer))
+ {
+ printf ("Got %s expected %s\n", babl_get_name (gegl_buffer_get_format (sink_buffer)),
+ babl_get_name (out_format));
+ result = FALSE;
+ }
+
+ if (!gegl_rectangle_equal (gegl_buffer_get_extent (src_buffer),
+ gegl_buffer_get_extent (sink_buffer)))
+ result = FALSE;
+
+ g_object_unref (ptn);
+ g_object_unref (src_buffer);
+ g_object_unref (sink_buffer);
+
+ return result;
+}
+
+static gboolean
+test_convert_001 (void)
+{
+ return test_convert_common (babl_format ("RGB float"),
+ babl_format ("Y float"));
+}
+
+static gboolean
+test_convert_002 (void)
+{
+ return test_convert_common (babl_format ("RGB float"),
+ babl_format ("RGB u8"));
+}
+
+static gboolean
+test_same_001 (void)
+{
+ return test_convert_common (babl_format ("RGB float"),
+ babl_format ("RGB float"));
+}
+
+#define RUN_TEST(test_name) \
+{ \
+ if (test_name()) \
+ { \
+ printf ("" #test_name " ... PASS\n"); \
+ tests_passed++; \
+ } \
+ else \
+ { \
+ printf ("" #test_name " ... FAIL\n"); \
+ tests_failed++; \
+ } \
+ tests_run++; \
+}
+
+int main(int argc, char *argv[])
+{
+ gint tests_run = 0;
+ gint tests_passed = 0;
+ gint tests_failed = 0;
+
+ gegl_init (&argc, &argv);
+
+ RUN_TEST (test_convert_001)
+ RUN_TEST (test_convert_002)
+ RUN_TEST (test_same_001)
+
+ gegl_exit ();
+
+ if (tests_passed == tests_run)
+ return SUCCESS;
+ return FAILURE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]