[gnumeric] StyleColor: fix potential roundtrip-via-GdkRGBA problem.



commit 3ee319264a1a719621cf48395aafeab79f828f57
Author: Morten Welinder <terra gnome org>
Date:   Fri Jun 15 11:27:07 2012 -0400

    StyleColor: fix potential roundtrip-via-GdkRGBA problem.

 ChangeLog         |    5 +++++
 src/style-color.c |   10 +++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ee58db6..e0744f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-06-15  Morten Welinder  <terra gnome org>
+
+	* src/style-color.c (style_color_new_gdk): Improve roundtrip.
+	[#667484]
+
 2012-06-14  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/sheet-object.c (sheet_objects_clear): filter-combos are not
diff --git a/src/style-color.c b/src/style-color.c
index 387a1fc..f635c29 100644
--- a/src/style-color.c
+++ b/src/style-color.c
@@ -60,7 +60,15 @@ style_color_new_pango (PangoColor const *c)
 GnmColor *
 style_color_new_gdk (GdkRGBA const *c)
 {
-	return style_color_new_i8 (c->red * 255, c->green * 255, c->blue * 255);
+	/*
+	 * The important property here is that a color #rrggbb
+	 * (i.e., an 8-bit color) roundtrips correctly when
+	 * translated into GdkRGBA using /255 and back.  Using
+	 * multiplication by 256 here makes rounding unnecessary.
+	 */
+	return style_color_new_i8 (CLAMP (c->red * 256, 0, 255),
+				   CLAMP (c->green * 256, 0, 255),
+				   CLAMP (c->blue * 256, 0, 255));
 }
 
 GnmColor *



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