2 * Copyright (c) 2001-2003, David Janssens
3 * Copyright (c) 2002-2003, Yannick Verschueren
4 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
5 * Copyright (c) 2005, Herv� Drolon, FreeImage Team
6 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
7 * Copyright (c) 2006, M�nica D�ez Garc�a, Image Processing Laboratory, University of Valladolid, Spain
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 @brief Implementation of a tile coder/decoder (TCD)
37 The functions in TCD.C have for goal to encode or decode each tile independently from
38 each other. The functions in TCD.C are used by some function in JP3D.C.
41 /** @defgroup TCD TCD - Implementation of a tile coder/decoder */
45 Tile coder/decoder: segment instance
47 typedef struct opj_tcd_seg {
48 /** Number of passes in the segment */
50 /** Length of information */
54 /** Number of passes posible for the segment */
56 /** Number of passes added to the segment */
58 /** New length after inclusion of segments */
63 Tile coder/decoder: pass instance
65 typedef struct opj_tcd_pass {
66 /** Rate obtained in the pass*/
68 /** Distorsion obtained in the pass*/
71 /** Length of information */
76 Tile coder/decoder: layer instance
78 typedef struct opj_tcd_layer {
79 /** Number of passes in the layer */
81 /** Length of information */
83 /** Distortion within layer */
84 double disto; /* add for index (Cfr. Marcela) */
85 unsigned char *data; /* data */
89 Tile coder/decoder: codeblock instance
91 typedef struct opj_tcd_cblk {
92 /** Dimension of the code-blocks : left upper corner (x0, y0, z0) */
94 /** Dimension of the code-blocks : right low corner (x1,y1,z1) */
96 /** Number of bits per simbol in codeblock */
100 /** Number of pass already done for the code-blocks */
102 /** number of pass added to the code-blocks */
104 /** Number of segments */
106 /** Segments informations */
107 opj_tcd_seg_t segs[100];
108 /** Number of passes in the layer */
109 int numpassesinlayers;
110 /** Layer information */
111 opj_tcd_layer_t layers[100];
112 /** Total number of passes */
114 /** Information about the passes */
115 opj_tcd_pass_t passes[100];
117 unsigned char data[524288];
118 //unsigned char *data;
122 Tile coder/decoder: precint instance
124 typedef struct opj_tcd_precinct {
125 /** Dimension of the precint : left upper corner (x0, y0, z0) */
127 /** Dimension of the precint : right low corner (x1,y1,z1) */
129 /** Number of codeblocks in precinct in width and heigth and length*/
131 /** Information about the codeblocks */
132 opj_tcd_cblk_t *cblks;
133 /** Inclusion tree */
134 opj_tgt_tree_t *incltree;
135 /** Missing MSBs tree */
136 opj_tgt_tree_t *imsbtree;
137 } opj_tcd_precinct_t;
140 Tile coder/decoder: subband instance
142 typedef struct opj_tcd_band {
143 /** Dimension of the subband : left upper corner (x0, y0, z0) */
145 /** Dimension of the subband : right low corner (x1,y1,z1) */
147 /** Information about the precints */
148 opj_tcd_precinct_t *precincts; /* precinct information */
149 /** Number of bits per symbol in band */
151 /** Quantization stepsize associated */
153 /** Band orientation (O->LLL,...,7->HHH) */
158 Tile coder/decoder: resolution instance
160 typedef struct opj_tcd_resolution {
161 /** Dimension of the resolution level : left upper corner (x0, y0, z0) */
163 /** Dimension of the resolution level : right low corner (x1,y1,z1) */
165 /** Number of precints in each dimension for the resolution level */
167 /** Number of subbands for the resolution level */
169 /** Subband information */
170 opj_tcd_band_t *bands;
171 } opj_tcd_resolution_t;
174 Tile coder/decoder: component instance
176 typedef struct opj_tcd_tilecomp {
177 /** Dimension of the component : left upper corner (x0, y0, z0) */
179 /** Dimension of the component : right low corner (x1,y1,z1) */
181 /** Number of resolutions level if DWT transform*/
182 int numresolution[3];
183 /** Resolution information */
184 opj_tcd_resolution_t *resolutions;
185 /** Data of the component */
187 /** Fixed_quality related */
189 /** Number of bits per voxel in component */
191 } opj_tcd_tilecomp_t;
194 Tile coder/decoder: tile instance
196 typedef struct opj_tcd_tile {
197 /** Dimension of the tile : left upper corner (x0, y0, z0) */
199 /** Dimension of the tile : right low corner (x1,y1,z1) */
201 /** Number of components in tile */
203 /** Components information */
204 opj_tcd_tilecomp_t *comps;
205 /** Fixed_quality related : no of bytes of data*/
207 /** Fixed_quality related : distortion achieved in tile */
209 /** Fixed_quality related : distortion achieved in each layer */
210 double distolayer[100];
214 Tile coder/decoder: volume instance
216 typedef struct opj_tcd_volume {
217 /** Number of tiles in width and heigth and length */
219 /** Tiles information */
220 opj_tcd_tile_t *tiles;
226 typedef struct opj_tcd {
228 opj_common_ptr cinfo;
229 /** Volume information */
230 opj_volume_t *volume;
231 /** Coding parameters */
233 /** Coding/decoding parameters common to all tiles */
235 /** Info on each volume tile */
236 opj_tcd_volume_t *tcd_volume;
237 /** Pointer to the current encoded/decoded tile */
238 opj_tcd_tile_t *tcd_tile;
239 /** Current encoded/decoded tile */
242 /**@name working variables */
244 opj_tcd_tile_t *tile;
245 opj_tcd_tilecomp_t *tilec;
246 opj_tcd_resolution_t *res;
247 opj_tcd_band_t *band;
248 opj_tcd_precinct_t *prc;
249 opj_tcd_cblk_t *cblk;
253 /** @name Funciones generales */
255 /* ----------------------------------------------------------------------- */
258 Dump the content of a tcd structure
260 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t *img);
262 Create a new TCD handle
263 @param cinfo Codec context info
264 @return Returns a new TCD handle if successful returns NULL otherwise
266 opj_tcd_t* tcd_create(opj_common_ptr cinfo);
268 Destroy a previously created TCD handle
269 @param tcd TCD handle to destroy
271 void tcd_destroy(opj_tcd_t *tcd);
273 Initialize the tile coder (allocate the memory)
274 @param tcd TCD handle
275 @param volume Raw volume
276 @param cp Coding parameters
277 @param curtileno Number that identifies the tile that will be encoded
279 void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno);
281 Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)(for 3D-DWT)
282 @param tcd TCD handle
283 @param volume Raw volume
284 @param cp Coding parameters
285 @param curtileno Number that identifies the tile that will be encoded
287 void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno);
289 Free the memory allocated for encoding
290 @param tcd TCD handle
292 void tcd_free_encode(opj_tcd_t *tcd);
294 Initialize the tile decoder
295 @param tcd TCD handle
296 @param volume Raw volume
297 @param cp Coding parameters
299 void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp);
301 void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
302 void tcd_rateallocate_fixed(opj_tcd_t *tcd);
303 void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
304 bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_info_t * volume_info);
306 Encode a tile from the raw volume into a buffer
307 @param tcd TCD handle
308 @param tileno Number that identifies one of the tiles to be encoded
309 @param dest Destination buffer
310 @param len Length of destination buffer
311 @param volume_info Creation of index file
314 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info);
316 Decode a tile from a buffer into a raw volume
317 @param tcd TCD handle
318 @param src Source buffer
319 @param len Length of source buffer
320 @param tileno Number that identifies one of the tiles to be decoded
322 bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno);
324 Free the memory allocated for decoding
325 @param tcd TCD handle
327 void tcd_free_decode(opj_tcd_t *tcd);
329 /* ----------------------------------------------------------------------- */