[FFmpeg-devel] [PATCH]Do not add palette size to the bitmapheader size

Michael Niedermayer michaelni at gmx.at
Mon Sep 29 12:53:48 CEST 2014

On Mon, Sep 29, 2014 at 09:33:16AM +0200, Carl Eugen Hoyos wrote:
> On Monday 29 September 2014 01:22:38 am Carl Eugen Hoyos wrote:
> > Attached patch is the first part of the fix for ticket #1304.
> New, tested patch attached.
> Please comment, Carl Eugen

>  riffenc.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> c7feae247cefeb7d71dc1f9c828c3cb598a0b106  patchpalextra2.diff
> diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
> index 2eb2ae1..723e802 100644
> --- a/libavformat/riffenc.c
> +++ b/libavformat/riffenc.c
> @@ -212,9 +212,12 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
>      int keep_height = enc->extradata_size >= 9 &&
>                        !memcmp(enc->extradata + enc->extradata_size - 9, "BottomUp", 9);
>      int extradata_size = enc->extradata_size - 9*keep_height;
> +    int palette_size = enc->pix_fmt == AV_PIX_FMT_PAL8 && extradata_size >= AVPALETTE_SIZE ?
> +                       AVPALETTE_SIZE :
> +                       0;
>      /* size */
> -    avio_wl32(pb, 40 + (ignore_extradata ? 0 :extradata_size));
> +    avio_wl32(pb, 40 + (ignore_extradata ? 0 : extradata_size - palette_size));

what if the palette size is different from AVPALETTE_SIZE ?
avidec certainly supports that, and i think ive seen a file that
was monochrome but not black and white though iam not sure it was in
also which codecs put both some header and the palette in extradata ?
its quite plausible some do, but i have some doubts that this code
would work with them, and ive not found such codec afer a quick look

i mean if i would be adding pal8 support to ffv1 then this code
would certainly cut extradata wrong while prior to this patch it would
work, maybe it doesnt happen with any existing coedecs but it
certainly doesnt give me a very good feeling that the code tries to
support something but the only case that i could think of that being
used it wouldnt work

I think to solve this the obvious solution would be to
make a list of codec ids for which extradata is always the
palette and just the palette in case of PAL8 pix fmt.
and in these cases simply assume palette_size == extradata_size.
and maybe print a warning for codec ids that have extradata and pal8
but arent in the list
we would need to design a system so that a encoder and demuxer could
communicate the palette size information to the muxer and that then
stores this value properly. 

above is assuming iam not missing anything


Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once"    - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140929/8eb5f9c1/attachment.asc>

More information about the ffmpeg-devel mailing list