diff options
author | David Schleef <ds@schleef.org> | 2012-02-19 00:15:47 -0800 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2012-02-19 00:16:31 -0800 |
commit | e0db2faa12e84eeb87ab2ea9c1302d0f0661a30d (patch) | |
tree | 61fa7279aefbdbbdac5fe85cd4bc6ca667f9b8f7 | |
parent | 8f8d7bf78159e0329d3efc329a575335afab90b9 (diff) | |
download | gstreamer-plugins-bad-e0db2faa12e84eeb87ab2ea9c1302d0f0661a30d.tar.gz |
colorspace: clamp intermediates when dithering
-rw-r--r-- | gst/colorspace/colorspace.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/gst/colorspace/colorspace.c b/gst/colorspace/colorspace.c index e1f630275..79ff31dad 100644 --- a/gst/colorspace/colorspace.c +++ b/gst/colorspace/colorspace.c @@ -1823,10 +1823,14 @@ colorspace_dither_verterr (ColorspaceConvert * convert, int j) int i; guint16 *tmpline = convert->tmpline16; guint16 *errline = convert->errline; + unsigned int mask = 0xff; for (i = 0; i < 4 * convert->width; i++) { - tmpline[i] += errline[i]; - errline[i] = tmpline[i] & 0xff; + int x = tmpline[i] + errline[i]; + if (x > 65535) + x = 65535; + tmpline[i] = x; + errline[i] = x & mask; } } @@ -1847,7 +1851,11 @@ colorspace_dither_halftone (ColorspaceConvert * convert, int j) }; for (i = 0; i < convert->width * 4; i++) { - tmpline[i] += halftone[(i >> 2) & 7][j & 7]; + int x; + x = tmpline[i] + halftone[(i >> 2) & 7][j & 7]; + if (x > 65535) + x = 65535; + tmpline[i] = x; } } |