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