[cairo-commit] src/cairo-color.c test/reference

Søren Sandmann Pedersen sandmann at kemper.freedesktop.org
Tue Oct 22 11:29:11 PDT 2013


 src/cairo-color.c                                  |   11 +++--------
 test/reference/pthread-similar.ref.png             |binary
 test/reference/record-paint-alpha.ref.png          |binary
 test/reference/record90-paint-alpha.argb32.ref.png |binary
 test/reference/record90-paint-alpha.rgb24.ref.png  |binary
 test/reference/xcb-huge-image-shm.ref.png          |binary
 test/reference/xcb-huge-subimage.ref.png           |binary
 7 files changed, 3 insertions(+), 8 deletions(-)

New commits:
commit 98fef3cef2d0f7f463a2e4f9f1b35b09f7b6ea77
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date:   Wed Oct 9 15:53:16 2013 -0400

    _cairo_color_double_to_short(): Use standard rounding algorithm
    
    The _cairo_color_double_to_short() function converts a double
    precision floating point value in the range of [0.0, 1.0] to a
    uint16_t integer by dividing the [0.0, 1.0] range into 65536
    equal-sized intervals and then associating each interval with an
    integer.
    
    Under the assumption that an integer i corresponds to the real value i
    / 65535.0 this algorithm introduces more error than necessary as can
    be seen from the following picture showing the analogous
    transformation for two-bit integers:
    
        +-----------+-----------+-----------+-----------+
       0b00         |  0b01     |      0b10 |          0b11
        +-----------+-----------+-----------+-----------+
    
    which shows that some floating point values are not converted to the
    integer that would minimize the error in value that that integer
    corresponds to.
    
    Instead, this patch uses standard rounding, which makes the diagram
    look like this:
    
        +-------+---------------+---------------+-------+
       0b00     |      0b01     |      0b10     |      0b11
        +-------+---------------+---------------+-------+
    
    It's clear that if the values corresponding to the given integers are
    fixed, then it's not possible to decrease the resulting error by
    moving any of the interval boundaries.
    
    See this thread for more information:
    
        http://lists.freedesktop.org/archives/cairo/2013-October/024691.html
    
    Reference images updated:
    
      pthread-similar.ref.png
      record-paint-alpha.ref.png
      record90-paint-alpha.argb32.ref
      record90-paint-alpha.rgb24.ref.png
      xcb-huge-image-shm.ref.png
      xcb-huge-subimage.ref.png
    
    All of these have only one-step differences to the old images.

diff --git a/src/cairo-color.c b/src/cairo-color.c
index 9c85255..c2a11a1 100644
--- a/src/cairo-color.c
+++ b/src/cairo-color.c
@@ -78,18 +78,13 @@ _cairo_stock_color (cairo_stock_t stock)
 }
 
 /* Convert a double in [0.0, 1.0] to an integer in [0, 65535]
- * The conversion is designed to divide the input range into 65536
- * equally-sized regions. This is achieved by multiplying by 65536 and
- * then special-casing the result of an input value of 1.0 so that it
- * maps to 65535 instead of 65536.
+ * The conversion is designed to choose the integer i such that
+ * i / 65535.0 is as close as possible to the input value.
  */
 uint16_t
 _cairo_color_double_to_short (double d)
 {
-    uint32_t i;
-    i = (uint32_t) (d * 65536);
-    i -= (i >> 16);
-    return i;
+    return d * 65535.0 + 0.5;
 }
 
 static void
diff --git a/test/reference/pthread-similar.ref.png b/test/reference/pthread-similar.ref.png
index a22210d..c8763ba 100644
Binary files a/test/reference/pthread-similar.ref.png and b/test/reference/pthread-similar.ref.png differ
diff --git a/test/reference/record-paint-alpha.ref.png b/test/reference/record-paint-alpha.ref.png
index ab7ce3e..487b8b6 100644
Binary files a/test/reference/record-paint-alpha.ref.png and b/test/reference/record-paint-alpha.ref.png differ
diff --git a/test/reference/record90-paint-alpha.argb32.ref.png b/test/reference/record90-paint-alpha.argb32.ref.png
index 57aa95d..5e9cb58 100644
Binary files a/test/reference/record90-paint-alpha.argb32.ref.png and b/test/reference/record90-paint-alpha.argb32.ref.png differ
diff --git a/test/reference/record90-paint-alpha.rgb24.ref.png b/test/reference/record90-paint-alpha.rgb24.ref.png
index 57aa95d..5e9cb58 100644
Binary files a/test/reference/record90-paint-alpha.rgb24.ref.png and b/test/reference/record90-paint-alpha.rgb24.ref.png differ
diff --git a/test/reference/xcb-huge-image-shm.ref.png b/test/reference/xcb-huge-image-shm.ref.png
index a0b24c8..5c274f8 100644
Binary files a/test/reference/xcb-huge-image-shm.ref.png and b/test/reference/xcb-huge-image-shm.ref.png differ
diff --git a/test/reference/xcb-huge-subimage.ref.png b/test/reference/xcb-huge-subimage.ref.png
index a0b24c8..5c274f8 100644
Binary files a/test/reference/xcb-huge-subimage.ref.png and b/test/reference/xcb-huge-subimage.ref.png differ


More information about the cairo-commit mailing list