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) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren
11 * Copyright (c) 2003-2007, Francois-Olivier Devaux
12 * Copyright (c) 2003-2014, Antonin Descampe
13 * Copyright (c) 2005, Herve Drolon, FreeImage Team
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
41 @brief Implementation of a tile coder/decoder (TCD)
43 The functions in TCD.C have for goal to encode or decode each tile independently from
44 each other. The functions in TCD.C are used by some function in J2K.C.
47 /** @defgroup TCD TCD - Implementation of a tile coder/decoder */
53 typedef struct opj_tcd_seg {
66 typedef struct opj_tcd_pass {
75 typedef struct opj_tcd_layer {
76 int numpasses; /* Number of passes in the layer */
77 int len; /* len of information */
78 double disto; /* add for index (Cfr. Marcela) */
79 unsigned char *data; /* data */
85 typedef struct opj_tcd_cblk_enc {
86 unsigned char* data; /* Data */
87 opj_tcd_layer_t* layers; /* layer information */
88 opj_tcd_pass_t* passes; /* information about the passes */
90 y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
93 int numpasses; /* number of pass already done for the code-blocks */
94 int numpassesinlayers; /* number of passes in the layer */
95 int totalpasses; /* total number of passes */
98 typedef struct opj_tcd_cblk_dec {
99 unsigned char* data; /* Data */
100 opj_tcd_seg_t* segs; /* segments information */
102 y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
105 int len; /* length */
106 int numnewpasses; /* number of pass added to the code-blocks */
107 int numsegs; /* number of segments */
108 } opj_tcd_cblk_dec_t;
113 typedef struct opj_tcd_precinct {
115 y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
116 int cw, ch; /* number of precinct in width and height */
117 union { /* code-blocks informations */
118 opj_tcd_cblk_enc_t* enc;
119 opj_tcd_cblk_dec_t* dec;
121 opj_tgt_tree_t *incltree; /* inclusion tree */
122 opj_tgt_tree_t *imsbtree; /* IMSB tree */
123 } opj_tcd_precinct_t;
128 typedef struct opj_tcd_band {
130 y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
132 opj_tcd_precinct_t *precincts; /* precinct information */
140 typedef struct opj_tcd_resolution {
142 y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
144 int numbands; /* number sub-band for the resolution level */
145 opj_tcd_band_t bands[3]; /* subband information */
146 } opj_tcd_resolution_t;
151 typedef struct opj_tcd_tilecomp {
153 y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
154 int numresolutions; /* number of resolutions level */
155 opj_tcd_resolution_t *resolutions; /* resolutions information */
156 int *data; /* data of the component */
157 int numpix; /* add fixed_quality */
158 } opj_tcd_tilecomp_t;
163 typedef struct opj_tcd_tile {
165 y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
166 int numcomps; /* number of components in tile */
167 opj_tcd_tilecomp_t *comps; /* Components information */
168 int numpix; /* add fixed_quality */
169 double distotile; /* add fixed_quality */
170 double distolayer[100]; /* add fixed_quality */
178 typedef struct opj_tcd_image {
179 int tw, th; /* number of tiles in width and height */
180 opj_tcd_tile_t *tiles; /* Tiles information */
186 typedef struct opj_tcd {
187 /** Position of the tilepart flag in Progression order*/
189 /** Tile part number*/
191 /** Current tile part number*/
193 /** Total number of tileparts of the current tile*/
195 /** Current Packet iterator number */
198 opj_common_ptr cinfo;
200 /** info on each image tile */
201 opj_tcd_image_t *tcd_image;
204 /** coding parameters */
206 /** pointer to the current encoded/decoded tile */
207 opj_tcd_tile_t *tcd_tile;
208 /** coding/decoding parameters common to all tiles */
210 /** current encoded/decoded tile */
212 /** Time taken to encode a tile*/
213 double encoding_time;
216 /** @name Exported functions */
218 /* ----------------------------------------------------------------------- */
221 Dump the content of a tcd structure
223 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);
225 Create a new TCD handle
226 @param cinfo Codec context info
227 @return Returns a new TCD handle if successful returns NULL otherwise
229 opj_tcd_t* tcd_create(opj_common_ptr cinfo);
231 Destroy a previously created TCD handle
232 @param tcd TCD handle to destroy
234 void tcd_destroy(opj_tcd_t *tcd);
236 Initialize the tile coder (allocate the memory)
237 @param tcd TCD handle
238 @param image Raw image
239 @param cp Coding parameters
240 @param curtileno Number that identifies the tile that will be encoded
242 void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
245 Free the memory allocated for encoding
246 @param tcd TCD handle
248 void tcd_free_encode(opj_tcd_t *tcd);
250 Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)
251 @param tcd TCD handle
252 @param image Raw image
253 @param cp Coding parameters
254 @param curtileno Number that identifies the tile that will be encoded
256 void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
259 Initialize the tile decoder
260 @param tcd TCD handle
261 @param image Raw image
262 @param cp Coding parameters
264 void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
265 void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
266 int tileno, opj_codestream_info_t *cstr_info);
267 void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
268 void tcd_rateallocate_fixed(opj_tcd_t *tcd);
269 void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
270 opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len,
271 opj_codestream_info_t *cstr_info);
273 Encode a tile from the raw image into a buffer
274 @param tcd TCD handle
275 @param tileno Number that identifies one of the tiles to be encoded
276 @param dest Destination buffer
277 @param len Length of destination buffer
278 @param cstr_info Codestream information structure
281 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len,
282 opj_codestream_info_t *cstr_info);
284 Decode a tile from a buffer into a raw image
285 @param tcd TCD handle
286 @param src Source buffer
287 @param len Length of source buffer
288 @param tileno Number that identifies one of the tiles to be decoded
289 @param cstr_info Codestream information structure
291 opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len,
292 int tileno, opj_codestream_info_t *cstr_info);
294 Free the memory allocated for decoding
295 @param tcd TCD handle
297 void tcd_free_decode(opj_tcd_t *tcd);
298 void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
300 /* ----------------------------------------------------------------------- */