Initial revision
[openjpeg.git] / indexer_JPIP / j2k.h
1 /*
2  * Copyright (c) 2001-2002, David Janssens
3  * Copyright (c) 2003, Yannick Verschueren
4  * Copyright (c) 2003,  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 x0, y0; // XOsiz, YOsiz
72     int x1, y1; // Xsiz, Ysiz 
73     int numcomps; // number of components
74     int index_on; // 0 = no index || 1 = index
75   //int PPT;
76     j2k_comp_t *comps; // image-components
77 } j2k_image_t;
78
79 typedef struct {
80     int expn; // exponent
81     int mant; // mantissa
82 } j2k_stepsize_t;
83
84 typedef struct {
85     int csty; // coding style
86     int numresolutions; // number of resolutions
87     int cblkw; // width of code-blocks
88     int cblkh; // height of code-blocks
89     int cblksty; // code-block coding style
90     int qmfbid; // discrete wavelet transform identifier
91     int qntsty; // quantisation style
92     j2k_stepsize_t stepsizes[J2K_MAXBANDS]; // stepsizes used for quantisation
93     int numgbits; // number of guard bits
94     int roishift; // Region Of Interest shift
95     int prcw[J2K_MAXRLVLS]; // Precinct width
96     int prch[J2K_MAXRLVLS]; // Precinct height
97 } j2k_tccp_t;
98
99 typedef struct {
100     int resno0, compno0; 
101     int layno1, resno1, compno1;
102     int prg;
103     int tile;
104     char progorder[4];
105 } j2k_poc_t;
106
107 typedef struct {
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     j2k_poc_t pocs[32]; // progression order changes
115     j2k_tccp_t *tccps; // tile-component coding parameters
116 } j2k_tcp_t;
117
118 typedef struct {
119     int tx0, ty0; // XTOsiz, YTOsiz
120     int tdx, tdy; // XTsiz, YTsiz
121     int tw, th;
122     j2k_tcp_t *tcps; // tile coding parameters
123 } j2k_cp_t;
124
125 typedef struct {  
126   int len;
127   int len_header;
128   int offset;
129 } info_layer_t;
130
131 typedef struct {  
132   info_layer_t *layer;
133 } info_prec_t;
134
135 typedef struct {  
136   info_prec_t *prec;
137 } info_reso_t;
138
139 typedef struct {  
140   info_reso_t *reso;
141 } info_compo_t;
142
143 typedef struct {
144   int num_tile;   // Number of Tile
145   int start_pos;  // Start position
146   int end_header; // End position of the header
147   int end_pos;    // End position
148   int pw, ph;     // number of precinct by tile
149   int num_packet; // number of packet in the tile
150   info_compo_t *compo;  // component [packet]
151 } info_tile_t; // index struct
152
153 typedef struct {
154   int type;   // type of marker [SIZ, QCD, POC, PPM, CRG] appearing only once
155   int start_pos;  // Start position of the marker
156   int len; // Length of the marker
157 } info_marker_t; // index struct
158
159 typedef struct{
160   info_marker_t *COD;
161   int num_COD;
162   info_marker_t *COC;
163   int num_COC;
164   info_marker_t *RGN;
165   int num_RGN;
166   info_marker_t *QCC;
167   int num_QCC;
168   info_marker_t *TLM;
169   int num_TLM;
170   info_marker_t *PLM;
171   int num_PLM;
172   info_marker_t *PPM;
173   int num_PPM;
174   info_marker_t *COM;
175   int num_COM;
176 } info_marker_mul_t; // index struct
177
178 typedef struct {
179   int index_on;
180   int num;  // numero of packet
181   int index_write; // writing the packet inthe index with t2_encode_packets
182   int Im_w, Im_h; // Image width and Height
183   int Prog; // progression order
184   int Tile_x, Tile_y; // Number of Tile in X and Y
185   int tw, th;
186   int Comp; // Component numbers
187   int Layer; // number of layer
188   int Decomposition; // number of decomposition
189   int pw, ph;   // nombre precinct in X and Y
190   int pdx, pdy; // size of precinct in X and Y
191   int Main_head_end; // Main header position
192   int codestream_size; // codestream's size
193   info_tile_t *tile;  // information concerning tiles inside image
194   info_marker_t *marker; // information concerning markers inside image [only one apparition]
195   info_marker_mul_t marker_mul;  // information concerning markers inside image [multiple apparition] 
196   int num_marker; // number of marker
197   int num_packet_max;  // MAximum number of packet
198 } info_image_t; // index struct
199
200
201
202 /* 
203  * Encode an image into a JPEG-2000 codestream
204  * i: image to encode
205  * cp: coding parameters
206  * dest: destination buffer
207  * len: length of destination buffer
208  * index : index file name
209  */
210 LIBJ2K_API int j2k_encode(j2k_image_t *i, j2k_cp_t *cp,char *outfile, int len,char *index);
211
212 //LIBJ2K_API int j2k_encode(j2k_image_t *i, j2k_cp_t *cp,unsigned char *dest, int len);
213 /*
214  * Decode an image from a JPEG-2000 codestream
215  * src: source buffer
216  * len: length of source buffer
217  * i: decode image
218  * cp: coding parameters that were used to encode the image
219  */
220 LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t **i, j2k_cp_t **cp);
221
222 #endif