]> Creatis software - gdcm.git/blob - src/gdcmjasper/src/libjasper/jpc/jpc_mqcod.c
ENH: Ok since OJ warnings are not going to be fixed anytime soon remove them
[gdcm.git] / src / gdcmjasper / src / libjasper / jpc / jpc_mqcod.c
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
8 /* __START_OF_JASPER_LICENSE__
9  * 
10  * JasPer License Version 2.0
11  * 
12  * Copyright (c) 1999-2000 Image Power, Inc.
13  * Copyright (c) 1999-2000 The University of British Columbia
14  * Copyright (c) 2001-2003 Michael David Adams
15  * 
16  * All rights reserved.
17  * 
18  * Permission is hereby granted, free of charge, to any person (the
19  * "User") obtaining a copy of this software and associated documentation
20  * files (the "Software"), to deal in the Software without restriction,
21  * including without limitation the rights to use, copy, modify, merge,
22  * publish, distribute, and/or sell copies of the Software, and to permit
23  * persons to whom the Software is furnished to do so, subject to the
24  * following conditions:
25  * 
26  * 1.  The above copyright notices and this permission notice (which
27  * includes the disclaimer below) shall be included in all copies or
28  * substantial portions of the Software.
29  * 
30  * 2.  The name of a copyright holder shall not be used to endorse or
31  * promote products derived from the Software without specific prior
32  * written permission.
33  * 
34  * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35  * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36  * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37  * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39  * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
40  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
45  * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46  * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47  * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48  * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49  * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
50  * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51  * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
52  * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53  * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54  * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55  * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56  * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57  * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58  * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59  * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
60  * 
61  * __END_OF_JASPER_LICENSE__
62  */
63
64 /*
65  * MQ Arithmetic Coder
66  *
67  * $Id: jpc_mqcod.c,v 1.1 2005/05/22 18:33:04 malaterre Exp $
68  */
69
70 /******************************************************************************\
71 * Includes.
72 \******************************************************************************/
73
74 #include "jasper/jas_malloc.h"
75
76 #include "jpc_mqcod.h"
77
78 /******************************************************************************\
79 * Data.
80 \******************************************************************************/
81
82 /* MQ coder per-state information. */
83
84 jpc_mqstate_t jpc_mqstates[47 * 2] = {
85   {0x5601, 0, &jpc_mqstates[ 2], &jpc_mqstates[ 3]},
86   {0x5601, 1, &jpc_mqstates[ 3], &jpc_mqstates[ 2]},
87   {0x3401, 0, &jpc_mqstates[ 4], &jpc_mqstates[12]},
88   {0x3401, 1, &jpc_mqstates[ 5], &jpc_mqstates[13]},
89   {0x1801, 0, &jpc_mqstates[ 6], &jpc_mqstates[18]},
90   {0x1801, 1, &jpc_mqstates[ 7], &jpc_mqstates[19]},
91   {0x0ac1, 0, &jpc_mqstates[ 8], &jpc_mqstates[24]},
92   {0x0ac1, 1, &jpc_mqstates[ 9], &jpc_mqstates[25]},
93   {0x0521, 0, &jpc_mqstates[10], &jpc_mqstates[58]},
94   {0x0521, 1, &jpc_mqstates[11], &jpc_mqstates[59]},
95   {0x0221, 0, &jpc_mqstates[76], &jpc_mqstates[66]},
96   {0x0221, 1, &jpc_mqstates[77], &jpc_mqstates[67]},
97   {0x5601, 0, &jpc_mqstates[14], &jpc_mqstates[13]},
98   {0x5601, 1, &jpc_mqstates[15], &jpc_mqstates[12]},
99   {0x5401, 0, &jpc_mqstates[16], &jpc_mqstates[28]},
100   {0x5401, 1, &jpc_mqstates[17], &jpc_mqstates[29]},
101   {0x4801, 0, &jpc_mqstates[18], &jpc_mqstates[28]},
102   {0x4801, 1, &jpc_mqstates[19], &jpc_mqstates[29]},
103   {0x3801, 0, &jpc_mqstates[20], &jpc_mqstates[28]},
104   {0x3801, 1, &jpc_mqstates[21], &jpc_mqstates[29]},
105   {0x3001, 0, &jpc_mqstates[22], &jpc_mqstates[34]},
106   {0x3001, 1, &jpc_mqstates[23], &jpc_mqstates[35]},
107   {0x2401, 0, &jpc_mqstates[24], &jpc_mqstates[36]},
108   {0x2401, 1, &jpc_mqstates[25], &jpc_mqstates[37]},
109   {0x1c01, 0, &jpc_mqstates[26], &jpc_mqstates[40]},
110   {0x1c01, 1, &jpc_mqstates[27], &jpc_mqstates[41]},
111   {0x1601, 0, &jpc_mqstates[58], &jpc_mqstates[42]},
112   {0x1601, 1, &jpc_mqstates[59], &jpc_mqstates[43]},
113   {0x5601, 0, &jpc_mqstates[30], &jpc_mqstates[29]},
114   {0x5601, 1, &jpc_mqstates[31], &jpc_mqstates[28]},
115   {0x5401, 0, &jpc_mqstates[32], &jpc_mqstates[28]},
116   {0x5401, 1, &jpc_mqstates[33], &jpc_mqstates[29]},
117   {0x5101, 0, &jpc_mqstates[34], &jpc_mqstates[30]},
118   {0x5101, 1, &jpc_mqstates[35], &jpc_mqstates[31]},
119   {0x4801, 0, &jpc_mqstates[36], &jpc_mqstates[32]},
120   {0x4801, 1, &jpc_mqstates[37], &jpc_mqstates[33]},
121   {0x3801, 0, &jpc_mqstates[38], &jpc_mqstates[34]},
122   {0x3801, 1, &jpc_mqstates[39], &jpc_mqstates[35]},
123   {0x3401, 0, &jpc_mqstates[40], &jpc_mqstates[36]},
124   {0x3401, 1, &jpc_mqstates[41], &jpc_mqstates[37]},
125   {0x3001, 0, &jpc_mqstates[42], &jpc_mqstates[38]},
126   {0x3001, 1, &jpc_mqstates[43], &jpc_mqstates[39]},
127   {0x2801, 0, &jpc_mqstates[44], &jpc_mqstates[38]},
128   {0x2801, 1, &jpc_mqstates[45], &jpc_mqstates[39]},
129   {0x2401, 0, &jpc_mqstates[46], &jpc_mqstates[40]},
130   {0x2401, 1, &jpc_mqstates[47], &jpc_mqstates[41]},
131   {0x2201, 0, &jpc_mqstates[48], &jpc_mqstates[42]},
132   {0x2201, 1, &jpc_mqstates[49], &jpc_mqstates[43]},
133   {0x1c01, 0, &jpc_mqstates[50], &jpc_mqstates[44]},
134   {0x1c01, 1, &jpc_mqstates[51], &jpc_mqstates[45]},
135   {0x1801, 0, &jpc_mqstates[52], &jpc_mqstates[46]},
136   {0x1801, 1, &jpc_mqstates[53], &jpc_mqstates[47]},
137   {0x1601, 0, &jpc_mqstates[54], &jpc_mqstates[48]},
138   {0x1601, 1, &jpc_mqstates[55], &jpc_mqstates[49]},
139   {0x1401, 0, &jpc_mqstates[56], &jpc_mqstates[50]},
140   {0x1401, 1, &jpc_mqstates[57], &jpc_mqstates[51]},
141   {0x1201, 0, &jpc_mqstates[58], &jpc_mqstates[52]},
142   {0x1201, 1, &jpc_mqstates[59], &jpc_mqstates[53]},
143   {0x1101, 0, &jpc_mqstates[60], &jpc_mqstates[54]},
144   {0x1101, 1, &jpc_mqstates[61], &jpc_mqstates[55]},
145   {0x0ac1, 0, &jpc_mqstates[62], &jpc_mqstates[56]},
146   {0x0ac1, 1, &jpc_mqstates[63], &jpc_mqstates[57]},
147   {0x09c1, 0, &jpc_mqstates[64], &jpc_mqstates[58]},
148   {0x09c1, 1, &jpc_mqstates[65], &jpc_mqstates[59]},
149   {0x08a1, 0, &jpc_mqstates[66], &jpc_mqstates[60]},
150   {0x08a1, 1, &jpc_mqstates[67], &jpc_mqstates[61]},
151   {0x0521, 0, &jpc_mqstates[68], &jpc_mqstates[62]},
152   {0x0521, 1, &jpc_mqstates[69], &jpc_mqstates[63]},
153   {0x0441, 0, &jpc_mqstates[70], &jpc_mqstates[64]},
154   {0x0441, 1, &jpc_mqstates[71], &jpc_mqstates[65]},
155   {0x02a1, 0, &jpc_mqstates[72], &jpc_mqstates[66]},
156   {0x02a1, 1, &jpc_mqstates[73], &jpc_mqstates[67]},
157   {0x0221, 0, &jpc_mqstates[74], &jpc_mqstates[68]},
158   {0x0221, 1, &jpc_mqstates[75], &jpc_mqstates[69]},
159   {0x0141, 0, &jpc_mqstates[76], &jpc_mqstates[70]},
160   {0x0141, 1, &jpc_mqstates[77], &jpc_mqstates[71]},
161   {0x0111, 0, &jpc_mqstates[78], &jpc_mqstates[72]},
162   {0x0111, 1, &jpc_mqstates[79], &jpc_mqstates[73]},
163   {0x0085, 0, &jpc_mqstates[80], &jpc_mqstates[74]},
164   {0x0085, 1, &jpc_mqstates[81], &jpc_mqstates[75]},
165   {0x0049, 0, &jpc_mqstates[82], &jpc_mqstates[76]},
166   {0x0049, 1, &jpc_mqstates[83], &jpc_mqstates[77]},
167   {0x0025, 0, &jpc_mqstates[84], &jpc_mqstates[78]},
168   {0x0025, 1, &jpc_mqstates[85], &jpc_mqstates[79]},
169   {0x0015, 0, &jpc_mqstates[86], &jpc_mqstates[80]},
170   {0x0015, 1, &jpc_mqstates[87], &jpc_mqstates[81]},
171   {0x0009, 0, &jpc_mqstates[88], &jpc_mqstates[82]},
172   {0x0009, 1, &jpc_mqstates[89], &jpc_mqstates[83]},
173   {0x0005, 0, &jpc_mqstates[90], &jpc_mqstates[84]},
174   {0x0005, 1, &jpc_mqstates[91], &jpc_mqstates[85]},
175   {0x0001, 0, &jpc_mqstates[90], &jpc_mqstates[86]},
176   {0x0001, 1, &jpc_mqstates[91], &jpc_mqstates[87]},
177   {0x5601, 0, &jpc_mqstates[92], &jpc_mqstates[92]},
178   {0x5601, 1, &jpc_mqstates[93], &jpc_mqstates[93]},
179 };