[Ffmpeg-devel] [PATCH] BMP encoder

Michel Bardiaux mbardiaux
Mon Oct 30 17:36:24 CET 2006


Michael Niedermayer wrote:
> Hi
> 
> On Mon, Oct 30, 2006 at 04:05:39PM +0100, Michel Bardiaux wrote:
>> Currently, only straight RGB.
> [...]
>> +    init_put_bits(&s->pb, buf, buf_size);
>> +    // STRUCTURE.field refer to the MSVC documentation
>> +    // BITMAPFILEHEADER.bfType
>> +    put_bits(&s->pb, 8, 'B');
>> +    put_bits(&s->pb, 8, 'M');
>> +    // BITMAPFILEHEADER.bfSize
>> +    write32(&s->pb, n_bytes);
>> +    // BITMAPFILEHEADER.bfReserved1
>> +    write16(&s->pb, 0);
>> +    // BITMAPFILEHEADER.bfReserved2
>> +    write16(&s->pb, 0);
>> +    // BITMAPFILEHEADER.bfOffBits
>> +    write32(&s->pb, 14 /* BITMAPFILEHEADER */ + 40);
>> +    // BITMAPINFOHEADER.biSize
>> +    write32(&s->pb, 40);
>> +    // BITMAPINFOHEADER.biWidth
>> +    write32(&s->pb, avctx->width);
>> +    // BITMAPINFOHEADER.biHeight
>> +    write32(&s->pb, avctx->height);
>> +    // BITMAPINFOHEADER.biPlanes
>> +    write16(&s->pb, 1);
>> +    // BITMAPINFOHEADER.biBitCount
>> +    write16(&s->pb, 24);
>> +    // BITMAPINFOHEADER.biCompression
>> +    write32(&s->pb, BMP_RGB);
>> +    // BITMAPINFOHEADER.biSizeImage
>> +    write32(&s->pb, n_bytes_image);
>> +    // BITMAPINFOHEADER.biXPelsPerMeter
>> +    write32(&s->pb, 0);
>> +    // BITMAPINFOHEADER.biYPelsPerMeter
>> +    write32(&s->pb, 0);
>> +    // BITMAPINFOHEADER.biClrUsed
>> +    write32(&s->pb, 0);
>> +    // BITMAPINFOHEADER.biClrImportant
> 
> see put_bmp_header()

Right, I have recoded the wheel. But I cant use it unchanged; first 
because it is in libavformat, second because it seems intimately linked 
to asf and avi.

I see 2 ways: recode it in the bmp encoder; or define our own bitmap 
structures to separate setting the values and writing them. For the time 
being I will take the 1st way.

> 
> 
>> +    write32(&s->pb, 0);
>> +    // BMP files are bottom-to-top
>> +    ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
>> +    linesize = -p->linesize[0];
>> +    for(i = 0; i < avctx->height; i++){
>> +        uint8_t *src = ptr;
>> +        int n = 0;
>> +        for(j=0;j<avctx->width;j++) {
>> +            put_bits(&s->pb, 8, src[0]);
>> +            put_bits(&s->pb, 8, src[1]);
>> +            put_bits(&s->pb, 8, src[2]);
> 
> using the bitstream reader for a purely byte based format is unacceptable
> (reason is that its several times slower and more complex)

Right. Will change to use put_le16 etc. But see above.

> 
> 
>> +            src += 3;
>> +            n += 3;
>> +        }
>> +        for(;n<n_bytes_per_row;n++) put_bits(&s->pb, 8, 0);
>> +        ptr += linesize;
>> +    }
>> +    return n_bytes;
>> +}
> 
> [...]
> 
>> Index: libavcodec/amr.c
>> ===================================================================
>> --- libavcodec/amr.c	(revision 6838)
>> +++ libavcodec/amr.c	(working copy)
>> @@ -57,6 +57,8 @@
>>  
>>  #include "avcodec.h"
>>  
>> +#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED)
>> +
>>  #ifdef CONFIG_AMR_NB_FIXED
>>  
>>  #define MMS_IO
>> @@ -494,8 +496,6 @@
>>  
>>  #endif
>>  
>> -#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED)
>> -
>>  AVCodec amr_nb_decoder =
>>  {
>>      "amr_nb",
> 
> huh? what is this?

An unrelated work that indeed has nothing to do in that patch.

> 
> [...]
> 


-- 
Michel Bardiaux
R&D Director
T +32 [0] 2 790 29 41
F +32 [0] 2 790 29 02
E mailto:mbardiaux at mediaxim.be

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/




More information about the ffmpeg-devel mailing list