summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-04-05 00:42:55 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-04-20 10:17:13 -0400
commit4d2fee14063b960c6b81b55dd3aa94b956d23eeb (patch)
tree829b7e9e460eb381868d8e61efcc00ad34a5574f
parente2917645846b64fdc7f2190806c97b0ef4b0fd5b (diff)
test/utils.c: Clip values to the [0, 255] interval
Unpremultiplying a superluminescent pixel can result in values greater than 255.
-rw-r--r--test/utils.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/test/utils.c b/test/utils.c
index cc0365aa..c1bf6dc2 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -358,9 +358,16 @@ a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels)
if (a != 0)
{
- r = (r * 255) / a;
- g = (g * 255) / a;
- b = (b * 255) / a;
+#define DIVIDE(c, a) \
+ do \
+ { \
+ int t = ((c) * 255) / a; \
+ (c) = t < 0? 0 : t > 255? 255 : t; \
+ } while (0)
+
+ DIVIDE (r, a);
+ DIVIDE (g, a);
+ DIVIDE (b, a);
}
*dst8++ = r;