]> Creatis software - gdcm.git/blob - src/gdcmopenjpeg/libopenjpeg/j2k.h
17e13d1a2a3bf23f35c989ec10297371ad567841
[gdcm.git] / src / gdcmopenjpeg / libopenjpeg / j2k.h
1 /*
2  * Copyright (c) 2001-2002, David Janssens
3  * Copyright (c) 2002-2003, Yannick Verschueren
4  * Copyright (c) 2002-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 #if defined(_WIN32) && defined (OPENJPEGDLL)
32 #ifdef gdcmopenjpeg_EXPORTS /*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 #if defined(_WIN32) && defined (OPENJPEGSTATIC)
42 #define LIBJ2K_API __declspec(dllexport)
43 #else
44 #define LIBJ2K_API extern
45 #endif
46
47 #ifndef __J2K_H
48 #define __J2K_H
49
50 #define J2K_MAXRLVLS 33      /* Number of maximum resolution level authorized                   */
51 #define J2K_MAXBANDS (3*J2K_MAXRLVLS-2)   /* Number of maximum sub-band linked to number of resolution level */
52 #define J2K_CFMT 0
53 #define JP2_CFMT 1
54 #define JPT_CFMT 2
55 #define MJ2_CFMT 3
56 #define PXM_DFMT 0
57 #define PGX_DFMT 1
58 #define BMP_DFMT 2
59 #define YUV_DFMT 3
60
61 #define J2K_CP_CSTY_PRT 0x01
62 #define J2K_CP_CSTY_SOP 0x02
63 #define J2K_CP_CSTY_EPH 0x04
64 #define J2K_CCP_CSTY_PRT 0x01
65 #define J2K_CCP_CBLKSTY_LAZY 0x01
66 #define J2K_CCP_CBLKSTY_RESET 0x02
67 #define J2K_CCP_CBLKSTY_TERMALL 0x04
68 #define J2K_CCP_CBLKSTY_VSC 0x08
69 #define J2K_CCP_CBLKSTY_PTERM 0x10
70 #define J2K_CCP_CBLKSTY_SEGSYM 0x20
71 #define J2K_CCP_QNTSTY_NOQNT 0
72 #define J2K_CCP_QNTSTY_SIQNT 1
73 #define J2K_CCP_QNTSTY_SEQNT 2
74
75 typedef struct {
76   int dx, dy;         /* XRsiz, YRsiz              */
77   int w, h;         /* width and height of data  */
78   int x0, y0;         /* offset of the component compare to the whole image  */
79   int prec;         /* precision                 */
80   int bpp;         /* deapth of image in bits   */
81   int sgnd;         /* signed                    */
82   int resno_decoded;      /* number of decoded resolution */
83   int factor;         /* number of division by 2 of the out image  compare to the original size of image */
84   int *data;         /* image-component data      */
85 } j2k_comp_t;
86
87 typedef struct {
88   int x0, y0;         /* XOsiz, YOsiz              */
89   int x1, y1;         /* Xsiz, Ysiz                */
90   int numcomps;         /* number of components      */
91   int color_space;      /* sRGB, Greyscale or YUV */
92   j2k_comp_t *comps;      /* image-components          */
93 } j2k_image_t;
94
95 typedef struct {
96   int expn;         /* exponent                  */
97   int mant;         /* mantissa                  */
98 } j2k_stepsize_t;
99
100 typedef struct {
101   int csty;         /* coding style                          */
102   int numresolutions;      /* number of resolutions                 */
103   int cblkw;         /* width of code-blocks                  */
104   int cblkh;         /* height of code-blocks                 */
105   int cblksty;         /* code-block coding style               */
106   int qmfbid;         /* discrete wavelet transform identifier */
107   int qntsty;         /* quantisation style                    */
108   j2k_stepsize_t stepsizes[J2K_MAXBANDS];   /* stepsizes used for quantization       */
109   int numgbits;         /* number of guard bits                  */
110   int roishift;         /* Region Of Interest shift              */
111   int prcw[J2K_MAXRLVLS];   /* Precinct width                        */
112   int prch[J2K_MAXRLVLS];   /* Precinct height                       */
113 } j2k_tccp_t;
114
115 typedef struct {
116   int resno0, compno0;
117   int layno1, resno1, compno1;
118   int prg;
119   int tile;
120   char progorder[4];
121 } j2k_poc_t;
122
123 typedef struct {
124   int first;         /* 1 : first part-tile of a tile                                     */
125   int csty;         /* coding style                                                      */
126   int prg;         /* progression order                                                 */
127   int numlayers;      /* number of layers                                                  */
128   int mct;         /* multi-component transform identifier                              */
129   int rates[100];      /* rates of layers                                                   */
130   int numpocs;         /* number of progression order changes                               */
131   int POC;         /* Precise if a POC marker has been used O:NO, 1:YES                 */
132   j2k_poc_t pocs[32];      /* progression order changes                                         */
133   unsigned char *ppt_data;   /* packet header store there for futur use in t2_decode_packet       */
134   unsigned char *ppt_data_first;   /* pointer remaining on the first byte of the first header if ppt is used */
135   int ppt;         /* If ppt == 1 --> there was a PPT marker for the present tile       */
136   int ppt_store;      /* Use in case of multiple marker PPT (number of info already store) */
137   int ppt_len;         /* ppmbug1 */
138   float distoratio[100];   /* add fixed_quality */
139   j2k_tccp_t *tccps;      /* tile-component coding parameters                                  */
140 } j2k_tcp_t;
141
142 typedef struct {
143   int intermed_file;      /* 1: Store each encoded tile one by one in the output file (for mega-Images)*/
144   int decod_format;      /* 0: PGX, 1: PxM, 2: BMP */
145   int cod_format;      /* 0: J2K, 1: JP2, 2: JPT */
146   int disto_alloc;      /* Allocation by rate/distortion     */
147   int fixed_alloc;      /* Allocation by fixed layer         */
148   int fixed_quality;      /* add fixed_quality */
149   int reduce;         /* if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
150   int layer;         /* if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
151   int index_on;         /* 0 = no index || 1 = index */
152   int tx0, ty0;         /* XTOsiz, YTOsiz                    */
153   int tdx, tdy;         /* XTsiz, YTsiz                      */
154   char *comment;      /* comment for coding                */
155   int tw, th;         /* number of tiles in width and heigth */
156   int *tileno;         /* ID number of the tiles present in the codestream */
157   int tileno_size;      /* size of the vector tileno */
158   unsigned char *ppm_data;   /* packet header store there for futur use in t2_decode_packet             */
159   unsigned char *ppm_data_first;   /* pointer remaining on the first byte of the first header if ppm is used */
160   int ppm;         /* If ppm == 1 --> there was a PPM marker for the present tile             */
161   int ppm_store;      /* Use in case of multiple marker PPM (number of info already store)       */
162   int ppm_previous;      /* Use in case of multiple marker PPM (case on non-finished previous info) */
163   int ppm_len;         /* ppmbug1 */
164   j2k_tcp_t *tcps;      /* tile coding parameters                                                  */
165   int *matrice;         /* Fixed layer                                                             */
166 } j2k_cp_t;
167
168 typedef struct {
169   int start_pos, end_pos;   /* start and end position            */
170   double disto;         /* ADD for Marcela                   */
171 } info_packet;         /* Index struct                      */
172
173 typedef struct {
174   double *thresh;      /* value of thresh for each layer by tile cfr. Marcela   */
175   int num_tile;         /* Number of Tile                                        */
176   int start_pos;      /* Start position                                        */
177   int end_header;      /* End position of the header                            */
178   int end_pos;         /* End position                                          */
179   int pw[33], ph[33];      /* precinct number for each resolution level             */
180
181   int pdx[33], pdy[33];      /* precinct size (in power of 2), in X and Y for each resolution level */
182   info_packet *packet;      /* information concerning packets inside tile            */
183   int nbpix;         /* add fixed_quality                                     */
184   double distotile;      /* add fixed_quality                                     */
185 } info_tile;         /* index struct                                          */
186
187 typedef struct {
188   int index_on;
189   double D_max;         /* ADD for Marcela                                       */
190   int num;         /* numero of packet                                      */
191   int index_write;      /* writing the packet inthe index with t2_encode_packets */
192   int Im_w, Im_h;      /* Image width and Height                                */
193   int Prog;         /* progression order                                     */
194   int Tile_x, Tile_y;      /* Tile size in x and y                                  */
195   int Tile_Ox, Tile_Oy;
196   int tw, th;         /* Number of Tile in X and Y                             */
197   int Comp;         /* Component numbers                                     */
198   int Layer;         /* number of layer                                       */
199   int Decomposition;      /* number of decomposition                               */
200   int Main_head_end;      /* Main header position                                  */
201   int codestream_size;      /* codestream's size                                     */
202   info_tile *tile;      /* information concerning tiles inside image             */
203 } info_image;         /* index struct                                          */
204
205 /* 
206  * Encode an image into a JPEG-2000 codestream
207  * i: image to encode
208  * cp: coding parameters
209  * output: destination buffer or name of the output file when cp->intermed_file==1
210  * len: length of destination buffer
211  * index : index file name
212  */
213 LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *output,
214            int len, char *index);
215
216 /* LIBJ2K_API int j2k_encode(j2k_image_t *i, j2k_cp_t *cp,unsigned char *dest, int len); */
217 /*
218  * Decode an image from a JPEG-2000 codestream
219  * src: source buffer
220  * len: length of source buffer
221  * i: decode image
222  * cp: coding parameters that were used to encode the image
223  */
224
225 LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t * img,
226            j2k_cp_t * cp);
227
228
229 /*
230  * Decode an image form a JPT-stream (JPEG 2000, JPIP)
231  * src: source buffer
232  * len: length of source buffer
233  * i: decode image
234  * cp: coding parameters that were used to encode the image
235  *
236  */
237 int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
238            j2k_cp_t * cp);
239
240 LIBJ2K_API void j2k_dec_release();/*antonin*/
241
242 #endif