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