[gimp] app: port gimp_palette_load_psp() to GIO



commit aedc3c0ddba48562306bf1ba30bf3ee924cd92ff
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 3 16:59:04 2014 +0200

    app: port gimp_palette_load_psp() to GIO

 app/core/gimppalette-import.c |    2 +-
 app/core/gimppalette-load.c   |   33 +++++++++++++++++++++++----------
 app/core/gimppalette-load.h   |    2 +-
 3 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index 08e645e..a30f59f 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -547,7 +547,7 @@ gimp_palette_import_from_file (GimpContext  *context,
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_PSP_PAL:
-      palette_list = gimp_palette_load_psp (context, file, f, error);
+      palette_list = gimp_palette_load_psp (context, file, input, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_ACO:
diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c
index 8c2b95c..e89a088 100644
--- a/app/core/gimppalette-load.c
+++ b/app/core/gimppalette-load.c
@@ -343,7 +343,10 @@ gimp_palette_load_riff (GimpContext   *context,
   g_free (palette_name);
 
   if (! g_seekable_seek (G_SEEKABLE (input), 28, G_SEEK_SET, NULL, error))
-    return NULL;
+    {
+      g_object_unref (palette);
+      return NULL;
+    }
 
   while (g_input_stream_read_all (input, color_bytes, sizeof (color_bytes),
                                   &bytes_read, NULL, NULL) &&
@@ -363,17 +366,16 @@ gimp_palette_load_riff (GimpContext   *context,
 }
 
 GList *
-gimp_palette_load_psp (GimpContext  *context,
-                       GFile        *file,
-                       FILE         *f,
-                       GError      **error)
+gimp_palette_load_psp (GimpContext   *context,
+                       GFile         *file,
+                       GInputStream  *input,
+                       GError       **error)
 {
   GimpPalette *palette;
   gchar       *palette_name;
-  gint         fd = fileno (f);
   guchar       color_bytes[4];
   gint         number_of_colors;
-  gint         data_size;
+  gsize        bytes_read;
   gint         i, j;
   gboolean     color_ok;
   gchar        buffer[4096];
@@ -388,9 +390,20 @@ gimp_palette_load_psp (GimpContext  *context,
   palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
   g_free (palette_name);
 
-  lseek (fd, 16, SEEK_SET);
-  data_size = read (fd, buffer, sizeof (buffer) - 1);
-  buffer[data_size] = '\0';
+  if (! g_seekable_seek (G_SEEKABLE (input), 16, G_SEEK_SET, NULL, error))
+    {
+      g_object_unref (palette);
+      return NULL;
+    }
+
+  if (! g_input_stream_read_all (input, buffer, sizeof (buffer) - 1,
+                                 &bytes_read, NULL, error))
+    {
+      g_object_unref (palette);
+      return NULL;
+    }
+
+  buffer[bytes_read] = '\0';
 
   lines = g_strsplit (buffer, "\x0d\x0a", -1);
 
diff --git a/app/core/gimppalette-load.h b/app/core/gimppalette-load.h
index 5786d4d..6843f53 100644
--- a/app/core/gimppalette-load.h
+++ b/app/core/gimppalette-load.h
@@ -51,7 +51,7 @@ GList               * gimp_palette_load_riff          (GimpContext   *context,
                                                        GError       **error);
 GList               * gimp_palette_load_psp           (GimpContext   *context,
                                                        GFile         *file,
-                                                       FILE          *f,
+                                                       GInputStream  *input,
                                                        GError       **error);
 GList               * gimp_palette_load_aco           (GimpContext   *context,
                                                        GFile         *file,


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