OpenJpeg.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. {
  2. * Copyright (c) 2001-2003, David Janssens
  3. * Copyright (c) 2002-2003, Yannick Verschueren
  4. * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
  5. * Copyright (c) 2005, Hervé Drolon, FreeImage Team
  6. * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. }
  30. {
  31. Translated to Object Pascal by Marek Mauder for Vampyre Imaging Library
  32. http://imaginglib.sourceforge.net
  33. }
  34. unit OpenJpeg;
  35. {$I ImagingOptions.inc}
  36. interface
  37. const
  38. OPENJPEG_VERSION = '1.1.0';
  39. { ==========================================================
  40. Compiler directives
  41. ========================================================== }
  42. type
  43. //Bool = LongBool;
  44. Bool = ByteBool;
  45. Char = AnsiChar;
  46. const
  47. { Maximum allowed size for filenames }
  48. MAX_PATH = 260;
  49. { Number of maximum resolution level authorized }
  50. J2K_MAXRLVLS = 33;
  51. { Number of maximum sub-band linked to number of resolution level }
  52. J2K_MAXBANDS = 3 * J2K_MAXRLVLS - 2;
  53. { ==========================================================
  54. enum definitions
  55. ========================================================== }
  56. type
  57. { Progression order }
  58. PROG_ORDER = (
  59. PROG_UNKNOWN = -1, { place-holder }
  60. LRCP = 0, { layer-resolution-component-precinct order }
  61. RLCP = 1, { resolution-layer-component-precinct order }
  62. RPCL = 2, { resolution-precinct-component-layer order }
  63. PCRL = 3, { precinct-component-resolution-layer order }
  64. CPRL = 4); { component-precinct-resolution-layer order }
  65. OPJ_PROG_ORDER = PROG_ORDER;
  66. { Supported image color spaces }
  67. COLOR_SPACE = (
  68. CLRSPC_UNKNOWN = -1, { place-holder }
  69. CLRSPC_SRGB = 1, { sRGB }
  70. CLRSPC_GRAY = 2, { grayscale }
  71. CLRSPC_SYCC = 3, { YUV }
  72. CLRSCR_FORCE32);
  73. OPJ_COLOR_SPACE = COLOR_SPACE;
  74. { Supported codec }
  75. CODEC_FORMAT = (
  76. CODEC_UNKNOWN = -1, { place-holder }
  77. CODEC_J2K = 0, { JPEG-2000 codestream : read/write }
  78. CODEC_JPT = 1, { JPT-stream (JPEG 2000, JPIP) : read only }
  79. CODEC_JP2 = 2); { JPEG-2000 file format : read/write }
  80. OPJ_CODEC_FORMAT = CODEC_FORMAT;
  81. { ==========================================================
  82. event manager typedef definitions
  83. ========================================================== }
  84. { Callback function prototype for events }
  85. opj_msg_callback = procedure(msg: PChar; client_data: Pointer); cdecl;
  86. { Message handler object }
  87. opj_event_mgr = record
  88. error_handler: opj_msg_callback; { Error message callback if available, NULL otherwise }
  89. warning_handler: opj_msg_callback; { Warning message callback if available, NULL otherwise }
  90. info_handler: opj_msg_callback; { Debug message callback if available, NULL otherwise }
  91. end;
  92. opj_event_mgr_t = opj_event_mgr;
  93. popj_event_mgr_t = ^opj_event_mgr_t;
  94. { ==========================================================
  95. codec typedef definitions
  96. ========================================================== }
  97. { Progression order changes }
  98. opj_poc = record
  99. resno0: Integer;
  100. compno0: Integer;
  101. layno1: Integer;
  102. resno1: Integer;
  103. compno1: Integer;
  104. prg: OPJ_PROG_ORDER;
  105. tile: Integer;
  106. progorder: array[0..3] of Char;
  107. end;
  108. opj_poc_t = opj_poc;
  109. { Compression parameters }
  110. opj_cparameters = record
  111. tile_size_on: Bool;
  112. cp_tx0: Integer;
  113. cp_ty0: Integer;
  114. cp_tdx: Integer;
  115. cp_tdy: Integer;
  116. cp_disto_alloc: Integer;
  117. cp_fixed_alloc: Integer;
  118. cp_fixed_quality: Integer;
  119. cp_matrice: PInteger;
  120. cp_comment: PChar;
  121. csty: Integer;
  122. prog_order: OPJ_PROG_ORDER;
  123. POC: array[0..31] of opj_poc_t;
  124. numpocs: Integer;
  125. tcp_numlayers: Integer;
  126. tcp_rates: array[0..99] of Single;
  127. tcp_distoratio: array[0..99] of Single;
  128. numresolution: Integer;
  129. cblockw_init: Integer;
  130. cblockh_init: Integer;
  131. mode: Integer;
  132. irreversible: Integer;
  133. roi_compno: Integer;
  134. roi_shift: Integer;
  135. res_spec: Integer;
  136. prcw_init: array[0..J2K_MAXRLVLS - 1] of Integer;
  137. prch_init: array[0..J2K_MAXRLVLS - 1] of Integer;
  138. infile: array[0..MAX_PATH - 1] of Char;
  139. outfile: array[0..MAX_PATH - 1] of Char;
  140. index_on: Integer;
  141. index: array[0..MAX_PATH - 1] of Char;
  142. image_offset_x0: Integer;
  143. image_offset_y0: Integer;
  144. subsampling_dx: Integer;
  145. subsampling_dy: Integer;
  146. decod_format: Integer;
  147. cod_format: Integer;
  148. end;
  149. opj_cparameters_t = opj_cparameters;
  150. popj_cparameters_t = ^opj_cparameters_t;
  151. { Decompression parameters }
  152. opj_dparameters = record
  153. { Set the number of highest resolution levels to be discarded.
  154. The image resolution is effectively divided by 2 to the power of the number of discarded levels.
  155. The reduce factor is limited by the smallest total number of decomposition levels among tiles.
  156. if != 0, then original dimension divided by 2^(reduce);
  157. if == 0 or not used, image is decoded to the full resolution }
  158. cp_reduce: Integer;
  159. { Set the maximum number of quality layers to decode.
  160. If there are less quality layers than the specified number, all the quality layers are decoded.
  161. if != 0, then only the first "layer" layers are decoded;
  162. if == 0 or not used, all the quality layers are decoded }
  163. cp_layer: Integer;
  164. { @name command line encoder parameters (not used inside the library) }
  165. { input file name }
  166. infile: array[0..MAX_PATH - 1] of Char;
  167. { output file name }
  168. outfile: array[0..MAX_PATH - 1] of Char;
  169. { input file format 0: J2K, 1: JP2, 2: JPT }
  170. decod_format: Integer;
  171. { output file format 0: PGX, 1: PxM, 2: BMP }
  172. cod_format: Integer;
  173. end;
  174. opj_dparameters_t = opj_dparameters;
  175. popj_dparameters_t = ^opj_dparameters_t;
  176. { Routines that are to be used by both halves of the library are declared
  177. to receive a Pointer to this structure. There are no actual instances of
  178. opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t. }
  179. opj_common_struct = record
  180. event_mgr: popj_event_mgr_t; { Pointer to the event manager }
  181. client_data: Pointer; { Available for use by application }
  182. is_decompressor: Bool; { So common code can tell which is which }
  183. codec_format: OPJ_CODEC_FORMAT; { selected codec }
  184. j2k_handle: Pointer; { Pointer to the J2K codec }
  185. jp2_handle: Pointer; { Pointer to the JP2 codec }
  186. end;
  187. opj_common_struct_t = opj_common_struct;
  188. opj_common_ptr = ^opj_common_struct_t;
  189. { Compression context info }
  190. opj_cinfo = record
  191. event_mgr: popj_event_mgr_t;
  192. client_data: Pointer;
  193. is_decompressor: Bool;
  194. codec_format: OPJ_CODEC_FORMAT;
  195. j2k_handle: Pointer;
  196. jp2_handle: Pointer;
  197. end;
  198. opj_cinfo_t = opj_cinfo;
  199. popj_cinfo_t = ^opj_cinfo_t;
  200. { Decompression context info }
  201. opj_dinfo = record
  202. event_mgr: popj_event_mgr_t;
  203. client_data: Pointer;
  204. is_decompressor: Bool;
  205. codec_format: OPJ_CODEC_FORMAT;
  206. j2k_handle: Pointer;
  207. jp2_handle: Pointer;
  208. end;
  209. opj_dinfo_t = opj_dinfo;
  210. popj_dinfo_t = ^opj_dinfo_t;
  211. { ==========================================================
  212. I/O stream typedef definitions
  213. ========================================================== }
  214. const
  215. { Stream open flags. }
  216. { The stream was opened for reading. }
  217. OPJ_STREAM_READ = $0001;
  218. {* The stream was opened for writing. }
  219. OPJ_STREAM_WRITE = $0002;
  220. type
  221. { Byte input-output stream (CIO) }
  222. opj_cio = record
  223. cinfo: opj_common_ptr; { codec context }
  224. openmode: Integer; { open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE }
  225. buffer: PChar; { Pointer to the start of the buffer }
  226. length: Integer; { buffer size in bytes }
  227. start: PChar; { Pointer to the start of the stream }
  228. end_: PChar; { Pointer to the end of the stream }
  229. bp: PChar; { Pointer to the current position }
  230. end;
  231. opj_cio_t = opj_cio;
  232. popj_cio_t = ^opj_cio_t;
  233. { ==========================================================
  234. image typedef definitions
  235. ========================================================== }
  236. { Defines a single image component }
  237. opj_image_comp = record
  238. dx: Integer; { XRsiz: horizontal separation of a sample of ith component with respect to the reference grid }
  239. dy: Integer; { YRsiz: vertical separation of a sample of ith component with respect to the reference grid }
  240. w: Integer; { data width }
  241. h: Integer; { data height }
  242. x0: Integer; { x component offset compared to the whole image }
  243. y0: Integer; { y component offset compared to the whole image }
  244. prec: Integer; { precision }
  245. bpp: Integer; { image depth in bits }
  246. sgnd: Integer; { signed (1) / unsigned (0) }
  247. resno_decoded: Integer; { number of decoded resolution }
  248. factor: Integer; { number of division by 2 of the out image compared to the original size of image }
  249. data: PIntegerArray; { image component data }
  250. end;
  251. opj_image_comp_t = opj_image_comp;
  252. popj_image_comp_t = ^opj_image_comp_t;
  253. opj_image_comp_array = array[0..255] of opj_image_comp_t;
  254. popj_image_comp_array = ^opj_image_comp_array;
  255. { Defines image data and Characteristics }
  256. opj_image = record
  257. x0: Integer; { XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area }
  258. y0: Integer; { YOsiz: vertical offset from the origin of the reference grid to the top side of the image area }
  259. x1: Integer; { Xsiz: width of the reference grid }
  260. y1: Integer; { Ysiz: height of the reference grid }
  261. numcomps: Integer; { number of components in the image }
  262. color_space: OPJ_COLOR_SPACE; { color space: sRGB, Greyscale or YUV }
  263. comps: popj_image_comp_array; { image components }
  264. end;
  265. opj_image_t = opj_image;
  266. popj_image_t = ^opj_image_t;
  267. { Component parameters structure used by the opj_image_create function }
  268. opj_image_comptparm = record
  269. dx: Integer; { XRsiz: horizontal separation of a sample of ith component with respect to the reference grid }
  270. dy: Integer; { YRsiz: vertical separation of a sample of ith component with respect to the reference grid }
  271. w: Integer; { data width }
  272. h: Integer; { data height }
  273. x0: Integer; { x component offset compared to the whole image }
  274. y0: Integer; { y component offset compared to the whole image }
  275. prec: Integer; { precision }
  276. bpp: Integer; { image depth in bits }
  277. sgnd: Integer; { signed (1) / unsigned (0) }
  278. end;
  279. opj_image_cmptparm_t = opj_image_comptparm;
  280. popj_image_cmptparm_t = ^opj_image_cmptparm_t;
  281. opj_image_cmptparm_array = array[0..255] of opj_image_cmptparm_t;
  282. popj_image_cmptparm_array = ^opj_image_cmptparm_array;
  283. { ==========================================================
  284. openjpeg version
  285. ========================================================== }
  286. function opj_version: PChar; cdecl; external;
  287. { ==========================================================
  288. image functions definitions
  289. ========================================================== }
  290. { Create an image
  291. @param numcmpts number of components
  292. @param cmptparms components parameters
  293. @param clrspc image color space
  294. @return returns a new image structure if successful, returns NULL otherwise }
  295. function opj_image_create(numcmpts: Integer; cmptparms: popj_image_cmptparm_t;
  296. clrspc: OPJ_COLOR_SPACE): popj_image_t; cdecl; external;
  297. { Deallocate any resources associated with an image
  298. @param image image to be destroyed }
  299. procedure opj_image_destroy(image: popj_image_t); cdecl; external;
  300. { ==========================================================
  301. stream functions definitions
  302. ========================================================== }
  303. { Open and allocate a memory stream for read / write.
  304. On reading, the user must provide a buffer containing encoded data. The buffer will be
  305. wrapped by the returned CIO handle.
  306. On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
  307. to contain encoded data.
  308. @param cinfo Codec context info
  309. @param buffer Reading: buffer address. Writing: NULL
  310. @param length Reading: buffer length. Writing: 0
  311. @return Returns a CIO handle if successful, returns NULL otherwise }
  312. function opj_cio_open(cinfo: opj_common_ptr; buffer: PByte;
  313. length: Integer): popj_cio_t; cdecl; external;
  314. { Close and free a CIO handle
  315. @param cio CIO handle to free }
  316. procedure opj_cio_close(cio: popj_cio_t); cdecl; external;
  317. { Get position in byte stream
  318. @param cio CIO handle
  319. @return Returns the position in bytes }
  320. function cio_tell(cio: popj_cio_t): Integer; cdecl; external;
  321. { Set position in byte stream
  322. @param cio CIO handle
  323. @param pos Position, in number of bytes, from the beginning of the stream }
  324. procedure cio_seek(cio: popj_cio_t; pos: Integer); cdecl; external;
  325. { ==========================================================
  326. event manager functions definitions
  327. ========================================================== }
  328. function opj_set_event_mgr(cinfo: opj_common_ptr; event_mgr: popj_event_mgr_t;
  329. context: Pointer): popj_event_mgr_t; cdecl; external;
  330. { ==========================================================
  331. codec functions definitions
  332. ========================================================== }
  333. { Creates a J2K/JPT/JP2 decompression structure
  334. @param format Decoder to select
  335. @return Returns a handle to a decompressor if successful, returns NULL otherwise }
  336. function opj_create_decompress(format: OPJ_CODEC_FORMAT): popj_dinfo_t; cdecl; external;
  337. { Destroy a decompressor handle
  338. @param dinfo decompressor handle to destroy }
  339. procedure opj_destroy_decompress(dinfo: popj_dinfo_t); cdecl; external;
  340. { Set decoding parameters to default values
  341. @param parameters Decompression parameters }
  342. procedure opj_set_default_decoder_parameters(parameters: popj_dparameters_t); cdecl; external ;
  343. { Setup the decoder decoding parameters using user parameters.
  344. Decoding parameters are returned in j2k->cp.
  345. @param dinfo decompressor handle
  346. @param parameters decompression parameters }
  347. procedure opj_setup_decoder(dinfo: popj_dinfo_t; parameters: popj_dparameters_t); cdecl; external;
  348. { Decode an image from a JPEG-2000 codestream
  349. @param dinfo decompressor handle
  350. @param cio Input buffer stream
  351. @return Returns a decoded image if successful, returns NULL otherwise }
  352. function opj_decode(dinfo: popj_dinfo_t; cio: popj_cio_t): popj_image_t; cdecl; external;
  353. { Creates a J2K/JP2 compression structure
  354. @param format Coder to select
  355. @return Returns a handle to a compressor if successful, returns NULL otherwise }
  356. function opj_create_compress(format: OPJ_CODEC_FORMAT): popj_cinfo_t; cdecl; external;
  357. { Destroy a compressor handle
  358. @param cinfo compressor handle to destroy }
  359. procedure opj_destroy_compress(cinfo: popj_cinfo_t); cdecl; external;
  360. { Set encoding parameters to default values, that means :
  361. <ul>
  362. <li>Lossless
  363. <li>1 tile
  364. <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
  365. <li>Size of code-block : 64 x 64
  366. <li>Number of resolutions: 6
  367. <li>No SOP marker in the codestream
  368. <li>No EPH marker in the codestream
  369. <li>No sub-sampling in x or y direction
  370. <li>No mode switch activated
  371. <li>Progression order: LRCP
  372. <li>No index file
  373. <li>No ROI upshifted
  374. <li>No offset of the origin of the image
  375. <li>No offset of the origin of the tiles
  376. <li>Reversible DWT 5-3
  377. </ul>
  378. @param parameters Compression parameters }
  379. procedure opj_set_default_encoder_parameters(parameters: popj_cparameters_t); cdecl; external;
  380. { Setup the encoder parameters using the current image and using user parameters.
  381. @param cinfo compressor handle
  382. @param parameters compression parameters
  383. @param image input filled image }
  384. procedure opj_setup_encoder(cinfo: popj_cinfo_t; parameters: popj_cparameters_t;
  385. image: popj_image_t); cdecl; external;
  386. { Encode an image into a JPEG-2000 codestream
  387. @param cinfo compressor handle
  388. @param cio Output buffer stream
  389. @param image Image to encode
  390. @param index Name of the index file if required, NULL otherwise
  391. @return Returns true if successful, returns false otherwise }
  392. function opj_encode(cinfo: popj_cinfo_t; cio: popj_cio_t; image: popj_image_t;
  393. index: PChar): Bool; cdecl; external;
  394. implementation
  395. uses
  396. SysUtils, ImagingUtility;
  397. {$IF Defined(MSWINDOWS)}
  398. const
  399. MSCRuntimeLib = 'msvcrt.dll';
  400. {$IFDEF DCC}
  401. {$L J2KObjects\w32bor_pi.obj}
  402. {$L J2KObjects\w32bor_openjpeg.obj}
  403. {$L J2KObjects\w32bor_j2k_lib.obj}
  404. {$L J2KObjects\w32bor_event.obj}
  405. {$L J2KObjects\w32bor_cio.obj}
  406. {$L J2KObjects\w32bor_image.obj}
  407. {$L J2KObjects\w32bor_j2k.obj}
  408. {$L J2KObjects\w32bor_jp2.obj}
  409. {$L J2KObjects\w32bor_jpt.obj}
  410. {$L J2KObjects\w32bor_mqc.obj}
  411. {$L J2KObjects\w32bor_raw.obj}
  412. {$L J2KObjects\w32bor_bio.obj}
  413. {$L J2KObjects\w32bor_tgt.obj}
  414. {$L J2KObjects\w32bor_tcd.obj}
  415. {$L J2KObjects\w32bor_t1.obj}
  416. {$L J2KObjects\w32bor_dwt.obj}
  417. {$L J2KObjects\w32bor_t2.obj}
  418. {$L J2KObjects\w32bor_mct.obj}
  419. var
  420. __turboFloat: LongInt;
  421. _max_dble: Double;
  422. procedure opj_realloc; cdecl; external;
  423. procedure mqc_create; cdecl; external;
  424. procedure raw_create; cdecl; external;
  425. procedure bio_create; cdecl; external;
  426. procedure opj_image_create0; cdecl; external;
  427. procedure opj_event_msg; cdecl; external;
  428. procedure opj_clock; cdecl; external;
  429. procedure cio_read; cdecl; external;
  430. procedure cio_write; cdecl; external;
  431. procedure cio_skip; cdecl; external;
  432. procedure bio_read; cdecl; external;
  433. procedure bio_write; cdecl; external;
  434. procedure cio_numbytesleft; cdecl; external;
  435. procedure cio_getbp; cdecl; external;
  436. procedure j2k_destroy_compress; cdecl; external;
  437. procedure tgt_create; cdecl; external;
  438. procedure tgt_destroy; cdecl; external;
  439. procedure mqc_setcurctx; cdecl; external;
  440. procedure mqc_bypass_enc; cdecl; external;
  441. procedure mqc_encode; cdecl; external;
  442. procedure mqc_decode; cdecl; external;
  443. procedure raw_decode; cdecl; external;
  444. procedure mqc_resetstates; cdecl; external;
  445. procedure mqc_setstate; cdecl; external;
  446. procedure mqc_init_enc; cdecl; external;
  447. procedure mqc_segmark_enc; cdecl; external;
  448. procedure mqc_flush; cdecl; external;
  449. procedure mqc_bypass_init_enc; cdecl; external;
  450. procedure mqc_numbytes; cdecl; external;
  451. procedure mqc_reset_enc; cdecl; external;
  452. procedure mqc_erterm_enc; cdecl; external;
  453. procedure mqc_init_dec; cdecl; external;
  454. procedure raw_init_dec; cdecl; external;
  455. procedure mqc_destroy; cdecl; external;
  456. procedure mqc_restart_init_enc; cdecl; external;
  457. procedure raw_destroy; cdecl; external;
  458. procedure tgt_reset; cdecl; external;
  459. procedure tgt_setvalue; cdecl; external;
  460. procedure bio_init_enc; cdecl; external;
  461. procedure bio_flush; cdecl; external;
  462. procedure bio_numbytes; cdecl; external;
  463. procedure bio_destroy; cdecl; external;
  464. procedure bio_init_dec; cdecl; external;
  465. procedure pi_create; cdecl; external;
  466. procedure pi_next; cdecl; external;
  467. procedure pi_destroy; cdecl; external;
  468. procedure tgt_encode; cdecl; external;
  469. procedure tgt_decode; cdecl; external;
  470. procedure bio_inalign; cdecl; external;
  471. {$ELSE}
  472. {$L J2KObjects\w32gcc_openjpeg.o}
  473. {$L J2KObjects\w32gcc_j2k_lib.o}
  474. {$L J2KObjects\w32gcc_event.o}
  475. {$L J2KObjects\w32gcc_cio.o}
  476. {$L J2KObjects\w32gcc_image.o}
  477. {$L J2KObjects\w32gcc_j2k.o}
  478. {$L J2KObjects\w32gcc_jp2.o}
  479. {$L J2KObjects\w32gcc_jpt.o}
  480. {$L J2KObjects\w32gcc_mqc.o}
  481. {$L J2KObjects\w32gcc_raw.o}
  482. {$L J2KObjects\w32gcc_bio.o}
  483. {$L J2KObjects\w32gcc_tgt.o}
  484. {$L J2KObjects\w32gcc_tcd.o}
  485. {$L J2KObjects\w32gcc_t1.o}
  486. {$L J2KObjects\w32gcc_dwt.o}
  487. {$L J2KObjects\w32gcc_pi.o}
  488. {$L J2KObjects\w32gcc_t2.o}
  489. {$L J2KObjects\w32gcc_mct.o}
  490. {$ENDIF}
  491. function malloc(Size: Integer): Pointer; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  492. begin
  493. GetMem(Result, Size);
  494. end;
  495. procedure free(Ptr: Pointer); cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  496. begin
  497. FreeMem(Ptr);
  498. end;
  499. function realloc(Ptr: Pointer; Size: Integer): Pointer; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  500. begin
  501. ReallocMem(Ptr, Size);
  502. Result := Ptr;
  503. end;
  504. function memset(S: Pointer; C, N: Integer): Pointer; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  505. begin
  506. FillMemoryByte(S, N, C);
  507. Result := S;
  508. end;
  509. function memcpy(S1, S2: Pointer; N: Integer): Pointer; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  510. begin
  511. Move(S2^, S1^, N);
  512. Result := S1;
  513. end;
  514. function strlen(S: PChar): Integer; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  515. begin
  516. Result := SysUtils.StrLen(S);
  517. end;
  518. function strcat(S1, S2: PChar): PChar; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  519. begin
  520. Result := SysUtils.StrCat(S1, S2);
  521. end;
  522. function strcpy(S1, S2: PChar): PChar; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  523. begin
  524. Result := SysUtils.StrCopy(S1, S2);
  525. end;
  526. function fabs(const Num: Double): Double; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  527. begin
  528. Result := Abs(Num);
  529. end;
  530. function floor(const X: Double): Double; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  531. begin
  532. Result := Trunc(X);
  533. if Frac(X) < 0.0 then
  534. Result := Result - 1.0;
  535. end;
  536. function ceil(const Num: Double): Double; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  537. begin
  538. Result := Trunc(Num);
  539. if Frac(Num) > 0.0 then
  540. Result := Result + 1;
  541. end;
  542. function pow(const Base, Exponent: Double): Double; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  543. begin
  544. if Exponent = 0.0 then
  545. Result := 1.0
  546. else if (Base = 0.0) and (Exponent > 0.0) then
  547. Result := 0.0
  548. else
  549. Result := Exp(Exponent * Ln(Base));
  550. end;
  551. procedure _llmul; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  552. asm
  553. // taken from Delphi's System.pas __llmul
  554. push edx
  555. push eax
  556. mov eax, [esp+16]
  557. mul dword ptr [esp]
  558. mov ecx, eax
  559. mov eax, [esp+4]
  560. mul dword ptr [esp+12]
  561. add ecx, eax
  562. mov eax, [esp]
  563. mul dword ptr [esp+12]
  564. add edx, ecx
  565. pop ecx
  566. pop ecx
  567. ret 8
  568. end;
  569. procedure _allshr; cdecl; {$IFDEF FPC}[Public];{$ENDIF}
  570. asm
  571. // taken from Delphi's System.pas __llshr
  572. cmp cl, 32
  573. jl @__llshr@below32
  574. cmp cl, 64
  575. jl @__llshr@below64
  576. sar edx, 1fh
  577. mov eax,edx
  578. ret
  579. @__llshr@below64:
  580. mov eax, edx
  581. cdq
  582. sar eax,cl
  583. ret
  584. @__llshr@below32:
  585. shrd eax, edx, cl
  586. sar edx, cl
  587. ret
  588. end;
  589. {$IFDEF DCC}
  590. function sprintf(S, Format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  591. function printf(Format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  592. function fprintf(F: Pointer; Format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  593. function fopen(FileName, Mode: PChar): Pointer; cdecl; external MSCRuntimeLib;
  594. function fclose(F: Pointer): Integer; cdecl; external MSCRuntimeLib;
  595. function vsprintf(S, Format: PChar): Integer; cdecl; varargs; external MSCRuntimeLib;
  596. function tolower(C: Integer): Integer; cdecl; external MSCRuntimeLib;
  597. function _ltolower(C: Integer): Integer;cdecl; external MSCRuntimeLib name 'tolower';
  598. function _ftol(X: Single): LongInt; cdecl; external MSCRuntimeLib;
  599. {$ELSE}
  600. function _fopen(FileName, Mode: PChar): Pointer; cdecl; external MSCRuntimeLib name 'fopen';
  601. function _fclose(F: Pointer): Integer; cdecl; external MSCRuntimeLib name 'fclose';
  602. function fopen(FileName, Mode: PChar): Pointer; cdecl; [Public];
  603. begin
  604. Result := _fopen(FileName, Mode);
  605. end;
  606. function fclose(F: Pointer): Integer; cdecl; [Public];
  607. begin
  608. Result := _fclose(F);
  609. end;
  610. procedure fprintf; cdecl; [Public];
  611. begin
  612. end;
  613. procedure vsprintf; cdecl; [Public];
  614. begin
  615. end;
  616. function fwrite(Buffer: Pointer; Size, Count: Integer; Stream: Pointer): Integer; cdecl; [Public];
  617. begin
  618. end;
  619. function fputc(C: Integer; Stream: Pointer): Integer; cdecl; [Public];
  620. begin
  621. end;
  622. function puts(S: PChar): Integer; cdecl; [Public];
  623. begin
  624. end;
  625. {$ENDIF}
  626. {$ELSEIF Defined(UNIX)}
  627. {$IF Defined(FPC)}
  628. {$LINKLIB stdc++}
  629. {$IF Defined(CPU86)}
  630. // Object files distributed with OpenJPEG-pas
  631. // are for Linux 386. If you are running
  632. // other platform compile OpenJPEG C sources and
  633. // use your new object files.
  634. {$L J2KObjects/lin386_openjpeg.o}
  635. {$L J2KObjects/lin386_j2k_lib.o}
  636. {$L J2KObjects/lin386_event.o}
  637. {$L J2KObjects/lin386_cio.o}
  638. {$L J2KObjects/lin386_image.o}
  639. {$L J2KObjects/lin386_j2k.o}
  640. {$L J2KObjects/lin386_jp2.o}
  641. {$L J2KObjects/lin386_jpt.o}
  642. {$L J2KObjects/lin386_mqc.o}
  643. {$L J2KObjects/lin386_raw.o}
  644. {$L J2KObjects/lin386_bio.o}
  645. {$L J2KObjects/lin386_tgt.o}
  646. {$L J2KObjects/lin386_tcd.o}
  647. {$L J2KObjects/lin386_t1.o}
  648. {$L J2KObjects/lin386_dwt.o}
  649. {$L J2KObjects/lin386_pi.o}
  650. {$L J2KObjects/lin386_t2.o}
  651. {$L J2KObjects/lin386_mct.o}
  652. {$ELSE}
  653. First compile OpenJPEG for your platform
  654. and put object files here:
  655. {$L J2KObjects/openjpeg.o}
  656. {$L J2KObjects/j2k_lib.o}
  657. {$L J2KObjects/event.o}
  658. {$L J2KObjects/cio.o}
  659. {$L J2KObjects/image.o}
  660. {$L J2KObjects/j2k.o}
  661. {$L J2KObjects/jp2.o}
  662. {$L J2KObjects/jpt.o}
  663. {$L J2KObjects/mqc.o}
  664. {$L J2KObjects/raw.o}
  665. {$L J2KObjects/bio.o}
  666. {$L J2KObjects/tgt.o}
  667. {$L J2KObjects/tcd.o}
  668. {$L J2KObjects/t1.o}
  669. {$L J2KObjects/dwt.o}
  670. {$L J2KObjects/pi.o}
  671. {$L J2KObjects/t2.o}
  672. {$L J2KObjects/mct.o}
  673. {$IFEND}
  674. {$ELSE}
  675. No JPEG2000 Support for this compiler
  676. {$IFEND}
  677. {$ELSE}
  678. No JPEG2000 Support for this platform
  679. {$IFEND}
  680. end.