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