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