wok-next diff mupdf/stuff/patches/use_openjpeg_1.5.patch @ rev 20663

Fix web site for the Shimmer Project themes
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu May 10 22:58:32 2018 +0300 (2018-05-10)
parents ae25e1ecf064
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mupdf/stuff/patches/use_openjpeg_1.5.patch	Thu May 10 22:58:32 2018 +0300
     1.3 @@ -0,0 +1,149 @@
     1.4 +commit a7341e98ef48d6041028b7294d1acc13665b04ba
     1.5 +Author: Quoc-Viet Nguyen <afelion@gmail.com>
     1.6 +Date:   Fri Apr 18 23:48:29 2014 +1000
     1.7 +
     1.8 +    Use openjpeg 1.5 rather than 2.0
     1.9 +---
    1.10 + source/fitz/load-jpx.c | 104 +++++++++----------------------------------------
    1.11 + 1 file changed, 18 insertions(+), 86 deletions(-)
    1.12 +
    1.13 +diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
    1.14 +index dfb89f4..d27b5de 100644
    1.15 +--- a/source/fitz/load-jpx.c
    1.16 ++++ b/source/fitz/load-jpx.c
    1.17 +@@ -605,41 +605,6 @@
    1.18 + 	/* fz_warn("openjpeg info: %s", msg); */
    1.19 + }
    1.20 + 
    1.21 +-static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
    1.22 +-{
    1.23 +-	stream_block *sb = (stream_block *)p_user_data;
    1.24 +-	OPJ_SIZE_T len;
    1.25 +-
    1.26 +-	len = sb->size - sb->pos;
    1.27 +-	if (len == 0)
    1.28 +-		return (OPJ_SIZE_T)-1; /* End of file! */
    1.29 +-	if (len > p_nb_bytes)
    1.30 +-		len = p_nb_bytes;
    1.31 +-	memcpy(p_buffer, sb->data + sb->pos, len);
    1.32 +-	sb->pos += len;
    1.33 +-	return len;
    1.34 +-}
    1.35 +-
    1.36 +-static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data)
    1.37 +-{
    1.38 +-	stream_block *sb = (stream_block *)p_user_data;
    1.39 +-
    1.40 +-	if (skip > (OPJ_OFF_T)(sb->size - sb->pos))
    1.41 +-		skip = (OPJ_OFF_T)(sb->size - sb->pos);
    1.42 +-	sb->pos += skip;
    1.43 +-	return sb->pos;
    1.44 +-}
    1.45 +-
    1.46 +-static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data)
    1.47 +-{
    1.48 +-	stream_block *sb = (stream_block *)p_user_data;
    1.49 +-
    1.50 +-	if (seek_pos > (OPJ_OFF_T)sb->size)
    1.51 +-		return OPJ_FALSE;
    1.52 +-	sb->pos = seek_pos;
    1.53 +-	return OPJ_TRUE;
    1.54 +-}
    1.55 +-
    1.56 + static int
    1.57 + l2subfactor(fz_context *ctx, unsigned int max_w, unsigned int w)
    1.58 + {
    1.59 +@@ -656,10 +621,11 @@
    1.60 + jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
    1.61 + {
    1.62 + 	fz_pixmap *img;
    1.63 ++	opj_event_mgr_t evtmgr;
    1.64 + 	opj_dparameters_t params;
    1.65 +-	opj_codec_t *codec;
    1.66 ++	opj_dinfo_t *codec;
    1.67 + 	opj_image_t *jpx;
    1.68 +-	opj_stream_t *stream;
    1.69 ++	opj_cio_t *stream;
    1.70 + 	unsigned char *p;
    1.71 + 	OPJ_CODEC_FORMAT format;
    1.72 + 	int a, n, w, h, depth, sgnd;
    1.73 +@@ -677,55 +643,30 @@
    1.74 + 
    1.75 + 	/* Check for SOC marker -- if found we have a bare J2K stream */
    1.76 + 	if (data[0] == 0xFF && data[1] == 0x4F)
    1.77 +-		format = OPJ_CODEC_J2K;
    1.78 ++		format = CODEC_J2K;
    1.79 + 	else
    1.80 +-		format = OPJ_CODEC_JP2;
    1.81 ++		format = CODEC_JP2;
    1.82 + 
    1.83 ++	memset(&evtmgr, 0, sizeof(evtmgr));
    1.84 ++	evtmgr.error_handler = fz_opj_error_callback;
    1.85 ++	evtmgr.warning_handler = fz_opj_warning_callback;
    1.86 ++	evtmgr.info_handler = fz_opj_info_callback;
    1.87 ++
    1.88 + 	opj_set_default_decoder_parameters(&params);
    1.89 + 	if (fz_colorspace_is_indexed(ctx, defcs))
    1.90 + 		params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
    1.91 + 
    1.92 + 	codec = opj_create_decompress(format);
    1.93 +-	opj_set_info_handler(codec, fz_opj_info_callback, ctx);
    1.94 +-	opj_set_warning_handler(codec, fz_opj_warning_callback, ctx);
    1.95 +-	opj_set_error_handler(codec, fz_opj_error_callback, ctx);
    1.96 +-	if (!opj_setup_decoder(codec, &params))
    1.97 +-	{
    1.98 +-		opj_destroy_codec(codec);
    1.99 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed");
   1.100 +-	}
   1.101 ++	opj_set_event_mgr((opj_common_ptr)codec, &evtmgr, ctx);
   1.102 ++	opj_setup_decoder(codec, &params);
   1.103 + 
   1.104 +-	stream = opj_stream_default_create(OPJ_TRUE);
   1.105 +-	sb.data = data;
   1.106 +-	sb.pos = 0;
   1.107 +-	sb.size = size;
   1.108 ++	stream = opj_cio_open((opj_common_ptr)codec, data, size);
   1.109 + 
   1.110 +-	opj_stream_set_read_function(stream, fz_opj_stream_read);
   1.111 +-	opj_stream_set_skip_function(stream, fz_opj_stream_skip);
   1.112 +-	opj_stream_set_seek_function(stream, fz_opj_stream_seek);
   1.113 +-	opj_stream_set_user_data(stream, &sb, NULL);
   1.114 +-	/* Set the length to avoid an assert */
   1.115 +-	opj_stream_set_user_data_length(stream, size);
   1.116 ++	jpx = opj_decode(codec, stream);
   1.117 + 
   1.118 +-	if (!opj_read_header(stream, codec, &jpx))
   1.119 +-	{
   1.120 +-		opj_stream_destroy(stream);
   1.121 +-		opj_destroy_codec(codec);
   1.122 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header");
   1.123 +-	}
   1.124 ++	opj_cio_close(stream);
   1.125 ++	opj_destroy_decompress(codec);
   1.126 + 
   1.127 +-	if (!opj_decode(codec, stream, jpx))
   1.128 +-	{
   1.129 +-		opj_stream_destroy(stream);
   1.130 +-		opj_destroy_codec(codec);
   1.131 +-		opj_image_destroy(jpx);
   1.132 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image");
   1.133 +-	}
   1.134 +-
   1.135 +-	opj_stream_destroy(stream);
   1.136 +-	opj_destroy_codec(codec);
   1.137 +-
   1.138 +-	/* jpx should never be NULL here, but check anyway */
   1.139 + 	if (!jpx)
   1.140 + 		fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed");
   1.141 + 
   1.142 +@@ -733,8 +674,8 @@
   1.143 + 	depth = jpx->comps[0].prec;
   1.144 + 	sgnd = jpx->comps[0].sgnd;
   1.145 + 
   1.146 +-	if (jpx->color_space == OPJ_CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
   1.147 +-	else if (jpx->color_space == OPJ_CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
   1.148 ++	if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
   1.149 ++	else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
   1.150 + 	else if (n == 2) { n = 1; a = 1; }
   1.151 + 	else if (n > 4) { n = 4; a = 1; }
   1.152 + 	else { a = 0; }