wok view mupdf/stuff/use_openjpeg_1.5.patch @ rev 25491
Up foomatic-db-nonfree (20221116)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Nov 17 12:13:24 2022 +0000 (23 months ago) |
parents | |
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 @@ -27,119 +27,51 @@ static void fz_opj_info_callback(const char *msg, void *client_data)
15 /* fz_warn("openjpeg info: %s", msg); */
16 }
18 -typedef struct stream_block_s
19 -{
20 - unsigned char *data;
21 - int size;
22 - int pos;
23 -} stream_block;
24 -
25 -static OPJ_SIZE_T fz_opj_stream_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
26 -{
27 - stream_block *sb = (stream_block *)p_user_data;
28 - int len;
29 -
30 - len = sb->size - sb->pos;
31 - if (len < 0)
32 - len = 0;
33 - if (len == 0)
34 - return (OPJ_SIZE_T)-1; /* End of file! */
35 - if ((OPJ_SIZE_T)len > p_nb_bytes)
36 - len = p_nb_bytes;
37 - memcpy(p_buffer, sb->data + sb->pos, len);
38 - sb->pos += len;
39 - return len;
40 -}
41 -
42 -static OPJ_OFF_T fz_opj_stream_skip(OPJ_OFF_T skip, void * p_user_data)
43 -{
44 - stream_block *sb = (stream_block *)p_user_data;
45 -
46 - if (skip > sb->size - sb->pos)
47 - skip = sb->size - sb->pos;
48 - sb->pos += skip;
49 - return sb->pos;
50 -}
51 -
52 -static OPJ_BOOL fz_opj_stream_seek(OPJ_OFF_T seek_pos, void * p_user_data)
53 -{
54 - stream_block *sb = (stream_block *)p_user_data;
55 -
56 - if (seek_pos > sb->size)
57 - return OPJ_FALSE;
58 - sb->pos = seek_pos;
59 - return OPJ_TRUE;
60 -}
61 -
62 fz_pixmap *
63 fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs, int indexed)
64 {
65 fz_pixmap *img;
66 fz_colorspace *origcs;
67 + opj_event_mgr_t evtmgr;
68 opj_dparameters_t params;
69 - opj_codec_t *codec;
70 + opj_dinfo_t *codec;
71 opj_image_t *jpx;
72 - opj_stream_t *stream;
73 + opj_cio_t *stream;
74 fz_colorspace *colorspace;
75 unsigned char *p;
76 OPJ_CODEC_FORMAT format;
77 int a, n, w, h, depth, sgnd;
78 int x, y, k, v;
79 - stream_block sb;
81 if (size < 2)
82 fz_throw(ctx, FZ_ERROR_GENERIC, "not enough data to determine image format");
84 /* Check for SOC marker -- if found we have a bare J2K stream */
85 if (data[0] == 0xFF && data[1] == 0x4F)
86 - format = OPJ_CODEC_J2K;
87 + format = CODEC_J2K;
88 else
89 - format = OPJ_CODEC_JP2;
90 + format = CODEC_JP2;
91 +
92 + memset(&evtmgr, 0, sizeof(evtmgr));
93 + evtmgr.error_handler = fz_opj_error_callback;
94 + evtmgr.warning_handler = fz_opj_warning_callback;
95 + evtmgr.info_handler = fz_opj_info_callback;
97 opj_set_default_decoder_parameters(¶ms);
98 if (indexed)
99 params.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
101 codec = opj_create_decompress(format);
102 - opj_set_info_handler(codec, fz_opj_info_callback, ctx);
103 - opj_set_warning_handler(codec, fz_opj_warning_callback, ctx);
104 - opj_set_error_handler(codec, fz_opj_error_callback, ctx);
105 - if (!opj_setup_decoder(codec, ¶ms))
106 - {
107 - fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed");
108 - }
109 -
110 - stream = opj_stream_default_create(OPJ_TRUE);
111 - sb.data = data;
112 - sb.pos = 0;
113 - sb.size = size;
114 + opj_set_event_mgr((opj_common_ptr)codec, &evtmgr, ctx);
115 + opj_setup_decoder(codec, ¶ms);
117 - opj_stream_set_read_function(stream, fz_opj_stream_read);
118 - opj_stream_set_skip_function(stream, fz_opj_stream_skip);
119 - opj_stream_set_seek_function(stream, fz_opj_stream_seek);
120 - opj_stream_set_user_data(stream, &sb);
121 - /* Set the length to avoid an assert */
122 - opj_stream_set_user_data_length(stream, size);
123 + stream = opj_cio_open((opj_common_ptr)codec, data, size);
125 - if (!opj_read_header(stream, codec, &jpx))
126 - {
127 - opj_stream_destroy(stream);
128 - opj_destroy_codec(codec);
129 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header");
130 - }
131 -
132 - if (!opj_decode(codec, stream, jpx))
133 - {
134 - opj_stream_destroy(stream);
135 - opj_destroy_codec(codec);
136 - opj_image_destroy(jpx);
137 - fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image");
138 - }
139 + jpx = opj_decode(codec, stream);
141 - opj_stream_destroy(stream);
142 - opj_destroy_codec(codec);
143 + opj_cio_close(stream);
144 + opj_destroy_decompress(codec);
146 - /* jpx should never be NULL here, but check anyway */
147 if (!jpx)
148 fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed");
150 @@ -173,8 +105,8 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs
151 depth = jpx->comps[0].prec;
152 sgnd = jpx->comps[0].sgnd;
154 - if (jpx->color_space == OPJ_CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
155 - else if (jpx->color_space == OPJ_CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
156 + if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
157 + else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
158 else if (n == 2) { n = 1; a = 1; }
159 else if (n > 4) { n = 4; a = 1; }
160 else { a = 0; }