pixman-combine32.c: Fix bugs related to integer promotion
authorSøren Sandmann Pedersen <ssp@redhat.com>
Fri, 18 Oct 2013 20:39:38 +0000 (16:39 -0400)
committerSøren Sandmann <ssp@redhat.com>
Sat, 4 Jan 2014 21:13:27 +0000 (16:13 -0500)
In the component alpha part of the PDF_SEPARABLE_BLEND_MODE macro, the
expression ~RED_8 (m) is used. Because RED_8(m) gets promoted to int
before ~ is applied, the whole expression typically becomes some
negative value rather than (255 - RED_8(m)) as desired.

Fix this by using unsigned temporary variables.

This reduces the number of failures in pixel-test to 363.

pixman/pixman-combine32.c
test/blitters-test.c

index 977c05782cb96f390d37f200be28865b32886a6f..01c2523d59f418b73c7522330747eb33a20c4f05 100644 (file)
@@ -640,13 +640,18 @@ combine_multiply_ca (pixman_implementation_t *imp,
            uint8_t da = ALPHA_8 (d);                                   \
            uint8_t ida = ~da;                                          \
            int32_t ra, rr, rg, rb;                                     \
+           uint8_t ira, iga, iba;                                      \
                                                                        \
            combine_mask_ca (&s, &m);                                   \
                                                                        \
+           ira = ~RED_8 (m);                                           \
+           iga = ~GREEN_8 (m);                                         \
+           iba = ~BLUE_8 (m);                                          \
+                                                                       \
            ra = da * 0xff + ALPHA_8 (s) * 0xff - ALPHA_8 (s) * da;     \
-           rr = (~RED_8 (m)) * RED_8 (d) + ida * RED_8 (s);            \
-           rg = (~GREEN_8 (m)) * GREEN_8 (d) + ida * GREEN_8 (s);      \
-           rb = (~BLUE_8 (m)) * BLUE_8 (d) + ida * BLUE_8 (s);         \
+           rr = ira * RED_8 (d) + ida * RED_8 (s);                     \
+           rg = iga * GREEN_8 (d) + ida * GREEN_8 (s);                 \
+           rb = iba * BLUE_8 (d) + ida * BLUE_8 (s);                   \
                                                                        \
            rr += blend_ ## name (RED_8 (d), da, RED_8 (s), RED_8 (m)); \
            rg += blend_ ## name (GREEN_8 (d), da, GREEN_8 (s), GREEN_8 (m)); \
index ac8901f00eee05d597c2e9917fc2884c71168e6b..e2a2e7fc89affb58fac2982664faf7ce3b27af25 100644 (file)
@@ -394,6 +394,6 @@ main (int argc, const char *argv[])
     }
 
     return fuzzer_test_main("blitters", 2000000,
-                           0x613BBD64,
+                           0xB1D1F40E,
                            test_composite, argc, argv);
 }