OpenJpeg.pas 25 KB

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