32 #define GLYPH_COORD_VECT_SIZE 16
33 #define PALETTE_SIZE 256
34 #define PALETTE_DELTA 768
37 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
41 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
45 0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
49 0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
53 { 0, 0 }, { -1, -43 }, { 6, -43 }, { -9, -42 }, { 13, -41 },
54 { -16, -40 }, { 19, -39 }, { -23, -36 }, { 26, -34 }, { -2, -33 },
55 { 4, -33 }, { -29, -32 }, { -9, -32 }, { 11, -31 }, { -16, -29 },
56 { 32, -29 }, { 18, -28 }, { -34, -26 }, { -22, -25 }, { -1, -25 },
57 { 3, -25 }, { -7, -24 }, { 8, -24 }, { 24, -23 }, { 36, -23 },
58 { -12, -22 }, { 13, -21 }, { -38, -20 }, { 0, -20 }, { -27, -19 },
59 { -4, -19 }, { 4, -19 }, { -17, -18 }, { -8, -17 }, { 8, -17 },
60 { 18, -17 }, { 28, -17 }, { 39, -17 }, { -12, -15 }, { 12, -15 },
61 { -21, -14 }, { -1, -14 }, { 1, -14 }, { -41, -13 }, { -5, -13 },
62 { 5, -13 }, { 21, -13 }, { -31, -12 }, { -15, -11 }, { -8, -11 },
63 { 8, -11 }, { 15, -11 }, { -2, -10 }, { 1, -10 }, { 31, -10 },
64 { -23, -9 }, { -11, -9 }, { -5, -9 }, { 4, -9 }, { 11, -9 },
65 { 42, -9 }, { 6, -8 }, { 24, -8 }, { -18, -7 }, { -7, -7 },
66 { -3, -7 }, { -1, -7 }, { 2, -7 }, { 18, -7 }, { -43, -6 },
67 { -13, -6 }, { -4, -6 }, { 4, -6 }, { 8, -6 }, { -33, -5 },
68 { -9, -5 }, { -2, -5 }, { 0, -5 }, { 2, -5 }, { 5, -5 },
69 { 13, -5 }, { -25, -4 }, { -6, -4 }, { -3, -4 }, { 3, -4 },
70 { 9, -4 }, { -19, -3 }, { -7, -3 }, { -4, -3 }, { -2, -3 },
71 { -1, -3 }, { 0, -3 }, { 1, -3 }, { 2, -3 }, { 4, -3 },
72 { 6, -3 }, { 33, -3 }, { -14, -2 }, { -10, -2 }, { -5, -2 },
73 { -3, -2 }, { -2, -2 }, { -1, -2 }, { 0, -2 }, { 1, -2 },
74 { 2, -2 }, { 3, -2 }, { 5, -2 }, { 7, -2 }, { 14, -2 },
75 { 19, -2 }, { 25, -2 }, { 43, -2 }, { -7, -1 }, { -3, -1 },
76 { -2, -1 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { 2, -1 },
77 { 3, -1 }, { 10, -1 }, { -5, 0 }, { -3, 0 }, { -2, 0 },
78 { -1, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 5, 0 },
79 { 7, 0 }, { -10, 1 }, { -7, 1 }, { -3, 1 }, { -2, 1 },
80 { -1, 1 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 },
81 { -43, 2 }, { -25, 2 }, { -19, 2 }, { -14, 2 }, { -5, 2 },
82 { -3, 2 }, { -2, 2 }, { -1, 2 }, { 0, 2 }, { 1, 2 },
83 { 2, 2 }, { 3, 2 }, { 5, 2 }, { 7, 2 }, { 10, 2 },
84 { 14, 2 }, { -33, 3 }, { -6, 3 }, { -4, 3 }, { -2, 3 },
85 { -1, 3 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 4, 3 },
86 { 19, 3 }, { -9, 4 }, { -3, 4 }, { 3, 4 }, { 7, 4 },
87 { 25, 4 }, { -13, 5 }, { -5, 5 }, { -2, 5 }, { 0, 5 },
88 { 2, 5 }, { 5, 5 }, { 9, 5 }, { 33, 5 }, { -8, 6 },
89 { -4, 6 }, { 4, 6 }, { 13, 6 }, { 43, 6 }, { -18, 7 },
90 { -2, 7 }, { 0, 7 }, { 2, 7 }, { 7, 7 }, { 18, 7 },
91 { -24, 8 }, { -6, 8 }, { -42, 9 }, { -11, 9 }, { -4, 9 },
92 { 5, 9 }, { 11, 9 }, { 23, 9 }, { -31, 10 }, { -1, 10 },
93 { 2, 10 }, { -15, 11 }, { -8, 11 }, { 8, 11 }, { 15, 11 },
94 { 31, 12 }, { -21, 13 }, { -5, 13 }, { 5, 13 }, { 41, 13 },
95 { -1, 14 }, { 1, 14 }, { 21, 14 }, { -12, 15 }, { 12, 15 },
96 { -39, 17 }, { -28, 17 }, { -18, 17 }, { -8, 17 }, { 8, 17 },
97 { 17, 18 }, { -4, 19 }, { 0, 19 }, { 4, 19 }, { 27, 19 },
98 { 38, 20 }, { -13, 21 }, { 12, 22 }, { -36, 23 }, { -24, 23 },
99 { -8, 24 }, { 7, 24 }, { -3, 25 }, { 1, 25 }, { 22, 25 },
100 { 34, 26 }, { -18, 28 }, { -32, 29 }, { 16, 29 }, { -11, 31 },
101 { 9, 32 }, { 29, 32 }, { -4, 33 }, { 2, 33 }, { -26, 34 },
102 { 23, 36 }, { -19, 39 }, { 16, 40 }, { -13, 41 }, { 9, 42 },
103 { -6, 43 }, { 1, 43 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
107 0, 0, 1, 0, 2, 0, 3, 0, 5, 0,
108 8, 0, 13, 0, 21, 0, -1, 0, -2, 0,
109 -3, 0, -5, 0, -8, 0, -13, 0, -17, 0,
110 -21, 0, 0, 1, 1, 1, 2, 1, 3, 1,
111 5, 1, 8, 1, 13, 1, 21, 1, -1, 1,
112 -2, 1, -3, 1, -5, 1, -8, 1, -13, 1,
113 -17, 1, -21, 1, 0, 2, 1, 2, 2, 2,
114 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
115 -1, 2, -2, 2, -3, 2, -5, 2, -8, 2,
116 -13, 2, -17, 2, -21, 2, 0, 3, 1, 3,
117 2, 3, 3, 3, 5, 3, 8, 3, 13, 3,
118 21, 3, -1, 3, -2, 3, -3, 3, -5, 3,
119 -8, 3, -13, 3, -17, 3, -21, 3, 0, 5,
120 1, 5, 2, 5, 3, 5, 5, 5, 8, 5,
121 13, 5, 21, 5, -1, 5, -2, 5, -3, 5,
122 -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
123 0, 8, 1, 8, 2, 8, 3, 8, 5, 8,
124 8, 8, 13, 8, 21, 8, -1, 8, -2, 8,
125 -3, 8, -5, 8, -8, 8, -13, 8, -17, 8,
126 -21, 8, 0, 13, 1, 13, 2, 13, 3, 13,
127 5, 13, 8, 13, 13, 13, 21, 13, -1, 13,
128 -2, 13, -3, 13, -5, 13, -8, 13, -13, 13,
129 -17, 13, -21, 13, 0, 21, 1, 21, 2, 21,
130 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
131 -1, 21, -2, 21, -3, 21, -5, 21, -8, 21,
132 -13, 21, -17, 21, -21, 21, 0, -1, 1, -1,
133 2, -1, 3, -1, 5, -1, 8, -1, 13, -1,
134 21, -1, -1, -1, -2, -1, -3, -1, -5, -1,
135 -8, -1, -13, -1, -17, -1, -21, -1, 0, -2,
136 1, -2, 2, -2, 3, -2, 5, -2, 8, -2,
137 13, -2, 21, -2, -1, -2, -2, -2, -3, -2,
138 -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
139 0, -3, 1, -3, 2, -3, 3, -3, 5, -3,
140 8, -3, 13, -3, 21, -3, -1, -3, -2, -3,
141 -3, -3, -5, -3, -8, -3, -13, -3, -17, -3,
142 -21, -3, 0, -5, 1, -5, 2, -5, 3, -5,
143 5, -5, 8, -5, 13, -5, 21, -5, -1, -5,
144 -2, -5, -3, -5, -5, -5, -8, -5, -13, -5,
145 -17, -5, -21, -5, 0, -8, 1, -8, 2, -8,
146 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
147 -1, -8, -2, -8, -3, -8, -5, -8, -8, -8,
148 -13, -8, -17, -8, -21, -8, 0, -13, 1, -13,
149 2, -13, 3, -13, 5, -13, 8, -13, 13, -13,
150 21, -13, -1, -13, -2, -13, -3, -13, -5, -13,
151 -8, -13, -13, -13, -17, -13, -21, -13, 0, -17,
152 1, -17, 2, -17, 3, -17, 5, -17, 8, -17,
153 13, -17, 21, -17, -1, -17, -2, -17, -3, -17,
154 -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
155 0, -21, 1, -21, 2, -21, 3, -21, 5, -21,
156 8, -21, 13, -21, 21, -21, -1, -21, -2, -21,
157 -3, -21, -5, -21, -8, -21, -13, -21, -17, -21,
158 0, 0, -8, -29, 8, -29, -18, -25, 17, -25,
159 0, -23, -6, -22, 6, -22, -13, -19, 12, -19,
160 0, -18, 25, -18, -25, -17, -5, -17, 5, -17,
161 -10, -15, 10, -15, 0, -14, -4, -13, 4, -13,
162 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
163 2, -11, 8, -11, -15, -10, -4, -10, 4, -10,
164 15, -10, -6, -9, -1, -9, 1, -9, 6, -9,
165 -29, -8, -11, -8, -8, -8, -3, -8, 3, -8,
166 8, -8, 11, -8, 29, -8, -5, -7, -2, -7,
167 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
168 -6, -6, -3, -6, -1, -6, 1, -6, 3, -6,
169 6, -6, 9, -6, 22, -6, -17, -5, -7, -5,
170 -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
171 7, -5, 17, -5, -13, -4, -10, -4, -5, -4,
172 -3, -4, -1, -4, 0, -4, 1, -4, 3, -4,
173 5, -4, 10, -4, 13, -4, -8, -3, -6, -3,
174 -4, -3, -3, -3, -2, -3, -1, -3, 0, -3,
175 1, -3, 2, -3, 4, -3, 6, -3, 8, -3,
176 -11, -2, -7, -2, -5, -2, -3, -2, -2, -2,
177 -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
178 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
179 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
180 1, -1, 2, -1, 3, -1, 4, -1, 6, -1,
181 9, -1, -31, 0, -23, 0, -18, 0, -14, 0,
182 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
183 -2, 0, -1, 0, 0, -31, 1, 0, 2, 0,
184 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
185 14, 0, 18, 0, 23, 0, 31, 0, -9, 1,
186 -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
187 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
188 6, 1, 9, 1, -11, 2, -7, 2, -5, 2,
189 -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
190 2, 2, 3, 2, 5, 2, 7, 2, 11, 2,
191 -8, 3, -6, 3, -4, 3, -2, 3, -1, 3,
192 0, 3, 1, 3, 2, 3, 3, 3, 4, 3,
193 6, 3, 8, 3, -13, 4, -10, 4, -5, 4,
194 -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
195 5, 4, 10, 4, 13, 4, -17, 5, -7, 5,
196 -4, 5, -2, 5, 0, 5, 2, 5, 4, 5,
197 7, 5, 17, 5, -22, 6, -9, 6, -6, 6,
198 -3, 6, -1, 6, 1, 6, 3, 6, 6, 6,
199 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
200 2, 7, 5, 7, -29, 8, -11, 8, -8, 8,
201 -3, 8, 3, 8, 8, 8, 11, 8, 29, 8,
202 -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
203 -4, 10, 4, 10, 15, 10, -8, 11, -2, 11,
204 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
205 -4, 13, 4, 13, 0, 14, -10, 15, 10, 15,
206 -5, 17, 5, 17, 25, 17, -25, 18, 0, 18,
207 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
208 -17, 25, 18, 25, -8, 29, 8, 29, 0, 31,
209 0, 0, -6, -22, 6, -22, -13, -19, 12, -19,
210 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
211 0, -14, -4, -13, 4, -13, 19, -13, -19, -12,
212 -8, -11, -2, -11, 0, -11, 2, -11, 8, -11,
213 -15, -10, -4, -10, 4, -10, 15, -10, -6, -9,
214 -1, -9, 1, -9, 6, -9, -11, -8, -8, -8,
215 -3, -8, 0, -8, 3, -8, 8, -8, 11, -8,
216 -5, -7, -2, -7, 0, -7, 2, -7, 5, -7,
217 -22, -6, -9, -6, -6, -6, -3, -6, -1, -6,
218 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
219 -17, -5, -7, -5, -4, -5, -2, -5, -1, -5,
220 0, -5, 1, -5, 2, -5, 4, -5, 7, -5,
221 17, -5, -13, -4, -10, -4, -5, -4, -3, -4,
222 -2, -4, -1, -4, 0, -4, 1, -4, 2, -4,
223 3, -4, 5, -4, 10, -4, 13, -4, -8, -3,
224 -6, -3, -4, -3, -3, -3, -2, -3, -1, -3,
225 0, -3, 1, -3, 2, -3, 3, -3, 4, -3,
226 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
227 -4, -2, -3, -2, -2, -2, -1, -2, 0, -2,
228 1, -2, 2, -2, 3, -2, 4, -2, 5, -2,
229 7, -2, 11, -2, -9, -1, -6, -1, -5, -1,
230 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
231 1, -1, 2, -1, 3, -1, 4, -1, 5, -1,
232 6, -1, 9, -1, -23, 0, -18, 0, -14, 0,
233 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
234 -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
235 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
236 14, 0, 18, 0, 23, 0, -9, 1, -6, 1,
237 -5, 1, -4, 1, -3, 1, -2, 1, -1, 1,
238 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
239 5, 1, 6, 1, 9, 1, -11, 2, -7, 2,
240 -5, 2, -4, 2, -3, 2, -2, 2, -1, 2,
241 0, 2, 1, 2, 2, 2, 3, 2, 4, 2,
242 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
243 -4, 3, -3, 3, -2, 3, -1, 3, 0, 3,
244 1, 3, 2, 3, 3, 3, 4, 3, 6, 3,
245 8, 3, -13, 4, -10, 4, -5, 4, -3, 4,
246 -2, 4, -1, 4, 0, 4, 1, 4, 2, 4,
247 3, 4, 5, 4, 10, 4, 13, 4, -17, 5,
248 -7, 5, -4, 5, -2, 5, -1, 5, 0, 5,
249 1, 5, 2, 5, 4, 5, 7, 5, 17, 5,
250 -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
251 1, 6, 3, 6, 6, 6, 9, 6, 22, 6,
252 -5, 7, -2, 7, 0, 7, 2, 7, 5, 7,
253 -11, 8, -8, 8, -3, 8, 0, 8, 3, 8,
254 8, 8, 11, 8, -6, 9, -1, 9, 1, 9,
255 6, 9, -15, 10, -4, 10, 4, 10, 15, 10,
256 -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
257 19, 12, -19, 13, -4, 13, 4, 13, 0, 14,
258 -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
259 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
327 const int edge_max = edge_size - 1;
331 else if (y == edge_max)
335 else if (x == edge_max)
364 static void interp_point(int8_t *points,
int x0,
int y0,
int x1,
int y1,
365 int pos,
int npoints)
368 points[0] = (x0 *
pos + x1 * (npoints -
pos) + (npoints >> 1)) / npoints;
369 points[1] = (y0 *
pos + y1 * (npoints -
pos) + (npoints >> 1)) / npoints;
384 static void make_glyphs(int8_t *pglyphs,
const int8_t *xvec,
const int8_t *yvec,
385 const int side_length)
387 const int glyph_size = side_length * side_length;
388 int8_t *pglyph = pglyphs;
404 for (ipoint = 0; ipoint <= npoints; ipoint++) {
412 for (irow = point[1]; irow >= 0; irow--)
413 pglyph[point[0] + irow * side_length] = 1;
417 for (irow = point[1]; irow < side_length; irow++)
418 pglyph[point[0] + irow * side_length] = 1;
422 for (icol = point[0]; icol >= 0; icol--)
423 pglyph[icol + point[1] * side_length] = 1;
427 for (icol = point[0]; icol < side_length; icol++)
428 pglyph[icol + point[1] * side_length] = 1;
445 ctx->buf_size =
ctx->aligned_width *
ctx->aligned_height *
sizeof(
ctx->frm0[0]);
469 &
ctx->stored_frame_size,
ctx->buf_size);
471 if (!
ctx->frm0 || !
ctx->frm1 || !
ctx->frm2 ||
472 (!
ctx->stored_frame && !
ctx->version)) {
482 if (rotate_code == 2)
535 opcode = bytestream2_get_byte(&
ctx->gb);
541 color = bytestream2_get_byte(&
ctx->gb);
559 uint8_t *dst = ((uint8_t *)
ctx->frm0) +
left + top *
ctx->pitch;
568 len = bytestream2_get_le16u(&
ctx->gb);
575 code = bytestream2_get_byteu(&
ctx->gb);
581 val = bytestream2_get_byteu(&
ctx->gb);
588 for (j = 0; j <
code; j++) {
589 val = bytestream2_get_byteu(&
ctx->gb);
598 ctx->rotate_code = 0;
609 for (j = 0; j < 4; j++) {
610 for (
i = 0;
i < 4;
i++) {
629 int compr = bytestream2_get_byte(&
ctx->gb);
630 int mvoff = bytestream2_get_byte(&
ctx->gb);
631 int seq = bytestream2_get_le16(&
ctx->gb);
632 uint32_t decoded_size = bytestream2_get_le32(&
ctx->gb);
636 flags = bytestream2_get_byte(&
ctx->gb);
644 ctx->rotate_code = 0;
646 if (((seq & 1) || !(
flags & 1)) && (compr && compr != 2))
669 memset(
ctx->frm1, 0,
ctx->frm1_size);
670 memset(
ctx->frm2, 0,
ctx->frm2_size);
675 for (j = 0; j <
height; j += 4) {
685 code = bytestream2_get_byteu(&
ctx->gb);
690 for (k = 0; k < 4; k++)
696 for (k = 0; k < 4; k++)
697 memset(dst +
i + k *
stride, bytestream2_get_byteu(&
ctx->gb), 4);
702 t = bytestream2_get_byteu(&
ctx->gb);
703 for (k = 0; k < 4; k++)
704 memset(dst +
i + k *
stride, t, 4);
707 if (compr == 4 && !
code) {
710 skip_run = bytestream2_get_byteu(&
ctx->gb) + 1;
726 for (j = 0; j <
height; j += 4) {
734 code = bytestream2_get_byte(&
ctx->gb);
738 for (k = 0; k < 4; k++)
740 }
else if (compr == 4 && !
code) {
743 skip_run = bytestream2_get_byteu(&
ctx->gb) + 1;
761 "Subcodec 37 compression %d", compr);
769 uint8_t *prev2,
int stride,
int tbl,
int size)
778 code = bytestream2_get_byteu(&
ctx->gb);
785 dst[0] = bytestream2_get_byteu(&
ctx->gb);
786 dst[1] = bytestream2_get_byteu(&
ctx->gb);
787 dst[0 +
stride] = bytestream2_get_byteu(&
ctx->gb);
788 dst[1 +
stride] = bytestream2_get_byteu(&
ctx->gb);
810 t = bytestream2_get_byteu(&
ctx->gb);
811 for (k = 0; k <
size; k++)
818 code = bytestream2_get_byteu(&
ctx->gb);
822 for (k = 0; k <
size; k++)
823 for (t = 0; t <
size; t++)
824 dst[t + k *
stride] = colors[!*pglyph++];
827 for (k = 0; k <
size; k++)
833 t = bytestream2_get_byte(&
ctx->gb);
835 for (k = 0; k <
size; k++)
841 int index = prev2 - (
const uint8_t *)
ctx->frm2;
851 for (k = 0; k <
size; k++)
861 uint32_t decoded_size;
865 uint8_t *prev1 = (uint8_t *)
ctx->frm1;
866 uint8_t *prev2 = (uint8_t *)
ctx->frm2;
868 int seq = bytestream2_get_le16(&
ctx->gb);
869 int compr = bytestream2_get_byte(&
ctx->gb);
870 int new_rot = bytestream2_get_byte(&
ctx->gb);
871 int skip = bytestream2_get_byte(&
ctx->gb);
874 decoded_size = bytestream2_get_le32(&
ctx->gb);
894 for (j = 0; j <
height; j++) {
902 for (j = 0; j <
height; j += 2) {
907 dst[
stride +
i + 1] = bytestream2_get_byteu(&
ctx->gb);
913 if (seq ==
ctx->prev_seq + 1) {
914 for (j = 0; j <
height; j += 8) {
937 "Subcodec 47 compression %d", compr);
940 if (seq ==
ctx->prev_seq + 1)
941 ctx->rotate_code = new_rot;
943 ctx->rotate_code = 0;
951 uint16_t codec = bytestream2_get_le16u(&
ctx->gb);
952 uint16_t
left = bytestream2_get_le16u(&
ctx->gb);
953 uint16_t top = bytestream2_get_le16u(&
ctx->gb);
954 uint16_t
w = bytestream2_get_le16u(&
ctx->gb);
955 uint16_t
h = bytestream2_get_le16u(&
ctx->gb);
992 uint16_t *frm =
ctx->frm0;
999 for (y = 0; y <
ctx->height; y++) {
1000 for (x = 0; x <
ctx->width; x++)
1001 frm[x] = bytestream2_get_le16u(&
ctx->gb);
1013 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size, ptrdiff_t pitch)
1015 uint8_t *dst = (uint8_t *)pdest;
1016 uint8_t *
src = (uint8_t *)psrc;
1017 ptrdiff_t
stride = pitch * 2;
1019 switch (block_size) {
1036 pitch -= block_size;
1037 for (y = 0; y < block_size; y++, pdest += pitch)
1038 for (x = 0; x < block_size; x++)
1043 uint16_t fg_color, uint16_t bg_color,
int block_size,
1047 uint16_t colors[2] = { fg_color, bg_color };
1055 pglyph = block_size == 8 ?
ctx->p8x8glyphs[
index] :
ctx->p4x4glyphs[
index];
1056 pitch -= block_size;
1058 for (y = 0; y < block_size; y++, dst += pitch)
1059 for (x = 0; x < block_size; x++)
1060 *dst++ = colors[*pglyph++];
1066 uint16_t *dst =
ctx->frm0 + cx + cy *
ctx->pitch;
1068 if (block_size == 2) {
1074 indices = bytestream2_get_le32u(&
ctx->gb);
1075 dst[0] =
ctx->codebook[indices & 0xFF];
1077 dst[1] =
ctx->codebook[indices & 0xFF];
1079 dst[pitch] =
ctx->codebook[indices & 0xFF];
1081 dst[pitch + 1] =
ctx->codebook[indices & 0xFF];
1083 uint16_t fgcolor, bgcolor;
1089 glyph = bytestream2_get_byteu(&
ctx->gb);
1090 bgcolor =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
1091 fgcolor =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
1093 draw_glyph(
ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
1100 uint16_t *dst =
ctx->frm0 + cx + cy *
ctx->pitch;
1102 if (block_size == 2) {
1106 dst[0] = bytestream2_get_le16u(&
ctx->gb);
1107 dst[1] = bytestream2_get_le16u(&
ctx->gb);
1108 dst[pitch] = bytestream2_get_le16u(&
ctx->gb);
1109 dst[pitch + 1] = bytestream2_get_le16u(&
ctx->gb);
1111 uint16_t fgcolor, bgcolor;
1117 glyph = bytestream2_get_byteu(&
ctx->gb);
1118 bgcolor = bytestream2_get_le16u(&
ctx->gb);
1119 fgcolor = bytestream2_get_le16u(&
ctx->gb);
1121 draw_glyph(
ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
1129 int start_pos = cx + mx + (cy + my) *
ctx->pitch;
1130 int end_pos = start_pos + (block_size - 1) * (
ctx->pitch + 1);
1132 int good = start_pos >= 0 && end_pos < (
ctx->buf_size >> 1);
1136 "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
1137 cx + mx, cy + my, cx, cy, block_size);
1144 int16_t mx, my,
index;
1150 opcode = bytestream2_get_byteu(&
ctx->gb);
1159 ctx->frm2 + cx + mx +
ctx->pitch * (cy + my),
1160 blk_size,
ctx->pitch);
1166 index = bytestream2_get_le16u(&
ctx->gb);
1173 ctx->frm2 + cx + mx +
ctx->pitch * (cy + my),
1174 blk_size,
ctx->pitch);
1179 ctx->frm1 + cx +
ctx->pitch * cy,
1180 blk_size,
ctx->pitch);
1194 ctx->small_codebook[opcode - 0xf9], blk_size,
ctx->pitch);
1200 ctx->codebook[bytestream2_get_byteu(&
ctx->gb)], blk_size,
ctx->pitch);
1206 bytestream2_get_le16u(&
ctx->gb), blk_size,
ctx->pitch);
1209 if (blk_size == 2) {
1231 for (cy = 0; cy <
ctx->aligned_height; cy += 8)
1232 for (cx = 0; cx <
ctx->aligned_width; cx += 8)
1241 memcpy(
ctx->frm0,
ctx->frm2,
ctx->frm2_size);
1247 memcpy(
ctx->frm0,
ctx->frm1,
ctx->frm1_size);
1257 uint8_t *dst = (uint8_t*)
ctx->frm0;
1263 npixels =
ctx->npixels;
1276 int npixels =
ctx->npixels;
1277 uint16_t *frm =
ctx->frm0;
1284 *frm++ =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
1291 uint16_t *pdest =
ctx->frm0;
1293 long npixels =
ctx->npixels;
1296 if (!
ctx->rle_buf) {
1300 rsrc =
ctx->rle_buf;
1306 *pdest++ =
ctx->codebook[*rsrc++];
1329 hdr->
width = bytestream2_get_le32u(&
ctx->gb);
1330 hdr->
height = bytestream2_get_le32u(&
ctx->gb);
1337 hdr->
seq_num = bytestream2_get_le16u(&
ctx->gb);
1338 hdr->
codec = bytestream2_get_byteu(&
ctx->gb);
1343 for (
i = 0;
i < 4;
i++)
1344 ctx->small_codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
1350 for (
i = 0;
i < 256;
i++)
1351 ctx->codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
1369 const uint8_t *
src = (uint8_t*)
ctx->frm0;
1371 ptrdiff_t dstpitch, srcpitch =
ctx->pitch * (hdr ?
sizeof(
ctx->frm0[0]) : 1);
1376 dst =
ctx->frame->data[0];
1377 dstpitch =
ctx->frame->linesize[0];
1380 memcpy(dst,
src, srcpitch);
1397 if (!
ctx->version) {
1404 sig = bytestream2_get_be32u(&
ctx->gb);
1405 size = bytestream2_get_be32u(&
ctx->gb);
1413 case MKBETAG(
'N',
'P',
'A',
'L'):
1416 "Incorrect palette block size %"PRIu32
".\n",
size);
1420 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
1422 case MKBETAG(
'F',
'O',
'B',
'J'):
1428 case MKBETAG(
'X',
'P',
'A',
'L'):
1434 for (j = 0; j < 3; j++) {
1435 int t = (
ctx->pal[
i] >> (16 - j * 8)) & 0xFF;
1443 "Incorrect palette change block size %"PRIu32
".\n",
1449 ctx->delta_pal[
i] = bytestream2_get_le16u(&
ctx->gb);
1452 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
1454 memset(
ctx->pal, 0,
sizeof(
ctx->pal));
1458 case MKBETAG(
'S',
'T',
'O',
'R'):
1461 case MKBETAG(
'F',
'T',
'C',
'H'):
1462 memcpy(
ctx->frm0,
ctx->stored_frame,
ctx->buf_size);
1467 "Unknown/unsupported chunk %"PRIx32
".\n", sig);
1476 memcpy(
ctx->stored_frame,
ctx->frm0,
ctx->buf_size);
1479 memcpy(
ctx->frame->data[1],
ctx->pal, 1024);
1500 "Subcodec %d: error decoding frame.\n",
header.codec);
1511 if (
ctx->rotate_code)