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