OpenJpeg.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. (*
  2. * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
  3. * Copyright (c) 2002-2007, Professor Benoit Macq
  4. * Copyright (c) 2001-2003, David Janssens
  5. * Copyright (c) 2002-2003, Yannick Verschueren
  6. * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
  7. * Copyright (c) 2005, Herve Drolon, FreeImage Team
  8. * Copyright (c) 2006-2007, Parvatha Elangovan
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *)
  32. {
  33. Translated to Object Pascal by Marek Mauder (http://galfar.vevb.net)
  34. for Vampyre Imaging Library (http://imaginglib.sourceforge.net)
  35. Current translation is based on OpenJpeg 1.2.0 SVN revision 484
  36. }
  37. unit OpenJpeg;
  38. {$IFDEF FPC}
  39. { Free Pascal settings }
  40. {$MODE DELPHI}
  41. {$PACKRECORDS 8}
  42. {$PACKENUM 4}
  43. {$ELSE}
  44. { Delphi settings }
  45. {$DEFINE DCC}
  46. {$ALIGN 8}
  47. {$MINENUMSIZE 4}
  48. {$ENDIF}
  49. interface
  50. const
  51. OPENJPEG_VERSION = '1.2.0';
  52. type
  53. Bool = ByteBool;
  54. Char = AnsiChar;
  55. const
  56. { Maximum allowed size for filenames }
  57. OPJ_PATH_LEN = 4096;
  58. { Number of maximum resolution level authorized }
  59. J2K_MAXRLVLS = 33;
  60. { Number of maximum sub-band linked to number of resolution level }
  61. J2K_MAXBANDS = 3 * J2K_MAXRLVLS - 2;
  62. JPWL_MAX_NO_TILESPECS = 16;
  63. JPWL_MAX_NO_PACKSPECS = 16;
  64. JPWL_MAX_NO_MARKERS = 512;
  65. JPWL_PRIVATEINDEX_NAME = 'jpwl_index_privatefilename';
  66. JPWL_EXPECTED_COMPONENTS = 3;
  67. JPWL_MAXIMUM_TILES = 8192;
  68. JPWL_MAXIMUM_HAMMING = 2;
  69. JPWL_MAXIMUM_EPB_ROOM = 65450;
  70. { ==========================================================
  71. enum definitions
  72. ========================================================== }
  73. type
  74. { Rsiz Capabilities }
  75. RSIZ_CAPABILITIES = (
  76. STD_RSIZ = 0, { Standard JPEG2000 profile }
  77. CINEMA2K = 3, { Profile name for a 2K image }
  78. CINEMA4K = 4 { Profile name for a 4K image }
  79. );
  80. OPJ_RSIZ_CAPABILITIES = RSIZ_CAPABILITIES;
  81. { Digital cinema operation mode }
  82. CINEMA_MODE = (
  83. OFF = 0, { Not Digital Cinema }
  84. CINEMA2K_24 = 1, { 2K Digital Cinema at 24 fps }
  85. CINEMA2K_48 = 2, { 2K Digital Cinema at 48 fps }
  86. CINEMA4K_24 = 3 { 4K Digital Cinema at 24 fps }
  87. );
  88. OPJ_CINEMA_MODE = CINEMA_MODE;
  89. { Progression order }
  90. PROG_ORDER = (
  91. PROG_UNKNOWN = -1, { place-holder }
  92. LRCP = 0, { layer-resolution-component-precinct order }
  93. RLCP = 1, { resolution-layer-component-precinct order }
  94. RPCL = 2, { resolution-precinct-component-layer order }
  95. PCRL = 3, { precinct-component-resolution-layer order }
  96. CPRL = 4); { component-precinct-resolution-layer order }
  97. OPJ_PROG_ORDER = PROG_ORDER;
  98. { Supported image color spaces }
  99. COLOR_SPACE = (
  100. CLRSPC_UNKNOWN = -1, { place-holder }
  101. CLRSPC_SRGB = 1, { sRGB }
  102. CLRSPC_GRAY = 2, { grayscale }
  103. CLRSPC_SYCC = 3 { YUV }
  104. );
  105. OPJ_COLOR_SPACE = COLOR_SPACE;
  106. { Supported codec }
  107. CODEC_FORMAT = (
  108. CODEC_UNKNOWN = -1, { place-holder }
  109. CODEC_J2K = 0, { JPEG-2000 codestream : read/write }
  110. CODEC_JPT = 1, { JPT-stream (JPEG 2000, JPIP) : read only }
  111. CODEC_JP2 = 2); { JPEG-2000 file format : read/write }
  112. OPJ_CODEC_FORMAT = CODEC_FORMAT;
  113. { Limit decoding to certain portions of the codestream. }
  114. LIMIT_DECODING = (
  115. NO_LIMITATION = 0, { No limitation for the decoding. The entire codestream will de decoded }
  116. LIMIT_TO_MAIN_HEADER = 1, { The decoding is limited to the Main Header }
  117. DECODE_ALL_BUT_PACKETS = 2 { Decode everything except the JPEG 2000 packets }
  118. );
  119. OPJ_LIMIT_DECODING = LIMIT_DECODING;
  120. { ==========================================================
  121. event manager typedef definitions
  122. ========================================================== }
  123. { Callback function prototype for events }
  124. opj_msg_callback = procedure(msg: PChar; client_data: Pointer); cdecl;
  125. { Message handler object }
  126. opj_event_mgr = record
  127. error_handler: opj_msg_callback; { Error message callback if available, NULL otherwise }
  128. warning_handler: opj_msg_callback; { Warning message callback if available, NULL otherwise }
  129. info_handler: opj_msg_callback; { Debug message callback if available, NULL otherwise }
  130. end;
  131. opj_event_mgr_t = opj_event_mgr;
  132. popj_event_mgr_t = ^opj_event_mgr_t;
  133. { ==========================================================
  134. codec typedef definitions
  135. ========================================================== }
  136. { Progression order changes }
  137. opj_poc = record
  138. resno0, compno0: Integer;
  139. layno1, resno1, compno1: Integer;
  140. layno0, precno0, precno1: Integer;
  141. prg1, prg: OPJ_PROG_ORDER;
  142. progorder: array[0..4] of Char;
  143. tile: Integer;
  144. tx0, tx1, ty0, ty1: Integer;
  145. layS, resS, compS, prcS: Integer;
  146. layE, resE, compE, prcE: Integer;
  147. txS, txE, tyS, tyE, dx, dy: Integer;
  148. lay_t, res_t, comp_t, prc_t, tx0_t, ty0_t: Integer;
  149. end;
  150. opj_poc_t = opj_poc;
  151. { Compression parameters }
  152. opj_cparameters = record
  153. tile_size_on: Bool;
  154. cp_tx0: Integer;
  155. cp_ty0: Integer;
  156. cp_tdx: Integer;
  157. cp_tdy: Integer;
  158. cp_disto_alloc: Integer;
  159. cp_fixed_alloc: Integer;
  160. cp_fixed_quality: Integer;
  161. cp_matrice: PInteger;
  162. cp_comment: PChar;
  163. csty: Integer;
  164. prog_order: OPJ_PROG_ORDER;
  165. POC: array[0..31] of opj_poc_t;
  166. numpocs: Integer;
  167. tcp_numlayers: Integer;
  168. tcp_rates: array[0..99] of Single;
  169. tcp_distoratio: array[0..99] of Single;
  170. numresolution: Integer;
  171. cblockw_init: Integer;
  172. cblockh_init: Integer;
  173. mode: Integer;
  174. irreversible: Integer;
  175. roi_compno: Integer;
  176. roi_shift: Integer;
  177. res_spec: Integer;
  178. prcw_init: array[0..J2K_MAXRLVLS - 1] of Integer;
  179. prch_init: array[0..J2K_MAXRLVLS - 1] of Integer;
  180. infile: array[0..OPJ_PATH_LEN - 1] of Char;
  181. outfile: array[0..OPJ_PATH_LEN - 1] of Char;
  182. index_on: Integer;
  183. index: array[0..OPJ_PATH_LEN - 1] of Char;
  184. image_offset_x0: Integer;
  185. image_offset_y0: Integer;
  186. subsampling_dx: Integer;
  187. subsampling_dy: Integer;
  188. decod_format: Integer;
  189. cod_format: Integer;
  190. jpwl_epc_on: Bool;
  191. jpwl_hprot_MH: Integer;
  192. jpwl_hprot_TPH_tileno: array[0..JPWL_MAX_NO_TILESPECS - 1] of Integer;
  193. jpwl_hprot_TPH: array[0..JPWL_MAX_NO_TILESPECS - 1] of Integer;
  194. jpwl_pprot_tileno: array[0..JPWL_MAX_NO_PACKSPECS - 1] of Integer;
  195. jpwl_pprot_packno: array[0..JPWL_MAX_NO_PACKSPECS - 1] of Integer;
  196. jpwl_pprot: array[0..JPWL_MAX_NO_PACKSPECS - 1] of Integer;
  197. jpwl_sens_size: Integer;
  198. jpwl_sens_addr: Integer;
  199. jpwl_sens_range: Integer;
  200. jpwl_sens_MH: Integer;
  201. jpwl_sens_TPH_tileno: array[0..JPWL_MAX_NO_TILESPECS - 1] of Integer;
  202. jpwl_sens_TPH: array[0..JPWL_MAX_NO_TILESPECS - 1] of Integer;
  203. cp_cinema: OPJ_CINEMA_MODE;
  204. max_comp_size: Integer;
  205. cp_rsiz: OPJ_RSIZ_CAPABILITIES;
  206. tp_on: Byte;
  207. tp_flag: Byte;
  208. tcp_mct: Byte;
  209. end;
  210. opj_cparameters_t = opj_cparameters;
  211. popj_cparameters_t = ^opj_cparameters_t;
  212. { Decompression parameters }
  213. opj_dparameters = record
  214. cp_reduce: Integer;
  215. cp_layer: Integer;
  216. infile: array[0..OPJ_PATH_LEN - 1] of Char;
  217. outfile: array[0..OPJ_PATH_LEN - 1] of Char;
  218. decod_format: Integer;
  219. cod_format: Integer;
  220. jpwl_correct: Bool;
  221. jpwl_exp_comps: Integer;
  222. jpwl_max_tiles: Integer;
  223. cp_limit_decoding: OPJ_LIMIT_DECODING;
  224. end;
  225. opj_dparameters_t = opj_dparameters;
  226. popj_dparameters_t = ^opj_dparameters_t;
  227. { Routines that are to be used by both halves of the library are declared
  228. to receive a Pointer to this structure. There are no actual instances of
  229. opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t. }
  230. opj_common_struct = record
  231. event_mgr: popj_event_mgr_t; { Pointer to the event manager }
  232. client_data: Pointer; { Available for use by application }
  233. is_decompressor: Bool; { So common code can tell which is which }
  234. codec_format: OPJ_CODEC_FORMAT; { selected codec }
  235. j2k_handle: Pointer; { Pointer to the J2K codec }
  236. jp2_handle: Pointer; { Pointer to the JP2 codec }
  237. mj2_handle: Pointer;
  238. end;
  239. opj_common_struct_t = opj_common_struct;
  240. opj_common_ptr = ^opj_common_struct_t;
  241. { Compression context info }
  242. opj_cinfo = record
  243. event_mgr: popj_event_mgr_t;
  244. client_data: Pointer;
  245. is_decompressor: Bool;
  246. codec_format: OPJ_CODEC_FORMAT;
  247. j2k_handle: Pointer;
  248. jp2_handle: Pointer;
  249. mj2_handle: Pointer;
  250. end;
  251. opj_cinfo_t = opj_cinfo;
  252. popj_cinfo_t = ^opj_cinfo_t;
  253. { Decompression context info }
  254. opj_dinfo = record
  255. event_mgr: popj_event_mgr_t;
  256. client_data: Pointer;
  257. is_decompressor: Bool;
  258. codec_format: OPJ_CODEC_FORMAT;
  259. j2k_handle: Pointer;
  260. jp2_handle: Pointer;
  261. mj2_handle: Pointer;
  262. end;
  263. opj_dinfo_t = opj_dinfo;
  264. popj_dinfo_t = ^opj_dinfo_t;
  265. { ==========================================================
  266. I/O stream typedef definitions
  267. ========================================================== }
  268. const
  269. { Stream open flags. }
  270. { The stream was opened for reading. }
  271. OPJ_STREAM_READ = $0001;
  272. { The stream was opened for writing. }
  273. OPJ_STREAM_WRITE = $0002;
  274. type
  275. { Byte input-output stream (CIO) }
  276. opj_cio = record
  277. cinfo: opj_common_ptr; { codec context }
  278. openmode: Integer; { open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE }
  279. buffer: PChar; { Pointer to the start of the buffer }
  280. length: Integer; { buffer size in bytes }
  281. start: PChar; { Pointer to the start of the stream }
  282. end_: PChar; { Pointer to the end of the stream }
  283. bp: PChar; { Pointer to the current position }
  284. end;
  285. opj_cio_t = opj_cio;
  286. popj_cio_t = ^opj_cio_t;
  287. { ==========================================================
  288. image typedef definitions
  289. ========================================================== }
  290. { Defines a single image component }
  291. opj_image_comp = record
  292. dx: Integer; { XRsiz: horizontal separation of a sample of ith component with respect to the reference grid }
  293. dy: Integer; { YRsiz: vertical separation of a sample of ith component with respect to the reference grid }
  294. w: Integer; { data width }
  295. h: Integer; { data height }
  296. x0: Integer; { x component offset compared to the whole image }
  297. y0: Integer; { y component offset compared to the whole image }
  298. prec: Integer; { precision }
  299. bpp: Integer; { image depth in bits }
  300. sgnd: Integer; { signed (1) / unsigned (0) }
  301. resno_decoded: Integer; { number of decoded resolution }
  302. factor: Integer; { number of division by 2 of the out image compared to the original size of image }
  303. data: PIntegerArray; { image component data }
  304. end;
  305. opj_image_comp_t = opj_image_comp;
  306. popj_image_comp_t = ^opj_image_comp_t;
  307. opj_image_comp_array = array[0..255] of opj_image_comp_t;
  308. popj_image_comp_array = ^opj_image_comp_array;
  309. { Defines image data and Characteristics }
  310. opj_image = record
  311. x0: Integer; { XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area }
  312. y0: Integer; { YOsiz: vertical offset from the origin of the reference grid to the top side of the image area }
  313. x1: Integer; { Xsiz: width of the reference grid }
  314. y1: Integer; { Ysiz: height of the reference grid }
  315. numcomps: Integer; { number of components in the image }
  316. color_space: OPJ_COLOR_SPACE; { color space: sRGB, Greyscale or YUV }
  317. comps: popj_image_comp_array; { image components }
  318. end;
  319. opj_image_t = opj_image;
  320. popj_image_t = ^opj_image_t;
  321. { Component parameters structure used by the opj_image_create function }
  322. opj_image_comptparm = record
  323. dx: Integer; { XRsiz: horizontal separation of a sample of ith component with respect to the reference grid }
  324. dy: Integer; { YRsiz: vertical separation of a sample of ith component with respect to the reference grid }
  325. w: Integer; { data width }
  326. h: Integer; { data height }
  327. x0: Integer; { x component offset compared to the whole image }
  328. y0: Integer; { y component offset compared to the whole image }
  329. prec: Integer; { precision }
  330. bpp: Integer; { image depth in bits }
  331. sgnd: Integer; { signed (1) / unsigned (0) }
  332. end;
  333. opj_image_cmptparm_t = opj_image_comptparm;
  334. popj_image_cmptparm_t = ^opj_image_cmptparm_t;
  335. opj_image_cmptparm_array = array[0..255] of opj_image_cmptparm_t;
  336. popj_image_cmptparm_array = ^opj_image_cmptparm_array;
  337. { ==========================================================
  338. openjpeg version
  339. ========================================================== }
  340. function opj_version: PChar; cdecl; external;
  341. { ==========================================================
  342. image functions definitions
  343. ========================================================== }
  344. { Create an image
  345. @param numcmpts number of components
  346. @param cmptparms components parameters
  347. @param clrspc image color space
  348. @return returns a new image structure if successful, returns NULL otherwise }
  349. function opj_image_create(numcmpts: Integer; cmptparms: popj_image_cmptparm_t;
  350. clrspc: OPJ_COLOR_SPACE): popj_image_t; cdecl; external;
  351. { Deallocate any resources associated with an image
  352. @param image image to be destroyed }
  353. procedure opj_image_destroy(image: popj_image_t); cdecl; external;
  354. { ==========================================================
  355. stream functions definitions
  356. ========================================================== }
  357. { Open and allocate a memory stream for read / write.
  358. On reading, the user must provide a buffer containing encoded data. The buffer will be
  359. wrapped by the returned CIO handle.
  360. On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
  361. to contain encoded data.
  362. @param cinfo Codec context info
  363. @param buffer Reading: buffer address. Writing: NULL
  364. @param length Reading: buffer length. Writing: 0
  365. @return Returns a CIO handle if successful, returns NULL otherwise }
  366. function opj_cio_open(cinfo: opj_common_ptr; buffer: PByte;
  367. length: Integer): popj_cio_t; cdecl; external;
  368. { Close and free a CIO handle
  369. @param cio CIO handle to free }
  370. procedure opj_cio_close(cio: popj_cio_t); cdecl; external;
  371. { Get position in byte stream
  372. @param cio CIO handle
  373. @return Returns the position in bytes }
  374. function cio_tell(cio: popj_cio_t): Integer; cdecl; external;
  375. { Set position in byte stream
  376. @param cio CIO handle
  377. @param pos Position, in number of bytes, from the beginning of the stream }
  378. procedure cio_seek(cio: popj_cio_t; pos: Integer); cdecl; external;
  379. { ==========================================================
  380. event manager functions definitions
  381. ========================================================== }
  382. function opj_set_event_mgr(cinfo: opj_common_ptr; event_mgr: popj_event_mgr_t;
  383. context: Pointer): popj_event_mgr_t; cdecl; external;
  384. { ==========================================================
  385. codec functions definitions
  386. ========================================================== }
  387. { Creates a J2K/JPT/JP2 decompression structure
  388. @param format Decoder to select
  389. @return Returns a handle to a decompressor if successful, returns NULL otherwise }
  390. function opj_create_decompress(format: OPJ_CODEC_FORMAT): popj_dinfo_t; cdecl; external;
  391. { Destroy a decompressor handle
  392. @param dinfo decompressor handle to destroy }
  393. procedure opj_destroy_decompress(dinfo: popj_dinfo_t); cdecl; external;
  394. { Set decoding parameters to default values
  395. @param parameters Decompression parameters }
  396. procedure opj_set_default_decoder_parameters(parameters: popj_dparameters_t); cdecl; external ;
  397. { Setup the decoder decoding parameters using user parameters.
  398. Decoding parameters are returned in j2k->cp.
  399. @param dinfo decompressor handle
  400. @param parameters decompression parameters }
  401. procedure opj_setup_decoder(dinfo: popj_dinfo_t; parameters: popj_dparameters_t); cdecl; external;
  402. { Decode an image from a JPEG-2000 codestream
  403. @param dinfo decompressor handle
  404. @param cio Input buffer stream
  405. @return Returns a decoded image if successful, returns NULL otherwise }
  406. function opj_decode(dinfo: popj_dinfo_t; cio: popj_cio_t): popj_image_t; cdecl; external;
  407. { Creates a J2K/JP2 compression structure
  408. @param format Coder to select
  409. @return Returns a handle to a compressor if successful, returns NULL otherwise }
  410. function opj_create_compress(format: OPJ_CODEC_FORMAT): popj_cinfo_t; cdecl; external;
  411. { Destroy a compressor handle
  412. @param cinfo compressor handle to destroy }
  413. procedure opj_destroy_compress(cinfo: popj_cinfo_t); cdecl; external;
  414. { Set encoding parameters to default values, that means :
  415. <ul>
  416. <li>Lossless
  417. <li>1 tile
  418. <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
  419. <li>Size of code-block : 64 x 64
  420. <li>Number of resolutions: 6
  421. <li>No SOP marker in the codestream
  422. <li>No EPH marker in the codestream
  423. <li>No sub-sampling in x or y direction
  424. <li>No mode switch activated
  425. <li>Progression order: LRCP
  426. <li>No index file
  427. <li>No ROI upshifted
  428. <li>No offset of the origin of the image
  429. <li>No offset of the origin of the tiles
  430. <li>Reversible DWT 5-3
  431. </ul>
  432. @param parameters Compression parameters }
  433. procedure opj_set_default_encoder_parameters(parameters: popj_cparameters_t); cdecl; external;
  434. { Setup the encoder parameters using the current image and using user parameters.
  435. @param cinfo compressor handle
  436. @param parameters compression parameters
  437. @param image input filled image }
  438. procedure opj_setup_encoder(cinfo: popj_cinfo_t; parameters: popj_cparameters_t;
  439. image: popj_image_t); cdecl; external;
  440. { Encode an image into a JPEG-2000 codestream
  441. @param cinfo compressor handle
  442. @param cio Output buffer stream
  443. @param image Image to encode
  444. @param index Name of the index file if required, NULL otherwise
  445. @return Returns true if successful, returns false otherwise }
  446. function opj_encode(cinfo: popj_cinfo_t; cio: popj_cio_t; image: popj_image_t;
  447. index: PChar): Bool; cdecl; external;
  448. implementation
  449. {$IF Defined(WIN32)}
  450. {$IF Defined(DCC)}
  451. { Delphi Win32 }
  452. { First link object files created with C++ Builder.}
  453. {$L J2KObjects\w32bor_pi.obj}
  454. {$L J2KObjects\w32bor_openjpeg.obj}
  455. {$L J2KObjects\w32bor_j2k_lib.obj}
  456. {$L J2KObjects\w32bor_event.obj}
  457. {$L J2KObjects\w32bor_cio.obj}
  458. {$L J2KObjects\w32bor_image.obj}
  459. {$L J2KObjects\w32bor_j2k.obj}
  460. {$L J2KObjects\w32bor_jp2.obj}
  461. {$L J2KObjects\w32bor_jpt.obj}
  462. {$L J2KObjects\w32bor_mqc.obj}
  463. {$L J2KObjects\w32bor_raw.obj}
  464. {$L J2KObjects\w32bor_bio.obj}
  465. {$L J2KObjects\w32bor_tgt.obj}
  466. {$L J2KObjects\w32bor_tcd.obj}
  467. {$L J2KObjects\w32bor_t1.obj}
  468. {$L J2KObjects\w32bor_dwt.obj}
  469. {$L J2KObjects\w32bor_t2.obj}
  470. {$L J2KObjects\w32bor_mct.obj}
  471. const
  472. { MS C Runtime library needed for importing std C functions.}
  473. MSCRuntimeLib = 'msvcrt.dll';
  474. var
  475. { Some unresolved external constants.}
  476. __turboFloat: Integer;
  477. _max_dble: Double;
  478. _streams: Pointer;
  479. { Internal OpenJpeg functions external declarations.
  480. Delphi yells 'unsatisfied external declaration' if they are not referenced here.}
  481. procedure mqc_create; cdecl; external;
  482. procedure raw_create; cdecl; external;
  483. procedure bio_create; cdecl; external;
  484. procedure opj_image_create0; cdecl; external;
  485. procedure opj_event_msg; cdecl; external;
  486. procedure opj_clock; cdecl; external;
  487. procedure cio_read; cdecl; external;
  488. procedure cio_write; cdecl; external;
  489. procedure cio_skip; cdecl; external;
  490. procedure bio_read; cdecl; external;
  491. procedure bio_write; cdecl; external;
  492. procedure cio_numbytesleft; cdecl; external;
  493. procedure cio_getbp; cdecl; external;
  494. procedure j2k_destroy_compress; cdecl; external;
  495. procedure tgt_create; cdecl; external;
  496. procedure tgt_destroy; cdecl; external;
  497. procedure mqc_bypass_enc; cdecl; external;
  498. procedure mqc_encode; cdecl; external;
  499. procedure mqc_decode; cdecl; external;
  500. procedure raw_decode; cdecl; external;
  501. procedure mqc_resetstates; cdecl; external;
  502. procedure mqc_setstate; cdecl; external;
  503. procedure mqc_init_enc; cdecl; external;
  504. procedure mqc_segmark_enc; cdecl; external;
  505. procedure mqc_flush; cdecl; external;
  506. procedure mqc_bypass_init_enc; cdecl; external;
  507. procedure mqc_numbytes; cdecl; external;
  508. procedure mqc_reset_enc; cdecl; external;
  509. procedure mqc_erterm_enc; cdecl; external;
  510. procedure mqc_init_dec; cdecl; external;
  511. procedure raw_init_dec; cdecl; external;
  512. procedure mqc_destroy; cdecl; external;
  513. procedure mqc_restart_init_enc; cdecl; external;
  514. procedure raw_destroy; cdecl; external;
  515. procedure tgt_reset; cdecl; external;
  516. procedure tgt_setvalue; cdecl; external;
  517. procedure bio_init_enc; cdecl; external;
  518. procedure bio_flush; cdecl; external;
  519. procedure bio_numbytes; cdecl; external;
  520. procedure bio_destroy; cdecl; external;
  521. procedure bio_init_dec; cdecl; external;
  522. procedure pi_create_encode; cdecl; external;
  523. procedure pi_initialise_encode; cdecl; external;
  524. procedure pi_create_decode; cdecl; external;
  525. procedure pi_next; cdecl; external;
  526. procedure pi_destroy; cdecl; external;
  527. procedure tgt_encode; cdecl; external;
  528. procedure tgt_decode; cdecl; external;
  529. procedure bio_inalign; cdecl; external;
  530. procedure _llmul; cdecl;
  531. asm
  532. { from Delphi's System.pas __llmul }
  533. push edx
  534. push eax
  535. mov eax, [esp+16]
  536. mul dword ptr [esp]
  537. mov ecx, eax
  538. mov eax, [esp+4]
  539. mul dword ptr [esp+12]
  540. add ecx, eax
  541. mov eax, [esp]
  542. mul dword ptr [esp+12]
  543. add edx, ecx
  544. pop ecx
  545. pop ecx
  546. ret 8
  547. end;
  548. { C library imports }
  549. function malloc(size: Cardinal): Pointer; cdecl; external MSCRuntimeLib;
  550. function calloc(nelem, elsize: Cardinal): Pointer; cdecl; external MSCRuntimeLib;
  551. procedure free(ptr: Pointer); cdecl; external MSCRuntimeLib;
  552. function realloc(ptr: Pointer; size: Cardinal): Pointer; cdecl; external MSCRuntimeLib;
  553. function memset(s: Pointer; c, n: Cardinal): Pointer; cdecl; external MSCRuntimeLib;
  554. function memcpy(s1, s2: Pointer; n: Cardinal): Pointer; cdecl; external MSCRuntimeLib;
  555. function floor(const x: Double): Double; cdecl; external MSCRuntimeLib;
  556. function ceil(const num: Double): Double; cdecl; external MSCRuntimeLib;
  557. function pow(const base, exponent: Double): Double; cdecl; external MSCRuntimeLib;
  558. function printf(format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  559. function fprintf(f: Pointer; format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  560. function vsprintf(s, format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  561. function _ftol(x: Single): LongInt; cdecl; external MSCRuntimeLib;
  562. function wcscpy(s1, s2: PWideChar): PWideChar; cdecl; external MSCRuntimeLib;
  563. function strcpy(s1, s2: PChar): PChar; cdecl; external MSCRuntimeLib;
  564. function strlen(s: PChar): Integer; cdecl; external MSCRuntimeLib;
  565. {$ELSEIF Defined(FPC)}
  566. { Free Pascal Win32 }
  567. { Link OpenJpeg static library and C runtime library.}
  568. {$linklib libopenjpegwin32.a}
  569. {$linklib libcrtdll.a}
  570. {$IFEND}
  571. {$ELSEIF Defined(LINUX)}
  572. {$IF Defined(FPC)}
  573. { Free Pascal Linux }
  574. { Link C runtime library.}
  575. {$LINKLIB stdc++}
  576. {$IF Defined(CPU86)}
  577. { Free Pascal Linux x86 }
  578. { Link OpenJpeg static library.}
  579. {$linklib libopenjpeglinx86.a}
  580. {$ELSEIF Defined(CPUX86_64)}
  581. { Free Pascal Linux x86_64 }
  582. { Link OpenJpeg static library.}
  583. {$linklib libopenjpeglinx86_64.a}
  584. {$ELSE}
  585. No support for this CPU architecture.
  586. {$IFEND}
  587. {$ELSE}
  588. No support for this compiler
  589. {$IFEND}
  590. {$ELSE}
  591. No suppor for this OS
  592. {$IFEND}
  593. end.