[FFmpeg-devel] [PATCH] Add 1bpp, 8bpp, 15bpp, and 16bpp support to BMP encoder
Michael Niedermayer
michaelni
Thu Mar 12 16:01:22 CET 2009
On Wed, Mar 11, 2009 at 10:33:13PM -0400, Daniel Verkamp wrote:
> On Wed, Mar 11, 2009 at 9:25 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Wed, Mar 11, 2009 at 05:47:57PM -0400, Daniel Verkamp wrote:
> >> On Tue, Mar 10, 2009 at 6:14 PM, Stefan Gehrer <stefan.gehrer at gmx.de> wrote:
> >> > Daniel Verkamp wrote:
> >> > + ? ?n_bytes_per_row = (avctx->width * bit_count) >> 3;
> >> > + ? ?pad_bytes_per_row = (4 - n_bytes_per_row) & 3;
> >> > + ? ?n_bytes_image = avctx->height * (n_bytes_per_row + pad_bytes_per_row);
> >> >
> >> > For the case of PIX_FMT_MONOBLACK, a picture that is e.g. 36 pixels
> >> > wide would only get 32 bit allocated for a line. Could that become
> >> > a problem?
> >> >
> >> > Maybe
> >> >
> >> > n_bytes_per_row = (avctx->width * bit_count + 7) >> 3;
> >> >
> >> > would be enough to fix that.
> >> >
> >> > Stefan
> >>
> >> Indeed, I didn't think the < 8 bit case through thoroughly enough -
> >> fixed as you said.
> >>
> >> Also changed in this round: masked palette entries to avoid any alpha
> >> bits in the high byte leaking out, removed trailing whitespace from
> >> one line.
> > [...]
> >
> >> @@ -37,19 +41,52 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
> >> ? ? ?AVFrame *pict = data;
> >> ? ? ?AVFrame * const p= (AVFrame*)&s->picture;
> >> ? ? ?int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize;
> >> + ? ?const uint32_t *pal = NULL;
> >> + ? ?int pad_bytes_per_row, bit_count, pal_entries = 0, compression = BMP_RGB;
> >> ? ? ?uint8_t *ptr;
> >> ? ? ?unsigned char* buf0 = buf;
> >> ? ? ?*p = *pict;
> >> ? ? ?p->pict_type= FF_I_TYPE;
> >> ? ? ?p->key_frame= 1;
> >> - ? ?n_bytes_per_row = (avctx->width*3 + 3) & ~3;
> >> - ? ?n_bytes_image = avctx->height*n_bytes_per_row;
> >> + ? ?switch (avctx->pix_fmt) {
> >> + ? ?case PIX_FMT_BGR24:
> >> + ? ? ? ?bit_count = 24;
> >> + ? ? ? ?break;
> >> + ? ?case PIX_FMT_RGB555:
> >> + ? ? ? ?bit_count = 16;
> >> + ? ? ? ?break;
> >> + ? ?case PIX_FMT_RGB565:
> >> + ? ? ? ?bit_count = 16;
> >> + ? ? ? ?compression = BMP_BITFIELDS;
> >> + ? ? ? ?pal = rgb565_masks; // abuse pal to hold color masks
> >> + ? ? ? ?pal_entries = 3;
> >> + ? ? ? ?break;
> >> + ? ?case PIX_FMT_RGB8:
> >> + ? ?case PIX_FMT_BGR8:
> >> + ? ?case PIX_FMT_RGB4_BYTE:
> >> + ? ?case PIX_FMT_BGR4_BYTE:
> >> + ? ?case PIX_FMT_GRAY8:
> >> + ? ?case PIX_FMT_PAL8:
> >> + ? ? ? ?bit_count = 8;
> >> + ? ? ? ?pal = (uint32_t *)p->data[1];
> >> + ? ? ? ?break;
> >> + ? ?case PIX_FMT_MONOBLACK:
> >> + ? ? ? ?bit_count = 1;
> >> + ? ? ? ?pal = monoblack_pal;
> >> + ? ? ? ?break;
> >> + ? ?default:
> >> + ? ? ? ?return -1;
> >> + ? ?}
> >> + ? ?if (pal && !pal_entries) pal_entries = 1 << bit_count;
> >
> >> + ? ?n_bytes_per_row = (avctx->width * bit_count + 7) >> 3;
> >
> > must be done in 64bit to be sure it doesnt overflow
> >
>
> Fixed.
>
> > also is the available space checked to avoid buffer overflows?
> >
>
> I think this handles it:
patch looks ok
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090312/da58c3c1/attachment.pgp>
More information about the ffmpeg-devel
mailing list