[vlc-devel] [PATCH] bmp: fix demuxing for some BMP formats
Tristan Matthews
tmatth at videolan.org
Thu Apr 14 23:26:09 CEST 2016
---
modules/demux/image.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/modules/demux/image.c b/modules/demux/image.c
index 43c4847..033627f 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -603,6 +603,42 @@ static const image_format_t formats[] = {
{ .codec = 0 }
};
+static int parse_bmp(stream_t *stream, video_format_t *fmt)
+{
+/* See:
+ https://en.wikipedia.org/wiki/BMP_file_format#DIB_header_.28bitmap_information_header.29
+ */
+ const uint8_t *header;
+ if (stream_Peek(stream, &header, 18 + 12) < 18 + 12)
+ return VLC_EGENERIC;
+ uint32_t header_size = GetDWLE(&header[14]);
+ switch (header_size) {
+ case 12: { /* BITMAPCOREHEADER, OS21XBITMAPHEADER */
+ if( stream_Peek(stream, &header, 18 + 12) < 18 + 12 )
+ return VLC_EGENERIC;
+ fmt->i_width = fmt->i_visible_width = GetWLE(&header[18]);
+ fmt->i_height = fmt->i_visible_height = GetWLE(&header[20]);
+ fmt->i_bits_per_pixel = GetWLE(&header[24]);
+ break;
+ }
+ case 40: /* BITMAPINFOHEADER */
+ case 52: /* BITMAPV2INFOHEADER */
+ case 56: /* BITMAPV3INFOHEADER */
+ case 64: /* OS22XBITMAPHEADER */
+ case 108: /* BITMAPV4HEADER */
+ case 124: /* BITMAPV5HEADER */
+ {
+ fmt->i_width = fmt->i_visible_width = GetDWLE(&header[18]);
+ fmt->i_height = fmt->i_visible_height = GetDWLE(&header[22]);
+ fmt->i_bits_per_pixel = GetWLE(&header[28]);
+ break;
+ }
+ default:
+ return VLC_EGENERIC;
+ }
+ return VLC_SUCCESS;
+}
+
static int Open(vlc_object_t *object)
{
demux_t *demux = (demux_t*)object;
@@ -641,6 +677,12 @@ static int Open(vlc_object_t *object)
es_format_Init(&fmt, VIDEO_ES, img->codec);
fmt.video.i_chroma = fmt.i_codec;
+ if( img->codec == VLC_CODEC_BMP )
+ {
+ if (parse_bmp(demux->s, &fmt.video) < 0)
+ return VLC_EGENERIC; /* let avformat demux this file */
+ }
+
block_t *data = Load(demux);
if (data && var_InheritBool(demux, "image-decode")) {
char *string = var_InheritString(demux, "image-chroma");
--
1.9.1
More information about the vlc-devel
mailing list