OpenJpeg.pas 25 KB

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