openjpeg.h 28 KB

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