summaryrefslogtreecommitdiff
path: root/pixman/pixman-bits-image.c
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-11-20 23:28:43 -0500
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-11-22 01:06:29 -0500
commit74319e9d39f5d7f85cb75fcb91343f298b0e62e2 (patch)
tree757df6a7991c983e5fdc13e53339bd04cb59debe /pixman/pixman-bits-image.c
parentf0816ddaf4e61d9295de5b1cbe51f956db7fbd16 (diff)
Convolution filter: round color values instead of truncating
The pixel computed by the convolution filter should be rounded off, not truncated. As a simple example consider a convolution matrix consisting of five times 0x3333. If all five all five input pixels are 0xff, then the result of truncating will be (5 * 0x3333 * 255) >> 16 = 254 But the real value of the computation is (5 * 0x3333 / 65536.0) * 254 = 254.9961, so the error is almost 1. If the user isn't very careful about normalizing the convolution kernel so that it sums to one in fixed point, such error might cause solid images to change color, or opaque images to become translucent. The fix is simply to round instead of truncate.
Diffstat (limited to 'pixman/pixman-bits-image.c')
-rw-r--r--pixman/pixman-bits-image.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
index 085dd16..7787ef1 100644
--- a/pixman/pixman-bits-image.c
+++ b/pixman/pixman-bits-image.c
@@ -413,10 +413,10 @@ bits_image_fetch_pixel_convolution (bits_image_t *image,
}
}
- satot >>= 16;
- srtot >>= 16;
- sgtot >>= 16;
- sbtot >>= 16;
+ satot = (satot + 0x8000) >> 16;
+ srtot = (srtot + 0x8000) >> 16;
+ sgtot = (sgtot + 0x8000) >> 16;
+ sbtot = (sbtot + 0x8000) >> 16;
satot = CLIP (satot, 0, 0xff);
srtot = CLIP (srtot, 0, 0xff);