[MPlayer-dev-eng] [PATCH] si2us() in libaf is off-by-one
dega
deganews at quickclic.net
Wed Sep 7 06:39:26 CEST 2005
si2us() is biased by -1, turning -128 => 255 and 127 => 254 (for 8-bit)
instead of -128 => 0 and 127 => 255. It makes the same kind of mistake for
all other sample widths as well.
Obviously, this causes nasty pops in the output stream if one should ever
encounter extreme values in the input stream. (Discovered during ao_sgi
testing)
Here is the patch.
dega
Index: libaf/af_format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.c,v
retrieving revision 1.29
diff -u -r1.29 af_format.c
--- libaf/af_format.c 1 May 2005 09:02:25 -0000 1.29
+++ libaf/af_format.c 7 Sep 2005 04:42:28 -0000
@@ -392,19 +392,19 @@
switch(bps){
case(1):
for(i=0;i<len;i++)
- ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i]));
+ ((uint8_t*)out)[i]=(uint8_t)(((int)((int8_t*)in)[i])-SCHAR_MIN);
break;
case(2):
for(i=0;i<len;i++)
- ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i]));
+ ((uint16_t*)out)[i]=(uint16_t)(((int)((int16_t*)in)[i])-SHRT_MIN);
break;
case(3):
for(i=0;i<len;i++)
- store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i)));
+ store24bit(out, i, (uint32_t)((int32_t)load24bit(in, i)-INT_MIN));
break;
case(4):
for(i=0;i<len;i++)
- ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]);
+ ((uint32_t*)out)[i]=(uint32_t)(((int32_t*)in)[i]-INT_MIN);
break;
}
}
More information about the MPlayer-dev-eng
mailing list