wok-next view 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 source
1 commit a7341e98ef48d6041028b7294d1acc13665b04ba
2 Author: Quoc-Viet Nguyen <afelion@gmail.com>
3 Date: Fri Apr 18 23:48:29 2014 +1000
5 Use openjpeg 1.5 rather than 2.0
6 ---
7 source/fitz/load-jpx.c | 104 +++++++++----------------------------------------
8 1 file changed, 18 insertions(+), 86 deletions(-)
10 diff --git a/source/fitz/load-jpx.c b/source/fitz/load-jpx.c
11 index dfb89f4..d27b5de 100644
12 --- a/source/fitz/load-jpx.c
13 +++ b/source/fitz/load-jpx.c
14 @@ -605,41 +605,6 @@
15 /* fz_warn("openjpeg info: %s", msg); */
16 }
18 -static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
19 -{
20 - stream_block *sb = (stream_block *)p_user_data;
21 - OPJ_SIZE_T len;
22 -
23 - len = sb->size - sb->pos;
24 - if (len == 0)
25 - return (OPJ_SIZE_T)-1; /* End of file! */
26 - if (len > p_nb_bytes)
27 - len = p_nb_bytes;
28 - memcpy(p_buffer, sb->data + sb->pos, len);
29 - sb->pos += len;
30 - return len;
31 -}
32 -
33 -static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data)
34 -{
35 - stream_block *sb = (stream_block *)p_user_data;
36 -
37 - if (skip > (OPJ_OFF_T)(sb->size - sb->pos))
38 - skip = (OPJ_OFF_T)(sb->size - sb->pos);
39 - sb->pos += skip;
40 - return sb->pos;
41 -}
42 -
43 -static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data)
44 -{
45 - stream_block *sb = (stream_block *)p_user_data;
46 -
47 - if (seek_pos > (OPJ_OFF_T)sb->size)
48 - return OPJ_FALSE;
49 - sb->pos = seek_pos;
50 - return OPJ_TRUE;
51 -}
52 -
53 static int
54 l2subfactor(fz_context *ctx, unsigned int max_w, unsigned int w)
55 {
56 @@ -656,10 +621,11 @@
57 jpx_read_image(fz_context *ctx, fz_jpxd *state, unsigned char *data, size_t size, fz_colorspace *defcs, int onlymeta)
58 {
59 fz_pixmap *img;
60 + opj_event_mgr_t evtmgr;
61 opj_dparameters_t params;
62 - opj_codec_t *codec;
63 + opj_dinfo_t *codec;
64 opj_image_t *jpx;
65 - opj_stream_t *stream;
66 + opj_cio_t *stream;
67 unsigned char *p;
68 OPJ_CODEC_FORMAT format;
69 int a, n, w, h, depth, sgnd;
70 @@ -677,55 +643,30 @@
72 /* Check for SOC marker -- if found we have a bare J2K stream */
73 if (data[0] == 0xFF && data[1] == 0x4F)
74 - format = OPJ_CODEC_J2K;
75 + format = CODEC_J2K;
76 else
77 - format = OPJ_CODEC_JP2;
78 + format = CODEC_JP2;
80 + memset(&evtmgr, 0, sizeof(evtmgr));
81 + evtmgr.error_handler = fz_opj_error_callback;
82 + evtmgr.warning_handler = fz_opj_warning_callback;
83 + evtmgr.info_handler = fz_opj_info_callback;
84 +
85 opj_set_default_decoder_parameters(¶ms);
86 if (fz_colorspace_is_indexed(ctx, defcs))
87 params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
89 codec = opj_create_decompress(format);
90 - opj_set_info_handler(codec, fz_opj_info_callback, ctx);
91 - opj_set_warning_handler(codec, fz_opj_warning_callback, ctx);
92 - opj_set_error_handler(codec, fz_opj_error_callback, ctx);
93 - if (!opj_setup_decoder(codec, ¶ms))
94 - {
95 - opj_destroy_codec(codec);
96 - fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed");
97 - }
98 + opj_set_event_mgr((opj_common_ptr)codec, &evtmgr, ctx);
99 + opj_setup_decoder(codec, ¶ms);
101 - stream = opj_stream_default_create(OPJ_TRUE);
102 - sb.data = data;
103 - sb.pos = 0;
104 - sb.size = size;
105 + stream = opj_cio_open((opj_common_ptr)codec, data, size);
107 - opj_stream_set_read_function(stream, fz_opj_stream_read);
108 - opj_stream_set_skip_function(stream, fz_opj_stream_skip);
109 - opj_stream_set_seek_function(stream, fz_opj_stream_seek);
110 - opj_stream_set_user_data(stream, &sb, NULL);
111 - /* Set the length to avoid an assert */
112 - opj_stream_set_user_data_length(stream, size);
113 + jpx = opj_decode(codec, stream);
115 - if (!opj_read_header(stream, codec, &jpx))
116 - {
117 - opj_stream_destroy(stream);
118 - opj_destroy_codec(codec);
119 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header");
120 - }
121 + opj_cio_close(stream);
122 + opj_destroy_decompress(codec);
124 - if (!opj_decode(codec, stream, jpx))
125 - {
126 - opj_stream_destroy(stream);
127 - opj_destroy_codec(codec);
128 - opj_image_destroy(jpx);
129 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image");
130 - }
131 -
132 - opj_stream_destroy(stream);
133 - opj_destroy_codec(codec);
134 -
135 - /* jpx should never be NULL here, but check anyway */
136 if (!jpx)
137 fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed");
139 @@ -733,8 +674,8 @@
140 depth = jpx->comps[0].prec;
141 sgnd = jpx->comps[0].sgnd;
143 - if (jpx->color_space == OPJ_CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
144 - else if (jpx->color_space == OPJ_CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
145 + if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
146 + else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
147 else if (n == 2) { n = 1; a = 1; }
148 else if (n > 4) { n = 4; a = 1; }
149 else { a = 0; }