summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-10-11 14:02:57 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-10-12 15:18:06 +0200
commit0e03d243af21da13af66af6c688300ff7d72ade6 (patch)
treebb86c7d131ccd0c7b78be85bdc100eaa5c744245
parent1246b9c7fa031c3db8f0bfaeb7be367636d7cdec (diff)
downloadmupdf-0e03d243af21da13af66af6c688300ff7d72ade6.tar.xz
Make image loading use const data pointers.
-rw-r--r--include/mupdf/fitz/image.h40
-rw-r--r--source/fitz/load-bmp.c56
-rw-r--r--source/fitz/load-gif.c52
-rw-r--r--source/fitz/load-jpeg.c4
-rw-r--r--source/fitz/load-jpx.c16
-rw-r--r--source/fitz/load-jxr.c16
-rw-r--r--source/fitz/load-png.c22
-rw-r--r--source/fitz/load-pnm.c42
-rw-r--r--source/fitz/load-tiff.c26
9 files changed, 139 insertions, 135 deletions
diff --git a/include/mupdf/fitz/image.h b/include/mupdf/fitz/image.h
index ba950ebf..3d6fe431 100644
--- a/include/mupdf/fitz/image.h
+++ b/include/mupdf/fitz/image.h
@@ -266,26 +266,26 @@ struct fz_image_s
float decode[FZ_MAX_COLORS * 2];
};
-fz_pixmap *fz_load_jpeg(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *cs);
-fz_pixmap *fz_load_png(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_tiff(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_jxr(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_gif(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_bmp(fz_context *ctx, unsigned char *data, size_t size);
-fz_pixmap *fz_load_pnm(fz_context *ctx, unsigned char *data, size_t size);
-
-void fz_load_jpeg_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_jpx_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_png_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_tiff_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_jxr_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_gif_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_bmp_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-void fz_load_pnm_info(fz_context *ctx, unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
-
-int fz_load_tiff_subimage_count(fz_context *ctx, unsigned char *buf, size_t len);
-fz_pixmap *fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, size_t len, int subimage);
+fz_pixmap *fz_load_jpeg(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_jpx(fz_context *ctx, const unsigned char *data, size_t size, fz_colorspace *cs);
+fz_pixmap *fz_load_png(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_tiff(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_jxr(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_gif(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_bmp(fz_context *ctx, const unsigned char *data, size_t size);
+fz_pixmap *fz_load_pnm(fz_context *ctx, const unsigned char *data, size_t size);
+
+void fz_load_jpeg_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_jpx_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_png_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_tiff_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_jxr_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_gif_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_bmp_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+void fz_load_pnm_info(fz_context *ctx, const unsigned char *data, size_t size, int *w, int *h, int *xres, int *yres, fz_colorspace **cspace);
+
+int fz_load_tiff_subimage_count(fz_context *ctx, const unsigned char *buf, size_t len);
+fz_pixmap *fz_load_tiff_subimage(fz_context *ctx, const unsigned char *buf, size_t len, int subimage);
/*
fz_image_resolution: Request the natural resolution
diff --git a/source/fitz/load-bmp.c b/source/fitz/load-bmp.c
index dd852b0f..16953338 100644
--- a/source/fitz/load-bmp.c
+++ b/source/fitz/load-bmp.c
@@ -102,8 +102,8 @@ struct info
#define read16(p) (((p)[1] << 8) | (p)[0])
#define read32(p) (((p)[3] << 24) | ((p)[2] << 16) | ((p)[1] << 8) | (p)[0])
-static unsigned char *
-bmp_read_file_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_file_header(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 14)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in file header in bmp image");
@@ -117,8 +117,8 @@ bmp_read_file_header(fz_context *ctx, struct info *info, unsigned char *p, unsig
return p + 14;
}
-static unsigned char *
-bmp_read_bitmap_core_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_bitmap_core_header(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
int size;
@@ -144,8 +144,8 @@ bmp_read_bitmap_core_header(fz_context *ctx, struct info *info, unsigned char *p
return p + size;
}
-static unsigned char *
-bmp_read_bitmap_os2_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_bitmap_os2_header(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
int size;
@@ -202,8 +202,8 @@ static void maskinfo(unsigned int mask, int *shift, int *bits)
}
}
-static unsigned char *
-bmp_read_bitmap_info_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_bitmap_info_header(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
int size;
@@ -272,8 +272,8 @@ bmp_read_bitmap_info_header(fz_context *ctx, struct info *info, unsigned char *p
return p + size;
}
-static unsigned char *
-bmp_read_extra_masks(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_extra_masks(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
int size = 0;
@@ -356,8 +356,8 @@ bmp_load_default_palette(fz_context *ctx, struct info *info, int readcolors)
memcpy(info->palette, bw_palette, sizeof(bw_palette));
}
-static unsigned char *
-bmp_read_color_table(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+bmp_read_color_table(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
int i, colors, readcolors;
@@ -403,9 +403,10 @@ bmp_read_color_table(fz_context *ctx, struct info *info, unsigned char *p, unsig
}
static unsigned char *
-bmp_decompress_rle24(fz_context *ctx, struct info *info, unsigned char *p, unsigned char **end)
+bmp_decompress_rle24(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char **end)
{
- unsigned char *sp, *dp, *ep, *decompressed;
+ const unsigned char *sp;
+ unsigned char *dp, *ep, *decompressed;
int width = info->width;
int height = info->height;
int stride;
@@ -490,9 +491,10 @@ bmp_decompress_rle24(fz_context *ctx, struct info *info, unsigned char *p, unsig
}
static unsigned char *
-bmp_decompress_rle8(fz_context *ctx, struct info *info, unsigned char *p, unsigned char **end)
+bmp_decompress_rle8(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char **end)
{
- unsigned char *sp, *dp, *ep, *decompressed;
+ const unsigned char *sp;
+ unsigned char *dp, *ep, *decompressed;
int width = info->width;
int height = info->height;
int stride;
@@ -572,9 +574,10 @@ bmp_decompress_rle8(fz_context *ctx, struct info *info, unsigned char *p, unsign
}
static unsigned char *
-bmp_decompress_rle4(fz_context *ctx, struct info *info, unsigned char *p, unsigned char **end)
+bmp_decompress_rle4(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char **end)
{
- unsigned char *sp, *dp, *ep, *decompressed;
+ const unsigned char *sp;
+ unsigned char *dp, *ep, *decompressed;
int width = info->width;
int height = info->height;
int stride;
@@ -663,12 +666,13 @@ bmp_decompress_rle4(fz_context *ctx, struct info *info, unsigned char *p, unsign
}
static fz_pixmap *
-bmp_read_bitmap(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+bmp_read_bitmap(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
const int mults[] = { 0, 8191, 2730, 1170, 546, 264, 130, 64 };
fz_pixmap *pix;
+ const unsigned char *ssp;
+ unsigned char *ddp;
unsigned char *decompressed = NULL;
- unsigned char *ssp, *ddp;
int bitcount, width, height;
int sstride, dstride;
int rmult, gmult, bmult, amult;
@@ -732,7 +736,7 @@ bmp_read_bitmap(fz_context *ctx, struct info *info, unsigned char *p, unsigned c
for (y = 0; y < height; y++)
{
- unsigned char *sp = ssp + y * sstride;
+ const unsigned char *sp = ssp + y * sstride;
unsigned char *dp = ddp + y * dstride;
switch (bitcount)
@@ -849,10 +853,10 @@ bmp_read_bitmap(fz_context *ctx, struct info *info, unsigned char *p, unsigned c
}
static fz_pixmap *
-bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata)
+bmp_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_t total, int only_metadata)
{
- unsigned char *begin = p;
- unsigned char *end = p + total;
+ const unsigned char *begin = p;
+ const unsigned char *end = p + total;
int size;
memset(info, 0x00, sizeof (*info));
@@ -938,7 +942,7 @@ bmp_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t tota
}
fz_pixmap *
-fz_load_bmp(fz_context *ctx, unsigned char *p, size_t total)
+fz_load_bmp(fz_context *ctx, const unsigned char *p, size_t total)
{
struct info bmp;
fz_pixmap *image;
@@ -951,7 +955,7 @@ fz_load_bmp(fz_context *ctx, unsigned char *p, size_t total)
}
void
-fz_load_bmp_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_bmp_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct info bmp;
diff --git a/source/fitz/load-gif.c b/source/fitz/load-gif.c
index 88779e88..cc87ff84 100644
--- a/source/fitz/load-gif.c
+++ b/source/fitz/load-gif.c
@@ -96,8 +96,8 @@ static const unsigned char dct[256 * 3] = {
0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfe, 0xfe, 0xfe,
};
-static unsigned char *
-gif_read_subblocks(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end, fz_buffer *buf)
+static const unsigned char *
+gif_read_subblocks(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end, fz_buffer *buf)
{
int len;
@@ -121,8 +121,8 @@ gif_read_subblocks(fz_context *ctx, struct info *info, unsigned char *p, unsigne
return p;
}
-static unsigned char *
-gif_read_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_header(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 6)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in header in gif image");
@@ -137,8 +137,8 @@ gif_read_header(fz_context *ctx, struct info *info, unsigned char *p, unsigned c
return p + 6;
}
-static unsigned char *
-gif_read_lsd(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_lsd(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 7)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in logical screen descriptor in gif image");
@@ -168,8 +168,8 @@ gif_read_lsd(fz_context *ctx, struct info *info, unsigned char *p, unsigned char
return p + 7;
}
-static unsigned char *
-gif_read_gct(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_gct(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < info->gct_entries * 3)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in global color table in gif image");
@@ -180,8 +180,8 @@ gif_read_gct(fz_context *ctx, struct info *info, unsigned char *p, unsigned char
return p + info->gct_entries * 3;
}
-static unsigned char *
-gif_read_id(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_id(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 10)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in image descriptor in gif image");
@@ -199,8 +199,8 @@ gif_read_id(fz_context *ctx, struct info *info, unsigned char *p, unsigned char
return p + 10;
}
-static unsigned char *
-gif_read_lct(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_lct(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < info->lct_entries * 3)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in local color table in gif image");
@@ -234,8 +234,8 @@ gif_read_line(fz_context *ctx, struct info *info, unsigned char *dest, int ct_en
*mp = 0x00;
}
-static unsigned char *
-gif_read_tbid(fz_context *ctx, struct info *info, unsigned char *dest, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_tbid(fz_context *ctx, struct info *info, unsigned char *dest, const unsigned char *p, const unsigned char *end)
{
fz_stream *stm, *lzwstm = NULL;
unsigned int mincodesize, y;
@@ -318,8 +318,8 @@ gif_read_tbid(fz_context *ctx, struct info *info, unsigned char *dest, unsigned
return p;
}
-static unsigned char *
-gif_read_gce(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_gce(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 8)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in graphic control extension in gif image");
@@ -333,14 +333,14 @@ gif_read_gce(fz_context *ctx, struct info *info, unsigned char *p, unsigned char
return p + 8;
}
-static unsigned char *
-gif_read_ce(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char *
+gif_read_ce(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
return gif_read_subblocks(ctx, info, p + 2, end, NULL);
}
-static unsigned char*
-gif_read_pte(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+static const unsigned char*
+gif_read_pte(fz_context *ctx, struct info *info, const unsigned char *p, const unsigned char *end)
{
if (end - p < 15)
fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in plain text extension in gif image");
@@ -374,8 +374,8 @@ ZGATEXTI5 ZGATILEI5 ZGACTRLI5 ZGANPIMGI5
ZGAVECTI5 ZGAALPHAI5 ZGATITLE4.0 ZGATEXTI4.0
Zoner GIF animator 4.0 and 5.0
*/
-static unsigned char *
-gif_read_ae(fz_context *ctx, struct info *info, unsigned char *p, unsigned char *end)
+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",
@@ -417,10 +417,10 @@ gif_mask_transparency(fz_context *ctx, fz_pixmap *image, struct info *info)
}
static fz_pixmap *
-gif_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata)
+gif_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_t total, int only_metadata)
{
fz_pixmap *pix;
- unsigned char *end = p + total;
+ const unsigned char *end = p + total;
memset(info, 0x00, sizeof (*info));
@@ -546,7 +546,7 @@ gif_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t tota
}
fz_pixmap *
-fz_load_gif(fz_context *ctx, unsigned char *p, size_t total)
+fz_load_gif(fz_context *ctx, const unsigned char *p, size_t total)
{
fz_pixmap *image;
struct info gif;
@@ -559,7 +559,7 @@ fz_load_gif(fz_context *ctx, unsigned char *p, size_t total)
}
void
-fz_load_gif_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_gif_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct info gif;
diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c
index a156c84d..7a78e7ad 100644
--- a/source/fitz/load-jpeg.c
+++ b/source/fitz/load-jpeg.c
@@ -218,7 +218,7 @@ static int extract_app13_resolution(jpeg_saved_marker_ptr marker, int *xres, int
}
fz_pixmap *
-fz_load_jpeg(fz_context *ctx, unsigned char *rbuf, size_t rlen)
+fz_load_jpeg(fz_context *ctx, const unsigned char *rbuf, size_t rlen)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr err;
@@ -334,7 +334,7 @@ fz_load_jpeg(fz_context *ctx, unsigned char *rbuf, size_t rlen)
}
void
-fz_load_jpeg_info(fz_context *ctx, unsigned char *rbuf, size_t rlen, int *xp, int *yp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_jpeg_info(fz_context *ctx, const unsigned char *rbuf, size_t rlen, int *xp, int *yp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr err;
diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
index fb88498c..b7ddd505 100644
--- a/source/fitz/load-jpx.c
+++ b/source/fitz/load-jpx.c
@@ -73,7 +73,7 @@ struct fz_jpxd_s
struct stream_block_s
{
- unsigned char *data;
+ const unsigned char *data;
size_t size;
};
@@ -197,7 +197,7 @@ jpx_write(unsigned char * pucData, short sComponent, unsigned long ulRow,
}
static fz_pixmap *
-jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
+jpx_read_image(fz_context *ctx, fz_jpxd *state, const unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
{
JP2_Decomp_Handle doc;
JP2_Channel_Def_Params *chans = NULL;
@@ -421,7 +421,7 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size
}
fz_pixmap *
-fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *defcs)
+fz_load_jpx(fz_context *ctx, const unsigned char *data, size_t size, fz_colorspace *defcs)
{
fz_jpxd state = { 0 };
@@ -429,7 +429,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *de
}
void
-fz_load_jpx_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_jpx_info(fz_context *ctx, const unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
fz_jpxd state = { 0 };
@@ -464,7 +464,7 @@ struct fz_jpxd_s
struct stream_block_s
{
- unsigned char *data;
+ const unsigned char *data;
OPJ_SIZE_T size;
OPJ_SIZE_T pos;
};
@@ -653,7 +653,7 @@ l2subfactor(fz_context *ctx, unsigned int max_w, unsigned int w)
}
static fz_pixmap *
-jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
+jpx_read_image(fz_context *ctx, fz_jpxd *state, const unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
{
fz_pixmap *img = NULL;
opj_dparameters_t params;
@@ -889,7 +889,7 @@ jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size
}
fz_pixmap *
-fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *defcs)
+fz_load_jpx(fz_context *ctx, const unsigned char *data, size_t size, fz_colorspace *defcs)
{
fz_jpxd state = { 0 };
fz_pixmap *pix = NULL;
@@ -908,7 +908,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, size_t size, fz_colorspace *de
}
void
-fz_load_jpx_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_jpx_info(fz_context *ctx, const unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
fz_jpxd state = { 0 };
diff --git a/source/fitz/load-jxr.c b/source/fitz/load-jxr.c
index d81196c2..a83d7f6a 100644
--- a/source/fitz/load-jxr.c
+++ b/source/fitz/load-jxr.c
@@ -274,7 +274,7 @@ jxr_decode_block_alpha(jxr_image_t image, int mx, int my, int *data)
}
static void
-jxr_read_image(fz_context *ctx, unsigned char *data, int size, struct info *info, int only_metadata)
+jxr_read_image(fz_context *ctx, const unsigned char *data, int size, struct info *info, int only_metadata)
{
jxr_container_t container;
jxr_image_t image = NULL;
@@ -285,7 +285,7 @@ jxr_read_image(fz_context *ctx, unsigned char *data, int size, struct info *info
{
container = jxr_create_container();
- rc = jxr_read_image_container_memory(container, data, size);
+ rc = jxr_read_image_container_memory(container, (unsigned char *)data, size);
if (rc < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read jxr image container: %s", jxr_error_string(rc));
@@ -342,7 +342,7 @@ jxr_read_image(fz_context *ctx, unsigned char *data, int size, struct info *info
jxr_set_user_data(image, info);
jxr_set_block_output(image, jxr_decode_block);
- rc = jxr_read_image_bitstream_memory(image, data + image_offset, size - image_offset);
+ rc = jxr_read_image_bitstream_memory(image, (unsigned char *)data + image_offset, size - image_offset);
if (rc < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read jxr image: %s", jxr_error_string(rc));
@@ -370,7 +370,7 @@ jxr_read_image(fz_context *ctx, unsigned char *data, int size, struct info *info
jxr_set_user_data(alpha, info);
jxr_set_block_output(alpha, jxr_decode_block_alpha);
- rc = jxr_read_image_bitstream_memory(alpha, data + alpha_offset, size - alpha_offset);
+ rc = jxr_read_image_bitstream_memory(alpha, (unsigned char *)data + alpha_offset, size - alpha_offset);
if (rc < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read jxr image: %s", jxr_error_string(rc));
}
@@ -391,7 +391,7 @@ jxr_read_image(fz_context *ctx, unsigned char *data, int size, struct info *info
}
fz_pixmap *
-fz_load_jxr(fz_context *ctx, unsigned char *data, size_t size)
+fz_load_jxr(fz_context *ctx, const unsigned char *data, size_t size)
{
struct info info = { 0 };
fz_pixmap *image = NULL;
@@ -426,7 +426,7 @@ fz_load_jxr(fz_context *ctx, unsigned char *data, size_t size)
}
void
-fz_load_jxr_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_jxr_info(fz_context *ctx, const unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct info info = { 0 };
@@ -441,13 +441,13 @@ fz_load_jxr_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int
#else /* HAVE_JPEGXR */
fz_pixmap *
-fz_load_jxr(fz_context *ctx, unsigned char *data, size_t size)
+fz_load_jxr(fz_context *ctx, const unsigned char *data, size_t size)
{
fz_throw(ctx, FZ_ERROR_GENERIC, "JPEG-XR codec is not available");
}
void
-fz_load_jxr_info(fz_context *ctx, unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_jxr_info(fz_context *ctx, const unsigned char *data, size_t size, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
fz_throw(ctx, FZ_ERROR_GENERIC, "JPEG-XR codec is not available");
}
diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c
index 8f204015..999f0457 100644
--- a/source/fitz/load-png.c
+++ b/source/fitz/load-png.c
@@ -16,12 +16,12 @@ struct info
int xres, yres;
};
-static inline unsigned int getuint(unsigned char *p)
+static inline unsigned int getuint(const unsigned char *p)
{
return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
}
-static inline int getcomp(unsigned char *line, int x, int bpc)
+static inline int getcomp(const unsigned char *line, int x, int bpc)
{
switch (bpc)
{
@@ -220,7 +220,7 @@ png_deinterlace(fz_context *ctx, struct info *info, unsigned int *passw, unsigne
}
static void
-png_read_ihdr(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size)
+png_read_ihdr(fz_context *ctx, struct info *info, const unsigned char *p, unsigned int size)
{
int color, compression, filter;
@@ -281,7 +281,7 @@ png_read_ihdr(fz_context *ctx, struct info *info, unsigned char *p, unsigned int
}
static void
-png_read_plte(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size)
+png_read_plte(fz_context *ctx, struct info *info, const unsigned char *p, unsigned int size)
{
int n = size / 3;
int i;
@@ -309,7 +309,7 @@ png_read_plte(fz_context *ctx, struct info *info, unsigned char *p, unsigned int
}
static void
-png_read_trns(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size)
+png_read_trns(fz_context *ctx, struct info *info, const unsigned char *p, unsigned int size)
{
unsigned int i;
@@ -338,11 +338,11 @@ png_read_trns(fz_context *ctx, struct info *info, unsigned char *p, unsigned int
}
static void
-png_read_idat(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size, z_stream *stm)
+png_read_idat(fz_context *ctx, struct info *info, const unsigned char *p, unsigned int size, z_stream *stm)
{
int code;
- stm->next_in = p;
+ stm->next_in = (Bytef*)p;
stm->avail_in = size;
code = inflate(stm, Z_SYNC_FLUSH);
@@ -357,7 +357,7 @@ png_read_idat(fz_context *ctx, struct info *info, unsigned char *p, unsigned int
}
static void
-png_read_phys(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size)
+png_read_phys(fz_context *ctx, struct info *info, const unsigned char *p, unsigned int size)
{
if (size != 9)
fz_throw(ctx, FZ_ERROR_GENERIC, "pHYs chunk is the wrong size");
@@ -369,7 +369,7 @@ png_read_phys(fz_context *ctx, struct info *info, unsigned char *p, unsigned int
}
static void
-png_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t total, int only_metadata)
+png_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_t total, int only_metadata)
{
unsigned int passw[7], passh[7], passofs[8];
unsigned int code, size;
@@ -557,7 +557,7 @@ png_mask_transparency(struct info *info, fz_pixmap *dst)
}
fz_pixmap *
-fz_load_png(fz_context *ctx, unsigned char *p, size_t total)
+fz_load_png(fz_context *ctx, const unsigned char *p, size_t total)
{
fz_pixmap *image = NULL;
fz_colorspace *colorspace;
@@ -615,7 +615,7 @@ fz_load_png(fz_context *ctx, unsigned char *p, size_t total)
}
void
-fz_load_png_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_png_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct info png;
diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c
index f0865e51..0a1fa3f4 100644
--- a/source/fitz/load-pnm.c
+++ b/source/fitz/load-pnm.c
@@ -74,8 +74,8 @@ static inline int bitdepth_from_maxval(int maxval)
return depth;
}
-static unsigned char *
-pnm_read_white(fz_context *ctx, unsigned char *p, unsigned char *e, int single_line)
+static const unsigned char *
+pnm_read_white(fz_context *ctx, const unsigned char *p, const unsigned char *e, int single_line)
{
if (e - p < 1)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse whitespace in pnm image");
@@ -119,8 +119,8 @@ pnm_read_white(fz_context *ctx, unsigned char *p, unsigned char *e, int single_l
return p;
}
-static unsigned char *
-pnm_read_signature(fz_context *ctx, unsigned char *p, unsigned char *e, char *signature)
+static const unsigned char *
+pnm_read_signature(fz_context *ctx, const unsigned char *p, const unsigned char *e, char *signature)
{
if (e - p < 2)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse magic number in pnm image");
@@ -132,8 +132,8 @@ pnm_read_signature(fz_context *ctx, unsigned char *p, unsigned char *e, char *si
return p;
}
-static unsigned char *
-pnm_read_number(fz_context *ctx, unsigned char *p, unsigned char *e, int *number)
+static const unsigned char *
+pnm_read_number(fz_context *ctx, const unsigned char *p, const unsigned char *e, int *number)
{
if (e - p < 1)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse number in pnm image");
@@ -149,8 +149,8 @@ pnm_read_number(fz_context *ctx, unsigned char *p, unsigned char *e, int *number
return p;
}
-static unsigned char *
-pnm_read_tupletype(fz_context *ctx, unsigned char *p, unsigned char *e, int *tupletype)
+static const unsigned char *
+pnm_read_tupletype(fz_context *ctx, const unsigned char *p, const unsigned char *e, int *tupletype)
{
const struct { int len; char *str; int type; } tupletypes[] =
{
@@ -163,7 +163,7 @@ pnm_read_tupletype(fz_context *ctx, unsigned char *p, unsigned char *e, int *tup
{4, "CMYK", PAM_CMYK},
{10, "CMYK_ALPHA", PAM_CMYKA},
};
- unsigned char *s;
+ const unsigned char *s;
int i, len;
if (e - p < 1)
@@ -184,8 +184,8 @@ pnm_read_tupletype(fz_context *ctx, unsigned char *p, unsigned char *e, int *tup
fz_throw(ctx, FZ_ERROR_GENERIC, "unknown tuple type in pnm image");
}
-static unsigned char *
-pnm_read_token(fz_context *ctx, unsigned char *p, unsigned char *e, int *token)
+static const unsigned char *
+pnm_read_token(fz_context *ctx, const unsigned char *p, const unsigned char *e, int *token)
{
const struct { int len; char *str; int type; } tokens[] =
{
@@ -196,7 +196,7 @@ pnm_read_token(fz_context *ctx, unsigned char *p, unsigned char *e, int *token)
{8, "TUPLTYPE", TOKEN_TUPLTYPE},
{6, "ENDHDR", TOKEN_ENDHDR},
};
- unsigned char *s;
+ const unsigned char *s;
int i, len;
if (e - p < 1)
@@ -225,7 +225,7 @@ map_color(fz_context *ctx, int color, int inmax, int outmax)
}
static fz_pixmap *
-pnm_ascii_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsigned char *e, int onlymeta, int bitmap)
+pnm_ascii_read_image(fz_context *ctx, struct info *pnm, const unsigned char *p, const unsigned char *e, int onlymeta, int bitmap)
{
fz_pixmap *img = NULL;
@@ -303,7 +303,7 @@ pnm_ascii_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsign
}
static fz_pixmap *
-pnm_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsigned char *e, int onlymeta, int bitmap)
+pnm_binary_read_image(fz_context *ctx, struct info *pnm, const unsigned char *p, const unsigned char *e, int onlymeta, int bitmap)
{
fz_pixmap *img = NULL;
@@ -387,8 +387,8 @@ pnm_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
return img;
}
-static unsigned char *
-pam_binary_read_header(fz_context *ctx, struct info *pnm, unsigned char *p, unsigned char *e)
+static const unsigned char *
+pam_binary_read_header(fz_context *ctx, struct info *pnm, const unsigned char *p, const unsigned char *e)
{
int token = TOKEN_UNKNOWN;
@@ -416,7 +416,7 @@ pam_binary_read_header(fz_context *ctx, struct info *pnm, unsigned char *p, unsi
}
static fz_pixmap *
-pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsigned char *e, int onlymeta)
+pam_binary_read_image(fz_context *ctx, struct info *pnm, const unsigned char *p, const unsigned char *e, int onlymeta)
{
fz_pixmap *img = NULL;
int bitmap = 0;
@@ -576,9 +576,9 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig
}
static fz_pixmap *
-pnm_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, size_t total, int onlymeta)
+pnm_read_image(fz_context *ctx, struct info *pnm, const unsigned char *p, size_t total, int onlymeta)
{
- unsigned char *e = p + total;
+ const unsigned char *e = p + total;
char signature[3] = { 0 };
p = pnm_read_signature(ctx, p, e, signature);
@@ -621,7 +621,7 @@ pnm_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, size_t total
}
fz_pixmap *
-fz_load_pnm(fz_context *ctx, unsigned char *p, size_t total)
+fz_load_pnm(fz_context *ctx, const unsigned char *p, size_t total)
{
fz_pixmap *img = NULL;
struct info pnm = { 0 };
@@ -637,7 +637,7 @@ fz_load_pnm(fz_context *ctx, unsigned char *p, size_t total)
}
void
-fz_load_pnm_info(fz_context *ctx, unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_pnm_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
struct info pnm = { 0 };
diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c
index 56140e89..25ee5ef6 100644
--- a/source/fitz/load-tiff.c
+++ b/source/fitz/load-tiff.c
@@ -15,7 +15,7 @@
struct tiff
{
/* "file" */
- unsigned char *bp, *rp, *ep;
+ const unsigned char *bp, *rp, *ep;
/* byte order */
unsigned order;
@@ -62,7 +62,7 @@ struct tiff
unsigned ycbcrsubsamp[2];
- unsigned char *jpegtables; /* point into "file" buffer */
+ const unsigned char *jpegtables; /* point into "file" buffer */
unsigned jpegtableslen;
unsigned char *profile;
@@ -288,7 +288,7 @@ tiff_expand_colormap(fz_context *ctx, struct tiff *tiff)
}
static unsigned
-tiff_decode_data(fz_context *ctx, struct tiff *tiff, unsigned char *rp, unsigned int rlen, unsigned char *wp, unsigned int wlen)
+tiff_decode_data(fz_context *ctx, struct tiff *tiff, const unsigned char *rp, unsigned int rlen, unsigned char *wp, unsigned int wlen)
{
fz_stream *encstm = NULL;
fz_stream *stm = NULL;
@@ -596,7 +596,7 @@ tiff_decode_tiles(fz_context *ctx, struct tiff *tiff)
{
unsigned int offset = tiff->tileoffsets[tile];
unsigned int rlen = tiff->tilebytecounts[tile];
- unsigned char *rp = tiff->bp + offset;
+ const unsigned char *rp = tiff->bp + offset;
unsigned decoded;
if (offset > (unsigned)(tiff->ep - tiff->bp))
@@ -622,7 +622,7 @@ tiff_decode_tiles(fz_context *ctx, struct tiff *tiff)
{
unsigned int offset = tiff->tileoffsets[tile];
unsigned int rlen = tiff->tilebytecounts[tile];
- unsigned char *rp = tiff->bp + offset;
+ const unsigned char *rp = tiff->bp + offset;
if (offset > (unsigned)(tiff->ep - tiff->bp))
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid tile offset %u", offset);
@@ -673,7 +673,7 @@ tiff_decode_strips(fz_context *ctx, struct tiff *tiff)
{
unsigned offset = tiff->stripoffsets[strip];
unsigned rlen = tiff->stripbytecounts[strip];
- unsigned char *rp = tiff->bp + offset;
+ const unsigned char *rp = tiff->bp + offset;
int decoded;
if (offset > (unsigned)(tiff->ep - tiff->bp))
@@ -694,7 +694,7 @@ tiff_decode_strips(fz_context *ctx, struct tiff *tiff)
unsigned offset = tiff->stripoffsets[strip];
unsigned rlen = tiff->stripbytecounts[strip];
unsigned wlen = tiff->stride * tiff->rowsperstrip;
- unsigned char *rp = tiff->bp + offset;
+ const unsigned char *rp = tiff->bp + offset;
if (offset > (unsigned)(tiff->ep - tiff->bp))
fz_throw(ctx, FZ_ERROR_GENERIC, "invalid strip offset %u", offset);
@@ -963,7 +963,7 @@ tiff_scale_lab_samples(fz_context *ctx, unsigned char *buf, int bps, int n)
}
static void
-tiff_read_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, size_t len)
+tiff_read_header(fz_context *ctx, struct tiff *tiff, const unsigned char *buf, size_t len)
{
unsigned version;
@@ -1295,7 +1295,7 @@ tiff_decode_samples(fz_context *ctx, struct tiff *tiff)
}
fz_pixmap *
-fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, size_t len, int subimage)
+fz_load_tiff_subimage(fz_context *ctx, const unsigned char *buf, size_t len, int subimage)
{
fz_pixmap *image = NULL;
struct tiff tiff = { 0 };
@@ -1348,13 +1348,13 @@ fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, size_t len, int subim
}
fz_pixmap *
-fz_load_tiff(fz_context *ctx, unsigned char *buf, size_t len)
+fz_load_tiff(fz_context *ctx, const unsigned char *buf, size_t len)
{
return fz_load_tiff_subimage(ctx, buf, len, 0);
}
void
-fz_load_tiff_info_subimage(fz_context *ctx, unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep, int subimage)
+fz_load_tiff_info_subimage(fz_context *ctx, const unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep, int subimage)
{
struct tiff tiff = { 0 };
@@ -1391,13 +1391,13 @@ fz_load_tiff_info_subimage(fz_context *ctx, unsigned char *buf, size_t len, int
}
void
-fz_load_tiff_info(fz_context *ctx, unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
+fz_load_tiff_info(fz_context *ctx, const unsigned char *buf, size_t len, int *wp, int *hp, int *xresp, int *yresp, fz_colorspace **cspacep)
{
fz_load_tiff_info_subimage(ctx, buf, len, wp, hp, xresp, yresp, cspacep, 0);
}
int
-fz_load_tiff_subimage_count(fz_context *ctx, unsigned char *buf, size_t len)
+fz_load_tiff_subimage_count(fz_context *ctx, const unsigned char *buf, size_t len)
{
unsigned offset;
unsigned subimage_count = 0;