openjpeg.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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. #ifndef OPENJPEG_H
  33. #define OPENJPEG_H
  34. #define OPENJPEG_VERSION "1.4.0.635f"
  35. /*
  36. ==========================================================
  37. Compiler directives
  38. ==========================================================
  39. */
  40. #if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
  41. #define OPJ_API
  42. #define OPJ_CALLCONV
  43. #else
  44. #define OPJ_CALLCONV __stdcall
  45. /*
  46. The following ifdef block is the standard way of creating macros which make exporting
  47. from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
  48. symbol defined on the command line. this symbol should not be defined on any project
  49. that uses this DLL. This way any other project whose source files include this file see
  50. OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
  51. defined with this macro as being exported.
  52. */
  53. #ifdef OPJ_EXPORTS
  54. #define OPJ_API __declspec(dllexport)
  55. #else
  56. #define OPJ_API __declspec(dllimport)
  57. #endif /* OPJ_EXPORTS */
  58. #endif /* !OPJ_STATIC || !WIN32 */
  59. #ifndef __cplusplus
  60. #if defined(HAVE_STDBOOL_H)
  61. /*
  62. The C language implementation does correctly provide the standard header
  63. file "stdbool.h".
  64. */
  65. #include <stdbool.h>
  66. #else
  67. /*
  68. The C language implementation does not provide the standard header file
  69. "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
  70. braindamage below.
  71. */
  72. #if !defined(bool)
  73. #define bool int
  74. #endif
  75. #if !defined(true)
  76. #define true 1
  77. #endif
  78. #if !defined(false)
  79. #define false 0
  80. #endif
  81. #endif
  82. #endif /* __cplusplus */
  83. /*
  84. ==========================================================
  85. Useful constant definitions
  86. ==========================================================
  87. */
  88. #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
  89. #define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
  90. #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
  91. /* UniPG>> */
  92. #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
  93. #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
  94. #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
  95. #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
  96. #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
  97. #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
  98. #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
  99. #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
  100. /* <<UniPG */
  101. /*
  102. ==========================================================
  103. enum definitions
  104. ==========================================================
  105. */
  106. /**
  107. Rsiz Capabilities
  108. */
  109. typedef enum RSIZ_CAPABILITIES {
  110. STD_RSIZ = 0, /** Standard JPEG2000 profile*/
  111. CINEMA2K = 3, /** Profile name for a 2K image*/
  112. CINEMA4K = 4 /** Profile name for a 4K image*/
  113. } OPJ_RSIZ_CAPABILITIES;
  114. /**
  115. Digital cinema operation mode
  116. */
  117. typedef enum CINEMA_MODE {
  118. OFF = 0, /** Not Digital Cinema*/
  119. CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
  120. CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
  121. CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
  122. }OPJ_CINEMA_MODE;
  123. /**
  124. Progression order
  125. */
  126. typedef enum PROG_ORDER {
  127. PROG_UNKNOWN = -1, /**< place-holder */
  128. LRCP = 0, /**< layer-resolution-component-precinct order */
  129. RLCP = 1, /**< resolution-layer-component-precinct order */
  130. RPCL = 2, /**< resolution-precinct-component-layer order */
  131. PCRL = 3, /**< precinct-component-resolution-layer order */
  132. CPRL = 4 /**< component-precinct-resolution-layer order */
  133. } OPJ_PROG_ORDER;
  134. /**
  135. Supported image color spaces
  136. */
  137. typedef enum COLOR_SPACE {
  138. CLRSPC_UNKNOWN = -1, /**< not supported by the library */
  139. CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
  140. CLRSPC_SRGB = 1, /**< sRGB */
  141. CLRSPC_GRAY = 2, /**< grayscale */
  142. CLRSPC_SYCC = 3 /**< YUV */
  143. } OPJ_COLOR_SPACE;
  144. /**
  145. Supported codec
  146. */
  147. typedef enum CODEC_FORMAT {
  148. CODEC_UNKNOWN = -1, /**< place-holder */
  149. CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
  150. CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
  151. CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
  152. } OPJ_CODEC_FORMAT;
  153. /**
  154. Limit decoding to certain portions of the codestream.
  155. */
  156. typedef enum LIMIT_DECODING {
  157. NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
  158. LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
  159. DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
  160. } OPJ_LIMIT_DECODING;
  161. /*
  162. ==========================================================
  163. event manager typedef definitions
  164. ==========================================================
  165. */
  166. /**
  167. Callback function prototype for events
  168. @param msg Event message
  169. @param client_data
  170. */
  171. typedef void (*opj_msg_callback) (const char *msg, void *client_data);
  172. /**
  173. Message handler object
  174. used for
  175. <ul>
  176. <li>Error messages
  177. <li>Warning messages
  178. <li>Debugging messages
  179. </ul>
  180. */
  181. typedef struct opj_event_mgr {
  182. /** Error message callback if available, NULL otherwise */
  183. opj_msg_callback error_handler;
  184. /** Warning message callback if available, NULL otherwise */
  185. opj_msg_callback warning_handler;
  186. /** Debug message callback if available, NULL otherwise */
  187. opj_msg_callback info_handler;
  188. } opj_event_mgr_t;
  189. /*
  190. ==========================================================
  191. codec typedef definitions
  192. ==========================================================
  193. */
  194. /**
  195. Progression order changes
  196. */
  197. typedef struct opj_poc {
  198. /** Resolution num start, Component num start, given by POC */
  199. int resno0, compno0;
  200. /** Layer num end,Resolution num end, Component num end, given by POC */
  201. int layno1, resno1, compno1;
  202. /** Layer num start,Precinct num start, Precinct num end */
  203. int layno0, precno0, precno1;
  204. /** Progression order enum*/
  205. OPJ_PROG_ORDER prg1,prg;
  206. /** Progression order string*/
  207. char progorder[5];
  208. /** Tile number */
  209. int tile;
  210. /** Start and end values for Tile width and height*/
  211. int tx0,tx1,ty0,ty1;
  212. /** Start value, initialised in pi_initialise_encode*/
  213. int layS, resS, compS, prcS;
  214. /** End value, initialised in pi_initialise_encode */
  215. int layE, resE, compE, prcE;
  216. /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
  217. int txS,txE,tyS,tyE,dx,dy;
  218. /** Temporary values for Tile parts, initialised in pi_create_encode */
  219. int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
  220. } opj_poc_t;
  221. /**
  222. Compression parameters
  223. */
  224. typedef struct opj_cparameters {
  225. /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
  226. bool tile_size_on;
  227. /** XTOsiz */
  228. int cp_tx0;
  229. /** YTOsiz */
  230. int cp_ty0;
  231. /** XTsiz */
  232. int cp_tdx;
  233. /** YTsiz */
  234. int cp_tdy;
  235. /** allocation by rate/distortion */
  236. int cp_disto_alloc;
  237. /** allocation by fixed layer */
  238. int cp_fixed_alloc;
  239. /** add fixed_quality */
  240. int cp_fixed_quality;
  241. /** fixed layer */
  242. int *cp_matrice;
  243. /** comment for coding */
  244. char *cp_comment;
  245. /** csty : coding style */
  246. int csty;
  247. /** progression order (default LRCP) */
  248. OPJ_PROG_ORDER prog_order;
  249. /** progression order changes */
  250. opj_poc_t POC[32];
  251. /** number of progression order changes (POC), default to 0 */
  252. int numpocs;
  253. /** number of layers */
  254. int tcp_numlayers;
  255. /** rates of layers */
  256. float tcp_rates[100];
  257. /** different psnr for successive layers */
  258. float tcp_distoratio[100];
  259. /** number of resolutions */
  260. int numresolution;
  261. /** initial code block width, default to 64 */
  262. int cblockw_init;
  263. /** initial code block height, default to 64 */
  264. int cblockh_init;
  265. /** mode switch (cblk_style) */
  266. int mode;
  267. /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
  268. int irreversible;
  269. /** region of interest: affected component in [0..3], -1 means no ROI */
  270. int roi_compno;
  271. /** region of interest: upshift value */
  272. int roi_shift;
  273. /* number of precinct size specifications */
  274. int res_spec;
  275. /** initial precinct width */
  276. int prcw_init[J2K_MAXRLVLS];
  277. /** initial precinct height */
  278. int prch_init[J2K_MAXRLVLS];
  279. /**@name command line encoder parameters (not used inside the library) */
  280. /*@{*/
  281. /** input file name */
  282. char infile[OPJ_PATH_LEN];
  283. /** output file name */
  284. char outfile[OPJ_PATH_LEN];
  285. /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
  286. int index_on;
  287. /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
  288. char index[OPJ_PATH_LEN];
  289. /** subimage encoding: origin image offset in x direction */
  290. int image_offset_x0;
  291. /** subimage encoding: origin image offset in y direction */
  292. int image_offset_y0;
  293. /** subsampling value for dx */
  294. int subsampling_dx;
  295. /** subsampling value for dy */
  296. int subsampling_dy;
  297. /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
  298. int decod_format;
  299. /** output file format 0: J2K, 1: JP2, 2: JPT */
  300. int cod_format;
  301. /*@}*/
  302. /* UniPG>> */
  303. /**@name JPWL encoding parameters */
  304. /*@{*/
  305. /** enables writing of EPC in MH, thus activating JPWL */
  306. bool jpwl_epc_on;
  307. /** error protection method for MH (0,1,16,32,37-128) */
  308. int jpwl_hprot_MH;
  309. /** tile number of header protection specification (>=0) */
  310. int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
  311. /** error protection methods for TPHs (0,1,16,32,37-128) */
  312. int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
  313. /** tile number of packet protection specification (>=0) */
  314. int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
  315. /** packet number of packet protection specification (>=0) */
  316. int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
  317. /** error protection methods for packets (0,1,16,32,37-128) */
  318. int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
  319. /** enables writing of ESD, (0=no/1/2 bytes) */
  320. int jpwl_sens_size;
  321. /** sensitivity addressing size (0=auto/2/4 bytes) */
  322. int jpwl_sens_addr;
  323. /** sensitivity range (0-3) */
  324. int jpwl_sens_range;
  325. /** sensitivity method for MH (-1=no,0-7) */
  326. int jpwl_sens_MH;
  327. /** tile number of sensitivity specification (>=0) */
  328. int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
  329. /** sensitivity methods for TPHs (-1=no,0-7) */
  330. int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
  331. /*@}*/
  332. /* <<UniPG */
  333. /** Digital Cinema compliance 0-not compliant, 1-compliant*/
  334. OPJ_CINEMA_MODE cp_cinema;
  335. /** Maximum rate for each component. If == 0, component size limitation is not considered */
  336. int max_comp_size;
  337. /** Profile name*/
  338. OPJ_RSIZ_CAPABILITIES cp_rsiz;
  339. /** Tile part generation*/
  340. char tp_on;
  341. /** Flag for Tile part generation*/
  342. char tp_flag;
  343. /** MCT (multiple component transform) */
  344. char tcp_mct;
  345. } opj_cparameters_t;
  346. /**
  347. Decompression parameters
  348. */
  349. typedef struct opj_dparameters {
  350. /**
  351. Set the number of highest resolution levels to be discarded.
  352. The image resolution is effectively divided by 2 to the power of the number of discarded levels.
  353. The reduce factor is limited by the smallest total number of decomposition levels among tiles.
  354. if != 0, then original dimension divided by 2^(reduce);
  355. if == 0 or not used, image is decoded to the full resolution
  356. */
  357. int cp_reduce;
  358. /**
  359. Set the maximum number of quality layers to decode.
  360. If there are less quality layers than the specified number, all the quality layers are decoded.
  361. if != 0, then only the first "layer" layers are decoded;
  362. if == 0 or not used, all the quality layers are decoded
  363. */
  364. int cp_layer;
  365. /**@name command line encoder parameters (not used inside the library) */
  366. /*@{*/
  367. /** input file name */
  368. char infile[OPJ_PATH_LEN];
  369. /** output file name */
  370. char outfile[OPJ_PATH_LEN];
  371. /** input file format 0: J2K, 1: JP2, 2: JPT */
  372. int decod_format;
  373. /** output file format 0: PGX, 1: PxM, 2: BMP */
  374. int cod_format;
  375. /*@}*/
  376. /* UniPG>> */
  377. /**@name JPWL decoding parameters */
  378. /*@{*/
  379. /** activates the JPWL correction capabilities */
  380. bool jpwl_correct;
  381. /** expected number of components */
  382. int jpwl_exp_comps;
  383. /** maximum number of tiles */
  384. int jpwl_max_tiles;
  385. /*@}*/
  386. /* <<UniPG */
  387. /**
  388. Specify whether the decoding should be done on the entire codestream, or be limited to the main header
  389. Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
  390. if == NO_LIMITATION, the entire codestream is decoded;
  391. if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
  392. */
  393. OPJ_LIMIT_DECODING cp_limit_decoding;
  394. } opj_dparameters_t;
  395. /** Common fields between JPEG-2000 compression and decompression master structs. */
  396. #define opj_common_fields \
  397. opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
  398. void * client_data; /**< Available for use by application */\
  399. bool is_decompressor; /**< So common code can tell which is which */\
  400. OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
  401. void *j2k_handle; /**< pointer to the J2K codec */\
  402. void *jp2_handle; /**< pointer to the JP2 codec */\
  403. void *mj2_handle /**< pointer to the MJ2 codec */
  404. /* Routines that are to be used by both halves of the library are declared
  405. * to receive a pointer to this structure. There are no actual instances of
  406. * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
  407. */
  408. typedef struct opj_common_struct {
  409. opj_common_fields; /* Fields common to both master struct types */
  410. /* Additional fields follow in an actual opj_cinfo_t or
  411. * opj_dinfo_t. All three structs must agree on these
  412. * initial fields! (This would be a lot cleaner in C++.)
  413. */
  414. } opj_common_struct_t;
  415. typedef opj_common_struct_t * opj_common_ptr;
  416. /**
  417. Compression context info
  418. */
  419. typedef struct opj_cinfo {
  420. /** Fields shared with opj_dinfo_t */
  421. opj_common_fields;
  422. /* other specific fields go here */
  423. } opj_cinfo_t;
  424. /**
  425. Decompression context info
  426. */
  427. typedef struct opj_dinfo {
  428. /** Fields shared with opj_cinfo_t */
  429. opj_common_fields;
  430. /* other specific fields go here */
  431. } opj_dinfo_t;
  432. /*
  433. ==========================================================
  434. I/O stream typedef definitions
  435. ==========================================================
  436. */
  437. /*
  438. * Stream open flags.
  439. */
  440. /** The stream was opened for reading. */
  441. #define OPJ_STREAM_READ 0x0001
  442. /** The stream was opened for writing. */
  443. #define OPJ_STREAM_WRITE 0x0002
  444. /**
  445. Byte input-output stream (CIO)
  446. */
  447. typedef struct opj_cio {
  448. /** codec context */
  449. opj_common_ptr cinfo;
  450. /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
  451. int openmode;
  452. /** pointer to the start of the buffer */
  453. unsigned char *buffer;
  454. /** buffer size in bytes */
  455. int length;
  456. /** pointer to the start of the stream */
  457. unsigned char *start;
  458. /** pointer to the end of the stream */
  459. unsigned char *end;
  460. /** pointer to the current position */
  461. unsigned char *bp;
  462. } opj_cio_t;
  463. /*
  464. ==========================================================
  465. image typedef definitions
  466. ==========================================================
  467. */
  468. /**
  469. Defines a single image component
  470. */
  471. typedef struct opj_image_comp {
  472. /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
  473. int dx;
  474. /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
  475. int dy;
  476. /** data width */
  477. int w;
  478. /** data height */
  479. int h;
  480. /** x component offset compared to the whole image */
  481. int x0;
  482. /** y component offset compared to the whole image */
  483. int y0;
  484. /** precision */
  485. int prec;
  486. /** image depth in bits */
  487. int bpp;
  488. /** signed (1) / unsigned (0) */
  489. int sgnd;
  490. /** number of decoded resolution */
  491. int resno_decoded;
  492. /** number of division by 2 of the out image compared to the original size of image */
  493. int factor;
  494. /** image component data */
  495. int *data;
  496. } opj_image_comp_t;
  497. /**
  498. Defines image data and characteristics
  499. */
  500. typedef struct opj_image {
  501. /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
  502. int x0;
  503. /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
  504. int y0;
  505. /** Xsiz: width of the reference grid */
  506. int x1;
  507. /** Ysiz: height of the reference grid */
  508. int y1;
  509. /** number of components in the image */
  510. int numcomps;
  511. /** color space: sRGB, Greyscale or YUV */
  512. OPJ_COLOR_SPACE color_space;
  513. /** image components */
  514. opj_image_comp_t *comps;
  515. } opj_image_t;
  516. /**
  517. Component parameters structure used by the opj_image_create function
  518. */
  519. typedef struct opj_image_comptparm {
  520. /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
  521. int dx;
  522. /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
  523. int dy;
  524. /** data width */
  525. int w;
  526. /** data height */
  527. int h;
  528. /** x component offset compared to the whole image */
  529. int x0;
  530. /** y component offset compared to the whole image */
  531. int y0;
  532. /** precision */
  533. int prec;
  534. /** image depth in bits */
  535. int bpp;
  536. /** signed (1) / unsigned (0) */
  537. int sgnd;
  538. } opj_image_cmptparm_t;
  539. /*
  540. ==========================================================
  541. Information on the JPEG 2000 codestream
  542. ==========================================================
  543. */
  544. /**
  545. Index structure : Information concerning a packet inside tile
  546. */
  547. typedef struct opj_packet_info {
  548. /** packet start position (including SOP marker if it exists) */
  549. int start_pos;
  550. /** end of packet header position (including EPH marker if it exists)*/
  551. int end_ph_pos;
  552. /** packet end position */
  553. int end_pos;
  554. /** packet distorsion */
  555. double disto;
  556. } opj_packet_info_t;
  557. /**
  558. Index structure : Information concerning tile-parts
  559. */
  560. typedef struct opj_tp_info {
  561. /** start position of tile part */
  562. int tp_start_pos;
  563. /** end position of tile part header */
  564. int tp_end_header;
  565. /** end position of tile part */
  566. int tp_end_pos;
  567. /** start packet of tile part */
  568. int tp_start_pack;
  569. /** number of packets of tile part */
  570. int tp_numpacks;
  571. } opj_tp_info_t;
  572. /**
  573. Index structure : information regarding tiles
  574. */
  575. typedef struct opj_tile_info {
  576. /** value of thresh for each layer by tile cfr. Marcela */
  577. double *thresh;
  578. /** number of tile */
  579. int tileno;
  580. /** start position */
  581. int start_pos;
  582. /** end position of the header */
  583. int end_header;
  584. /** end position */
  585. int end_pos;
  586. /** precinct number for each resolution level (width) */
  587. int pw[33];
  588. /** precinct number for each resolution level (height) */
  589. int ph[33];
  590. /** precinct size (in power of 2), in X for each resolution level */
  591. int pdx[33];
  592. /** precinct size (in power of 2), in Y for each resolution level */
  593. int pdy[33];
  594. /** information concerning packets inside tile */
  595. opj_packet_info_t *packet;
  596. /** add fixed_quality */
  597. int numpix;
  598. /** add fixed_quality */
  599. double distotile;
  600. /** number of tile parts */
  601. int num_tps;
  602. /** information concerning tile parts */
  603. opj_tp_info_t *tp;
  604. } opj_tile_info_t;
  605. /* UniPG>> */
  606. /**
  607. Marker structure
  608. */
  609. typedef struct opj_marker_info_t {
  610. /** marker type */
  611. unsigned short int type;
  612. /** position in codestream */
  613. int pos;
  614. /** length, marker val included */
  615. int len;
  616. } opj_marker_info_t;
  617. /* <<UniPG */
  618. /**
  619. Index structure of the codestream
  620. */
  621. typedef struct opj_codestream_info {
  622. /** maximum distortion reduction on the whole image (add for Marcela) */
  623. double D_max;
  624. /** packet number */
  625. int packno;
  626. /** writing the packet in the index with t2_encode_packets */
  627. int index_write;
  628. /** image width */
  629. int image_w;
  630. /** image height */
  631. int image_h;
  632. /** progression order */
  633. OPJ_PROG_ORDER prog;
  634. /** tile size in x */
  635. int tile_x;
  636. /** tile size in y */
  637. int tile_y;
  638. /** */
  639. int tile_Ox;
  640. /** */
  641. int tile_Oy;
  642. /** number of tiles in X */
  643. int tw;
  644. /** number of tiles in Y */
  645. int th;
  646. /** component numbers */
  647. int numcomps;
  648. /** number of layer */
  649. int numlayers;
  650. /** number of decomposition for each component */
  651. int *numdecompos;
  652. /* UniPG>> */
  653. /** number of markers */
  654. int marknum;
  655. /** list of markers */
  656. opj_marker_info_t *marker;
  657. /** actual size of markers array */
  658. int maxmarknum;
  659. /* <<UniPG */
  660. /** main header position */
  661. int main_head_start;
  662. /** main header position */
  663. int main_head_end;
  664. /** codestream's size */
  665. int codestream_size;
  666. /** information regarding tiles inside image */
  667. opj_tile_info_t *tile;
  668. } opj_codestream_info_t;
  669. #ifdef __cplusplus
  670. extern "C" {
  671. #endif
  672. /*
  673. ==========================================================
  674. openjpeg version
  675. ==========================================================
  676. */
  677. OPJ_API const char * OPJ_CALLCONV opj_version(void);
  678. /*
  679. ==========================================================
  680. image functions definitions
  681. ==========================================================
  682. */
  683. /**
  684. Create an image
  685. @param numcmpts number of components
  686. @param cmptparms components parameters
  687. @param clrspc image color space
  688. @return returns a new image structure if successful, returns NULL otherwise
  689. */
  690. OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
  691. /**
  692. Deallocate any resources associated with an image
  693. @param image image to be destroyed
  694. */
  695. OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
  696. /*
  697. ==========================================================
  698. stream functions definitions
  699. ==========================================================
  700. */
  701. /**
  702. Open and allocate a memory stream for read / write.
  703. On reading, the user must provide a buffer containing encoded data. The buffer will be
  704. wrapped by the returned CIO handle.
  705. On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
  706. to contain encoded data.
  707. @param cinfo Codec context info
  708. @param buffer Reading: buffer address. Writing: NULL
  709. @param length Reading: buffer length. Writing: 0
  710. @return Returns a CIO handle if successful, returns NULL otherwise
  711. */
  712. OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
  713. /**
  714. Close and free a CIO handle
  715. @param cio CIO handle to free
  716. */
  717. OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
  718. /**
  719. Get position in byte stream
  720. @param cio CIO handle
  721. @return Returns the position in bytes
  722. */
  723. OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
  724. /**
  725. Set position in byte stream
  726. @param cio CIO handle
  727. @param pos Position, in number of bytes, from the beginning of the stream
  728. */
  729. OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
  730. /*
  731. ==========================================================
  732. event manager functions definitions
  733. ==========================================================
  734. */
  735. OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
  736. /*
  737. ==========================================================
  738. codec functions definitions
  739. ==========================================================
  740. */
  741. /**
  742. Creates a J2K/JPT/JP2 decompression structure
  743. @param format Decoder to select
  744. @return Returns a handle to a decompressor if successful, returns NULL otherwise
  745. */
  746. OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
  747. /**
  748. Destroy a decompressor handle
  749. @param dinfo decompressor handle to destroy
  750. */
  751. OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
  752. /**
  753. Set decoding parameters to default values
  754. @param parameters Decompression parameters
  755. */
  756. OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
  757. /**
  758. Setup the decoder decoding parameters using user parameters.
  759. Decoding parameters are returned in j2k->cp.
  760. @param dinfo decompressor handle
  761. @param parameters decompression parameters
  762. */
  763. OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
  764. /**
  765. Decode an image from a JPEG-2000 codestream
  766. @param dinfo decompressor handle
  767. @param cio Input buffer stream
  768. @return Returns a decoded image if successful, returns NULL otherwise
  769. */
  770. OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
  771. /**
  772. Decode an image from a JPEG-2000 codestream and extract the codestream information
  773. @param dinfo decompressor handle
  774. @param cio Input buffer stream
  775. @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
  776. @return Returns a decoded image if successful, returns NULL otherwise
  777. */
  778. OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
  779. /**
  780. Creates a J2K/JP2 compression structure
  781. @param format Coder to select
  782. @return Returns a handle to a compressor if successful, returns NULL otherwise
  783. */
  784. OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
  785. /**
  786. Destroy a compressor handle
  787. @param cinfo compressor handle to destroy
  788. */
  789. OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
  790. /**
  791. Set encoding parameters to default values, that means :
  792. <ul>
  793. <li>Lossless
  794. <li>1 tile
  795. <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
  796. <li>Size of code-block : 64 x 64
  797. <li>Number of resolutions: 6
  798. <li>No SOP marker in the codestream
  799. <li>No EPH marker in the codestream
  800. <li>No sub-sampling in x or y direction
  801. <li>No mode switch activated
  802. <li>Progression order: LRCP
  803. <li>No index file
  804. <li>No ROI upshifted
  805. <li>No offset of the origin of the image
  806. <li>No offset of the origin of the tiles
  807. <li>Reversible DWT 5-3
  808. </ul>
  809. @param parameters Compression parameters
  810. */
  811. OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
  812. /**
  813. Setup the encoder parameters using the current image and using user parameters.
  814. @param cinfo Compressor handle
  815. @param parameters Compression parameters
  816. @param image Input filled image
  817. */
  818. OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
  819. /**
  820. Encode an image into a JPEG-2000 codestream
  821. @param cinfo compressor handle
  822. @param cio Output buffer stream
  823. @param image Image to encode
  824. @param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
  825. @return Returns true if successful, returns false otherwise
  826. */
  827. OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
  828. /**
  829. Encode an image into a JPEG-2000 codestream and extract the codestream information
  830. @param cinfo compressor handle
  831. @param cio Output buffer stream
  832. @param image Image to encode
  833. @param cstr_info Codestream information structure if needed afterwards, NULL otherwise
  834. @return Returns true if successful, returns false otherwise
  835. */
  836. OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
  837. /**
  838. Destroy Codestream information after compression or decompression
  839. @param cstr_info Codestream information structure
  840. */
  841. OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
  842. #ifdef __cplusplus
  843. }
  844. #endif
  845. #endif /* OPENJPEG_H */