7 typedef struct _State State
;
15 static State states
[] = {
16 { 0x5a1d, 1, 1, 1 }, /* 0 */
21 { 0x01da, 23, 6, 0 }, /* 5 */
25 { 0x001a, 33, 10, 0 },
26 { 0x000d, 35, 11, 0 }, /* 10 */
28 { 0x0003, 10, 13, 0 },
29 { 0x0001, 12, 13, 0 },
30 { 0x5a7f, 15, 15, 1 },
31 { 0x3f25, 36, 16, 0 }, /* 15 */
32 { 0x2cf2, 38, 17, 0 },
33 { 0x207c, 39, 18, 0 },
34 { 0x17b9, 40, 18, 0 },
35 { 0x1182, 42, 20, 0 },
36 { 0x0cef, 43, 21, 0 }, /* 20 */
37 { 0x09a1, 45, 22, 0 },
38 { 0x072f, 46, 23, 0 },
39 { 0x055c, 48, 24, 0 },
40 { 0x0406, 49, 25, 0 },
41 { 0x0303, 51, 26, 0 }, /* 25 */
42 { 0x0240, 52, 27, 0 },
43 { 0x01b1, 54, 28, 0 },
44 { 0x0144, 56, 29, 0 },
45 { 0x00f5, 57, 30, 0 },
46 { 0x00b7, 59, 31, 0 }, /* 30 */
47 { 0x008a, 60, 32, 0 },
48 { 0x0068, 62, 33, 0 },
49 { 0x004e, 63, 34, 0 },
50 { 0x003b, 32, 35, 0 },
51 { 0x002c, 33, 9, 0 }, /* 35 */
52 { 0x5ae1, 37, 37, 1 },
53 { 0x484c, 64, 38, 0 },
54 { 0x3a0d, 65, 39, 0 },
55 { 0x2ef1, 67, 40, 0 },
56 { 0x261f, 68, 41, 0 }, /* 40 */
57 { 0x1f33, 69, 42, 0 },
58 { 0x1948, 70, 43, 0 },
59 { 0x1518, 72, 44, 0 },
60 { 0x1177, 73, 45, 0 },
61 { 0x0e74, 74, 46, 0 }, /* 45 */
62 { 0x0bfb, 75, 47, 0 },
63 { 0x09f8, 77, 48, 0 },
64 { 0x0861, 78, 49, 0 },
65 { 0x0706, 79, 50, 0 },
66 { 0x05cd, 48, 51, 0 }, /* 50 */
67 { 0x04de, 50, 52, 0 },
68 { 0x040f, 50, 53, 0 },
69 { 0x0363, 51, 54, 0 },
70 { 0x02d4, 52, 55, 0 },
71 { 0x025c, 53, 56, 0 }, /* 55 */
72 { 0x01f8, 54, 57, 0 },
73 { 0x01a4, 55, 58, 0 },
74 { 0x0160, 56, 59, 0 },
75 { 0x0125, 57, 60, 0 },
76 { 0x00f6, 58, 61, 0 }, /* 60 */
77 { 0x00cb, 59, 62, 0 },
78 { 0x00ab, 61, 63, 0 },
79 { 0x008f, 61, 32, 0 },
80 { 0x5b12, 65, 65, 1 },
81 { 0x4d04, 80, 66, 0 }, /* 65 */
82 { 0x412c, 81, 67, 0 },
83 { 0x37d8, 82, 68, 0 },
84 { 0x2fe8, 83, 69, 0 },
85 { 0x293c, 84, 70, 0 },
86 { 0x2379, 86, 71, 0 }, /* 70 */
87 { 0x1edf, 87, 72, 0 },
88 { 0x1aa9, 87, 73, 0 },
89 { 0x174e, 72, 74, 0 },
90 { 0x1424, 72, 75, 0 },
91 { 0x119c, 74, 76, 0 }, /* 75 */
92 { 0x0f6b, 74, 77, 0 },
93 { 0x0d51, 75, 78, 0 },
94 { 0x0bb6, 77, 79, 0 },
95 { 0x0a40, 77, 48, 0 },
96 { 0x5832, 80, 81, 1 }, /* 80 */
97 { 0x4d1c, 88, 82, 0 },
98 { 0x438e, 89, 83, 0 },
99 { 0x3bdd, 90, 84, 0 },
100 { 0x34ee, 91, 85, 0 },
101 { 0x2eae, 92, 86, 0 }, /* 85 */
102 { 0x299a, 93, 87, 0 },
103 { 0x2516, 86, 71, 0 },
104 { 0x5570, 88, 89, 1 },
105 { 0x4ca9, 95, 90, 0 },
106 { 0x44d9, 96, 91, 0 }, /* 90 */
107 { 0x3e22, 97, 92, 0 },
108 { 0x3824, 99, 93, 0 },
109 { 0x32b4, 99, 94, 0 },
110 { 0x2e17, 93, 86, 0 },
111 { 0x56a8, 95, 96, 1 }, /* 95 */
112 { 0x4f46,101, 97, 0 },
113 { 0x47e5,102, 98, 0 },
114 { 0x41cf,103, 99, 0 },
115 { 0x3c3d,104,100, 0 },
116 { 0x375e, 99, 93, 0 }, /* 100 */
117 { 0x5231,105,102, 0 },
118 { 0x4c0f,106,103, 0 },
119 { 0x4639,107,104, 0 },
120 { 0x415e,103, 99, 0 },
121 { 0x5627,105,106, 1 }, /* 105 */
122 { 0x50e7,108,107, 0 },
123 { 0x4b85,109,103, 0 },
124 { 0x5597,110,109, 0 },
125 { 0x50ef,111,107, 0 },
126 { 0x5a10,110,111, 1 }, /* 110 */
127 { 0x5522,112,109, 0 },
128 { 0x59eb,112,111, 1 }
132 byte_out (ArithQM
*coder
)
138 coder
->data
[coder
->bp
]++;
141 coder
->data
[coder
->bp
] = 0;
145 coder
->data
[coder
->bp
] = t
;
148 coder
->data
[coder
->bp
] = t
;
153 renorm_e (ArithQM
*coder
)
159 if (coder
->ct
== 0) {
163 } while (coder
->a
< 0x8000);
167 code_lps(ArithQM
*coder
, int s
)
171 qe
= states
[coder
->contexts_state
[s
]].qe_value
;
173 if (coder
->a
>= qe
) {
174 coder
->c
+= coder
->a
;
177 if(states
[coder
->contexts_state
[s
]].switch_mps
) {
178 coder
->contexts_mps
[s
] ^= 1;
180 coder
->contexts_state
[s
] = states
[coder
->contexts_state
[s
]].next_lps
;
185 code_mps(ArithQM
*coder
, int s
)
189 qe
= states
[coder
->contexts_state
[s
]].qe_value
;
192 if (coder
->a
< 0x8000) {
194 coder
->c
+= coder
->a
;
197 coder
->contexts_state
[s
] = states
[coder
->contexts_state
[s
]].next_mps
;
203 arith_qm_encode (ArithQM
*coder
, int s
, int value
)
205 if (coder
->contexts_mps
[s
] == value
) {
213 arith_qm_init (ArithQM
*coder
)
215 coder
->contexts_state
[0] = 0;
216 coder
->contexts_mps
[0] = 0;
226 arith_qm_flush (ArithQM
*coder
)