[FFmpeg-devel] [PATCH 1/3] Indeo 5 decoder: common functions

Maxim max_pole
Mon Jan 18 00:52:30 CET 2010


M?ns Rullg?rd schrieb:
> Maxim <max_pole at gmx.de> writes:
>
>   
>> Reimar D?ffinger schrieb:
>>     
>>> [...]
>>>       
>>>> static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
>>>>     
>>>>         
>>> No documentation.
>>>
>>>   
>>>       
>>>> /** convert unsigned values into signed ones (the sign is in the LSB) */
>>>> /* TODO: find a way to calculate this without the conditional using bit magic */
>>>> #define IVI_TOSIGNED(val) (((val) & 1) ? ((val) + 1) >> 1 : -(((val) + 1) >> 1))
>>>>     
>>>>         
>>> I'm sure this kind of code is already in other decoders.
>>> However the + 1 in the part after : sure is useless.
>>> Also I strongly suggest to make this a static inline function.
>>> And bit magic to do it should be
>>> ((sign_extend(val & 1, 1) ^ val) >> 1) + 1
>>>   
>>>       
>> Ok, I suggest the following bitexact replacement:
>>
>> -((val >> 1) ^ -(val & 1));
>>     
>
> Is val signed or unsigned there?
>
>   

It's unsigned and ranges between 0...16383.
Since entropy coding usually operates on unsigned values the way to code
a signed one is to incorporate the sign somewhere, for example, in the
LSB as it was done in indeo. The macro above unpacks the original signed
value from its unsigned code.

Regards
Maxim



More information about the ffmpeg-devel mailing list