[gegl] png-load: Move function for opening stream to library
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] png-load: Move function for opening stream to library
- Date: Mon, 10 Nov 2014 01:46:49 +0000 (UTC)
commit 14b0373b2e86e42011e4488030d307912fec61d0
Author: Jon Nordby <jononor gmail com>
Date: Mon Nov 10 01:12:32 2014 +0100
png-load: Move function for opening stream to library
In order to be able to reuse it in the other file loaders,
like gegl:jpg-load.
In private header for now.
gegl/Makefile.am | 2 +
gegl/gegl-gio-private.h | 32 +++++++++++++++++
gegl/gegl-gio.c | 76 ++++++++++++++++++++++++++++++++++++++++
operations/external/png-load.c | 57 ++----------------------------
4 files changed, 113 insertions(+), 54 deletions(-)
---
diff --git a/gegl/Makefile.am b/gegl/Makefile.am
index 67c4529..9e3e304 100644
--- a/gegl/Makefile.am
+++ b/gegl/Makefile.am
@@ -94,6 +94,7 @@ GEGL_sources = \
gegl-utils.c \
gegl-lookup.c \
gegl-xml.c \
+ gegl-gio.c \
gegl-random.c \
gegl-matrix.c \
\
@@ -114,6 +115,7 @@ GEGL_sources = \
gegl-op.h \
gegl-plugin.h \
gegl-random-private.h \
+ gegl-gio-private.h \
gegl-types-internal.h \
gegl-xml.h
diff --git a/gegl/gegl-gio-private.h b/gegl/gegl-gio-private.h
new file mode 100644
index 0000000..d918e4d
--- /dev/null
+++ b/gegl/gegl-gio-private.h
@@ -0,0 +1,32 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Jon Nordby, The Grid <jononor gmail com>
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#ifndef __GEGL_GIO_PRIVATE_H__
+#define __GEGL_GIO_PRIVATE_H__
+
+GInputStream *
+gegl_gio_open_input_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err);
+
+#endif // __GEGL_GIO_PRIVATE_H__
+
+G_END_DECLS
diff --git a/gegl/gegl-gio.c b/gegl/gegl-gio.c
new file mode 100644
index 0000000..b572d7e
--- /dev/null
+++ b/gegl/gegl-gio.c
@@ -0,0 +1,76 @@
+/* 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 <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Jon Nordby, The Grid <jononor gmail com>
+ */
+
+#include <gegl-gio-private.h>
+#include <string.h>
+
+#ifdef G_OS_WIN32
+#include <gio/gwin32inputstream.h>
+#else
+#include <gio/gunixinputstream.h>
+#endif
+
+/**
+ * gegl_gio_open_input_stream:
+ * @uri: (allow none) URI to open. @uri is preferred over @path if both are set
+ * @path: (allow none) path to open.
+ * @out_file: (out) (transfer full): return location for GFile, if stream is for a file
+ *
+ * Return value: (transfer full): A new #GInputStream, free with g_object_unref()
+ *
+ * Note: currently private API
+ */
+GInputStream *
+gegl_gio_open_input_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err)
+{
+ GFile *infile = NULL;
+ GInputStream *fis = NULL;
+ g_return_val_if_fail(uri || path, NULL);
+ g_return_val_if_fail(out_file, NULL);
+
+ if (path && g_strcmp0(path, "-") == 0)
+ {
+ const gboolean close_fd = FALSE;
+ infile = NULL;
+#ifdef G_OS_WIN32 // untested :)
+ fis = g_win32_input_stream_new(stdin, close_fd);
+#else
+ fis = g_unix_input_stream_new(STDIN_FILENO, close_fd);
+#endif
+ }
+ else if (uri && strlen(uri) > 0)
+ {
+ infile = g_file_new_for_uri(uri);
+ }
+ else if (path && strlen(path) > 0)
+ {
+ infile = g_file_new_for_path(path);
+ }
+ else {
+ return NULL;
+ }
+
+ if (infile)
+ {
+ g_assert(!fis);
+ fis = G_INPUT_STREAM(g_file_read(infile, NULL, err));
+ *out_file = infile;
+ }
+
+ return fis;
+}
diff --git a/operations/external/png-load.c b/operations/external/png-load.c
index eae9aad..3f91eb4 100644
--- a/operations/external/png-load.c
+++ b/operations/external/png-load.c
@@ -20,13 +20,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <gio/gio.h>
-
-#ifdef G_OS_WIN32
-#include <gio/gwin32inputstream.h>
-#else
-#include <gio/gunixinputstream.h>
-#endif
+#include <gegl-gio-private.h>
#ifdef GEGL_PROPERTIES
@@ -67,7 +61,6 @@ read_fn(png_structp png_ptr, png_bytep buffer, png_size_t length)
{
GError *err = NULL;
GInputStream *stream = G_INPUT_STREAM(png_get_io_ptr(png_ptr));
- gboolean success = FALSE;
gsize bytes_read = 0;
g_assert(stream);
@@ -118,50 +111,6 @@ check_valid_png_header(GInputStream *stream, GError **err)
return TRUE;
}
-
-// TODO: move somewhere general for operations to reuse?
-static GInputStream *
-open_stream(const gchar *uri, const gchar *path, GFile **out_file, GError **err)
-{
- GFile *infile = NULL;
- GInputStream *fis = NULL;
- g_return_val_if_fail(uri || path, NULL);
- g_return_val_if_fail(out_file, NULL);
-
- g_print("open_stream: path=%s uri=%s", path, uri);
-
- if (path && g_strcmp0(path, "-") == 0)
- {
- const gboolean close_fd = FALSE;
- infile = NULL;
-#ifdef G_OS_WIN32 // untested :)
- fis = g_win32_input_stream_new(stdin, close_fd);
-#else
- fis = g_unix_input_stream_new(STDIN_FILENO, close_fd);
-#endif
- }
- else if (uri && strlen(uri) > 0)
- {
- infile = g_file_new_for_uri(uri);
- }
- else if (path && strlen(path) > 0)
- {
- infile = g_file_new_for_path(path);
- }
- else {
- return NULL;
- }
-
- if (infile)
- {
- g_assert(!fis);
- fis = G_INPUT_STREAM(g_file_read(infile, NULL, err));
- *out_file = infile;
- }
-
- return fis;
-}
-
static const Babl *
get_babl_format(int bit_depth, int color_type)
{
@@ -470,7 +419,7 @@ get_bounding_box (GeglOperation *operation)
GError *err = NULL;
GFile *infile = NULL;
- GInputStream *stream = open_stream(o->uri, o->path, &infile, &err);
+ GInputStream *stream = gegl_gio_open_input_stream(o->uri, o->path, &infile, &err);
WARN_IF_ERROR(err);
status = query_png(stream, &width, &height, &format, &err);
WARN_IF_ERROR(err);
@@ -504,7 +453,7 @@ process (GeglOperation *operation,
Babl *format = NULL;
GError *err = NULL;
GFile *infile = NULL;
- GInputStream *stream = open_stream(o->uri, o->path, &infile, &err);
+ GInputStream *stream = gegl_gio_open_input_stream(o->uri, o->path, &infile, &err);
WARN_IF_ERROR(err);
problem = gegl_buffer_import_png (output, stream, 0, 0,
&width, &height, format, &err);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]