[gimp] plug-ins: add psd_read_len function



commit 2e2e43a404c7af07c3e7d2f0eb6628bdba418ccb
Author: Jacob Boerema <jgboerema gmail com>
Date:   Sun May 16 23:02:43 2021 -0400

    plug-ins: add psd_read_len function
    
    In certain places in a PSB file we need to read 64-bit
    lengths where in a PSD we read a 32-bit length.
    
    To make handling this easier we add a function that
    determines if we need to read 4 or 8 bytes and
    also handles converting the value from big endian.

 plug-ins/file-psd/psd-util.c | 21 +++++++++++++++++++++
 plug-ins/file-psd/psd-util.h |  5 +++++
 2 files changed, 26 insertions(+)
---
diff --git a/plug-ins/file-psd/psd-util.c b/plug-ins/file-psd/psd-util.c
index 533a9b0557..6dd07d11f7 100644
--- a/plug-ins/file-psd/psd-util.c
+++ b/plug-ins/file-psd/psd-util.c
@@ -202,6 +202,27 @@ psd_read (GInputStream  *input,
   return bytes_read;
 }
 
+gboolean
+psd_read_len (GInputStream  *input,
+              gsize         *data,
+              gint           psd_version,
+              GError       **error)
+{
+  gint block_len_size = (psd_version == 1 ? 4 : 8);
+
+  if (psd_read (input, data, block_len_size, error) < block_len_size)
+    {
+      psd_set_error (error);
+      return FALSE;
+    }
+
+  if (psd_version == 1)
+    *data = GUINT32_FROM_BE (*data);
+  else
+    *data = GUINT64_FROM_BE (*data);
+  return TRUE;
+}
+
 gboolean
 psd_seek (GInputStream  *input,
           goffset        offset,
diff --git a/plug-ins/file-psd/psd-util.h b/plug-ins/file-psd/psd-util.h
index 498622a508..1c3ca2524a 100644
--- a/plug-ins/file-psd/psd-util.h
+++ b/plug-ins/file-psd/psd-util.h
@@ -33,6 +33,11 @@ gint                    psd_read               (GInputStream        *input,
                                                 gint                 count,
                                                 GError             **error);
 
+gboolean                psd_read_len           (GInputStream        *input,
+                                                gsize               *data,
+                                                gint                 psd_version,
+                                                GError            **error);
+
 gboolean                psd_seek               (GInputStream        *input,
                                                 goffset              offset,
                                                 GSeekType            type,


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