summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-03-26 09:59:53 +0100
committerRobin Watts <robin.watts@artifex.com>2016-03-29 13:06:27 +0100
commit632f301b719295920870b68ba59019fb1ea403bd (patch)
treec7f7e0a33af9ae94032d6d02324967807aea2134 /source
parent276be80ab6bf01fab28778b8d95e50c31f7ca7fc (diff)
downloadmupdf-632f301b719295920870b68ba59019fb1ea403bd.tar.xz
bmp: Add support for extra alpha mask.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/load-bmp.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/source/fitz/load-bmp.c b/source/fitz/load-bmp.c
index 6641da80..94adf97c 100644
--- a/source/fitz/load-bmp.c
+++ b/source/fitz/load-bmp.c
@@ -69,6 +69,7 @@ enum {
BI_BITFIELDS = 3,
BI_JPEG = 4,
BI_PNG = 5,
+ BI_ALPHABITS = 6,
};
struct info
@@ -223,6 +224,8 @@ bmp_read_bitmap_info_header(fz_context *ctx, struct info *info, unsigned char *p
if (size == 40 && info->compression == BI_BITFIELDS && (info->bitcount == 16 || info->bitcount == 32))
info->extramasks = 1;
+ else if (size == 40 && info->compression == BI_ALPHABITS && (info->bitcount == 16 || info->bitcount == 32))
+ info->extramasks = 1;
if (info->bitcount == 16) {
info->rmask = 0x00007c00;
@@ -254,14 +257,31 @@ bmp_read_bitmap_info_header(fz_context *ctx, struct info *info, unsigned char *p
static unsigned char *
bmp_read_extra_masks(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
{
- if (end - p < 12)
- fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in mask header in bmp image");
+ int size = 0;
+
+ if (info->compression == BI_BITFIELDS)
+ {
+ size = 12;
+ if (end - p < 12)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in mask header in bmp image");
+
+ info->rmask = read32(p + 0);
+ info->gmask = read32(p + 4);
+ info->bmask = read32(p + 8);
+ }
+ else if (info->compression == BI_ALPHABITS)
+ {
+ size = 16;
+ if (end - p < 16)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in mask header in bmp image");
- info->rmask = read32(p + 0);
- info->gmask = read32(p + 4);
- info->bmask = read32(p + 8);
+ /* ignore alpha mask */
+ info->rmask = read32(p + 0);
+ info->gmask = read32(p + 4);
+ info->bmask = read32(p + 8);
+ }
- return p + 12;
+ return p + size;
}
static int
@@ -728,7 +748,8 @@ bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total,
info->width, info->height);
if (info->compression != BI_RGB && info->compression != BI_RLE8 &&
info->compression != BI_RLE4 && info->compression != BI_BITFIELDS &&
- info->compression != BI_JPEG && info->compression != BI_PNG)
+ info->compression != BI_JPEG && info->compression != BI_PNG &&
+ info->compression != BI_ALPHABITS)
fz_throw(ctx, FZ_ERROR_GENERIC, "unsupported compression method (%d) in bmp image", info->compression);
if ((info->compression == BI_RGB && info->bitcount != 1 &&
info->bitcount != 2 && info->bitcount != 4 &&
@@ -738,7 +759,8 @@ bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, int total,
(info->compression == BI_RLE4 && info->bitcount != 4) ||
(info->compression == BI_BITFIELDS && info->bitcount != 16 && info->bitcount != 32) ||
(info->compression == BI_JPEG && info->bitcount != 0) ||
- (info->compression == BI_PNG && info->bitcount != 0))
+ (info->compression == BI_PNG && info->bitcount != 0) ||
+ (info->compression == BI_ALPHABITS && info->bitcount != 16 && info->bitcount != 32))
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid bits per pixel (%d) for compression (%d) in bmp image",
info->bitcount, info->compression);
if (info->rbits > 0 && info->rbits != 4 && info->rbits != 5 && info->rbits != 8)