a6a8fbdf76ca006f8fe8b9762cb631f216d4191d
[openjpeg.git] / indexer_JPIP / j2k.h
1 /*
2  * Copyright (c) 2001-2002, David Janssens
3  * Copyright (c) 2003-2004, Yannick Verschueren
4  * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
5  * All rights reserved. 
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #define VERSION "0.0.8"
30
31 #ifdef WIN32
32 #ifdef LIBJ2K_EXPORTS
33 #define LIBJ2K_API __declspec(dllexport)
34 #else
35 #define LIBJ2K_API __declspec(dllimport)
36 #endif
37 #else
38 #define LIBJ2K_API
39 #endif
40
41 #ifndef __J2K_H
42 #define __J2K_H
43
44 #define J2K_MAXRLVLS 33
45 #define J2K_MAXBANDS (3*J2K_MAXRLVLS+1)
46
47 #define J2K_CP_CSTY_PRT 0x01
48 #define J2K_CP_CSTY_SOP 0x02
49 #define J2K_CP_CSTY_EPH 0x04
50 #define J2K_CCP_CSTY_PRT 0x01
51 #define J2K_CCP_CBLKSTY_LAZY 0x01
52 #define J2K_CCP_CBLKSTY_RESET 0x02
53 #define J2K_CCP_CBLKSTY_TERMALL 0x04
54 #define J2K_CCP_CBLKSTY_VSC 0x08
55 #define J2K_CCP_CBLKSTY_PTERM 0x10
56 #define J2K_CCP_CBLKSTY_SEGSYM 0x20
57 #define J2K_CCP_QNTSTY_NOQNT 0
58 #define J2K_CCP_QNTSTY_SIQNT 1
59 #define J2K_CCP_QNTSTY_SEQNT 2
60
61 typedef struct 
62 {
63   int dx, dy;   /* XRsiz, YRsiz            */
64   int prec;     /* precision               */
65   int bpp;      /* deapth of image in bits */
66   int sgnd;     /* signed                  */
67   int *data;    /* image-component data    */
68 } j2k_comp_t;
69
70 typedef struct {
71   int version;
72   int x0, y0;          /* XOsiz, YOsiz              */
73   int x1, y1;          /* Xsiz, Ysiz                */ 
74   int numcomps;        /* number of components      */
75   j2k_comp_t *comps;   /* image-components          */
76 } j2k_image_t;
77
78 typedef struct {
79   int expn;     /* exponent */
80   int mant;     /* mantissa */
81 } j2k_stepsize_t;
82
83 typedef struct {
84   int csty;                                /* coding style                          */
85   int numresolutions;                      /* number of resolutions                 */
86   int cblkw;                               /* width of code-blocks                  */
87   int cblkh;                               /* height of code-blocks                 */
88   int cblksty;                             /* code-block coding style               */
89   int qmfbid;                              /* discrete wavelet transform identifier */
90   int qntsty;                              /* quantisation style                    */
91   j2k_stepsize_t stepsizes[J2K_MAXBANDS];  /* stepsizes used for quantisation       */
92   int numgbits;                            /* number of guard bits                  */
93   int roishift;                            /* Region of Interest shift              */
94   int prcw[J2K_MAXRLVLS];                  /* Precinct width                        */
95   int prch[J2K_MAXRLVLS];                  /* Precinct height                       */
96 } j2k_tccp_t;
97
98 typedef struct {
99     int resno0, compno0; 
100     int layno1, resno1, compno1;
101     int prg;
102     int tile;
103     char progorder[4];
104 } j2k_poc_t;
105
106 typedef struct {
107   //int first;
108   int csty;                  /* coding style                                                            */  
109   int prg;                   /* progression order                                                       */
110   int numlayers;             /* number of layers                                                        */
111   int mct;                   /* multi-component transform identifier                                    */
112   int rates[100];            /* rates of layers                                                         */
113   int numpocs;               /* number of progression order changes                                     */
114   int POC;                   /* Precise if a POC marker has been used O:NO, 1:YES                       */
115   j2k_poc_t pocs[32];        /* progression order changes                                               */
116   unsigned char *ppt_data;   /* packet header store there for futur use in t2_decode_packet             */
117   int ppt;                   /* If ppt == 1 --> there was a PPT marker for the present tile             */
118   int ppt_store;             /* Use in case of multiple marker PPT (number of info already store)       */
119   j2k_tccp_t *tccps;         /* tile-component coding parameters                                        */
120 } j2k_tcp_t;
121
122 typedef struct {
123   int tx0, ty0;              /* XTOsiz, YTOsiz                                                          */
124   int tdx, tdy;              /* XTsiz, YTsiz                                                            */
125   int tw, th;
126   unsigned char *ppm_data;   /* packet header store there for futur use in t2_decode_packet             */
127   int ppm;                   /* If ppm == 1 --> there was a PPM marker for the present tile             */
128   int ppm_store;             /* Use in case of multiple marker PPM (number of info already store)       */
129   int ppm_previous;          /* Use in case of multiple marker PPM (case on non-finished previous info) */
130   int index_on;              /* 0 = no index || 1 = index */
131   j2k_tcp_t *tcps;           /* tile coding parameters                                                  */
132 } j2k_cp_t;
133
134
135
136
137
138 /* Packet information : Layer level */
139 typedef struct {  
140   int len;               /* Length of the body of the packet   */
141   int len_header;        /* Length of the header of the packet */
142   int offset;            /* Offset of the body of the packet   */
143   int offset_header;     /* Offset of the header of the packet */
144 } info_layer_t;
145
146
147 /* Access to packet information : precinct level */
148 typedef struct {  
149   info_layer_t *layer;
150 } info_prec_t;
151
152
153 /* Access to packet information : resolution level */
154 typedef struct {  
155   info_prec_t *prec;
156 } info_reso_t;
157
158
159 /* Access to packet information : component level */
160 typedef struct {  
161   info_reso_t *reso;
162 } info_compo_t;
163
164
165 /* Information about the marker */
166 typedef struct {
167   int type;       /* type of marker [SIZ, QCD, POC, PPM, CRG, COD] appearing only once */
168   int start_pos;  /* Start position of the marker                                      */
169   int len;        /* Length of the marker                                              */
170 } info_marker_t;
171
172
173 /* Multiple marker in tile header */
174 typedef struct{
175   info_marker_t *COC;    /* COC markers                    */
176   int num_COC;           /* Number of COC marker           */
177   int CzCOC;             /* Current size of the vector COC */
178   
179   info_marker_t *RGN;    /* RGN markers                    */
180   int num_RGN;           /* Number of RGN marker           */
181   int CzRGN;             /* Current size of the vector RGN */
182   
183   info_marker_t *QCC;    /* QCC markers                    */
184   int num_QCC;           /* Number of QCC marker           */
185   int CzQCC;             /* Current size of the vector QCC */
186   
187   info_marker_t *PLT;    /* PLT markers                    */
188   int num_PLT;           /* Number of PLT marker           */
189   int CzPLT;             /* Current size of the vector PLT */
190   
191   info_marker_t *PPT;    /* PPT markers                    */
192   int num_PPT;           /* Number of PPT marker           */
193   int CzPPT;             /* Current size of the vector PPT */
194   
195   info_marker_t *COM;    /* COM markers                    */
196   int num_COM;           /* Number of COM marker           */
197   int CzCOM;             /* Current size of the vector COC */
198 } info_marker_mul_tile_t; 
199
200
201 /* Information about each tile_part for a particulary tile */
202 typedef struct{
203   int start_pos;                      /* Start position of the tile_part       */ 
204   int length;                         /* Length of the tile_part header + body */
205   int length_header;                  /* Length of the header                  */
206   int end_pos;                        /* End position of the tile part         */
207   int end_header;                     /* End position of the tile part header  */
208
209   int num_reso_AUX;                   /* Number of resolution level completed  */
210 } info_tile_part_t;
211
212
213 /* Information about each tile */
214 typedef struct {
215   int num_tile;                       /* Number of Tile                                                    */
216   int pw, ph;                         /* number of precinct by tile                                        */
217   int num_packet;                     /* number of packet in the tile                                      */
218   info_compo_t *compo;                /* component [packet]                                                */
219   
220   info_marker_t *marker;              /* information concerning markers inside image [only one apparition] */
221   info_marker_mul_tile_t marker_mul;  /* information concerning markers inside image [multiple apparition] */ 
222   int num_marker;                     /* number of marker                                                  */
223   
224   int numparts;                       /* number of tile_part for this tile                                 */
225   info_tile_part_t *tile_parts;       /* Information about each tile_part                                  */
226   int Cztile_parts;                   /* Current size of the tile_parts vector                             */
227 } info_tile_t;                        /* index struct                                                      */
228
229
230 /* Multiple marker in main header */
231 typedef struct{
232   info_marker_t *COC;    /* COC markers                    */
233   int num_COC;           /* Number of COC marker           */
234   int CzCOC;             /* Current size of the vector COC */
235  
236   info_marker_t *RGN;    /* RGN markers                    */
237   int num_RGN;           /* Number of RGN marker           */
238   int CzRGN;             /* Current size of the vector RGN */
239   
240   info_marker_t *QCC;    /* QCC markers                    */
241   int num_QCC;           /* Number of QCC marker           */
242   int CzQCC;             /* Current size of the vector QCC */
243   
244   info_marker_t *TLM;    /* TLM markers                    */
245   int num_TLM;           /* Number of TLM marker           */
246   int CzTLM;             /* Current size of the vector TLM */
247   
248   info_marker_t *PLM;    /* PLM markers                    */
249   int num_PLM;           /* Number of PLM marker           */
250   int CzPLM;             /* Current size of the vector PLM */
251   
252   info_marker_t *PPM;    /* PPM markers                    */
253   int num_PPM;           /* Number of PPM marker           */
254   int CzPPM;             /* Current size of the vector PPM */
255   
256   info_marker_t *COM;    /* COM markers                    */
257   int num_COM;           /* Number of COM marker           */
258   int CzCOM;             /* Current size of the vector COM */
259 } info_marker_mul_t; /* index struct */
260
261
262 /* Information about image */
263 typedef struct {
264   int Im_w, Im_h;                /* Image width and Height                                            */
265   int Tile_x, Tile_y;            /* Number of Tile in X and Y                                         */
266   int tw, th;
267   int pw, ph;                    /* nombre precinct in X and Y                                        */
268   int pdx, pdy;                  /* size of precinct in X and Y                                       */
269
270   int Prog;                      /* progression order                                                 */
271   int Comp;                      /* Component numbers                                                 */
272   int Layer;                     /* number of layer                                                   */
273   int Decomposition;             /* number of decomposition                                           */
274
275   int Main_head_end;             /* Main header position                                              */
276   int codestream_size;           /* codestream's size                                                 */
277
278   info_marker_t *marker;         /* information concerning markers inside image [only one apparition] */
279   info_marker_mul_t marker_mul;  /* information concerning markers inside image [multiple apparition] */ 
280   int num_marker;                /* number of marker                                                  */
281
282   int num_packet_max;            /* Maximum number of packet                                          */
283
284   int num_max_tile_parts;        /* Maximum number of tile-part                                       */
285   info_tile_t *tile;             /* information concerning tiles inside image                         */
286 } info_image_t; /* index struct */
287
288
289 #endif