From b019dacb93b82c43e9f521af496fdf45cd091469 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 14 Aug 2016 12:43:26 +0100 Subject: cope with palette bitmaps that have a bad offset some palette bitmaps have a image data offset that does not account for the palette data. This works round the issue by skipping the palette data in such bitmaps to get a correct image. --- src/libnsbmp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/libnsbmp.c b/src/libnsbmp.c index 18ff002..4e31b93 100644 --- a/src/libnsbmp.c +++ b/src/libnsbmp.c @@ -485,6 +485,16 @@ static bmp_result bmp_analyse_header(bmp_image *bmp, uint8_t *data) { data += palette_size; bmp->colour_table[i] = read_uint32((uint8_t *)&bmp->colour_table[i],0); } + + /* some bitmaps have a bad offset if there is a pallete, work + * round this by fixing up the data offset to after the palette + * but only if there is data following the palette as some + * bitmaps encode data in the palette! + */ + if ((bmp->bitmap_offset < (data - bmp->bmp_data)) && + ((bmp->buffer_size - (data - bmp->bmp_data)) > 0)) { + bmp->bitmap_offset = data - bmp->bmp_data; + } } /* create our bitmap */ -- cgit v1.2.3