[FFmpeg-soc] [soc]: r282 - in jpeg2000: checkout.sh ffmpeg.patch j2k.h j2kenc.c

Loren Merritt lorenm at u.washington.edu
Wed Jul 4 03:31:26 CEST 2007


On Tue, 3 Jul 2007, ods15 at ods15.dyndns.org wrote:

> On Sat, Jun 30, 2007 at 04:35:10PM +0200, Kamil Nowosad wrote:
>> Hi
>>
>> On Mon, Jun 25, 2007 at 02:07:04PM +0200, Michael Niedermayer wrote:
>>>> +/* bitstream routines */
>>>> +
>>>> +/* put n times val bit */
>>>> +static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize
>>>> +{
>>>> +    while (n-- > 0){
>>>> +        if (s->bit_index == 8)
>>>> +        {
>>>> +            s->bit_index = *s->buf == 0xff ? 1:0;
>>>> +            *(++s->buf) = 0;
>>>> +        }
>>>> +        *s->buf |= val << (7 - s->bit_index++);
>>>> +    }
>>>> +}
>>>> +
>>>> +/* put n least significant bits of a number num */
>>>> +static void put_num(J2kEncoderContext *s, int num, int n)
>>>> +{
>>>> +    while(--n >= 0)
>>>> +        put_bits(s, (num & (1<<n)) ? 1:0, 1);
>>>> +}
>>>
>>> maybe something from libavcodec/bitstream.h could be used?
>>
>> I've read that through, but unfortunately nothing looked useful for me.
>
> Umm, am I missing something, or would this work?
>
> put_bits(s, num & ((1<<n)-1), n);

If you do that, then you have to run another pass over the compressed data 
to perform the "bit-stuffing". If any byte is 0xff, then insert a 0 bit 
after it.
Much like h264's startcode emulation prevention, except slower to perform 
separately because it doesn't maintain byte alignment.

--Loren Merritt



More information about the FFmpeg-soc mailing list