[Ffmpeg-devel] [PATCH] BMP encoder

Michael Niedermayer michaelni
Mon Oct 30 18:00:50 CET 2006


Hi

On Mon, Oct 30, 2006 at 05:36:24PM +0100, Michel Bardiaux wrote:
> 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.

hmm ok but please at least dont interleave the write32() and the comments
this is confusing, rather put the comments to the right of the write32() and
nicely aligned ...


> 
> >
> >
> >>+    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.

to put 8bit a simple uint8_t will do ...
for 16bit a simple uint16_t with le2me_16() will do as long as its
aligned and i think it is ...
same for 32bit
if its not aligned then there are ST16() ST32() in dsputil.h, they could
be moved into a bytesomething.h (in a seperate patch ...)


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is




More information about the ffmpeg-devel mailing list