videoconvert: clamp intermediates when dithering

Port from the colorspace plugin in -bad.
This commit is contained in:
David Schleef 2012-02-20 16:10:22 +01:00 committed by Wim Taymans
parent 4370d42cb9
commit bb19c41081

View file

@ -1783,10 +1783,14 @@ videoconvert_dither_verterr (VideoConvert * convert, int j)
int i; int i;
guint16 *tmpline = convert->tmpline16; guint16 *tmpline = convert->tmpline16;
guint16 *errline = convert->errline; guint16 *errline = convert->errline;
unsigned int mask = 0xff;
for (i = 0; i < 4 * convert->width; i++) { for (i = 0; i < 4 * convert->width; i++) {
tmpline[i] += errline[i]; int x = tmpline[i] + errline[i];
errline[i] = tmpline[i] & 0xff; if (x > 65535)
x = 65535;
tmpline[i] = x;
errline[i] = x & mask;
} }
} }
@ -1807,7 +1811,11 @@ videoconvert_dither_halftone (VideoConvert * convert, int j)
}; };
for (i = 0; i < convert->width * 4; i++) { 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;
} }
} }