summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-08-14 11:43:26 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2016-08-14 11:43:26 (GMT)
commitb019dacb93b82c43e9f521af496fdf45cd091469 (patch)
tree9e2b500280684d151f92220db4181ba4ac99a2c8
parent7cf0ca63776d33545454bcce8f09bdf068fe2ecb (diff)
downloadlibnsbmp-b019dacb93b82c43e9f521af496fdf45cd091469.tar.gz
libnsbmp-b019dacb93b82c43e9f521af496fdf45cd091469.tar.bz2
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.
-rw-r--r--src/libnsbmp.c10
1 files changed, 10 insertions, 0 deletions
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 */