jpc_mqcod.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. * MQ Arithmetic Coder
  64. *
  65. * $Id: jpc_mqcod.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. /******************************************************************************\
  68. * Includes.
  69. \******************************************************************************/
  70. #include "jasper/jas_malloc.h"
  71. #include "jpc_mqcod.h"
  72. /******************************************************************************\
  73. * Data.
  74. \******************************************************************************/
  75. /* MQ coder per-state information. */
  76. jpc_mqstate_t jpc_mqstates[47 * 2] = {
  77. {0x5601, 0, &jpc_mqstates[ 2], &jpc_mqstates[ 3]},
  78. {0x5601, 1, &jpc_mqstates[ 3], &jpc_mqstates[ 2]},
  79. {0x3401, 0, &jpc_mqstates[ 4], &jpc_mqstates[12]},
  80. {0x3401, 1, &jpc_mqstates[ 5], &jpc_mqstates[13]},
  81. {0x1801, 0, &jpc_mqstates[ 6], &jpc_mqstates[18]},
  82. {0x1801, 1, &jpc_mqstates[ 7], &jpc_mqstates[19]},
  83. {0x0ac1, 0, &jpc_mqstates[ 8], &jpc_mqstates[24]},
  84. {0x0ac1, 1, &jpc_mqstates[ 9], &jpc_mqstates[25]},
  85. {0x0521, 0, &jpc_mqstates[10], &jpc_mqstates[58]},
  86. {0x0521, 1, &jpc_mqstates[11], &jpc_mqstates[59]},
  87. {0x0221, 0, &jpc_mqstates[76], &jpc_mqstates[66]},
  88. {0x0221, 1, &jpc_mqstates[77], &jpc_mqstates[67]},
  89. {0x5601, 0, &jpc_mqstates[14], &jpc_mqstates[13]},
  90. {0x5601, 1, &jpc_mqstates[15], &jpc_mqstates[12]},
  91. {0x5401, 0, &jpc_mqstates[16], &jpc_mqstates[28]},
  92. {0x5401, 1, &jpc_mqstates[17], &jpc_mqstates[29]},
  93. {0x4801, 0, &jpc_mqstates[18], &jpc_mqstates[28]},
  94. {0x4801, 1, &jpc_mqstates[19], &jpc_mqstates[29]},
  95. {0x3801, 0, &jpc_mqstates[20], &jpc_mqstates[28]},
  96. {0x3801, 1, &jpc_mqstates[21], &jpc_mqstates[29]},
  97. {0x3001, 0, &jpc_mqstates[22], &jpc_mqstates[34]},
  98. {0x3001, 1, &jpc_mqstates[23], &jpc_mqstates[35]},
  99. {0x2401, 0, &jpc_mqstates[24], &jpc_mqstates[36]},
  100. {0x2401, 1, &jpc_mqstates[25], &jpc_mqstates[37]},
  101. {0x1c01, 0, &jpc_mqstates[26], &jpc_mqstates[40]},
  102. {0x1c01, 1, &jpc_mqstates[27], &jpc_mqstates[41]},
  103. {0x1601, 0, &jpc_mqstates[58], &jpc_mqstates[42]},
  104. {0x1601, 1, &jpc_mqstates[59], &jpc_mqstates[43]},
  105. {0x5601, 0, &jpc_mqstates[30], &jpc_mqstates[29]},
  106. {0x5601, 1, &jpc_mqstates[31], &jpc_mqstates[28]},
  107. {0x5401, 0, &jpc_mqstates[32], &jpc_mqstates[28]},
  108. {0x5401, 1, &jpc_mqstates[33], &jpc_mqstates[29]},
  109. {0x5101, 0, &jpc_mqstates[34], &jpc_mqstates[30]},
  110. {0x5101, 1, &jpc_mqstates[35], &jpc_mqstates[31]},
  111. {0x4801, 0, &jpc_mqstates[36], &jpc_mqstates[32]},
  112. {0x4801, 1, &jpc_mqstates[37], &jpc_mqstates[33]},
  113. {0x3801, 0, &jpc_mqstates[38], &jpc_mqstates[34]},
  114. {0x3801, 1, &jpc_mqstates[39], &jpc_mqstates[35]},
  115. {0x3401, 0, &jpc_mqstates[40], &jpc_mqstates[36]},
  116. {0x3401, 1, &jpc_mqstates[41], &jpc_mqstates[37]},
  117. {0x3001, 0, &jpc_mqstates[42], &jpc_mqstates[38]},
  118. {0x3001, 1, &jpc_mqstates[43], &jpc_mqstates[39]},
  119. {0x2801, 0, &jpc_mqstates[44], &jpc_mqstates[38]},
  120. {0x2801, 1, &jpc_mqstates[45], &jpc_mqstates[39]},
  121. {0x2401, 0, &jpc_mqstates[46], &jpc_mqstates[40]},
  122. {0x2401, 1, &jpc_mqstates[47], &jpc_mqstates[41]},
  123. {0x2201, 0, &jpc_mqstates[48], &jpc_mqstates[42]},
  124. {0x2201, 1, &jpc_mqstates[49], &jpc_mqstates[43]},
  125. {0x1c01, 0, &jpc_mqstates[50], &jpc_mqstates[44]},
  126. {0x1c01, 1, &jpc_mqstates[51], &jpc_mqstates[45]},
  127. {0x1801, 0, &jpc_mqstates[52], &jpc_mqstates[46]},
  128. {0x1801, 1, &jpc_mqstates[53], &jpc_mqstates[47]},
  129. {0x1601, 0, &jpc_mqstates[54], &jpc_mqstates[48]},
  130. {0x1601, 1, &jpc_mqstates[55], &jpc_mqstates[49]},
  131. {0x1401, 0, &jpc_mqstates[56], &jpc_mqstates[50]},
  132. {0x1401, 1, &jpc_mqstates[57], &jpc_mqstates[51]},
  133. {0x1201, 0, &jpc_mqstates[58], &jpc_mqstates[52]},
  134. {0x1201, 1, &jpc_mqstates[59], &jpc_mqstates[53]},
  135. {0x1101, 0, &jpc_mqstates[60], &jpc_mqstates[54]},
  136. {0x1101, 1, &jpc_mqstates[61], &jpc_mqstates[55]},
  137. {0x0ac1, 0, &jpc_mqstates[62], &jpc_mqstates[56]},
  138. {0x0ac1, 1, &jpc_mqstates[63], &jpc_mqstates[57]},
  139. {0x09c1, 0, &jpc_mqstates[64], &jpc_mqstates[58]},
  140. {0x09c1, 1, &jpc_mqstates[65], &jpc_mqstates[59]},
  141. {0x08a1, 0, &jpc_mqstates[66], &jpc_mqstates[60]},
  142. {0x08a1, 1, &jpc_mqstates[67], &jpc_mqstates[61]},
  143. {0x0521, 0, &jpc_mqstates[68], &jpc_mqstates[62]},
  144. {0x0521, 1, &jpc_mqstates[69], &jpc_mqstates[63]},
  145. {0x0441, 0, &jpc_mqstates[70], &jpc_mqstates[64]},
  146. {0x0441, 1, &jpc_mqstates[71], &jpc_mqstates[65]},
  147. {0x02a1, 0, &jpc_mqstates[72], &jpc_mqstates[66]},
  148. {0x02a1, 1, &jpc_mqstates[73], &jpc_mqstates[67]},
  149. {0x0221, 0, &jpc_mqstates[74], &jpc_mqstates[68]},
  150. {0x0221, 1, &jpc_mqstates[75], &jpc_mqstates[69]},
  151. {0x0141, 0, &jpc_mqstates[76], &jpc_mqstates[70]},
  152. {0x0141, 1, &jpc_mqstates[77], &jpc_mqstates[71]},
  153. {0x0111, 0, &jpc_mqstates[78], &jpc_mqstates[72]},
  154. {0x0111, 1, &jpc_mqstates[79], &jpc_mqstates[73]},
  155. {0x0085, 0, &jpc_mqstates[80], &jpc_mqstates[74]},
  156. {0x0085, 1, &jpc_mqstates[81], &jpc_mqstates[75]},
  157. {0x0049, 0, &jpc_mqstates[82], &jpc_mqstates[76]},
  158. {0x0049, 1, &jpc_mqstates[83], &jpc_mqstates[77]},
  159. {0x0025, 0, &jpc_mqstates[84], &jpc_mqstates[78]},
  160. {0x0025, 1, &jpc_mqstates[85], &jpc_mqstates[79]},
  161. {0x0015, 0, &jpc_mqstates[86], &jpc_mqstates[80]},
  162. {0x0015, 1, &jpc_mqstates[87], &jpc_mqstates[81]},
  163. {0x0009, 0, &jpc_mqstates[88], &jpc_mqstates[82]},
  164. {0x0009, 1, &jpc_mqstates[89], &jpc_mqstates[83]},
  165. {0x0005, 0, &jpc_mqstates[90], &jpc_mqstates[84]},
  166. {0x0005, 1, &jpc_mqstates[91], &jpc_mqstates[85]},
  167. {0x0001, 0, &jpc_mqstates[90], &jpc_mqstates[86]},
  168. {0x0001, 1, &jpc_mqstates[91], &jpc_mqstates[87]},
  169. {0x5601, 0, &jpc_mqstates[92], &jpc_mqstates[92]},
  170. {0x5601, 1, &jpc_mqstates[93], &jpc_mqstates[93]},
  171. };