summaryrefslogtreecommitdiff
path: root/source/fitz/load-gif.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2018-09-05 15:09:28 +0800
committerSebastian Rasmussen <sebras@gmail.com>2018-09-05 19:48:46 +0800
commit075fc6e3068e1a414de143d4b60c93618a75abab (patch)
tree14845823e3f48bdf1de5d9c2b424db0d79f7810c /source/fitz/load-gif.c
parent05c88cc1a6ab62f78ef9063838b851d46d2bb71a (diff)
downloadmupdf-075fc6e3068e1a414de143d4b60c93618a75abab.tar.xz
Bug 699715: Support embedded ICC color profiles in GIF.
Diffstat (limited to 'source/fitz/load-gif.c')
-rw-r--r--source/fitz/load-gif.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/source/fitz/load-gif.c b/source/fitz/load-gif.c
index ebd1d1b6..b94763ba 100644
--- a/source/fitz/load-gif.c
+++ b/source/fitz/load-gif.c
@@ -354,6 +354,46 @@ gif_read_pte(fz_context *ctx, struct info *info, const unsigned char *p, const u
return gif_read_subblocks(ctx, info, p + 15, end, NULL);
}
+static const unsigned char *
+gif_read_icc(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
+{
+ fz_colorspace *cs = NULL;
+ fz_stream *bstm = NULL;
+ fz_pixmap *newpix;
+ fz_buffer *icc;
+
+ icc = fz_new_buffer(ctx, 0);
+
+ fz_var(bstm);
+ fz_var(cs);
+
+ fz_try(ctx)
+ {
+ p = gif_read_subblocks(ctx, info, p, end, icc);
+ bstm = fz_open_buffer(ctx, icc);
+
+ cs = fz_new_icc_colorspace_from_stream(ctx, FZ_COLORSPACE_NONE, bstm);
+ if (fz_colorspace_n(ctx, cs) != 3)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unsupported number of components in ICC profile");
+
+ newpix = fz_convert_pixmap(ctx, info->pix, cs, NULL, NULL, NULL, 1);
+ fz_drop_pixmap(ctx, info->pix);
+ info->pix = newpix;
+ }
+ fz_always(ctx)
+ {
+ fz_drop_colorspace(ctx, cs);
+ fz_drop_stream(ctx, bstm);
+ fz_drop_buffer(ctx, icc);
+ }
+ fz_catch(ctx)
+ {
+ fz_rethrow(ctx);
+ }
+
+ return p;
+}
+
/*
NETSCAPE2.0
http://odur.let.rug.nl/~kleiweg/gif/netscape.html
@@ -383,7 +423,7 @@ static const unsigned char *
gif_read_ae(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
static char *ignorable[] = {
- "NETSACPE2.0", "ANIMEXTS1.0", "ICCRGBG1012", "XMP DataXMP",
+ "NETSACPE2.0", "ANIMEXTS1.0", "XMP DataXMP",
"ZGATEXTI5\0\0", "ZGATILEI5\0\0", "ZGANPIMGI5\0", "ZGACTRLI5\0\0",
"ZGAVECTI5\0\0", "ZGAALPHAI5\0", "ZGATITLE4.0", "ZGATEXTI4.0",
};
@@ -405,6 +445,9 @@ gif_read_ae(fz_context *ctx, struct info *info, const unsigned char *p, const un
fz_warn(ctx, "ignoring unsupported application extension '%s' in gif image", extension);
}
+ if (!memcmp(&p[3], "ICCRGBG1012", 11))
+ return gif_read_icc(ctx, info, p + 14, end);
+
return gif_read_subblocks(ctx, info, p + 14, end, NULL);
}