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