[gnumeric] xls: simplify image reading.



commit c0cb29faeb0e358a7babe1ebef408beaa4ce352a
Author: Morten Welinder <terra gnome org>
Date:   Sat Feb 22 17:18:39 2014 -0500

    xls: simplify image reading.
    
    Handling BIFF_CONTINUE in ms-biff.c makes for much more
    readable code.

 plugins/excel/ChangeLog       |    6 ++++++
 plugins/excel/ms-biff.c       |    4 ++++
 plugins/excel/ms-excel-read.c |   34 +++++-----------------------------
 3 files changed, 15 insertions(+), 29 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 8319f02..fe7be0c 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,11 @@
 2014-02-22  Morten Welinder  <terra gnome org>
 
+       * ms-excel-read.c (excel_read_IMDATA): No need to handle
+       BIFF_CONTINUE here.
+
+       * ms-biff.c (ms_biff_query_next): Handle BIFF_CONTINUE for images,
+       headers, and footers.
+
        * ms-formula-read.c (undo_save_hacks): Undo the
        long-string-constant hack in write_string.
 
diff --git a/plugins/excel/ms-biff.c b/plugins/excel/ms-biff.c
index 5d30740..734b48e 100644
--- a/plugins/excel/ms-biff.c
+++ b/plugins/excel/ms-biff.c
@@ -512,6 +512,10 @@ ms_biff_query_next (BiffQuery *q)
        case BIFF_FORMULA_v2:
        case BIFF_STRING_v0:
        case BIFF_STRING_v2:
+       case BIFF_HEADER:
+       case BIFF_FOOTER:
+       case BIFF_BG_PIC:
+       case BIFF_IMDATA:
                auto_continue = TRUE;
                break;
        case BIFF_CONTINUE:
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 9d94e0c..f3b4bd1 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -4395,7 +4395,6 @@ excel_read_COLINFO (BiffQuery *q, ExcelReadSheet *esheet)
 static GdkPixbuf *
 excel_read_os2bmp (BiffQuery *q, guint32 image_len)
 {
-       guint16 op;
        GError *err = NULL;
        GdkPixbufLoader *loader = NULL;
        GdkPixbuf       *pixbuf = NULL;
@@ -4410,14 +4409,6 @@ excel_read_os2bmp (BiffQuery *q, guint32 image_len)
        if (ret)
                ret = gdk_pixbuf_loader_write (loader, q->data+8,
                                               q->length-8, &err);
-       image_len += 8;
-       while (ret &&  image_len > q->length &&
-              ms_biff_query_peek_next (q, &op) && op == BIFF_CONTINUE) {
-               image_len -= q->length;
-               ms_biff_query_next (q);
-               ret = gdk_pixbuf_loader_write (loader, q->data, q->length,
-                                              &err);
-       }
        gdk_pixbuf_loader_close (loader, ret ? &err : NULL);
        if (ret) {
                pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
@@ -4459,10 +4450,6 @@ excel_read_IMDATA (BiffQuery *q, gboolean keep_image)
 
        /* Dump formats which weren't handled above to file */
        if (format != 0x9) {
-               guint16 op;
-               static int count = 0;
-               FILE *f = NULL;
-               char *file_name;
                char const *from_name;
                char const *format_name;
                guint16 const format   = GSF_LE_GET_GUINT16 (q->data);
@@ -4482,27 +4469,16 @@ excel_read_IMDATA (BiffQuery *q, gboolean keep_image)
                default: format_name = "Unknown format?"; break;
                }
 
-               d (1, { /* WARNING KEEP THIS DEBUG THE SAME AS BELOW */
+               d (1, {
+                               FILE *f;
+                               static int count = 0;
+                               char *file_name = g_strdup_printf ("imdata%d", count++);
                                g_printerr ("Picture from %s in %s format\n",
                                            from_name, format_name);
 
-                               file_name = g_strdup_printf ("imdata%d", count++);
                                f = g_fopen (file_name, "w");
                                fwrite (q->data+8, 1, q->length-8, f);
                                g_free (file_name);
-                       });
-
-               image_len += 8;
-               while (image_len > q->length &&
-                      ms_biff_query_peek_next (q, &op) &&
-                      op == BIFF_CONTINUE) {
-                       image_len -= q->length;
-                       ms_biff_query_next (q);
-                       d (1, { /* WARNING KEEP THIS DEBUG THE SAME AS ABOVE */
-                                       fwrite (q->data, 1, q->length, f);
-                               });
-               }
-               d (1, { /* WARNING KEEP THIS DEBUG THE SAME AS ABOVE */
                                fclose (f);
                        });
        }
@@ -6675,8 +6651,8 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer,
                        GdkPixbuf *pixbuf = excel_read_IMDATA (q, FALSE);
                        if (pixbuf)
                                g_object_unref (pixbuf);
-               }
                        break;
+               }
                case BIFF_GUTS:         excel_read_GUTS (q, esheet);            break;
                case BIFF_WSBOOL:       excel_read_WSBOOL (q, esheet);          break;
                case BIFF_GRIDSET:              break;


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