[XviD-devel]

suxen_drol suxen_drol at hotmail.com
Fri Mar 28 06:40:43 CET 2003


On Wed, 26 Mar 2003 20:07:24 +0800 ÃÏ¿Â <ke_ke_ke at 263.net> wrote:

> Hi,
>    I'm reading the source code of xvidcore-0.9.1. There is something in src\motion\sad.c making me a little puzzled.Can anyone help me?
>    The part annoying me is listed here:
> uint32_t
> sad16bi_c(const uint8_t * const cur,
>     const uint8_t * const ref1,
>     const uint8_t * const ref2,
>     const uint32_t stride)
> {
> 
>  uint32_t sad = 0;
>  uint32_t i, j;
>  uint8_t const *ptr_cur = cur;
>  uint8_t const *ptr_ref1 = ref1;
>  uint8_t const *ptr_ref2 = ref2;
> 
>  for (j = 0; j < 16; j++) {
> 
>   for (i = 0; i < 16; i++) {
>    int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2;
> 
>    if (pixel < 0) {
>     pixel = 0;
>    } else if (pixel > 255) {
>     pixel = 255;
>    }
>     Since ptr_ref1[i] and ptr_ref2[i] are two unsigned byte,why   is it possible that pixel < 0 or pixel > 255 ?Thanks very much

this is bounds check indeed unnecessary.
(255+255+1) / 2 = 255

-- pete; life is like a box of ammo





More information about the XviD-devel mailing list