jpc_t2cod.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 1999-2000 Image Power, Inc. and the University of
  3. * British Columbia.
  4. * Copyright (c) 2001-2002 Michael David Adams.
  5. * All rights reserved.
  6. */
  7. /* __START_OF_JASPER_LICENSE__
  8. *
  9. * JasPer License Version 2.0
  10. *
  11. * Copyright (c) 2001-2006 Michael David Adams
  12. * Copyright (c) 1999-2000 Image Power, Inc.
  13. * Copyright (c) 1999-2000 The University of British Columbia
  14. *
  15. * All rights reserved.
  16. *
  17. * Permission is hereby granted, free of charge, to any person (the
  18. * "User") obtaining a copy of this software and associated documentation
  19. * files (the "Software"), to deal in the Software without restriction,
  20. * including without limitation the rights to use, copy, modify, merge,
  21. * publish, distribute, and/or sell copies of the Software, and to permit
  22. * persons to whom the Software is furnished to do so, subject to the
  23. * following conditions:
  24. *
  25. * 1. The above copyright notices and this permission notice (which
  26. * includes the disclaimer below) shall be included in all copies or
  27. * substantial portions of the Software.
  28. *
  29. * 2. The name of a copyright holder shall not be used to endorse or
  30. * promote products derived from the Software without specific prior
  31. * written permission.
  32. *
  33. * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
  34. * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  35. * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
  36. * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  37. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  38. * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
  39. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
  40. * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
  41. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  42. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  43. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
  44. * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
  45. * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
  46. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
  47. * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
  48. * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
  49. * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
  50. * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
  51. * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
  52. * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
  53. * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
  54. * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
  55. * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
  56. * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
  57. * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
  58. * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
  59. *
  60. * __END_OF_JASPER_LICENSE__
  61. */
  62. /*
  63. * Tier-2 Coding Library
  64. *
  65. * $Id: jpc_t2cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. #ifndef JPC_T2COD_H
  68. #define JPC_T2COD_H
  69. /******************************************************************************\
  70. * Includes.
  71. \******************************************************************************/
  72. #include "jpc_cs.h"
  73. /******************************************************************************\
  74. * Types.
  75. \******************************************************************************/
  76. /* Progression change list. */
  77. typedef struct {
  78. /* The number of progression changes. */
  79. int numpchgs;
  80. /* The maximum number of progression changes that can be accomodated
  81. without growing the progression change array. */
  82. int maxpchgs;
  83. /* The progression changes. */
  84. jpc_pchg_t **pchgs;
  85. } jpc_pchglist_t;
  86. /* Packet iterator per-resolution-level information. */
  87. typedef struct {
  88. /* The number of precincts. */
  89. int numprcs;
  90. /* The last layer processed for each precinct. */
  91. int *prclyrnos;
  92. /* The precinct width exponent. */
  93. int prcwidthexpn;
  94. /* The precinct height exponent. */
  95. int prcheightexpn;
  96. /* The number of precincts spanning the resolution level in the horizontal
  97. direction. */
  98. int numhprcs;
  99. } jpc_pirlvl_t;
  100. /* Packet iterator per-component information. */
  101. typedef struct {
  102. /* The number of resolution levels. */
  103. int numrlvls;
  104. /* The per-resolution-level information. */
  105. jpc_pirlvl_t *pirlvls;
  106. /* The horizontal sampling period. */
  107. int hsamp;
  108. /* The vertical sampling period. */
  109. int vsamp;
  110. } jpc_picomp_t;
  111. /* Packet iterator class. */
  112. typedef struct {
  113. /* The number of layers. */
  114. int numlyrs;
  115. /* The number of resolution levels. */
  116. int maxrlvls;
  117. /* The number of components. */
  118. int numcomps;
  119. /* The per-component information. */
  120. jpc_picomp_t *picomps;
  121. /* The current component. */
  122. jpc_picomp_t *picomp;
  123. /* The current resolution level. */
  124. jpc_pirlvl_t *pirlvl;
  125. /* The number of the current component. */
  126. int compno;
  127. /* The number of the current resolution level. */
  128. int rlvlno;
  129. /* The number of the current precinct. */
  130. int prcno;
  131. /* The number of the current layer. */
  132. int lyrno;
  133. /* The x-coordinate of the current position. */
  134. int x;
  135. /* The y-coordinate of the current position. */
  136. int y;
  137. /* The horizontal step size. */
  138. int xstep;
  139. /* The vertical step size. */
  140. int ystep;
  141. /* The x-coordinate of the top-left corner of the tile on the reference
  142. grid. */
  143. int xstart;
  144. /* The y-coordinate of the top-left corner of the tile on the reference
  145. grid. */
  146. int ystart;
  147. /* The x-coordinate of the bottom-right corner of the tile on the
  148. reference grid (plus one). */
  149. int xend;
  150. /* The y-coordinate of the bottom-right corner of the tile on the
  151. reference grid (plus one). */
  152. int yend;
  153. /* The current progression change. */
  154. jpc_pchg_t *pchg;
  155. /* The progression change list. */
  156. jpc_pchglist_t *pchglist;
  157. /* The progression to use in the absense of explicit specification. */
  158. jpc_pchg_t defaultpchg;
  159. /* The current progression change number. */
  160. int pchgno;
  161. /* Is this the first time in the current progression volume? */
  162. bool prgvolfirst;
  163. /* Is the current iterator value valid? */
  164. bool valid;
  165. /* The current packet number. */
  166. int pktno;
  167. } jpc_pi_t;
  168. /******************************************************************************\
  169. * Functions/macros for packet iterators.
  170. \******************************************************************************/
  171. /* Create a packet iterator. */
  172. jpc_pi_t *jpc_pi_create0(void);
  173. /* Destroy a packet iterator. */
  174. void jpc_pi_destroy(jpc_pi_t *pi);
  175. /* Add a progression change to a packet iterator. */
  176. int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg);
  177. /* Prepare a packet iterator for iteration. */
  178. int jpc_pi_init(jpc_pi_t *pi);
  179. /* Set the iterator to the first packet. */
  180. int jpc_pi_begin(jpc_pi_t *pi);
  181. /* Proceed to the next packet in sequence. */
  182. int jpc_pi_next(jpc_pi_t *pi);
  183. /* Get the index of the current packet. */
  184. #define jpc_pi_getind(pi) ((pi)->pktno)
  185. /* Get the component number of the current packet. */
  186. #define jpc_pi_cmptno(pi) (assert(pi->valid), (pi)->compno)
  187. /* Get the resolution level of the current packet. */
  188. #define jpc_pi_rlvlno(pi) (assert(pi->valid), (pi)->rlvlno)
  189. /* Get the layer number of the current packet. */
  190. #define jpc_pi_lyrno(pi) (assert(pi->valid), (pi)->lyrno)
  191. /* Get the precinct number of the current packet. */
  192. #define jpc_pi_prcno(pi) (assert(pi->valid), (pi)->prcno)
  193. /* Get the progression order for the current packet. */
  194. #define jpc_pi_prg(pi) (assert(pi->valid), (pi)->pchg->prgord)
  195. /******************************************************************************\
  196. * Functions/macros for progression change lists.
  197. \******************************************************************************/
  198. /* Create a progression change list. */
  199. jpc_pchglist_t *jpc_pchglist_create(void);
  200. /* Destroy a progression change list. */
  201. void jpc_pchglist_destroy(jpc_pchglist_t *pchglist);
  202. /* Insert a new element into a progression change list. */
  203. int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg);
  204. /* Remove an element from a progression change list. */
  205. jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno);
  206. /* Get an element from a progression change list. */
  207. jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno);
  208. /* Copy a progression change list. */
  209. jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist);
  210. /* Get the number of elements in a progression change list. */
  211. int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist);
  212. /******************************************************************************\
  213. * Functions/macros for progression changes.
  214. \******************************************************************************/
  215. /* Destroy a progression change. */
  216. void jpc_pchg_destroy(jpc_pchg_t *pchg);
  217. /* Copy a progression change. */
  218. jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg);
  219. #endif