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