[gimp/gimp-2-10] plug-ins: refactor reading of raster layer extension info for psp images.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] plug-ins: refactor reading of raster layer extension info for psp images.
- Date: Mon, 31 Aug 2020 12:12:38 +0000 (UTC)
commit a4344fff7b1f06758a257a94adfbf9771cd90468
Author: Jacob Boerema <jgboerema gmail com>
Date: Sun Aug 30 16:44:04 2020 -0400
plug-ins: refactor reading of raster layer extension info for psp images.
(cherry picked from commit 0666f7a)
plug-ins/common/file-psp.c | 65 ++++++++++++++++++++++++++++++----------------
1 file changed, 42 insertions(+), 23 deletions(-)
---
diff --git a/plug-ins/common/file-psp.c b/plug-ins/common/file-psp.c
index 023655e036..cef1a48d64 100644
--- a/plug-ins/common/file-psp.c
+++ b/plug-ins/common/file-psp.c
@@ -1302,6 +1302,40 @@ read_channel_data (FILE *f,
return 0;
}
+static gboolean
+read_raster_layer_info (FILE *f,
+ long layer_extension_start,
+ guint16 *bitmap_count,
+ guint16 *channel_count,
+ GError **error)
+{
+ guint32 layer_extension_len;
+
+ if (fseek (f, layer_extension_start, SEEK_SET) < 0
+ || fread (&layer_extension_len, 4, 1, f) < 1)
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Error reading layer extension information"));
+ return FALSE;
+ }
+
+ layer_extension_len = GUINT32_FROM_LE (layer_extension_len);
+
+ if (fread (bitmap_count, 2, 1, f) < 1
+ || fread (channel_count, 2, 1, f) < 1)
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Error reading layer extension information"));
+ return FALSE;
+ }
+ if (try_fseek (f, layer_extension_start + layer_extension_len, SEEK_SET, error) < 0)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static gint
read_layer_block (FILE *f,
gint image_ID,
@@ -1314,7 +1348,7 @@ read_layer_block (FILE *f,
long layer_extension_start;
gint sub_id;
guint32 sub_init_len, sub_total_len;
- guint32 chunk_len, layer_extension_len;
+ guint32 chunk_len;
gchar *name = NULL;
gchar *layer_name = NULL;
guint16 namelen;
@@ -1387,33 +1421,24 @@ read_layer_block (FILE *f,
name[namelen] = 0;
layer_name = g_convert (name, -1, "utf-8", "iso8859-1", NULL, NULL, NULL);
g_free (name);
- chunk_len = GUINT32_FROM_LE (chunk_len);
- /* Skip remainder of layer info and read layer extension length */
+ chunk_len = GUINT32_FROM_LE (chunk_len);
layer_extension_start = sub_block_start + chunk_len;
- if (fseek(f, layer_extension_start, SEEK_SET) < 0
- || fread(&layer_extension_len, 4, 1, f) < 1)
- {
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- _("Error reading layer extension information"));
- g_free (layer_name);
- return -1;
- }
- layer_extension_len = GUINT32_FROM_LE (layer_extension_len);
+
switch (type)
{
case keGLTFloatingRasterSelection:
g_message ("Floating selection restored as normal layer (%s)", layer_name);
case keGLTRaster:
- can_handle_layer = TRUE;
- if (fread (&bitmap_count, 2, 1, f) < 1
- || fread (&channel_count, 2, 1, f) < 1)
+ if (! read_raster_layer_info (f, layer_extension_start,
+ &bitmap_count,
+ &channel_count,
+ error))
{
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- _("Error reading layer information"));
g_free (layer_name);
return -1;
}
+ can_handle_layer = TRUE;
break;
default:
bitmap_count = 0;
@@ -1421,12 +1446,6 @@ read_layer_block (FILE *f,
g_message ("Unsupported layer type %d (%s)", type, layer_name);
break;
}
-
- if (try_fseek (f, layer_extension_start + layer_extension_len, SEEK_SET, error) < 0)
- {
- g_free (layer_name);
- return -1;
- }
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]