]> Creatis software - gdcm.git/blob - src/gdcmopenjpeg/libopenjpeg/tcd.h
ENH: Huge update to openjpeg 1.0 (actually more CVS)...
[gdcm.git] / src / gdcmopenjpeg / libopenjpeg / tcd.h
1 /*\r
2  * Copyright (c) 2001-2003, David Janssens\r
3  * Copyright (c) 2002-2003, Yannick Verschueren\r
4  * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe\r
5  * Copyright (c) 2005, HervĂ© Drolon, FreeImage Team\r
6  * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\r
7  * All rights reserved.\r
8  *\r
9  * Redistribution and use in source and binary forms, with or without\r
10  * modification, are permitted provided that the following conditions\r
11  * are met:\r
12  * 1. Redistributions of source code must retain the above copyright\r
13  *    notice, this list of conditions and the following disclaimer.\r
14  * 2. Redistributions in binary form must reproduce the above copyright\r
15  *    notice, this list of conditions and the following disclaimer in the\r
16  *    documentation and/or other materials provided with the distribution.\r
17  *\r
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
28  * POSSIBILITY OF SUCH DAMAGE.\r
29  */\r
30 #ifndef __TCD_H\r
31 #define __TCD_H\r
32 /**\r
33 @file tcd.h\r
34 @brief Implementation of a tile coder/decoder (TCD)\r
35 \r
36 The functions in TCD.C have for goal to encode or decode each tile independently from\r
37 each other. The functions in TCD.C are used by some function in J2K.C.\r
38 */\r
39 \r
40 /** @defgroup TCD TCD - Implementation of a tile coder/decoder */\r
41 /*@{*/\r
42 \r
43 /**\r
44 FIXME: documentation\r
45 */\r
46 typedef struct opj_tcd_seg {\r
47   int numpasses;\r
48   int len;\r
49   unsigned char *data;\r
50   int maxpasses;\r
51   int numnewpasses;\r
52   int newlen;\r
53 } opj_tcd_seg_t;\r
54 \r
55 /**\r
56 FIXME: documentation\r
57 */\r
58 typedef struct opj_tcd_pass {\r
59   int rate;\r
60   double distortiondec;\r
61   int term, len;\r
62 } opj_tcd_pass_t;\r
63 \r
64 /**\r
65 FIXME: documentation\r
66 */\r
67 typedef struct opj_tcd_layer {\r
68   int numpasses;    /* Number of passes in the layer */\r
69   int len;      /* len of information */\r
70   double disto;      /* add for index (Cfr. Marcela) */\r
71   unsigned char *data;    /* data */\r
72 } opj_tcd_layer_t;\r
73 \r
74 /**\r
75 FIXME: documentation\r
76 */\r
77 typedef struct opj_tcd_cblk {\r
78   int x0, y0, x1, y1;    /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */\r
79   int numbps;\r
80   int numlenbits;\r
81   int len;      /* length */\r
82   int numpasses;    /* number of pass already done for the code-blocks */\r
83   int numnewpasses;    /* number of pass added to the code-blocks */\r
84   int numsegs;      /* number of segments */\r
85   opj_tcd_seg_t segs[100];    /* segments informations */\r
86   unsigned char data[8192];  /* Data */\r
87   int numpassesinlayers;  /* number of passes in the layer */\r
88   opj_tcd_layer_t layers[100];  /* layer information */\r
89   int totalpasses;    /* total number of passes */\r
90   opj_tcd_pass_t passes[100];  /* information about the passes */\r
91 } opj_tcd_cblk_t;\r
92 \r
93 /**\r
94 FIXME: documentation\r
95 */\r
96 typedef struct opj_tcd_precinct {\r
97   int x0, y0, x1, y1;    /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */\r
98   int cw, ch;      /* number of precinct in width and heigth */\r
99   opj_tcd_cblk_t *cblks;    /* code-blocks informations */\r
100   opj_tgt_tree_t *incltree;    /* inclusion tree */\r
101   opj_tgt_tree_t *imsbtree;    /* IMSB tree */\r
102 } opj_tcd_precinct_t;\r
103 \r
104 /**\r
105 FIXME: documentation\r
106 */\r
107 typedef struct opj_tcd_band {\r
108   int x0, y0, x1, y1;    /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */\r
109   int bandno;\r
110   opj_tcd_precinct_t *precincts;  /* precinct information */\r
111   int numbps;\r
112   float stepsize;\r
113 } opj_tcd_band_t;\r
114 \r
115 /**\r
116 FIXME: documentation\r
117 */\r
118 typedef struct opj_tcd_resolution {\r
119   int x0, y0, x1, y1;    /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */\r
120   int pw, ph;\r
121   int numbands;      /* number sub-band for the resolution level */\r
122   opj_tcd_band_t bands[3];    /* subband information */\r
123 } opj_tcd_resolution_t;\r
124 \r
125 /**\r
126 FIXME: documentation\r
127 */\r
128 typedef struct opj_tcd_tilecomp {\r
129   int x0, y0, x1, y1;    /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */\r
130   int numresolutions;    /* number of resolutions level */\r
131   opj_tcd_resolution_t *resolutions;  /* resolutions information */\r
132   int *data;      /* data of the component */\r
133   int nbpix;      /* add fixed_quality */\r
134 } opj_tcd_tilecomp_t;\r
135 \r
136 /**\r
137 FIXME: documentation\r
138 */\r
139 typedef struct opj_tcd_tile {\r
140   int x0, y0, x1, y1;    /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */\r
141   int numcomps;      /* number of components in tile */\r
142   opj_tcd_tilecomp_t *comps;  /* Components information */\r
143   int nbpix;      /* add fixed_quality */\r
144   double distotile;    /* add fixed_quality */\r
145   double distolayer[100];  /* add fixed_quality */\r
146 } opj_tcd_tile_t;\r
147 \r
148 /**\r
149 FIXME: documentation\r
150 */\r
151 typedef struct opj_tcd_image {\r
152   int tw, th;      /* number of tiles in width and heigth */\r
153   opj_tcd_tile_t *tiles;    /* Tiles information */\r
154 } opj_tcd_image_t;\r
155 \r
156 /**\r
157 Tile coder/decoder\r
158 */\r
159 typedef struct opj_tcd {\r
160   /** codec context */\r
161   opj_common_ptr cinfo;\r
162 \r
163   /** info on each image tile */\r
164   opj_tcd_image_t *tcd_image;\r
165   /** image */\r
166   opj_image_t *image;\r
167   /** coding parameters */\r
168   opj_cp_t *cp;\r
169   /** pointer to the current encoded/decoded tile */\r
170   opj_tcd_tile_t *tcd_tile;\r
171   /** coding/decoding parameters common to all tiles */\r
172   opj_tcp_t *tcp;\r
173   /** current encoded/decoded tile */\r
174   int tcd_tileno;\r
175   /**@name working variables */\r
176   /*@{*/\r
177   opj_tcd_tile_t *tile;\r
178   opj_tcd_tilecomp_t *tilec;\r
179   opj_tcd_resolution_t *res;\r
180   opj_tcd_band_t *band;\r
181   opj_tcd_precinct_t *prc;\r
182   opj_tcd_cblk_t *cblk;\r
183   /*@}*/\r
184 } opj_tcd_t;\r
185 \r
186 /** @name Exported functions */\r
187 /*@{*/\r
188 /* ----------------------------------------------------------------------- */\r
189 \r
190 /**\r
191 Dump the content of a tcd structure\r
192 */\r
193 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);\r
194 /**\r
195 Create a new TCD handle\r
196 @param cinfo Codec context info\r
197 @return Returns a new TCD handle if successful returns NULL otherwise\r
198 */\r
199 opj_tcd_t* tcd_create(opj_common_ptr cinfo);\r
200 /**\r
201 Destroy a previously created TCD handle\r
202 @param tcd TCD handle to destroy\r
203 */\r
204 void tcd_destroy(opj_tcd_t *tcd);\r
205 /**\r
206 Initialize the tile coder (allocate the memory)\r
207 @param tcd TCD handle\r
208 @param image Raw image\r
209 @param cp Coding parameters\r
210 @param curtileno Number that identifies the tile that will be encoded\r
211 */\r
212 void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);\r
213 /**\r
214 Free the memory allocated for encoding\r
215 @param tcd TCD handle\r
216 */\r
217 void tcd_free_encode(opj_tcd_t *tcd);\r
218 /**\r
219 Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)\r
220 @param tcd TCD handle\r
221 @param image Raw image\r
222 @param cp Coding parameters\r
223 @param curtileno Number that identifies the tile that will be encoded\r
224 */\r
225 void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);\r
226 /**\r
227 Initialize the tile decoder\r
228 @param tcd TCD handle\r
229 @param image Raw image\r
230 @param cp Coding parameters\r
231 */\r
232 void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);\r
233 void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);\r
234 void tcd_rateallocate_fixed(opj_tcd_t *tcd);\r
235 void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);\r
236 bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info);\r
237 /**\r
238 Encode a tile from the raw image into a buffer\r
239 @param tcd TCD handle\r
240 @param tileno Number that identifies one of the tiles to be encoded\r
241 @param dest Destination buffer\r
242 @param len Length of destination buffer\r
243 @param image_info Creation of index file\r
244 @return \r
245 */\r
246 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info);\r
247 /**\r
248 Decode a tile from a buffer into a raw image\r
249 @param tcd TCD handle\r
250 @param src Source buffer\r
251 @param len Length of source buffer\r
252 @param tileno Number that identifies one of the tiles to be decoded\r
253 */\r
254 bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno);\r
255 /**\r
256 Free the memory allocated for decoding\r
257 @param tcd TCD handle\r
258 */\r
259 void tcd_free_decode(opj_tcd_t *tcd);\r
260 \r
261 /* ----------------------------------------------------------------------- */\r
262 /*@}*/\r
263 \r
264 /*@}*/\r
265 \r
266 #endif /* __TCD_H */\r