tgt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 __TGT_H
  32. #define __TGT_H
  33. /**
  34. @file tgt.h
  35. @brief Implementation of a tag-tree coder (TGT)
  36. The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C
  37. are used by some function in T2.C.
  38. */
  39. /** @defgroup TGT TGT - Implementation of a tag-tree coder */
  40. /*@{*/
  41. /**
  42. Tag node
  43. */
  44. typedef struct opj_tgt_node {
  45. struct opj_tgt_node *parent;
  46. int value;
  47. int low;
  48. int known;
  49. } opj_tgt_node_t;
  50. /**
  51. Tag tree
  52. */
  53. typedef struct opj_tgt_tree {
  54. int numleafsh;
  55. int numleafsv;
  56. int numnodes;
  57. opj_tgt_node_t *nodes;
  58. } opj_tgt_tree_t;
  59. /** @name Exported functions */
  60. /*@{*/
  61. /* ----------------------------------------------------------------------- */
  62. /**
  63. Create a tag-tree
  64. @param numleafsh Width of the array of leafs of the tree
  65. @param numleafsv Height of the array of leafs of the tree
  66. @return Returns a new tag-tree if successful, returns NULL otherwise
  67. */
  68. opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
  69. /**
  70. Destroy a tag-tree, liberating memory
  71. @param tree Tag-tree to destroy
  72. */
  73. void tgt_destroy(opj_tgt_tree_t *tree);
  74. /**
  75. Reset a tag-tree (set all leaves to 0)
  76. @param tree Tag-tree to reset
  77. */
  78. void tgt_reset(opj_tgt_tree_t *tree);
  79. /**
  80. Set the value of a leaf of a tag-tree
  81. @param tree Tag-tree to modify
  82. @param leafno Number that identifies the leaf to modify
  83. @param value New value of the leaf
  84. */
  85. void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
  86. /**
  87. Encode the value of a leaf of the tag-tree up to a given threshold
  88. @param bio Pointer to a BIO handle
  89. @param tree Tag-tree to modify
  90. @param leafno Number that identifies the leaf to encode
  91. @param threshold Threshold to use when encoding value of the leaf
  92. */
  93. void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
  94. /**
  95. Decode the value of a leaf of the tag-tree up to a given threshold
  96. @param bio Pointer to a BIO handle
  97. @param tree Tag-tree to decode
  98. @param leafno Number that identifies the leaf to decode
  99. @param threshold Threshold to use when decoding value of the leaf
  100. @return Returns 1 if the node's value < threshold, returns 0 otherwise
  101. */
  102. int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
  103. /* ----------------------------------------------------------------------- */
  104. /*@}*/
  105. /*@}*/
  106. #endif /* __TGT_H */