Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4758 | right-hear | 1 | /* |
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 |
||
8 | * All rights reserved. |
||
9 | * |
||
10 | * Redistribution and use in source and binary forms, with or without |
||
11 | * modification, are permitted provided that the following conditions |
||
12 | * are met: |
||
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. |
||
18 | * |
||
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. |
||
30 | */ |
||
31 | #ifndef __TCD_H |
||
32 | #define __TCD_H |
||
33 | /** |
||
34 | @file tcd.h |
||
35 | @brief Implementation of a tile coder/decoder (TCD) |
||
36 | |||
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. |
||
39 | */ |
||
40 | |||
41 | /** @defgroup TCD TCD - Implementation of a tile coder/decoder */ |
||
42 | /*@{*/ |
||
43 | |||
44 | /** |
||
45 | Tile coder/decoder: segment instance |
||
46 | */ |
||
47 | typedef struct opj_tcd_seg { |
||
48 | /** Number of passes in the segment */ |
||
49 | int numpasses; |
||
50 | /** Length of information */ |
||
51 | int len; |
||
52 | /** Data */ |
||
53 | unsigned char *data; |
||
54 | /** Number of passes posible for the segment */ |
||
55 | int maxpasses; |
||
56 | /** Number of passes added to the segment */ |
||
57 | int numnewpasses; |
||
58 | /** New length after inclusion of segments */ |
||
59 | int newlen; |
||
60 | } opj_tcd_seg_t; |
||
61 | |||
62 | /** |
||
63 | Tile coder/decoder: pass instance |
||
64 | */ |
||
65 | typedef struct opj_tcd_pass { |
||
66 | /** Rate obtained in the pass*/ |
||
67 | int rate; |
||
68 | /** Distorsion obtained in the pass*/ |
||
69 | double distortiondec; |
||
70 | int term; |
||
71 | /** Length of information */ |
||
72 | int len; |
||
73 | } opj_tcd_pass_t; |
||
74 | |||
75 | /** |
||
76 | Tile coder/decoder: layer instance |
||
77 | */ |
||
78 | typedef struct opj_tcd_layer { |
||
79 | /** Number of passes in the layer */ |
||
80 | int numpasses; |
||
81 | /** Length of information */ |
||
82 | int len; |
||
83 | /** Distortion within layer */ |
||
84 | double disto; /* add for index (Cfr. Marcela) */ |
||
85 | unsigned char *data; /* data */ |
||
86 | } opj_tcd_layer_t; |
||
87 | |||
88 | /** |
||
89 | Tile coder/decoder: codeblock instance |
||
90 | */ |
||
91 | typedef struct opj_tcd_cblk { |
||
92 | /** Dimension of the code-blocks : left upper corner (x0, y0, z0) */ |
||
93 | int x0, y0, z0; |
||
94 | /** Dimension of the code-blocks : right low corner (x1,y1,z1) */ |
||
95 | int x1, y1, z1; |
||
96 | /** Number of bits per simbol in codeblock */ |
||
97 | int numbps; |
||
98 | int numlenbits; |
||
99 | int len; /* length */ |
||
100 | /** Number of pass already done for the code-blocks */ |
||
101 | int numpasses; |
||
102 | /** number of pass added to the code-blocks */ |
||
103 | int numnewpasses; |
||
104 | /** Number of segments */ |
||
105 | int numsegs; |
||
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 */ |
||
113 | int totalpasses; |
||
114 | /** Information about the passes */ |
||
115 | opj_tcd_pass_t passes[100]; |
||
116 | /* Data */ |
||
117 | unsigned char data[524288]; |
||
118 | //unsigned char *data; |
||
119 | } opj_tcd_cblk_t; |
||
120 | |||
121 | /** |
||
122 | Tile coder/decoder: precint instance |
||
123 | */ |
||
124 | typedef struct opj_tcd_precinct { |
||
125 | /** Dimension of the precint : left upper corner (x0, y0, z0) */ |
||
126 | int x0, y0, z0; |
||
127 | /** Dimension of the precint : right low corner (x1,y1,z1) */ |
||
128 | int x1, y1, z1; |
||
129 | /** Number of codeblocks in precinct in width and heigth and length*/ |
||
130 | int cblkno[3]; |
||
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; |
||
138 | |||
139 | /** |
||
140 | Tile coder/decoder: subband instance |
||
141 | */ |
||
142 | typedef struct opj_tcd_band { |
||
143 | /** Dimension of the subband : left upper corner (x0, y0, z0) */ |
||
144 | int x0, y0, z0; |
||
145 | /** Dimension of the subband : right low corner (x1,y1,z1) */ |
||
146 | int x1, y1, z1; |
||
147 | /** Information about the precints */ |
||
148 | opj_tcd_precinct_t *precincts; /* precinct information */ |
||
149 | /** Number of bits per symbol in band */ |
||
150 | int numbps; |
||
151 | /** Quantization stepsize associated */ |
||
152 | float stepsize; |
||
153 | /** Band orientation (O->LLL,...,7->HHH) */ |
||
154 | int bandno; |
||
155 | } opj_tcd_band_t; |
||
156 | |||
157 | /** |
||
158 | Tile coder/decoder: resolution instance |
||
159 | */ |
||
160 | typedef struct opj_tcd_resolution { |
||
161 | /** Dimension of the resolution level : left upper corner (x0, y0, z0) */ |
||
162 | int x0, y0, z0; |
||
163 | /** Dimension of the resolution level : right low corner (x1,y1,z1) */ |
||
164 | int x1, y1, z1; |
||
165 | /** Number of precints in each dimension for the resolution level */ |
||
166 | int prctno[3]; |
||
167 | /** Number of subbands for the resolution level */ |
||
168 | int numbands; |
||
169 | /** Subband information */ |
||
170 | opj_tcd_band_t *bands; |
||
171 | } opj_tcd_resolution_t; |
||
172 | |||
173 | /** |
||
174 | Tile coder/decoder: component instance |
||
175 | */ |
||
176 | typedef struct opj_tcd_tilecomp { |
||
177 | /** Dimension of the component : left upper corner (x0, y0, z0) */ |
||
178 | int x0, y0, z0; |
||
179 | /** Dimension of the component : right low corner (x1,y1,z1) */ |
||
180 | int 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 */ |
||
186 | int *data; |
||
187 | /** Fixed_quality related */ |
||
188 | int nbpix; |
||
189 | /** Number of bits per voxel in component */ |
||
190 | int bpp; |
||
191 | } opj_tcd_tilecomp_t; |
||
192 | |||
193 | /** |
||
194 | Tile coder/decoder: tile instance |
||
195 | */ |
||
196 | typedef struct opj_tcd_tile { |
||
197 | /** Dimension of the tile : left upper corner (x0, y0, z0) */ |
||
198 | int x0, y0, z0; |
||
199 | /** Dimension of the tile : right low corner (x1,y1,z1) */ |
||
200 | int x1, y1, z1; |
||
201 | /** Number of components in tile */ |
||
202 | int numcomps; |
||
203 | /** Components information */ |
||
204 | opj_tcd_tilecomp_t *comps; |
||
205 | /** Fixed_quality related : no of bytes of data*/ |
||
206 | int nbpix; |
||
207 | /** Fixed_quality related : distortion achieved in tile */ |
||
208 | double distotile; |
||
209 | /** Fixed_quality related : distortion achieved in each layer */ |
||
210 | double distolayer[100]; |
||
211 | } opj_tcd_tile_t; |
||
212 | |||
213 | /** |
||
214 | Tile coder/decoder: volume instance |
||
215 | */ |
||
216 | typedef struct opj_tcd_volume { |
||
217 | /** Number of tiles in width and heigth and length */ |
||
218 | int tw, th, tl; |
||
219 | /** Tiles information */ |
||
220 | opj_tcd_tile_t *tiles; |
||
221 | } opj_tcd_volume_t; |
||
222 | |||
223 | /** |
||
224 | Tile coder/decoder |
||
225 | */ |
||
226 | typedef struct opj_tcd { |
||
227 | /** Codec context */ |
||
228 | opj_common_ptr cinfo; |
||
229 | /** Volume information */ |
||
230 | opj_volume_t *volume; |
||
231 | /** Coding parameters */ |
||
232 | opj_cp_t *cp; |
||
233 | /** Coding/decoding parameters common to all tiles */ |
||
234 | opj_tcp_t *tcp; |
||
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 */ |
||
240 | int tcd_tileno; |
||
241 | |||
242 | /**@name working variables */ |
||
243 | /*@{*/ |
||
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; |
||
250 | /*@}*/ |
||
251 | } opj_tcd_t; |
||
252 | |||
253 | /** @name Funciones generales */ |
||
254 | /*@{*/ |
||
255 | /* ----------------------------------------------------------------------- */ |
||
256 | |||
257 | /** |
||
258 | Dump the content of a tcd structure |
||
259 | */ |
||
260 | void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t *img); |
||
261 | /** |
||
262 | Create a new TCD handle |
||
263 | @param cinfo Codec context info |
||
264 | @return Returns a new TCD handle if successful returns NULL otherwise |
||
265 | */ |
||
266 | opj_tcd_t* tcd_create(opj_common_ptr cinfo); |
||
267 | /** |
||
268 | Destroy a previously created TCD handle |
||
269 | @param tcd TCD handle to destroy |
||
270 | */ |
||
271 | void tcd_destroy(opj_tcd_t *tcd); |
||
272 | /** |
||
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 |
||
278 | */ |
||
279 | void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno); |
||
280 | /** |
||
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 |
||
286 | */ |
||
287 | void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno); |
||
288 | /** |
||
289 | Free the memory allocated for encoding |
||
290 | @param tcd TCD handle |
||
291 | */ |
||
292 | void tcd_free_encode(opj_tcd_t *tcd); |
||
293 | /** |
||
294 | Initialize the tile decoder |
||
295 | @param tcd TCD handle |
||
296 | @param volume Raw volume |
||
297 | @param cp Coding parameters |
||
298 | */ |
||
299 | void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp); |
||
300 | |||
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); |
||
305 | /** |
||
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 |
||
312 | @return |
||
313 | */ |
||
314 | int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info); |
||
315 | /** |
||
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 |
||
321 | */ |
||
322 | bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno); |
||
323 | /** |
||
324 | Free the memory allocated for decoding |
||
325 | @param tcd TCD handle |
||
326 | */ |
||
327 | void tcd_free_decode(opj_tcd_t *tcd); |
||
328 | |||
329 | /* ----------------------------------------------------------------------- */ |
||
330 | /*@}*/ |
||
331 | |||
332 | /*@}*/ |
||
333 | |||
334 | #endif /* __TCD_H */ |