[gegl] png-load: Add back code for reading from stdin



commit 21a2171221cfbf963698b4d6afe4d111e7579e07
Author: Jon Nordby <jononor gmail com>
Date:   Sun Nov 9 22:46:10 2014 +0100

    png-load: Add back code for reading from stdin
    
    Was temporarily missing after GIO refactor. Can now read stdin
    again, but the functionality is broken: get_bounding_box()
    eats some of PNG files, so process() sees an incomplete file.
    This bug was there before also.
    Includes an implementation for WIN32, but I have no idea if it compiles.

 configure.ac                   |   10 ++++++++++
 operations/external/png-load.c |   36 +++++++++++++++++++++++++-----------
 2 files changed, 35 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3e18a6d..97d946a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -494,6 +494,16 @@ AC_CHECK_FUNCS(fsync)
 PKG_CHECK_MODULES(BABL, babl >= babl_required_version)
 
 GLIB_PACKAGES="gobject-2.0 gmodule-2.0 gio-2.0"
+# select platform-specific GIO
+case "$os_win32" in
+  yes)
+    GLIB_PACKAGES+=" gio-windows-2.0"
+    ;;
+  *)
+    GLIB_PACKAGES+=" gio-unix-2.0"
+    ;;
+esac
+
 AC_SUBST(GLIB_PACKAGES)
 
 dnl This PATH_GLIB is somewhat redundant, but does a sanity compile and 
diff --git a/operations/external/png-load.c b/operations/external/png-load.c
index e9ac06f..f327d9f 100644
--- a/operations/external/png-load.c
+++ b/operations/external/png-load.c
@@ -22,6 +22,12 @@
 #include <glib/gi18n-lib.h>
 #include <gio/gio.h>
 
+#ifdef G_OS_WIN32
+#include <gio/gwin32inputstream.h>  
+#else
+#include <gio/gunixinputstream.h>
+#endif
+
 #ifdef GEGL_PROPERTIES
 
 property_file_path (path, _("File"), "")
@@ -113,35 +119,43 @@ check_valid_png_header(GInputStream *stream, GError **err)
 }
 
 
-
+// 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);
 
-  if (strlen(uri) > 0)
+  g_print("open_stream: path=%s uri=%s", path, uri);
+
+  if (path && g_strcmp0(path, "-") == 0)
     {
-      infile = g_file_new_for_uri(uri);
+      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 (g_strcmp0 (path, "-") == 0)
+  else if (uri && strlen(uri) > 0)
     {
-      //infile = stdin; // FIXME: implement
-      g_assert(FALSE);
+      infile = g_file_new_for_uri(uri);
     }
-  else
+  else if (path && strlen(path) > 0)
     {
       infile = g_file_new_for_path(path);
     }
-  g_return_val_if_fail(infile, NULL);
-
-  fis = G_INPUT_STREAM(g_file_read(infile, NULL, err));
+  else {
+    return NULL;
+  }
 
   if (infile)
     {
+      g_assert(!fis);
+      fis = G_INPUT_STREAM(g_file_read(infile, NULL, err));
       *out_file = infile;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]