[gnumeric] xlsx: fix parsing of alpha colour.



commit f86f9ced94a7ebafb1fb051d0d7f539d1ded5ec2
Author: Morten Welinder <terra gnome org>
Date:   Sat Mar 28 16:45:19 2015 -0400

    xlsx: fix parsing of alpha colour.

 plugins/excel/ChangeLog            |    1 +
 plugins/excel/xlsx-read-drawing.c  |    3 ++-
 plugins/excel/xlsx-write-drawing.c |    4 ++--
 3 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 794d92c..c9280da 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -2,6 +2,7 @@
 
        * xlsx-read-drawing.c (xlsx_axis_crossax): Improve parsing.  Take
        default values of many enum attributes into account.
+       (xlsx_draw_color_alpha): Fix clamping.
 
 2015-03-23  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 37e7211..2eeb81e 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -2016,7 +2016,8 @@ xlsx_draw_color_alpha (GsfXMLIn *xin, xmlChar const **attrs)
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        unsigned val;
        if (simple_uint (xin, attrs, &val)) {
-               int level = 255 * CLAMP (val, 0, 10000000) / 100000;
+               const unsigned scale = 100000u;
+               int level = 255u * CLAMP (val, 0u, scale) / scale;
                state->color = GO_COLOR_CHANGE_A (state->color, level);
                color_set_helper (state);
        }
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 52f4327..da6bd6d 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -119,13 +119,13 @@ static void
 xlsx_write_rgbarea (GsfXMLOut *xml, GOColor color)
 {
        char *buf = g_strdup_printf ("%06x", (guint) color >> 8);
-       int alpha = GO_COLOR_UINT_A (color);
+       unsigned alpha = GO_COLOR_UINT_A (color);
        gsf_xml_out_start_element (xml, "a:srgbClr");
        gsf_xml_out_add_cstr_unchecked (xml, "val", buf);
        g_free (buf);
        if (alpha < 255) {
                gsf_xml_out_start_element (xml, "a:alpha");
-               gsf_xml_out_add_int (xml, "val", alpha * 100000 / 255);
+               gsf_xml_out_add_uint (xml, "val", alpha * 100000u / 255u);
                gsf_xml_out_end_element (xml);
        }
        gsf_xml_out_end_element (xml);


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