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