tcd.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
  3. * Copyright (c) 2002-2007, Professor Benoit Macq
  4. * Copyright (c) 2001-2003, David Janssens
  5. * Copyright (c) 2002-2003, Yannick Verschueren
  6. * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
  7. * Copyright (c) 2005, Herve Drolon, FreeImage Team
  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. The functions in TCD.C have for goal to encode or decode each tile independently from
  37. each other. The functions in TCD.C are used by some function in J2K.C.
  38. */
  39. /** @defgroup TCD TCD - Implementation of a tile coder/decoder */
  40. /*@{*/
  41. /**
  42. FIXME: documentation
  43. */
  44. typedef struct opj_tcd_seg {
  45. unsigned char** data;
  46. int dataindex;
  47. int numpasses;
  48. int len;
  49. int maxpasses;
  50. int numnewpasses;
  51. int newlen;
  52. } opj_tcd_seg_t;
  53. /**
  54. FIXME: documentation
  55. */
  56. typedef struct opj_tcd_pass {
  57. int rate;
  58. double distortiondec;
  59. int term, len;
  60. } opj_tcd_pass_t;
  61. /**
  62. FIXME: documentation
  63. */
  64. typedef struct opj_tcd_layer {
  65. int numpasses; /* Number of passes in the layer */
  66. int len; /* len of information */
  67. double disto; /* add for index (Cfr. Marcela) */
  68. unsigned char *data; /* data */
  69. } opj_tcd_layer_t;
  70. /**
  71. FIXME: documentation
  72. */
  73. typedef struct opj_tcd_cblk_enc {
  74. unsigned char* data; /* Data */
  75. opj_tcd_layer_t* layers; /* layer information */
  76. opj_tcd_pass_t* passes; /* information about the passes */
  77. int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
  78. int numbps;
  79. int numlenbits;
  80. int numpasses; /* number of pass already done for the code-blocks */
  81. int numpassesinlayers; /* number of passes in the layer */
  82. int totalpasses; /* total number of passes */
  83. } opj_tcd_cblk_enc_t;
  84. typedef struct opj_tcd_cblk_dec {
  85. unsigned char* data; /* Data */
  86. opj_tcd_seg_t* segs; /* segments informations */
  87. int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
  88. int numbps;
  89. int numlenbits;
  90. int len; /* length */
  91. int numnewpasses; /* number of pass added to the code-blocks */
  92. int numsegs; /* number of segments */
  93. } opj_tcd_cblk_dec_t;
  94. /**
  95. FIXME: documentation
  96. */
  97. typedef struct opj_tcd_precinct {
  98. int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
  99. int cw, ch; /* number of precinct in width and heigth */
  100. union{ /* code-blocks informations */
  101. opj_tcd_cblk_enc_t* enc;
  102. opj_tcd_cblk_dec_t* dec;
  103. } cblks;
  104. opj_tgt_tree_t *incltree; /* inclusion tree */
  105. opj_tgt_tree_t *imsbtree; /* IMSB tree */
  106. } opj_tcd_precinct_t;
  107. /**
  108. FIXME: documentation
  109. */
  110. typedef struct opj_tcd_band {
  111. int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
  112. int bandno;
  113. opj_tcd_precinct_t *precincts; /* precinct information */
  114. int numbps;
  115. float stepsize;
  116. } opj_tcd_band_t;
  117. /**
  118. FIXME: documentation
  119. */
  120. typedef struct opj_tcd_resolution {
  121. int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
  122. int pw, ph;
  123. int numbands; /* number sub-band for the resolution level */
  124. opj_tcd_band_t bands[3]; /* subband information */
  125. } opj_tcd_resolution_t;
  126. /**
  127. FIXME: documentation
  128. */
  129. typedef struct opj_tcd_tilecomp {
  130. int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
  131. int numresolutions; /* number of resolutions level */
  132. opj_tcd_resolution_t *resolutions; /* resolutions information */
  133. int *data; /* data of the component */
  134. int numpix; /* add fixed_quality */
  135. } opj_tcd_tilecomp_t;
  136. /**
  137. FIXME: documentation
  138. */
  139. typedef struct opj_tcd_tile {
  140. int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
  141. int numcomps; /* number of components in tile */
  142. opj_tcd_tilecomp_t *comps; /* Components information */
  143. int numpix; /* add fixed_quality */
  144. double distotile; /* add fixed_quality */
  145. double distolayer[100]; /* add fixed_quality */
  146. /** packet number */
  147. int packno;
  148. } opj_tcd_tile_t;
  149. /**
  150. FIXME: documentation
  151. */
  152. typedef struct opj_tcd_image {
  153. int tw, th; /* number of tiles in width and heigth */
  154. opj_tcd_tile_t *tiles; /* Tiles information */
  155. } opj_tcd_image_t;
  156. /**
  157. Tile coder/decoder
  158. */
  159. typedef struct opj_tcd {
  160. /** Position of the tilepart flag in Progression order*/
  161. int tp_pos;
  162. /** Tile part number*/
  163. int tp_num;
  164. /** Current tile part number*/
  165. int cur_tp_num;
  166. /** Total number of tileparts of the current tile*/
  167. int cur_totnum_tp;
  168. /** Current Packet iterator number */
  169. int cur_pino;
  170. /** codec context */
  171. opj_common_ptr cinfo;
  172. /** info on each image tile */
  173. opj_tcd_image_t *tcd_image;
  174. /** image */
  175. opj_image_t *image;
  176. /** coding parameters */
  177. opj_cp_t *cp;
  178. /** pointer to the current encoded/decoded tile */
  179. opj_tcd_tile_t *tcd_tile;
  180. /** coding/decoding parameters common to all tiles */
  181. opj_tcp_t *tcp;
  182. /** current encoded/decoded tile */
  183. int tcd_tileno;
  184. /** Time taken to encode a tile*/
  185. double encoding_time;
  186. } opj_tcd_t;
  187. /** @name Exported functions */
  188. /*@{*/
  189. /* ----------------------------------------------------------------------- */
  190. /**
  191. Dump the content of a tcd structure
  192. */
  193. void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);
  194. /**
  195. Create a new TCD handle
  196. @param cinfo Codec context info
  197. @return Returns a new TCD handle if successful returns NULL otherwise
  198. */
  199. opj_tcd_t* tcd_create(opj_common_ptr cinfo);
  200. /**
  201. Destroy a previously created TCD handle
  202. @param tcd TCD handle to destroy
  203. */
  204. void tcd_destroy(opj_tcd_t *tcd);
  205. /**
  206. Initialize the tile coder (allocate the memory)
  207. @param tcd TCD handle
  208. @param image Raw image
  209. @param cp Coding parameters
  210. @param curtileno Number that identifies the tile that will be encoded
  211. */
  212. void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
  213. /**
  214. Free the memory allocated for encoding
  215. @param tcd TCD handle
  216. */
  217. void tcd_free_encode(opj_tcd_t *tcd);
  218. /**
  219. Initialize the tile coder (reuses the memory allocated by tcd_malloc_encode)
  220. @param tcd TCD handle
  221. @param image Raw image
  222. @param cp Coding parameters
  223. @param curtileno Number that identifies the tile that will be encoded
  224. */
  225. void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int curtileno);
  226. /**
  227. Initialize the tile decoder
  228. @param tcd TCD handle
  229. @param image Raw image
  230. @param cp Coding parameters
  231. */
  232. void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
  233. 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);
  234. void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
  235. void tcd_rateallocate_fixed(opj_tcd_t *tcd);
  236. void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
  237. opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
  238. /**
  239. Encode a tile from the raw image into a buffer
  240. @param tcd TCD handle
  241. @param tileno Number that identifies one of the tiles to be encoded
  242. @param dest Destination buffer
  243. @param len Length of destination buffer
  244. @param cstr_info Codestream information structure
  245. @return
  246. */
  247. int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
  248. /**
  249. Decode a tile from a buffer into a raw image
  250. @param tcd TCD handle
  251. @param src Source buffer
  252. @param len Length of source buffer
  253. @param tileno Number that identifies one of the tiles to be decoded
  254. @param cstr_info Codestream information structure
  255. */
  256. opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
  257. /**
  258. Free the memory allocated for decoding
  259. @param tcd TCD handle
  260. */
  261. void tcd_free_decode(opj_tcd_t *tcd);
  262. void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
  263. /* ----------------------------------------------------------------------- */
  264. /*@}*/
  265. /*@}*/
  266. #endif /* __TCD_H */