2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2001-2003, David Janssens
8 * Copyright (c) 2002-2003, Yannick Verschueren
9 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
10 * Copyright (c) 2005, Herve Drolon, FreeImage Team
11 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
12 * Copyright (c) 2006, M�nica D�ez Garc�a, Image Processing Laboratory, University of Valladolid, Spain
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
40 @brief Implementation of a tile coder/decoder (TCD)
42 The functions in TCD.C have for goal to encode or decode each tile independently from
43 each other. The functions in TCD.C are used by some function in JP3D.C.
46 /** @defgroup TCD TCD - Implementation of a tile coder/decoder */
50 Tile coder/decoder: segment instance
52 typedef struct opj_tcd_seg {
53 /** Number of passes in the segment */
55 /** Length of information */
59 /** Number of passes possible for the segment */
61 /** Number of passes added to the segment */
63 /** New length after inclusion of segments */
68 Tile coder/decoder: pass instance
70 typedef struct opj_tcd_pass {
71 /** Rate obtained in the pass*/
73 /** Distorsion obtained in the pass*/
76 /** Length of information */
81 Tile coder/decoder: layer instance
83 typedef struct opj_tcd_layer {
84 /** Number of passes in the layer */
86 /** Length of information */
88 /** Distortion within layer */
89 double disto; /* add for index (Cfr. Marcela) */
90 unsigned char *data; /* data */
94 Tile coder/decoder: codeblock instance
96 typedef struct opj_tcd_cblk {
97 /** Dimension of the code-blocks : left upper corner (x0, y0, z0) */
99 /** Dimension of the code-blocks : right low corner (x1,y1,z1) */
101 /** Number of bits per simbol in codeblock */
104 int len; /* length */
105 /** Number of pass already done for the code-blocks */
107 /** number of pass added to the code-blocks */
109 /** Number of segments */
111 /** Segments information */
112 opj_tcd_seg_t segs[100];
113 /** Number of passes in the layer */
114 int numpassesinlayers;
115 /** Layer information */
116 opj_tcd_layer_t layers[100];
117 /** Total number of passes */
119 /** Information about the passes */
120 opj_tcd_pass_t passes[100];
122 unsigned char data[524288];
123 /*unsigned char *data;*/
127 Tile coder/decoder: precint instance
129 typedef struct opj_tcd_precinct {
130 /** Dimension of the precint : left upper corner (x0, y0, z0) */
132 /** Dimension of the precint : right low corner (x1,y1,z1) */
134 /** Number of codeblocks in precinct in width and height and length*/
136 /** Information about the codeblocks */
137 opj_tcd_cblk_t *cblks;
138 /** Inclusion tree */
139 opj_tgt_tree_t *incltree;
140 /** Missing MSBs tree */
141 opj_tgt_tree_t *imsbtree;
142 } opj_tcd_precinct_t;
145 Tile coder/decoder: subband instance
147 typedef struct opj_tcd_band {
148 /** Dimension of the subband : left upper corner (x0, y0, z0) */
150 /** Dimension of the subband : right low corner (x1,y1,z1) */
152 /** Information about the precints */
153 opj_tcd_precinct_t *precincts; /* precinct information */
154 /** Number of bits per symbol in band */
156 /** Quantization stepsize associated */
158 /** Band orientation (O->LLL,...,7->HHH) */
163 Tile coder/decoder: resolution instance
165 typedef struct opj_tcd_resolution {
166 /** Dimension of the resolution level : left upper corner (x0, y0, z0) */
168 /** Dimension of the resolution level : right low corner (x1,y1,z1) */
170 /** Number of precints in each dimension for the resolution level */
172 /** Number of subbands for the resolution level */
174 /** Subband information */
175 opj_tcd_band_t *bands;
176 } opj_tcd_resolution_t;
179 Tile coder/decoder: component instance
181 typedef struct opj_tcd_tilecomp {
182 /** Dimension of the component : left upper corner (x0, y0, z0) */
184 /** Dimension of the component : right low corner (x1,y1,z1) */
186 /** Number of resolutions level if DWT transform*/
187 int numresolution[3];
188 /** Resolution information */
189 opj_tcd_resolution_t *resolutions;
190 /** Data of the component */
192 /** Fixed_quality related */
194 /** Number of bits per voxel in component */
196 } opj_tcd_tilecomp_t;
199 Tile coder/decoder: tile instance
201 typedef struct opj_tcd_tile {
202 /** Dimension of the tile : left upper corner (x0, y0, z0) */
204 /** Dimension of the tile : right low corner (x1,y1,z1) */
206 /** Number of components in tile */
208 /** Components information */
209 opj_tcd_tilecomp_t *comps;
210 /** Fixed_quality related : no of bytes of data*/
212 /** Fixed_quality related : distortion achieved in tile */
214 /** Fixed_quality related : distortion achieved in each layer */
215 double distolayer[100];
219 Tile coder/decoder: volume instance
221 typedef struct opj_tcd_volume {
222 /** Number of tiles in width and height and length */
224 /** Tiles information */
225 opj_tcd_tile_t *tiles;
231 typedef struct opj_tcd {
233 opj_common_ptr cinfo;
234 /** Volume information */
235 opj_volume_t *volume;
236 /** Coding parameters */
238 /** Coding/decoding parameters common to all tiles */
240 /** Info on each volume tile */
241 opj_tcd_volume_t *tcd_volume;
242 /** Pointer to the current encoded/decoded tile */
243 opj_tcd_tile_t *tcd_tile;
244 /** Current encoded/decoded tile */
247 /**@name working variables */
249 opj_tcd_tile_t *tile;
250 opj_tcd_tilecomp_t *tilec;
251 opj_tcd_resolution_t *res;
252 opj_tcd_band_t *band;
253 opj_tcd_precinct_t *prc;
254 opj_tcd_cblk_t *cblk;
258 /** @name Funciones generales */
260 /* ----------------------------------------------------------------------- */
263 Dump the content of a tcd structure
265 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t *img);
267 Create a new TCD handle
268 @param cinfo Codec context info
269 @return Returns a new TCD handle if successful returns NULL otherwise
271 opj_tcd_t* tcd_create(opj_common_ptr cinfo);
273 Destroy a previously created TCD handle
274 @param tcd TCD handle to destroy
276 void tcd_destroy(opj_tcd_t *tcd);
278 Initialize the tile coder (allocate the memory)
279 @param tcd TCD handle
280 @param volume Raw volume
281 @param cp Coding parameters
282 @param curtileno Number that identifies the tile that will be encoded
284 void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp,
287 Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)(for 3D-DWT)
288 @param tcd TCD handle
289 @param volume Raw volume
290 @param cp Coding parameters
291 @param curtileno Number that identifies the tile that will be encoded
293 void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp,
296 Free the memory allocated for encoding
297 @param tcd TCD handle
299 void tcd_free_encode(opj_tcd_t *tcd);
301 Initialize the tile decoder
302 @param tcd TCD handle
303 @param volume Raw volume
304 @param cp Coding parameters
306 void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp);
308 void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
309 void tcd_rateallocate_fixed(opj_tcd_t *tcd);
310 void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
311 bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len,
312 opj_volume_info_t * volume_info);
314 Encode a tile from the raw volume into a buffer
315 @param tcd TCD handle
316 @param tileno Number that identifies one of the tiles to be encoded
317 @param dest Destination buffer
318 @param len Length of destination buffer
319 @param volume_info Creation of index file
322 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len,
323 opj_volume_info_t * volume_info);
325 Decode a tile from a buffer into a raw volume
326 @param tcd TCD handle
327 @param src Source buffer
328 @param len Length of source buffer
329 @param tileno Number that identifies one of the tiles to be decoded
331 bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno);
333 Free the memory allocated for decoding
334 @param tcd TCD handle
336 void tcd_free_decode(opj_tcd_t *tcd);
338 /* ----------------------------------------------------------------------- */