[Ffmpeg-devel] [PATCH]BMP encoder

Alex Beregszaszi alex
Tue Jan 23 15:33:52 CET 2007


Hi,

> +#define read16(bits) bswap_16(get_bits(bits, 16))
> +#define read32(bits) bswap_32(get_bits_long(bits, 32))
...
> +#define write16(bits, val) put_bits(bits, 16, bswap_16(val))
> +#define write32(bits, val) put_bits(bits, 32, bswap_32(val))

What about using bytestream.h or intreadwrite.h instead this? I dont see
its putting/reading non-8bit aligned data:

> +    init_put_bits(&bits, buf, buf_size);
> +
> +    // STRUCTURE.field refer to the MSVC documentation for BITMAPFILEHEADER
> +    // and related pages.
> +    put_bits(&bits, 8, 'B');       // BITMAPFILEHEADER.bfType
> +    put_bits(&bits, 8, 'M');       // do.
> +    write32(&bits, n_bytes);       // BITMAPFILEHEADER.bfSize
> +    write16(&bits, 0);             // BITMAPFILEHEADER.bfReserved1
> +    write16(&bits, 0);             // BITMAPFILEHEADER.bfReserved2
> +    hsize = 14 /* BITMAPFILEHEADER */ + 40;
> +    write32(&bits, hsize);         // BITMAPFILEHEADER.bfOffBits
> +    write32(&bits, 40);            // BITMAPINFOHEADER.biSize
> +    write32(&bits, avctx->width);  // BITMAPINFOHEADER.biWidth
> +    write32(&bits, avctx->height); // BITMAPINFOHEADER.biHeight
> +    write16(&bits, 1);             // BITMAPINFOHEADER.biPlanes
> +    write16(&bits, 24);            // BITMAPINFOHEADER.biBitCount
> +    write32(&bits, BMP_RGB);       // BITMAPINFOHEADER.biCompression
> +    write32(&bits, n_bytes_image); // BITMAPINFOHEADER.biSizeImage
> +    write32(&bits, 0);             // BITMAPINFOHEADER.biXPelsPerMeter
> +    write32(&bits, 0);             // BITMAPINFOHEADER.biYPelsPerMeter
> +    write32(&bits, 0);             // BITMAPINFOHEADER.biClrUsed
> +    write32(&bits, 0);             // BITMAPINFOHEADER.biClrImportant
> +    // BMP files are bottom-to-top so we start from the end...
> +    ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
> +    buf += hsize;
> +    for(i = 0; i < avctx->height; i++) {
> +        n = 3*avctx->width;
> +        memcpy(buf, ptr, n);
> +        buf += n;
> +        memset(buf, 0, n_bytes_per_row-n);
> +        buf += n_bytes_per_row-n;
> +        ptr -= p->linesize[0]; // ... and go back
> +    }

--
Alex Beregszaszi





More information about the ffmpeg-devel mailing list