98d104cfcf3287b1ccc64c739af719dac4301241
[openjpeg.git] / 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 #ifdef DAVID_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                        /* Number of maximum resolution level authorized                   */
45 #define J2K_MAXBANDS (3*J2K_MAXRLVLS+1)        /* Number of maximum sub-band linked to number of resolution level */
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         int dx, dy;                             /* XRsiz, YRsiz              */
63         int prec;                               /* precision                 */
64         int bpp;                                /* deapth of image in bits   */
65         int sgnd;                               /* signed                    */
66         int *data;                              /* image-component data      */
67 } j2k_comp_t;
68
69 typedef struct {
70         int x0, y0;                             /* XOsiz, YOsiz              */
71         int x1, y1;                             /* Xsiz, Ysiz                */
72         int numcomps;                           /* number of components      */
73         int index_on;                           /* 0 = no index || 1 = index */
74         j2k_comp_t *comps;                      /* image-components          */
75 } j2k_image_t;
76
77 typedef struct {
78         int expn;                               /* exponent                  */
79         int mant;                               /* mantissa                  */
80 } j2k_stepsize_t;
81
82 typedef struct {
83         int csty;                               /* coding style                          */
84         int numresolutions;                     /* number of resolutions                 */
85         int cblkw;                              /* width of code-blocks                  */
86         int cblkh;                              /* height of code-blocks                 */
87         int cblksty;                            /* code-block coding style               */
88         int qmfbid;                             /* discrete wavelet transform identifier */
89         int qntsty;                             /* quantisation style                    */
90         j2k_stepsize_t stepsizes[J2K_MAXBANDS]; /* stepsizes used for quantisation       */
91         int numgbits;                           /* number of guard bits                  */
92         int roishift;                           /* Region Of Interest shift              */
93         int prcw[J2K_MAXRLVLS];                 /* Precinct width                        */
94         int prch[J2K_MAXRLVLS];                 /* Precinct height                       */
95 } j2k_tccp_t;
96
97 typedef struct {
98         int resno0, compno0;
99         int layno1, resno1, compno1;
100         int prg;
101         int tile;
102         char progorder[4];
103 } j2k_poc_t;
104
105 typedef struct {
106         int first;                      /* 1 : first part-tile of a tile                                     */
107         int csty;                       /* coding style                                                      */
108         int prg;                        /* progression order                                                 */
109         int numlayers;                  /* number of layers                                                  */
110         int mct;                        /* multi-component transform identifier                              */
111         int rates[100];                 /* rates of layers                                                   */
112         int numpocs;                    /* number of progression order changes                               */
113         int POC;                        /* Precise if a POC marker has been used O:NO, 1:YES                 */
114         j2k_poc_t pocs[32];             /* progression order changes                                         */
115         unsigned char *ppt_data;        /* packet header store there for futur use in t2_decode_packet       */
116         int ppt;                        /* If ppt == 1 --> there was a PPT marker for the present tile       */
117         int ppt_store;                  /* Use in case of multiple marker PPT (number of info already store) */
118         j2k_tccp_t *tccps;              /* tile-component coding parameters                                  */
119 } j2k_tcp_t;
120
121 typedef struct {
122         int image_type;                 /* 0: PNM, PGM, PPM 1: PGX           */
123         int disto_alloc;                /* Allocation by rate/distortion     */
124         int fixed_alloc;                /* Allocation by fixed layer         */
125         int tx0, ty0;                   /* XTOsiz, YTOsiz                    */
126         int tdx, tdy;                   /* XTsiz, YTsiz                      */
127         char *comment;                  /* comment for coding                */
128         int tw, th;
129         unsigned char *ppm_data;        /* packet header store there for futur use in t2_decode_packet             */
130         int ppm;                        /* If ppm == 1 --> there was a PPM marker for the present tile             */
131         int ppm_store;                  /* Use in case of multiple marker PPM (number of info already store)       */
132         int ppm_previous;               /* Use in case of multiple marker PPM (case on non-finished previous info) */
133         j2k_tcp_t *tcps;                /* tile coding parameters                                                  */
134         int *matrice;                   /* Fixed layer                                                             */
135 } j2k_cp_t;
136
137 typedef struct {
138         int start_pos, end_pos;         /* start and end position            */
139         double disto;                   /* ADD for Marcela                   */
140 } info_packet;                          /* Index struct                      */
141
142 typedef struct {
143         double *thresh;                 /* value of thresh for each layer by tile cfr. Marcela   */
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         info_packet *packet;            /* information concerning packets inside tile            */
150 } info_tile;                            /* index struct                                          */
151
152 typedef struct {
153         int index_on;
154         double D_max;                   /* ADD for Marcela                                       */
155         int num;                        /* numero of packet                                      */
156         int index_write;                /* writing the packet inthe index with t2_encode_packets */
157         int Im_w, Im_h;                 /* Image width and Height                                */
158         int Prog;                       /* progression order                                     */
159         int Tile_x, Tile_y;             /* Number of Tile in X and Y                             */
160         int tw, th;
161         int Comp;                       /* Component numbers                                     */
162         int Layer;                      /* number of layer                                       */
163         int Decomposition;              /* number of decomposition                               */
164         int pw, ph;                     /* nombre precinct in X and Y                            */
165         int pdx, pdy;                   /* size of precinct in X and Y                           */
166         int Main_head_end;              /* Main header position                                  */
167         int codestream_size;            /* codestream's size                                     */
168         info_tile *tile;                /* information concerning tiles inside image             */
169 } info_image;                           /* index struct                                          */
170
171 /* 
172  * Encode an image into a JPEG-2000 codestream
173  * i: image to encode
174  * cp: coding parameters
175  * dest: destination buffer
176  * len: length of destination buffer
177  * index : index file name
178  */
179 LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *outfile, int len, char *index);
180
181 /* LIBJ2K_API int j2k_encode(j2k_image_t *i, j2k_cp_t *cp,unsigned char *dest, int len); */
182 /*
183  * Decode an image from a JPEG-2000 codestream
184  * src: source buffer
185  * len: length of source buffer
186  * i: decode image
187  * cp: coding parameters that were used to encode the image
188  */
189 LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp);
190
191
192 /*
193  * Decode an image form a JPT-stream (JPEG 2000, JPIP)
194  * src: source buffer
195  * len: length of source buffer
196  * i: decode image
197  * cp: coding parameters that were used to encode the image
198  *
199  */
200 int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp);
201
202 #endif