openjpeg.c 37 KB

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