summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-10-13 21:08:25 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-10-14 01:19:06 +0800
commit1e7f53baed664ceec64af09dd73149f7136dbe77 (patch)
tree24ab82eca10e1fd16a904ad9c0fbb16f5f83c41a
parent18f07aea2f40164b3da68f155be1303d09fd2741 (diff)
downloadmupdf-1e7f53baed664ceec64af09dd73149f7136dbe77.tar.xz
pnm: Better guesses when tuple type is not specified.
-rw-r--r--source/fitz/load-pnm.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c
index d9d433c9..f585cd8a 100644
--- a/source/fitz/load-pnm.c
+++ b/source/fitz/load-pnm.c
@@ -430,7 +430,7 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
if (pnm->tupletype == PAM_UNKNOWN)
switch (pnm->depth)
{
- case 1: pnm->tupletype = PAM_BW; break;
+ case 1: pnm->tupletype = pnm->maxval == 1 ? PAM_BW : PAM_GRAY; break;
case 2: pnm->tupletype = PAM_GRAYA; break;
case 3: pnm->tupletype = PAM_RGB; break;
case 4: pnm->tupletype = PAM_CMYK; break;
@@ -439,6 +439,11 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot guess tuple type based on depth in pnm image");
}
+ if (pnm->tupletype == PAM_BW && pnm->maxval > 1)
+ pnm->tupletype = PAM_GRAY;
+ else if (pnm->tupletype == PAM_GRAY && pnm->maxval == 1)
+ pnm->tupletype = PAM_BW;
+
switch (pnm->tupletype)
{
case PAM_BW: