openjpeg.c 37 KB

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