[gegl] gegl-compression: add "nop" algorithm
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl-compression: add "nop" algorithm
- Date: Mon, 17 Dec 2018 11:39:57 +0000 (UTC)
commit 798cb4d6717fb75385e0b3f15818c31f9464bef4
Author: Ell <ell_se yahoo com>
Date: Mon Dec 17 04:45:39 2018 -0500
gegl-compression: add "nop" algorithm
A simple "compression" algorithm, which simply memcpy()s the data.
Useful mostly for testing.
gegl/buffer/Makefile.am | 2 +
gegl/buffer/gegl-compression-nop.c | 96 ++++++++++++++++++++++++++++++++++++++
gegl/buffer/gegl-compression-nop.h | 30 ++++++++++++
gegl/buffer/gegl-compression.c | 3 ++
4 files changed, 131 insertions(+)
---
diff --git a/gegl/buffer/Makefile.am b/gegl/buffer/Makefile.am
index 3d9ada9e2..235174cf8 100644
--- a/gegl/buffer/Makefile.am
+++ b/gegl/buffer/Makefile.am
@@ -43,6 +43,7 @@ libbuffer_la_SOURCES = \
gegl-buffer-save.c \
gegl-buffer-swap.c \
gegl-compression.c \
+ gegl-compression-nop.c \
gegl-sampler.c \
gegl-sampler-cubic.c \
gegl-sampler-linear.c \
@@ -75,6 +76,7 @@ libbuffer_la_SOURCES = \
gegl-buffer-swap.h \
gegl-buffer-swap-private.h \
gegl-compression.h \
+ gegl-compression-nop.h \
gegl-sampler.h \
gegl-sampler-cubic.h \
gegl-sampler-linear.h \
diff --git a/gegl/buffer/gegl-compression-nop.c b/gegl/buffer/gegl-compression-nop.c
new file mode 100644
index 000000000..02e648cbe
--- /dev/null
+++ b/gegl/buffer/gegl-compression-nop.c
@@ -0,0 +1,96 @@
+/* This file is part of 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include "gegl-compression.h"
+#include "gegl-compression-nop.h"
+
+
+/* local function prototypes */
+
+static gboolean gegl_compression_nop_compress (const GeglCompression *compression,
+ const Babl *format,
+ gconstpointer data,
+ gint n,
+ gpointer compressed,
+ gint *compressed_size,
+ gint max_compressed_size);
+static gboolean gegl_compression_nop_decompress (const GeglCompression *compression,
+ const Babl *format,
+ gpointer data,
+ gint n,
+ gconstpointer compressed,
+ gint compressed_size);
+
+
+/* private functions */
+
+static gboolean
+gegl_compression_nop_compress (const GeglCompression *compression,
+ const Babl *format,
+ gconstpointer data,
+ gint n,
+ gpointer compressed,
+ gint *compressed_size,
+ gint max_compressed_size)
+{
+ gint size = n * babl_format_get_bytes_per_pixel (format);
+
+ if (max_compressed_size < size)
+ return FALSE;
+
+ memcpy (compressed, data, size);
+
+ *compressed_size = size;
+
+ return TRUE;
+}
+
+static gboolean
+gegl_compression_nop_decompress (const GeglCompression *compression,
+ const Babl *format,
+ gpointer data,
+ gint n,
+ gconstpointer compressed,
+ gint compressed_size)
+{
+ gint size = n * babl_format_get_bytes_per_pixel (format);
+
+ if (compressed_size != size)
+ return FALSE;
+
+ memcpy (data, compressed, size);
+
+ return TRUE;
+}
+
+
+/* public functions */
+
+void
+gegl_compression_nop_init (void)
+{
+ static const GeglCompression compression_nop =
+ {
+ .compress = gegl_compression_nop_compress,
+ .decompress = gegl_compression_nop_decompress
+ };
+
+ gegl_compression_register ("nop", &compression_nop);
+}
diff --git a/gegl/buffer/gegl-compression-nop.h b/gegl/buffer/gegl-compression-nop.h
new file mode 100644
index 000000000..938c18d13
--- /dev/null
+++ b/gegl/buffer/gegl-compression-nop.h
@@ -0,0 +1,30 @@
+/* This file is part of 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 <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEGL_COMPRESSION_NOP_H__
+#define __GEGL_COMPRESSION_NOP_H__
+
+
+#include <glib.h>
+#include <babl/babl.h>
+
+G_BEGIN_DECLS
+
+void gegl_compression_nop_init (void);
+
+G_END_DECLS
+
+#endif
diff --git a/gegl/buffer/gegl-compression.c b/gegl/buffer/gegl-compression.c
index 5e932991c..51e89177d 100644
--- a/gegl/buffer/gegl-compression.c
+++ b/gegl/buffer/gegl-compression.c
@@ -20,6 +20,7 @@
#include <string.h>
#include "gegl-compression.h"
+#include "gegl-compression-nop.h"
/* local variables */
@@ -35,6 +36,8 @@ gegl_compression_init (void)
g_return_if_fail (algorithms == NULL);
algorithms = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ gegl_compression_nop_init ();
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]