/src/ghostpdl/openjpeg/src/lib/openjp2/openjpeg.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The copyright in this software is being made available under the 2-clauses |
3 | | * BSD License, included below. This software may be subject to other third |
4 | | * party and contributor rights, including patent rights, and no such rights |
5 | | * are granted under this license. |
6 | | * |
7 | | * Copyright (c) 2005, Herve Drolon, FreeImage Team |
8 | | * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR |
9 | | * Copyright (c) 2012, CS Systemes d'Information, France |
10 | | * All rights reserved. |
11 | | * |
12 | | * Redistribution and use in source and binary forms, with or without |
13 | | * modification, are permitted provided that the following conditions |
14 | | * are met: |
15 | | * 1. Redistributions of source code must retain the above copyright |
16 | | * notice, this list of conditions and the following disclaimer. |
17 | | * 2. Redistributions in binary form must reproduce the above copyright |
18 | | * notice, this list of conditions and the following disclaimer in the |
19 | | * documentation and/or other materials provided with the distribution. |
20 | | * |
21 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' |
22 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
25 | | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
26 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
27 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
28 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
29 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
30 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31 | | * POSSIBILITY OF SUCH DAMAGE. |
32 | | */ |
33 | | |
34 | | #ifdef _WIN32 |
35 | | #include <windows.h> |
36 | | #endif /* _WIN32 */ |
37 | | |
38 | | #include "opj_includes.h" |
39 | | |
40 | | |
41 | | /* ---------------------------------------------------------------------- */ |
42 | | /* Functions to set the message handlers */ |
43 | | |
44 | | OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, |
45 | | opj_msg_callback p_callback, |
46 | | void * p_user_data) |
47 | 13.3k | { |
48 | 13.3k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
49 | 13.3k | if (! l_codec) { |
50 | 0 | return OPJ_FALSE; |
51 | 0 | } |
52 | | |
53 | 13.3k | l_codec->m_event_mgr.info_handler = p_callback; |
54 | 13.3k | l_codec->m_event_mgr.m_info_data = p_user_data; |
55 | | |
56 | 13.3k | return OPJ_TRUE; |
57 | 13.3k | } |
58 | | |
59 | | OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, |
60 | | opj_msg_callback p_callback, |
61 | | void * p_user_data) |
62 | 13.3k | { |
63 | 13.3k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
64 | 13.3k | if (! l_codec) { |
65 | 0 | return OPJ_FALSE; |
66 | 0 | } |
67 | | |
68 | 13.3k | l_codec->m_event_mgr.warning_handler = p_callback; |
69 | 13.3k | l_codec->m_event_mgr.m_warning_data = p_user_data; |
70 | | |
71 | 13.3k | return OPJ_TRUE; |
72 | 13.3k | } |
73 | | |
74 | | OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, |
75 | | opj_msg_callback p_callback, |
76 | | void * p_user_data) |
77 | 13.3k | { |
78 | 13.3k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
79 | 13.3k | if (! l_codec) { |
80 | 0 | return OPJ_FALSE; |
81 | 0 | } |
82 | | |
83 | 13.3k | l_codec->m_event_mgr.error_handler = p_callback; |
84 | 13.3k | l_codec->m_event_mgr.m_error_data = p_user_data; |
85 | | |
86 | 13.3k | return OPJ_TRUE; |
87 | 13.3k | } |
88 | | |
89 | | /* ---------------------------------------------------------------------- */ |
90 | | |
91 | | static OPJ_SIZE_T opj_read_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, |
92 | | void * p_user_data) |
93 | 0 | { |
94 | 0 | FILE* p_file = (FILE*)p_user_data; |
95 | 0 | OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, (FILE*)p_file); |
96 | 0 | return l_nb_read ? l_nb_read : (OPJ_SIZE_T) - 1; |
97 | 0 | } |
98 | | |
99 | | static OPJ_UINT64 opj_get_data_length_from_file(void * p_user_data) |
100 | 0 | { |
101 | 0 | FILE* p_file = (FILE*)p_user_data; |
102 | 0 | OPJ_OFF_T file_length = 0; |
103 | |
|
104 | 0 | OPJ_FSEEK(p_file, 0, SEEK_END); |
105 | 0 | file_length = (OPJ_OFF_T)OPJ_FTELL(p_file); |
106 | 0 | OPJ_FSEEK(p_file, 0, SEEK_SET); |
107 | |
|
108 | 0 | return (OPJ_UINT64)file_length; |
109 | 0 | } |
110 | | |
111 | | static OPJ_SIZE_T opj_write_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, |
112 | | void * p_user_data) |
113 | 0 | { |
114 | 0 | FILE* p_file = (FILE*)p_user_data; |
115 | 0 | return fwrite(p_buffer, 1, p_nb_bytes, p_file); |
116 | 0 | } |
117 | | |
118 | | static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) |
119 | 0 | { |
120 | 0 | FILE* p_file = (FILE*)p_user_data; |
121 | 0 | if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_CUR)) { |
122 | 0 | return -1; |
123 | 0 | } |
124 | | |
125 | 0 | return p_nb_bytes; |
126 | 0 | } |
127 | | |
128 | | static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) |
129 | 0 | { |
130 | 0 | FILE* p_file = (FILE*)p_user_data; |
131 | 0 | if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_SET)) { |
132 | 0 | return OPJ_FALSE; |
133 | 0 | } |
134 | | |
135 | 0 | return OPJ_TRUE; |
136 | 0 | } |
137 | | |
138 | | static void opj_close_from_file(void* p_user_data) |
139 | 0 | { |
140 | 0 | FILE* p_file = (FILE*)p_user_data; |
141 | 0 | fclose(p_file); |
142 | 0 | } |
143 | | |
144 | | /* ---------------------------------------------------------------------- */ |
145 | | #ifdef _WIN32 |
146 | | #ifndef OPJ_STATIC |
147 | | |
148 | | /* declaration to avoid warning: no previous prototype for 'DllMain' */ |
149 | | BOOL APIENTRY |
150 | | DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); |
151 | | |
152 | | BOOL APIENTRY |
153 | | DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) |
154 | | { |
155 | | |
156 | | OPJ_ARG_NOT_USED(lpReserved); |
157 | | OPJ_ARG_NOT_USED(hModule); |
158 | | |
159 | | switch (ul_reason_for_call) { |
160 | | case DLL_PROCESS_ATTACH : |
161 | | break; |
162 | | case DLL_PROCESS_DETACH : |
163 | | break; |
164 | | case DLL_THREAD_ATTACH : |
165 | | case DLL_THREAD_DETACH : |
166 | | break; |
167 | | } |
168 | | |
169 | | return TRUE; |
170 | | } |
171 | | #endif /* OPJ_STATIC */ |
172 | | #endif /* _WIN32 */ |
173 | | |
174 | | /* ---------------------------------------------------------------------- */ |
175 | | |
176 | | const char* OPJ_CALLCONV opj_version(void) |
177 | 0 | { |
178 | 0 | return OPJ_PACKAGE_VERSION; |
179 | 0 | } |
180 | | |
181 | | /* ---------------------------------------------------------------------- */ |
182 | | /* DECOMPRESSION FUNCTIONS*/ |
183 | | |
184 | | opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) |
185 | 13.3k | { |
186 | 13.3k | opj_codec_private_t *l_codec = 00; |
187 | | |
188 | 13.3k | l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t)); |
189 | 13.3k | if (!l_codec) { |
190 | 0 | return 00; |
191 | 0 | } |
192 | | |
193 | 13.3k | l_codec->is_decompressor = 1; |
194 | | |
195 | 13.3k | switch (p_format) { |
196 | 11 | case OPJ_CODEC_J2K: |
197 | 11 | l_codec->opj_dump_codec = (void (*)(void*, OPJ_INT32, FILE*)) j2k_dump; |
198 | | |
199 | 11 | l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*)( |
200 | 11 | void*)) j2k_get_cstr_info; |
201 | | |
202 | 11 | l_codec->opj_get_codec_index = (opj_codestream_index_t* (*)( |
203 | 11 | void*)) j2k_get_cstr_index; |
204 | | |
205 | 11 | l_codec->m_codec_data.m_decompression.opj_decode = |
206 | 11 | (OPJ_BOOL(*)(void *, |
207 | 11 | struct opj_stream_private *, |
208 | 11 | opj_image_t*, struct opj_event_mgr *)) opj_j2k_decode; |
209 | | |
210 | 11 | l_codec->m_codec_data.m_decompression.opj_end_decompress = |
211 | 11 | (OPJ_BOOL(*)(void *, |
212 | 11 | struct opj_stream_private *, |
213 | 11 | struct opj_event_mgr *)) opj_j2k_end_decompress; |
214 | | |
215 | 11 | l_codec->m_codec_data.m_decompression.opj_read_header = |
216 | 11 | (OPJ_BOOL(*)(struct opj_stream_private *, |
217 | 11 | void *, |
218 | 11 | opj_image_t **, |
219 | 11 | struct opj_event_mgr *)) opj_j2k_read_header; |
220 | | |
221 | 11 | l_codec->m_codec_data.m_decompression.opj_destroy = |
222 | 11 | (void (*)(void *))opj_j2k_destroy; |
223 | | |
224 | 11 | l_codec->m_codec_data.m_decompression.opj_setup_decoder = |
225 | 11 | (void (*)(void *, opj_dparameters_t *)) opj_j2k_setup_decoder; |
226 | | |
227 | 11 | l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = |
228 | 11 | (void (*)(void *, OPJ_BOOL)) opj_j2k_decoder_set_strict_mode; |
229 | | |
230 | | |
231 | 11 | l_codec->m_codec_data.m_decompression.opj_read_tile_header = |
232 | 11 | (OPJ_BOOL(*)(void *, |
233 | 11 | OPJ_UINT32*, |
234 | 11 | OPJ_UINT32*, |
235 | 11 | OPJ_INT32*, OPJ_INT32*, |
236 | 11 | OPJ_INT32*, OPJ_INT32*, |
237 | 11 | OPJ_UINT32*, |
238 | 11 | OPJ_BOOL*, |
239 | 11 | struct opj_stream_private *, |
240 | 11 | struct opj_event_mgr *)) opj_j2k_read_tile_header; |
241 | | |
242 | 11 | l_codec->m_codec_data.m_decompression.opj_decode_tile_data = |
243 | 11 | (OPJ_BOOL(*)(void *, |
244 | 11 | OPJ_UINT32, |
245 | 11 | OPJ_BYTE*, |
246 | 11 | OPJ_UINT32, |
247 | 11 | struct opj_stream_private *, |
248 | 11 | struct opj_event_mgr *)) opj_j2k_decode_tile; |
249 | | |
250 | 11 | l_codec->m_codec_data.m_decompression.opj_set_decode_area = |
251 | 11 | (OPJ_BOOL(*)(void *, |
252 | 11 | opj_image_t*, |
253 | 11 | OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, |
254 | 11 | struct opj_event_mgr *)) opj_j2k_set_decode_area; |
255 | | |
256 | 11 | l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = |
257 | 11 | (OPJ_BOOL(*)(void *p_codec, |
258 | 11 | opj_stream_private_t *p_cio, |
259 | 11 | opj_image_t *p_image, |
260 | 11 | struct opj_event_mgr * p_manager, |
261 | 11 | OPJ_UINT32 tile_index)) opj_j2k_get_tile; |
262 | | |
263 | 11 | l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = |
264 | 11 | (OPJ_BOOL(*)(void * p_codec, |
265 | 11 | OPJ_UINT32 res_factor, |
266 | 11 | struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor; |
267 | | |
268 | 11 | l_codec->m_codec_data.m_decompression.opj_set_decoded_components = |
269 | 11 | (OPJ_BOOL(*)(void * p_codec, |
270 | 11 | OPJ_UINT32 numcomps, |
271 | 11 | const OPJ_UINT32 * comps_indices, |
272 | 11 | struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_components; |
273 | | |
274 | 11 | l_codec->opj_set_threads = |
275 | 11 | (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; |
276 | | |
277 | 11 | l_codec->m_codec = opj_j2k_create_decompress(); |
278 | | |
279 | 11 | if (! l_codec->m_codec) { |
280 | 0 | opj_free(l_codec); |
281 | 0 | return NULL; |
282 | 0 | } |
283 | | |
284 | 11 | break; |
285 | | |
286 | 13.3k | case OPJ_CODEC_JP2: |
287 | | /* get a JP2 decoder handle */ |
288 | 13.3k | l_codec->opj_dump_codec = (void (*)(void*, OPJ_INT32, FILE*)) jp2_dump; |
289 | | |
290 | 13.3k | l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*)( |
291 | 13.3k | void*)) jp2_get_cstr_info; |
292 | | |
293 | 13.3k | l_codec->opj_get_codec_index = (opj_codestream_index_t* (*)( |
294 | 13.3k | void*)) jp2_get_cstr_index; |
295 | | |
296 | 13.3k | l_codec->m_codec_data.m_decompression.opj_decode = |
297 | 13.3k | (OPJ_BOOL(*)(void *, |
298 | 13.3k | struct opj_stream_private *, |
299 | 13.3k | opj_image_t*, |
300 | 13.3k | struct opj_event_mgr *)) opj_jp2_decode; |
301 | | |
302 | 13.3k | l_codec->m_codec_data.m_decompression.opj_end_decompress = |
303 | 13.3k | (OPJ_BOOL(*)(void *, |
304 | 13.3k | struct opj_stream_private *, |
305 | 13.3k | struct opj_event_mgr *)) opj_jp2_end_decompress; |
306 | | |
307 | 13.3k | l_codec->m_codec_data.m_decompression.opj_read_header = |
308 | 13.3k | (OPJ_BOOL(*)(struct opj_stream_private *, |
309 | 13.3k | void *, |
310 | 13.3k | opj_image_t **, |
311 | 13.3k | struct opj_event_mgr *)) opj_jp2_read_header; |
312 | | |
313 | 13.3k | l_codec->m_codec_data.m_decompression.opj_read_tile_header = |
314 | 13.3k | (OPJ_BOOL(*)(void *, |
315 | 13.3k | OPJ_UINT32*, |
316 | 13.3k | OPJ_UINT32*, |
317 | 13.3k | OPJ_INT32*, |
318 | 13.3k | OPJ_INT32*, |
319 | 13.3k | OPJ_INT32 *, |
320 | 13.3k | OPJ_INT32 *, |
321 | 13.3k | OPJ_UINT32 *, |
322 | 13.3k | OPJ_BOOL *, |
323 | 13.3k | struct opj_stream_private *, |
324 | 13.3k | struct opj_event_mgr *)) opj_jp2_read_tile_header; |
325 | | |
326 | 13.3k | l_codec->m_codec_data.m_decompression.opj_decode_tile_data = |
327 | 13.3k | (OPJ_BOOL(*)(void *, |
328 | 13.3k | OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, |
329 | 13.3k | struct opj_stream_private *, |
330 | 13.3k | struct opj_event_mgr *)) opj_jp2_decode_tile; |
331 | | |
332 | 13.3k | l_codec->m_codec_data.m_decompression.opj_destroy = (void (*)( |
333 | 13.3k | void *))opj_jp2_destroy; |
334 | | |
335 | 13.3k | l_codec->m_codec_data.m_decompression.opj_setup_decoder = |
336 | 13.3k | (void (*)(void *, opj_dparameters_t *)) opj_jp2_setup_decoder; |
337 | | |
338 | 13.3k | l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = |
339 | 13.3k | (void (*)(void *, OPJ_BOOL)) opj_jp2_decoder_set_strict_mode; |
340 | | |
341 | 13.3k | l_codec->m_codec_data.m_decompression.opj_set_decode_area = |
342 | 13.3k | (OPJ_BOOL(*)(void *, |
343 | 13.3k | opj_image_t*, |
344 | 13.3k | OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, |
345 | 13.3k | struct opj_event_mgr *)) opj_jp2_set_decode_area; |
346 | | |
347 | 13.3k | l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = |
348 | 13.3k | (OPJ_BOOL(*)(void *p_codec, |
349 | 13.3k | opj_stream_private_t *p_cio, |
350 | 13.3k | opj_image_t *p_image, |
351 | 13.3k | struct opj_event_mgr * p_manager, |
352 | 13.3k | OPJ_UINT32 tile_index)) opj_jp2_get_tile; |
353 | | |
354 | 13.3k | l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = |
355 | 13.3k | (OPJ_BOOL(*)(void * p_codec, |
356 | 13.3k | OPJ_UINT32 res_factor, |
357 | 13.3k | opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor; |
358 | | |
359 | 13.3k | l_codec->m_codec_data.m_decompression.opj_set_decoded_components = |
360 | 13.3k | (OPJ_BOOL(*)(void * p_codec, |
361 | 13.3k | OPJ_UINT32 numcomps, |
362 | 13.3k | const OPJ_UINT32 * comps_indices, |
363 | 13.3k | struct opj_event_mgr * p_manager)) opj_jp2_set_decoded_components; |
364 | | |
365 | 13.3k | l_codec->opj_set_threads = |
366 | 13.3k | (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; |
367 | | |
368 | 13.3k | l_codec->m_codec = opj_jp2_create(OPJ_TRUE); |
369 | | |
370 | 13.3k | if (! l_codec->m_codec) { |
371 | 0 | opj_free(l_codec); |
372 | 0 | return 00; |
373 | 0 | } |
374 | | |
375 | 13.3k | break; |
376 | 13.3k | case OPJ_CODEC_UNKNOWN: |
377 | 0 | case OPJ_CODEC_JPT: |
378 | 0 | default: |
379 | 0 | opj_free(l_codec); |
380 | 0 | return 00; |
381 | 13.3k | } |
382 | | |
383 | 13.3k | opj_set_default_event_handler(&(l_codec->m_event_mgr)); |
384 | 13.3k | return (opj_codec_t*) l_codec; |
385 | 13.3k | } |
386 | | |
387 | | void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t |
388 | | *parameters) |
389 | 13.3k | { |
390 | 13.3k | if (parameters) { |
391 | 13.3k | memset(parameters, 0, sizeof(opj_dparameters_t)); |
392 | | /* default decoding parameters */ |
393 | 13.3k | parameters->cp_layer = 0; |
394 | 13.3k | parameters->cp_reduce = 0; |
395 | | |
396 | 13.3k | parameters->decod_format = -1; |
397 | 13.3k | parameters->cod_format = -1; |
398 | 13.3k | parameters->flags = 0; |
399 | | /* UniPG>> */ |
400 | | #ifdef USE_JPWL |
401 | | parameters->jpwl_correct = OPJ_FALSE; |
402 | | parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS; |
403 | | parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES; |
404 | | #endif /* USE_JPWL */ |
405 | | /* <<UniPG */ |
406 | 13.3k | } |
407 | 13.3k | } |
408 | | |
409 | | |
410 | | OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, |
411 | | int num_threads) |
412 | 0 | { |
413 | 0 | if (p_codec && (num_threads >= 0)) { |
414 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
415 | |
|
416 | 0 | return l_codec->opj_set_threads(l_codec->m_codec, (OPJ_UINT32)num_threads); |
417 | 0 | } |
418 | 0 | return OPJ_FALSE; |
419 | 0 | } |
420 | | |
421 | | OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, |
422 | | opj_dparameters_t *parameters |
423 | | ) |
424 | 13.3k | { |
425 | 13.3k | if (p_codec && parameters) { |
426 | 13.3k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
427 | | |
428 | 13.3k | if (! l_codec->is_decompressor) { |
429 | 0 | opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, |
430 | 0 | "Codec provided to the opj_setup_decoder function is not a decompressor handler.\n"); |
431 | 0 | return OPJ_FALSE; |
432 | 0 | } |
433 | | |
434 | 13.3k | l_codec->m_codec_data.m_decompression.opj_setup_decoder(l_codec->m_codec, |
435 | 13.3k | parameters); |
436 | 13.3k | return OPJ_TRUE; |
437 | 13.3k | } |
438 | 0 | return OPJ_FALSE; |
439 | 13.3k | } |
440 | | |
441 | | OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, |
442 | | OPJ_BOOL strict) |
443 | 0 | { |
444 | 0 | if (p_codec) { |
445 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
446 | |
|
447 | 0 | if (! l_codec->is_decompressor) { |
448 | 0 | opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, |
449 | 0 | "Codec provided to the opj_decoder_set_strict_mode function is not a decompressor handler.\n"); |
450 | 0 | return OPJ_FALSE; |
451 | 0 | } |
452 | | |
453 | 0 | l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode( |
454 | 0 | l_codec->m_codec, |
455 | 0 | strict); |
456 | 0 | return OPJ_TRUE; |
457 | 0 | } |
458 | 0 | return OPJ_FALSE; |
459 | 0 | } |
460 | | |
461 | | OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, |
462 | | opj_codec_t *p_codec, |
463 | | opj_image_t **p_image) |
464 | 13.3k | { |
465 | 13.3k | if (p_codec && p_stream) { |
466 | 13.3k | opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; |
467 | 13.3k | opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; |
468 | | |
469 | 13.3k | if (! l_codec->is_decompressor) { |
470 | 0 | opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, |
471 | 0 | "Codec provided to the opj_read_header function is not a decompressor handler.\n"); |
472 | 0 | return OPJ_FALSE; |
473 | 0 | } |
474 | | |
475 | 13.3k | return l_codec->m_codec_data.m_decompression.opj_read_header(l_stream, |
476 | 13.3k | l_codec->m_codec, |
477 | 13.3k | p_image, |
478 | 13.3k | &(l_codec->m_event_mgr)); |
479 | 13.3k | } |
480 | | |
481 | 0 | return OPJ_FALSE; |
482 | 13.3k | } |
483 | | |
484 | | |
485 | | OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, |
486 | | OPJ_UINT32 numcomps, |
487 | | const OPJ_UINT32* comps_indices, |
488 | | OPJ_BOOL apply_color_transforms) |
489 | 0 | { |
490 | 0 | if (p_codec) { |
491 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
492 | |
|
493 | 0 | if (! l_codec->is_decompressor) { |
494 | 0 | opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, |
495 | 0 | "Codec provided to the opj_set_decoded_components function is not a decompressor handler.\n"); |
496 | 0 | return OPJ_FALSE; |
497 | 0 | } |
498 | | |
499 | 0 | if (apply_color_transforms) { |
500 | 0 | opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, |
501 | 0 | "apply_color_transforms = OPJ_TRUE is not supported.\n"); |
502 | 0 | return OPJ_FALSE; |
503 | 0 | } |
504 | | |
505 | 0 | return l_codec->m_codec_data.m_decompression.opj_set_decoded_components( |
506 | 0 | l_codec->m_codec, |
507 | 0 | numcomps, |
508 | 0 | comps_indices, |
509 | 0 | &(l_codec->m_event_mgr)); |
510 | 0 | } |
511 | 0 | return OPJ_FALSE; |
512 | 0 | } |
513 | | |
514 | | OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_codec, |
515 | | opj_stream_t *p_stream, |
516 | | opj_image_t* p_image) |
517 | 12.5k | { |
518 | 12.5k | if (p_codec && p_stream) { |
519 | 12.5k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
520 | 12.5k | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
521 | | |
522 | 12.5k | if (! l_codec->is_decompressor) { |
523 | 0 | return OPJ_FALSE; |
524 | 0 | } |
525 | | |
526 | 12.5k | return l_codec->m_codec_data.m_decompression.opj_decode(l_codec->m_codec, |
527 | 12.5k | l_stream, |
528 | 12.5k | p_image, |
529 | 12.5k | &(l_codec->m_event_mgr)); |
530 | 12.5k | } |
531 | | |
532 | 0 | return OPJ_FALSE; |
533 | 12.5k | } |
534 | | |
535 | | OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec, |
536 | | opj_image_t* p_image, |
537 | | OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, |
538 | | OPJ_INT32 p_end_x, OPJ_INT32 p_end_y |
539 | | ) |
540 | 0 | { |
541 | 0 | if (p_codec) { |
542 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
543 | |
|
544 | 0 | if (! l_codec->is_decompressor) { |
545 | 0 | return OPJ_FALSE; |
546 | 0 | } |
547 | | |
548 | 0 | return l_codec->m_codec_data.m_decompression.opj_set_decode_area( |
549 | 0 | l_codec->m_codec, |
550 | 0 | p_image, |
551 | 0 | p_start_x, p_start_y, |
552 | 0 | p_end_x, p_end_y, |
553 | 0 | &(l_codec->m_event_mgr)); |
554 | 0 | } |
555 | 0 | return OPJ_FALSE; |
556 | 0 | } |
557 | | |
558 | | OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec, |
559 | | opj_stream_t * p_stream, |
560 | | OPJ_UINT32 * p_tile_index, |
561 | | OPJ_UINT32 * p_data_size, |
562 | | OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, |
563 | | OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, |
564 | | OPJ_UINT32 * p_nb_comps, |
565 | | OPJ_BOOL * p_should_go_on) |
566 | 0 | { |
567 | 0 | if (p_codec && p_stream && p_data_size && p_tile_index) { |
568 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
569 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
570 | |
|
571 | 0 | if (! l_codec->is_decompressor) { |
572 | 0 | return OPJ_FALSE; |
573 | 0 | } |
574 | | |
575 | 0 | return l_codec->m_codec_data.m_decompression.opj_read_tile_header( |
576 | 0 | l_codec->m_codec, |
577 | 0 | p_tile_index, |
578 | 0 | p_data_size, |
579 | 0 | p_tile_x0, p_tile_y0, |
580 | 0 | p_tile_x1, p_tile_y1, |
581 | 0 | p_nb_comps, |
582 | 0 | p_should_go_on, |
583 | 0 | l_stream, |
584 | 0 | &(l_codec->m_event_mgr)); |
585 | 0 | } |
586 | 0 | return OPJ_FALSE; |
587 | 0 | } |
588 | | |
589 | | OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec, |
590 | | OPJ_UINT32 p_tile_index, |
591 | | OPJ_BYTE * p_data, |
592 | | OPJ_UINT32 p_data_size, |
593 | | opj_stream_t *p_stream |
594 | | ) |
595 | 0 | { |
596 | 0 | if (p_codec && p_data && p_stream) { |
597 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
598 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
599 | |
|
600 | 0 | if (! l_codec->is_decompressor) { |
601 | 0 | return OPJ_FALSE; |
602 | 0 | } |
603 | | |
604 | 0 | return l_codec->m_codec_data.m_decompression.opj_decode_tile_data( |
605 | 0 | l_codec->m_codec, |
606 | 0 | p_tile_index, |
607 | 0 | p_data, |
608 | 0 | p_data_size, |
609 | 0 | l_stream, |
610 | 0 | &(l_codec->m_event_mgr)); |
611 | 0 | } |
612 | 0 | return OPJ_FALSE; |
613 | 0 | } |
614 | | |
615 | | OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec, |
616 | | opj_stream_t *p_stream, |
617 | | opj_image_t *p_image, |
618 | | OPJ_UINT32 tile_index) |
619 | 0 | { |
620 | 0 | if (p_codec && p_stream) { |
621 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
622 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
623 | |
|
624 | 0 | if (! l_codec->is_decompressor) { |
625 | 0 | return OPJ_FALSE; |
626 | 0 | } |
627 | | |
628 | 0 | return l_codec->m_codec_data.m_decompression.opj_get_decoded_tile( |
629 | 0 | l_codec->m_codec, |
630 | 0 | l_stream, |
631 | 0 | p_image, |
632 | 0 | &(l_codec->m_event_mgr), |
633 | 0 | tile_index); |
634 | 0 | } |
635 | | |
636 | 0 | return OPJ_FALSE; |
637 | 0 | } |
638 | | |
639 | | OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, |
640 | | OPJ_UINT32 res_factor) |
641 | 0 | { |
642 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
643 | |
|
644 | 0 | if (!l_codec) { |
645 | 0 | return OPJ_FALSE; |
646 | 0 | } |
647 | | |
648 | 0 | return l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor( |
649 | 0 | l_codec->m_codec, |
650 | 0 | res_factor, |
651 | 0 | &(l_codec->m_event_mgr)); |
652 | 0 | } |
653 | | |
654 | | /* ---------------------------------------------------------------------- */ |
655 | | /* COMPRESSION FUNCTIONS*/ |
656 | | |
657 | | opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) |
658 | 0 | { |
659 | 0 | opj_codec_private_t *l_codec = 00; |
660 | |
|
661 | 0 | l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t)); |
662 | 0 | if (!l_codec) { |
663 | 0 | return 00; |
664 | 0 | } |
665 | | |
666 | 0 | l_codec->is_decompressor = 0; |
667 | |
|
668 | 0 | switch (p_format) { |
669 | 0 | case OPJ_CODEC_J2K: |
670 | 0 | l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, |
671 | 0 | struct opj_stream_private *, |
672 | 0 | struct opj_event_mgr *)) opj_j2k_encode; |
673 | |
|
674 | 0 | l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, |
675 | 0 | struct opj_stream_private *, |
676 | 0 | struct opj_event_mgr *)) opj_j2k_end_compress; |
677 | |
|
678 | 0 | l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, |
679 | 0 | struct opj_stream_private *, |
680 | 0 | struct opj_image *, |
681 | 0 | struct opj_event_mgr *)) opj_j2k_start_compress; |
682 | |
|
683 | 0 | l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, |
684 | 0 | OPJ_UINT32, |
685 | 0 | OPJ_BYTE*, |
686 | 0 | OPJ_UINT32, |
687 | 0 | struct opj_stream_private *, |
688 | 0 | struct opj_event_mgr *)) opj_j2k_write_tile; |
689 | |
|
690 | 0 | l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( |
691 | 0 | void *)) opj_j2k_destroy; |
692 | |
|
693 | 0 | l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, |
694 | 0 | opj_cparameters_t *, |
695 | 0 | struct opj_image *, |
696 | 0 | struct opj_event_mgr *)) opj_j2k_setup_encoder; |
697 | |
|
698 | 0 | l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( |
699 | 0 | *)(void *, |
700 | 0 | const char* const*, |
701 | 0 | struct opj_event_mgr *)) opj_j2k_encoder_set_extra_options; |
702 | |
|
703 | 0 | l_codec->opj_set_threads = |
704 | 0 | (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; |
705 | |
|
706 | 0 | l_codec->m_codec = opj_j2k_create_compress(); |
707 | 0 | if (! l_codec->m_codec) { |
708 | 0 | opj_free(l_codec); |
709 | 0 | return 00; |
710 | 0 | } |
711 | | |
712 | 0 | break; |
713 | | |
714 | 0 | case OPJ_CODEC_JP2: |
715 | | /* get a JP2 decoder handle */ |
716 | 0 | l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, |
717 | 0 | struct opj_stream_private *, |
718 | 0 | struct opj_event_mgr *)) opj_jp2_encode; |
719 | |
|
720 | 0 | l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, |
721 | 0 | struct opj_stream_private *, |
722 | 0 | struct opj_event_mgr *)) opj_jp2_end_compress; |
723 | |
|
724 | 0 | l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, |
725 | 0 | struct opj_stream_private *, |
726 | 0 | struct opj_image *, |
727 | 0 | struct opj_event_mgr *)) opj_jp2_start_compress; |
728 | |
|
729 | 0 | l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, |
730 | 0 | OPJ_UINT32, |
731 | 0 | OPJ_BYTE*, |
732 | 0 | OPJ_UINT32, |
733 | 0 | struct opj_stream_private *, |
734 | 0 | struct opj_event_mgr *)) opj_jp2_write_tile; |
735 | |
|
736 | 0 | l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( |
737 | 0 | void *)) opj_jp2_destroy; |
738 | |
|
739 | 0 | l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, |
740 | 0 | opj_cparameters_t *, |
741 | 0 | struct opj_image *, |
742 | 0 | struct opj_event_mgr *)) opj_jp2_setup_encoder; |
743 | |
|
744 | 0 | l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( |
745 | 0 | *)(void *, |
746 | 0 | const char* const*, |
747 | 0 | struct opj_event_mgr *)) opj_jp2_encoder_set_extra_options; |
748 | |
|
749 | 0 | l_codec->opj_set_threads = |
750 | 0 | (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; |
751 | |
|
752 | 0 | l_codec->m_codec = opj_jp2_create(OPJ_FALSE); |
753 | 0 | if (! l_codec->m_codec) { |
754 | 0 | opj_free(l_codec); |
755 | 0 | return 00; |
756 | 0 | } |
757 | | |
758 | 0 | break; |
759 | | |
760 | 0 | case OPJ_CODEC_UNKNOWN: |
761 | 0 | case OPJ_CODEC_JPT: |
762 | 0 | default: |
763 | 0 | opj_free(l_codec); |
764 | 0 | return 00; |
765 | 0 | } |
766 | | |
767 | 0 | opj_set_default_event_handler(&(l_codec->m_event_mgr)); |
768 | 0 | return (opj_codec_t*) l_codec; |
769 | 0 | } |
770 | | |
771 | | void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t |
772 | | *parameters) |
773 | 0 | { |
774 | 0 | if (parameters) { |
775 | 0 | memset(parameters, 0, sizeof(opj_cparameters_t)); |
776 | | /* default coding parameters */ |
777 | 0 | parameters->cp_cinema = OPJ_OFF; /* DEPRECATED */ |
778 | 0 | parameters->rsiz = OPJ_PROFILE_NONE; |
779 | 0 | parameters->max_comp_size = 0; |
780 | 0 | parameters->numresolution = OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION; |
781 | 0 | parameters->cp_rsiz = OPJ_STD_RSIZ; /* DEPRECATED */ |
782 | 0 | parameters->cblockw_init = OPJ_COMP_PARAM_DEFAULT_CBLOCKW; |
783 | 0 | parameters->cblockh_init = OPJ_COMP_PARAM_DEFAULT_CBLOCKH; |
784 | 0 | parameters->prog_order = OPJ_COMP_PARAM_DEFAULT_PROG_ORDER; |
785 | 0 | parameters->roi_compno = -1; /* no ROI */ |
786 | 0 | parameters->subsampling_dx = 1; |
787 | 0 | parameters->subsampling_dy = 1; |
788 | 0 | parameters->tp_on = 0; |
789 | 0 | parameters->decod_format = -1; |
790 | 0 | parameters->cod_format = -1; |
791 | 0 | parameters->tcp_rates[0] = 0; |
792 | 0 | parameters->tcp_numlayers = 0; |
793 | 0 | parameters->cp_disto_alloc = 0; |
794 | 0 | parameters->cp_fixed_alloc = 0; |
795 | 0 | parameters->cp_fixed_quality = 0; |
796 | 0 | parameters->jpip_on = OPJ_FALSE; |
797 | | /* UniPG>> */ |
798 | | #ifdef USE_JPWL |
799 | | parameters->jpwl_epc_on = OPJ_FALSE; |
800 | | parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */ |
801 | | { |
802 | | int i; |
803 | | for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { |
804 | | parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */ |
805 | | parameters->jpwl_hprot_TPH[i] = 0; /* absent */ |
806 | | } |
807 | | }; |
808 | | { |
809 | | int i; |
810 | | for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) { |
811 | | parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */ |
812 | | parameters->jpwl_pprot_packno[i] = -1; /* unassigned */ |
813 | | parameters->jpwl_pprot[i] = 0; /* absent */ |
814 | | } |
815 | | }; |
816 | | parameters->jpwl_sens_size = 0; /* 0 means no ESD */ |
817 | | parameters->jpwl_sens_addr = 0; /* 0 means auto */ |
818 | | parameters->jpwl_sens_range = 0; /* 0 means packet */ |
819 | | parameters->jpwl_sens_MH = -1; /* -1 means unassigned */ |
820 | | { |
821 | | int i; |
822 | | for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) { |
823 | | parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */ |
824 | | parameters->jpwl_sens_TPH[i] = -1; /* absent */ |
825 | | } |
826 | | }; |
827 | | #endif /* USE_JPWL */ |
828 | | /* <<UniPG */ |
829 | 0 | } |
830 | 0 | } |
831 | | |
832 | | OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, |
833 | | opj_cparameters_t *parameters, |
834 | | opj_image_t *p_image) |
835 | 0 | { |
836 | 0 | if (p_codec && parameters && p_image) { |
837 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
838 | |
|
839 | 0 | if (! l_codec->is_decompressor) { |
840 | 0 | return l_codec->m_codec_data.m_compression.opj_setup_encoder(l_codec->m_codec, |
841 | 0 | parameters, |
842 | 0 | p_image, |
843 | 0 | &(l_codec->m_event_mgr)); |
844 | 0 | } |
845 | 0 | } |
846 | | |
847 | 0 | return OPJ_FALSE; |
848 | 0 | } |
849 | | |
850 | | /* ----------------------------------------------------------------------- */ |
851 | | |
852 | | OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(opj_codec_t *p_codec, |
853 | | const char* const* options) |
854 | 0 | { |
855 | 0 | if (p_codec) { |
856 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
857 | |
|
858 | 0 | if (! l_codec->is_decompressor) { |
859 | 0 | return l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options( |
860 | 0 | l_codec->m_codec, |
861 | 0 | options, |
862 | 0 | &(l_codec->m_event_mgr)); |
863 | 0 | } |
864 | 0 | } |
865 | | |
866 | 0 | return OPJ_FALSE; |
867 | 0 | } |
868 | | |
869 | | /* ----------------------------------------------------------------------- */ |
870 | | |
871 | | OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, |
872 | | opj_image_t * p_image, |
873 | | opj_stream_t *p_stream) |
874 | 0 | { |
875 | 0 | if (p_codec && p_stream) { |
876 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
877 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
878 | |
|
879 | 0 | if (! l_codec->is_decompressor) { |
880 | 0 | return l_codec->m_codec_data.m_compression.opj_start_compress(l_codec->m_codec, |
881 | 0 | l_stream, |
882 | 0 | p_image, |
883 | 0 | &(l_codec->m_event_mgr)); |
884 | 0 | } |
885 | 0 | } |
886 | | |
887 | 0 | return OPJ_FALSE; |
888 | 0 | } |
889 | | |
890 | | OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream) |
891 | 0 | { |
892 | 0 | if (p_info && p_stream) { |
893 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_info; |
894 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
895 | |
|
896 | 0 | if (! l_codec->is_decompressor) { |
897 | 0 | return l_codec->m_codec_data.m_compression.opj_encode(l_codec->m_codec, |
898 | 0 | l_stream, |
899 | 0 | &(l_codec->m_event_mgr)); |
900 | 0 | } |
901 | 0 | } |
902 | | |
903 | 0 | return OPJ_FALSE; |
904 | |
|
905 | 0 | } |
906 | | |
907 | | OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec, |
908 | | opj_stream_t *p_stream) |
909 | 0 | { |
910 | 0 | if (p_codec && p_stream) { |
911 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
912 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
913 | |
|
914 | 0 | if (! l_codec->is_decompressor) { |
915 | 0 | return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec, |
916 | 0 | l_stream, |
917 | 0 | &(l_codec->m_event_mgr)); |
918 | 0 | } |
919 | 0 | } |
920 | 0 | return OPJ_FALSE; |
921 | |
|
922 | 0 | } |
923 | | |
924 | | OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec, |
925 | | opj_stream_t *p_stream) |
926 | 0 | { |
927 | 0 | if (p_codec && p_stream) { |
928 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
929 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
930 | |
|
931 | 0 | if (! l_codec->is_decompressor) { |
932 | 0 | return OPJ_FALSE; |
933 | 0 | } |
934 | | |
935 | 0 | return l_codec->m_codec_data.m_decompression.opj_end_decompress( |
936 | 0 | l_codec->m_codec, |
937 | 0 | l_stream, |
938 | 0 | &(l_codec->m_event_mgr)); |
939 | 0 | } |
940 | | |
941 | 0 | return OPJ_FALSE; |
942 | 0 | } |
943 | | |
944 | | OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, |
945 | | OPJ_FLOAT32 * pEncodingMatrix, |
946 | | OPJ_INT32 * p_dc_shift, OPJ_UINT32 pNbComp) |
947 | 0 | { |
948 | 0 | OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32); |
949 | 0 | OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32); |
950 | 0 | OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size; |
951 | | |
952 | | /* add MCT capability */ |
953 | 0 | if (OPJ_IS_PART2(parameters->rsiz)) { |
954 | 0 | parameters->rsiz |= OPJ_EXTENSION_MCT; |
955 | 0 | } else { |
956 | 0 | parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT)); |
957 | 0 | } |
958 | 0 | parameters->irreversible = 1; |
959 | | |
960 | | /* use array based MCT */ |
961 | 0 | parameters->tcp_mct = 2; |
962 | 0 | parameters->mct_data = opj_malloc(l_mct_total_size); |
963 | 0 | if (! parameters->mct_data) { |
964 | 0 | return OPJ_FALSE; |
965 | 0 | } |
966 | | |
967 | 0 | memcpy(parameters->mct_data, pEncodingMatrix, l_matrix_size); |
968 | 0 | memcpy(((OPJ_BYTE *) parameters->mct_data) + l_matrix_size, p_dc_shift, |
969 | 0 | l_dc_shift_size); |
970 | |
|
971 | 0 | return OPJ_TRUE; |
972 | 0 | } |
973 | | |
974 | | OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec, |
975 | | OPJ_UINT32 p_tile_index, |
976 | | OPJ_BYTE * p_data, |
977 | | OPJ_UINT32 p_data_size, |
978 | | opj_stream_t *p_stream) |
979 | 0 | { |
980 | 0 | if (p_codec && p_stream && p_data) { |
981 | 0 | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
982 | 0 | opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; |
983 | |
|
984 | 0 | if (l_codec->is_decompressor) { |
985 | 0 | return OPJ_FALSE; |
986 | 0 | } |
987 | | |
988 | 0 | return l_codec->m_codec_data.m_compression.opj_write_tile(l_codec->m_codec, |
989 | 0 | p_tile_index, |
990 | 0 | p_data, |
991 | 0 | p_data_size, |
992 | 0 | l_stream, |
993 | 0 | &(l_codec->m_event_mgr)); |
994 | 0 | } |
995 | | |
996 | 0 | return OPJ_FALSE; |
997 | 0 | } |
998 | | |
999 | | /* ---------------------------------------------------------------------- */ |
1000 | | |
1001 | | void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec) |
1002 | 13.3k | { |
1003 | 13.3k | if (p_codec) { |
1004 | 13.3k | opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; |
1005 | | |
1006 | 13.3k | if (l_codec->is_decompressor) { |
1007 | 13.3k | l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec); |
1008 | 13.3k | } else { |
1009 | 0 | l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec); |
1010 | 0 | } |
1011 | | |
1012 | 13.3k | l_codec->m_codec = 00; |
1013 | 13.3k | opj_free(l_codec); |
1014 | 13.3k | } |
1015 | 13.3k | } |
1016 | | |
1017 | | /* ---------------------------------------------------------------------- */ |
1018 | | |
1019 | | void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec, |
1020 | | OPJ_INT32 info_flag, |
1021 | | FILE* output_stream) |
1022 | 0 | { |
1023 | 0 | if (p_codec) { |
1024 | 0 | opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; |
1025 | |
|
1026 | 0 | l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream); |
1027 | 0 | return; |
1028 | 0 | } |
1029 | | |
1030 | | /* TODO return error */ |
1031 | | /* fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n"); */ |
1032 | 0 | return; |
1033 | 0 | } |
1034 | | |
1035 | | opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec) |
1036 | 0 | { |
1037 | 0 | if (p_codec) { |
1038 | 0 | opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; |
1039 | |
|
1040 | 0 | return l_codec->opj_get_codec_info(l_codec->m_codec); |
1041 | 0 | } |
1042 | | |
1043 | 0 | return NULL; |
1044 | 0 | } |
1045 | | |
1046 | | void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) |
1047 | 0 | { |
1048 | 0 | if (cstr_info) { |
1049 | |
|
1050 | 0 | if ((*cstr_info)->m_default_tile_info.tccp_info) { |
1051 | 0 | opj_free((*cstr_info)->m_default_tile_info.tccp_info); |
1052 | 0 | } |
1053 | |
|
1054 | 0 | if ((*cstr_info)->tile_info) { |
1055 | | /* FIXME not used for the moment*/ |
1056 | 0 | } |
1057 | |
|
1058 | 0 | opj_free((*cstr_info)); |
1059 | 0 | (*cstr_info) = NULL; |
1060 | 0 | } |
1061 | 0 | } |
1062 | | |
1063 | | opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec) |
1064 | 0 | { |
1065 | 0 | if (p_codec) { |
1066 | 0 | opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; |
1067 | |
|
1068 | 0 | return l_codec->opj_get_codec_index(l_codec->m_codec); |
1069 | 0 | } |
1070 | | |
1071 | 0 | return NULL; |
1072 | 0 | } |
1073 | | |
1074 | | void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) |
1075 | 0 | { |
1076 | 0 | if (*p_cstr_index) { |
1077 | 0 | j2k_destroy_cstr_index(*p_cstr_index); |
1078 | 0 | (*p_cstr_index) = NULL; |
1079 | 0 | } |
1080 | 0 | } |
1081 | | |
1082 | | opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream( |
1083 | | const char *fname, OPJ_BOOL p_is_read_stream) |
1084 | 0 | { |
1085 | 0 | return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, |
1086 | 0 | p_is_read_stream); |
1087 | 0 | } |
1088 | | |
1089 | | opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( |
1090 | | const char *fname, |
1091 | | OPJ_SIZE_T p_size, |
1092 | | OPJ_BOOL p_is_read_stream) |
1093 | 0 | { |
1094 | 0 | opj_stream_t* l_stream = 00; |
1095 | 0 | FILE *p_file; |
1096 | 0 | const char *mode; |
1097 | |
|
1098 | 0 | if (! fname) { |
1099 | 0 | return NULL; |
1100 | 0 | } |
1101 | | |
1102 | 0 | if (p_is_read_stream) { |
1103 | 0 | mode = "rb"; |
1104 | 0 | } else { |
1105 | 0 | mode = "wb"; |
1106 | 0 | } |
1107 | |
|
1108 | 0 | p_file = fopen(fname, mode); |
1109 | |
|
1110 | 0 | if (! p_file) { |
1111 | 0 | return NULL; |
1112 | 0 | } |
1113 | | |
1114 | 0 | l_stream = opj_stream_create(p_size, p_is_read_stream); |
1115 | 0 | if (! l_stream) { |
1116 | 0 | fclose(p_file); |
1117 | 0 | return NULL; |
1118 | 0 | } |
1119 | | |
1120 | 0 | opj_stream_set_user_data(l_stream, p_file, opj_close_from_file); |
1121 | 0 | opj_stream_set_user_data_length(l_stream, |
1122 | 0 | opj_get_data_length_from_file(p_file)); |
1123 | 0 | opj_stream_set_read_function(l_stream, opj_read_from_file); |
1124 | 0 | opj_stream_set_write_function(l_stream, |
1125 | 0 | (opj_stream_write_fn) opj_write_from_file); |
1126 | 0 | opj_stream_set_skip_function(l_stream, opj_skip_from_file); |
1127 | 0 | opj_stream_set_seek_function(l_stream, opj_seek_from_file); |
1128 | |
|
1129 | 0 | return l_stream; |
1130 | 0 | } |
1131 | | |
1132 | | |
1133 | | void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size) |
1134 | 34.4k | { |
1135 | 34.4k | void* ret = opj_aligned_malloc(size); |
1136 | | /* printf("opj_image_data_alloc %p\n", ret); */ |
1137 | 34.4k | return ret; |
1138 | 34.4k | } |
1139 | | |
1140 | | void OPJ_CALLCONV opj_image_data_free(void* ptr) |
1141 | 128k | { |
1142 | | /* printf("opj_image_data_free %p\n", ptr); */ |
1143 | 128k | opj_aligned_free(ptr); |
1144 | 128k | } |