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 */
89 int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
92 int numpasses; /* number of pass already done for the code-blocks */
93 int numpassesinlayers; /* number of passes in the layer */
94 int totalpasses; /* total number of passes */
97 typedef struct opj_tcd_cblk_dec {
98 unsigned char* data; /* Data */
99 opj_tcd_seg_t* segs; /* segments informations */
100 int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
103 int len; /* length */
104 int numnewpasses; /* number of pass added to the code-blocks */
105 int numsegs; /* number of segments */
106 } opj_tcd_cblk_dec_t;
111 typedef struct opj_tcd_precinct {
112 int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
113 int cw, ch; /* number of precinct in width and heigth */
114 union{ /* code-blocks informations */
115 opj_tcd_cblk_enc_t* enc;
116 opj_tcd_cblk_dec_t* dec;
118 opj_tgt_tree_t *incltree; /* inclusion tree */
119 opj_tgt_tree_t *imsbtree; /* IMSB tree */
120 } opj_tcd_precinct_t;
125 typedef struct opj_tcd_band {
126 int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
128 opj_tcd_precinct_t *precincts; /* precinct information */
136 typedef struct opj_tcd_resolution {
137 int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
139 int numbands; /* number sub-band for the resolution level */
140 opj_tcd_band_t bands[3]; /* subband information */
141 } opj_tcd_resolution_t;
146 typedef struct opj_tcd_tilecomp {
147 int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
148 int numresolutions; /* number of resolutions level */
149 opj_tcd_resolution_t *resolutions; /* resolutions information */
150 int *data; /* data of the component */
151 int numpix; /* add fixed_quality */
152 } opj_tcd_tilecomp_t;
157 typedef struct opj_tcd_tile {
158 int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
159 int numcomps; /* number of components in tile */
160 opj_tcd_tilecomp_t *comps; /* Components information */
161 int numpix; /* add fixed_quality */
162 double distotile; /* add fixed_quality */
163 double distolayer[100]; /* add fixed_quality */
171 typedef struct opj_tcd_image {
172 int tw, th; /* number of tiles in width and heigth */
173 opj_tcd_tile_t *tiles; /* Tiles information */
179 typedef struct opj_tcd {
180 /** Position of the tilepart flag in Progression order*/
182 /** Tile part number*/
184 /** Current tile part number*/
186 /** Total number of tileparts of the current tile*/
188 /** Current Packet iterator number */
191 opj_common_ptr cinfo;
193 /** info on each image tile */
194 opj_tcd_image_t *tcd_image;
197 /** coding parameters */
199 /** pointer to the current encoded/decoded tile */
200 opj_tcd_tile_t *tcd_tile;
201 /** coding/decoding parameters common to all tiles */
203 /** current encoded/decoded tile */
205 /** Time taken to encode a tile*/
206 double encoding_time;
209 /** @name Exported functions */
211 /* ----------------------------------------------------------------------- */
214 Dump the content of a tcd structure
216 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);
218 Create a new TCD handle
219 @param cinfo Codec context info
220 @return Returns a new TCD handle if successful returns NULL otherwise
222 opj_tcd_t* tcd_create(opj_common_ptr cinfo);
224 Destroy a previously created TCD handle
225 @param tcd TCD handle to destroy
227 void tcd_destroy(opj_tcd_t *tcd);
229 Initialize the tile coder (allocate the memory)
230 @param tcd TCD handle
231 @param image Raw image
232 @param cp Coding parameters
233 @param curtileno Number that identifies the tile that will be encoded
235 void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
237 Free the memory allocated for encoding
238 @param tcd TCD handle
240 void tcd_free_encode(opj_tcd_t *tcd);
242 Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)
243 @param tcd TCD handle
244 @param image Raw image
245 @param cp Coding parameters
246 @param curtileno Number that identifies the tile that will be encoded
248 void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
250 Initialize the tile decoder
251 @param tcd TCD handle
252 @param image Raw image
253 @param cp Coding parameters
255 void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
256 void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno, opj_codestream_info_t *cstr_info);
257 void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
258 void tcd_rateallocate_fixed(opj_tcd_t *tcd);
259 void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
260 opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
262 Encode a tile from the raw image into a buffer
263 @param tcd TCD handle
264 @param tileno Number that identifies one of the tiles to be encoded
265 @param dest Destination buffer
266 @param len Length of destination buffer
267 @param cstr_info Codestream information structure
270 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
272 Decode a tile from a buffer into a raw image
273 @param tcd TCD handle
274 @param src Source buffer
275 @param len Length of source buffer
276 @param tileno Number that identifies one of the tiles to be decoded
277 @param cstr_info Codestream information structure
279 opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
281 Free the memory allocated for decoding
282 @param tcd TCD handle
284 void tcd_free_decode(opj_tcd_t *tcd);
285 void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
287 /* ----------------------------------------------------------------------- */