1 /* 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. 6 * 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. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 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. 24 * 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. 36 */ 37 #ifndef __TCD_H 38 #define __TCD_H 39 /** 40 @file tcd.h 41 @brief Implementation of a tile coder/decoder (TCD) 42 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. 45 */ 46 47 /** @defgroup TCD TCD - Implementation of a tile coder/decoder */ 48 /*@{*/ 49 50 /** 51 FIXME: documentation 52 */ 53 typedef struct opj_tcd_seg { 54 unsigned char** data; 55 int dataindex; 56 int numpasses; 57 int len; 58 int maxpasses; 59 int numnewpasses; 60 int newlen; 61 } opj_tcd_seg_t; 62 63 /** 64 FIXME: documentation 65 */ 66 typedef struct opj_tcd_pass { 67 int rate; 68 double distortiondec; 69 int term, len; 70 } opj_tcd_pass_t; 71 72 /** 73 FIXME: documentation 74 */ 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 */ 80 } opj_tcd_layer_t; 81 82 /** 83 FIXME: documentation 84 */ 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, 90 y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ 91 int numbps; 92 int numlenbits; 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 */ 96 } opj_tcd_cblk_enc_t; 97 98 typedef struct opj_tcd_cblk_dec { 99 unsigned char* data; /* Data */ 100 opj_tcd_seg_t* segs; /* segments information */ 101 int x0, y0, x1, 102 y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ 103 int numbps; 104 int numlenbits; 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; 109 110 /** 111 FIXME: documentation 112 */ 113 typedef struct opj_tcd_precinct { 114 int x0, y0, x1, 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 information */ 118 opj_tcd_cblk_enc_t* enc; 119 opj_tcd_cblk_dec_t* dec; 120 } cblks; 121 opj_tgt_tree_t *incltree; /* inclusion tree */ 122 opj_tgt_tree_t *imsbtree; /* IMSB tree */ 123 } opj_tcd_precinct_t; 124 125 /** 126 FIXME: documentation 127 */ 128 typedef struct opj_tcd_band { 129 int x0, y0, x1, 130 y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */ 131 int bandno; 132 opj_tcd_precinct_t *precincts; /* precinct information */ 133 int numbps; 134 float stepsize; 135 } opj_tcd_band_t; 136 137 /** 138 FIXME: documentation 139 */ 140 typedef struct opj_tcd_resolution { 141 int x0, y0, x1, 142 y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */ 143 int pw, ph; 144 int numbands; /* number sub-band for the resolution level */ 145 opj_tcd_band_t bands[3]; /* subband information */ 146 } opj_tcd_resolution_t; 147 148 /** 149 FIXME: documentation 150 */ 151 typedef struct opj_tcd_tilecomp { 152 int x0, y0, x1, 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; 159 160 /** 161 FIXME: documentation 162 */ 163 typedef struct opj_tcd_tile { 164 int x0, y0, x1, 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 */ 171 /** packet number */ 172 int packno; 173 } opj_tcd_tile_t; 174 175 /** 176 FIXME: documentation 177 */ 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 */ 181 } opj_tcd_image_t; 182 183 /** 184 Tile coder/decoder 185 */ 186 typedef struct opj_tcd { 187 /** Position of the tilepart flag in Progression order*/ 188 int tp_pos; 189 /** Tile part number*/ 190 int tp_num; 191 /** Current tile part number*/ 192 int cur_tp_num; 193 /** Total number of tileparts of the current tile*/ 194 int cur_totnum_tp; 195 /** Current Packet iterator number */ 196 int cur_pino; 197 /** codec context */ 198 opj_common_ptr cinfo; 199 200 /** info on each image tile */ 201 opj_tcd_image_t *tcd_image; 202 /** image */ 203 opj_image_t *image; 204 /** coding parameters */ 205 opj_cp_t *cp; 206 /** pointer to the current encoded/decoded tile */ 207 opj_tcd_tile_t *tcd_tile; 208 /** coding/decoding parameters common to all tiles */ 209 opj_tcp_t *tcp; 210 /** current encoded/decoded tile */ 211 int tcd_tileno; 212 /** Time taken to encode a tile*/ 213 double encoding_time; 214 } opj_tcd_t; 215 216 /** @name Exported functions */ 217 /*@{*/ 218 /* ----------------------------------------------------------------------- */ 219 220 /** 221 Dump the content of a tcd structure 222 */ 223 void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img); 224 /** 225 Create a new TCD handle 226 @param cinfo Codec context info 227 @return Returns a new TCD handle if successful returns NULL otherwise 228 */ 229 opj_tcd_t* tcd_create(opj_common_ptr cinfo); 230 /** 231 Destroy a previously created TCD handle 232 @param tcd TCD handle to destroy 233 */ 234 void tcd_destroy(opj_tcd_t *tcd); 235 /** 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 241 */ 242 void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, 243 int curtileno); 244 /** 245 Free the memory allocated for encoding 246 @param tcd TCD handle 247 */ 248 void tcd_free_encode(opj_tcd_t *tcd); 249 /** 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 255 */ 256 void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, 257 int curtileno); 258 /** 259 Initialize the tile decoder 260 @param tcd TCD handle 261 @param image Raw image 262 @param cp Coding parameters 263 */ 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); 272 /** 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 279 @return 280 */ 281 int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, 282 opj_codestream_info_t *cstr_info); 283 /** 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 290 */ 291 opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, 292 int tileno, opj_codestream_info_t *cstr_info); 293 /** 294 Free the memory allocated for decoding 295 @param tcd TCD handle 296 */ 297 void tcd_free_decode(opj_tcd_t *tcd); 298 void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno); 299 300 /* ----------------------------------------------------------------------- */ 301 /*@}*/ 302 303 /*@}*/ 304 305 #endif /* __TCD_H */ 306