wok-current rev 16622

mupdf: add debian patch (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri May 09 07:59:54 2014 +0000 (2014-05-09)
parents ee113b0de7d8
children d4c113773ad1
files mupdf/stuff/use_openjpeg_1.5.patch
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mupdf/stuff/use_openjpeg_1.5.patch	Fri May 09 07:59:54 2014 +0000
     1.3 @@ -0,0 +1,160 @@
     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 +@@ -27,119 +27,51 @@ static void fz_opj_info_callback(const char *msg, void *client_data)
    1.18 + 	/* fz_warn("openjpeg info: %s", msg); */
    1.19 + }
    1.20 + 
    1.21 +-typedef struct stream_block_s
    1.22 +-{
    1.23 +-	unsigned char *data;
    1.24 +-	int size;
    1.25 +-	int pos;
    1.26 +-} stream_block;
    1.27 +-
    1.28 +-static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
    1.29 +-{
    1.30 +-	stream_block *sb = (stream_block *)p_user_data;
    1.31 +-	int len;
    1.32 +-
    1.33 +-	len = sb->size - sb->pos;
    1.34 +-	if (len < 0)
    1.35 +-		len = 0;
    1.36 +-	if (len == 0)
    1.37 +-		return (OPJ_SIZE_T)-1;  /* End of file! */
    1.38 +-	if ((OPJ_SIZE_T)len > p_nb_bytes)
    1.39 +-		len = p_nb_bytes;
    1.40 +-	memcpy(p_buffer, sb->data + sb->pos, len);
    1.41 +-	sb->pos += len;
    1.42 +-	return len;
    1.43 +-}
    1.44 +-
    1.45 +-static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data)
    1.46 +-{
    1.47 +-	stream_block *sb = (stream_block *)p_user_data;
    1.48 +-
    1.49 +-	if (skip > sb->size - sb->pos)
    1.50 +-		skip = sb->size - sb->pos;
    1.51 +-	sb->pos += skip;
    1.52 +-	return sb->pos;
    1.53 +-}
    1.54 +-
    1.55 +-static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data)
    1.56 +-{
    1.57 +-	stream_block *sb = (stream_block *)p_user_data;
    1.58 +-
    1.59 +-	if (seek_pos > sb->size)
    1.60 +-		return OPJ_FALSE;
    1.61 +-	sb->pos = seek_pos;
    1.62 +-	return OPJ_TRUE;
    1.63 +-}
    1.64 +-
    1.65 + fz_pixmap *
    1.66 + fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed)
    1.67 + {
    1.68 + 	fz_pixmap *img;
    1.69 + 	fz_colorspace *origcs;
    1.70 ++	opj_event_mgr_t evtmgr;
    1.71 + 	opj_dparameters_t params;
    1.72 +-	opj_codec_t *codec;
    1.73 ++	opj_dinfo_t *codec;
    1.74 + 	opj_image_t *jpx;
    1.75 +-	opj_stream_t *stream;
    1.76 ++	opj_cio_t *stream;
    1.77 + 	fz_colorspace *colorspace;
    1.78 + 	unsigned char *p;
    1.79 + 	OPJ_CODEC_FORMAT format;
    1.80 + 	int a, n, w, h, depth, sgnd;
    1.81 + 	int x, y, k, v;
    1.82 +-	stream_block sb;
    1.83 + 
    1.84 + 	if (size < 2)
    1.85 + 		fz_throw(ctx, FZ_ERROR_GENERIC, "not enough data to determine image format");
    1.86 + 
    1.87 + 	/* Check for SOC marker -- if found we have a bare J2K stream */
    1.88 + 	if (data[0] == 0xFF && data[1] == 0x4F)
    1.89 +-		format = OPJ_CODEC_J2K;
    1.90 ++		format = CODEC_J2K;
    1.91 + 	else
    1.92 +-		format = OPJ_CODEC_JP2;
    1.93 ++		format = CODEC_JP2;
    1.94 ++
    1.95 ++	memset(&evtmgr, 0, sizeof(evtmgr));
    1.96 ++	evtmgr.error_handler = fz_opj_error_callback;
    1.97 ++	evtmgr.warning_handler = fz_opj_warning_callback;
    1.98 ++	evtmgr.info_handler = fz_opj_info_callback;
    1.99 + 
   1.100 + 	opj_set_default_decoder_parameters(&params);
   1.101 + 	if (indexed)
   1.102 + 		params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
   1.103 + 
   1.104 + 	codec = opj_create_decompress(format);
   1.105 +-	opj_set_info_handler(codec, fz_opj_info_callback, ctx);
   1.106 +-	opj_set_warning_handler(codec, fz_opj_warning_callback, ctx);
   1.107 +-	opj_set_error_handler(codec, fz_opj_error_callback, ctx);
   1.108 +-	if (!opj_setup_decoder(codec, &params))
   1.109 +-	{
   1.110 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed");
   1.111 +-	}
   1.112 +-
   1.113 +-	stream = opj_stream_default_create(OPJ_TRUE);
   1.114 +-	sb.data = data;
   1.115 +-	sb.pos = 0;
   1.116 +-	sb.size = size;
   1.117 ++	opj_set_event_mgr((opj_common_ptr)codec, &evtmgr, ctx);
   1.118 ++	opj_setup_decoder(codec, &params);
   1.119 + 
   1.120 +-	opj_stream_set_read_function(stream, fz_opj_stream_read);
   1.121 +-	opj_stream_set_skip_function(stream, fz_opj_stream_skip);
   1.122 +-	opj_stream_set_seek_function(stream, fz_opj_stream_seek);
   1.123 +-	opj_stream_set_user_data(stream, &sb);
   1.124 +-	/* Set the length to avoid an assert */
   1.125 +-	opj_stream_set_user_data_length(stream, size);
   1.126 ++	stream = opj_cio_open((opj_common_ptr)codec, data, size);
   1.127 + 
   1.128 +-	if (!opj_read_header(stream, codec, &jpx))
   1.129 +-	{
   1.130 +-		opj_stream_destroy(stream);
   1.131 +-		opj_destroy_codec(codec);
   1.132 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header");
   1.133 +-	}
   1.134 +-
   1.135 +-	if (!opj_decode(codec, stream, jpx))
   1.136 +-	{
   1.137 +-		opj_stream_destroy(stream);
   1.138 +-		opj_destroy_codec(codec);
   1.139 +-		opj_image_destroy(jpx);
   1.140 +-		fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image");
   1.141 +-	}
   1.142 ++	jpx = opj_decode(codec, stream);
   1.143 + 
   1.144 +-	opj_stream_destroy(stream);
   1.145 +-	opj_destroy_codec(codec);
   1.146 ++	opj_cio_close(stream);
   1.147 ++	opj_destroy_decompress(codec);
   1.148 + 
   1.149 +-	/* jpx should never be NULL here, but check anyway */
   1.150 + 	if (!jpx)
   1.151 + 		fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed");
   1.152 + 
   1.153 +@@ -173,8 +105,8 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs
   1.154 + 	depth = jpx->comps[0].prec;
   1.155 + 	sgnd = jpx->comps[0].sgnd;
   1.156 + 
   1.157 +-	if (jpx->color_space == OPJ_CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
   1.158 +-	else if (jpx->color_space == OPJ_CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
   1.159 ++	if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
   1.160 ++	else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
   1.161 + 	else if (n == 2) { n = 1; a = 1; }
   1.162 + 	else if (n > 4) { n = 4; a = 1; }
   1.163 + 	else { a = 0; }