33 #define GLYPH_COORD_VECT_SIZE 16
34 #define PALETTE_SIZE 256
35 #define PALETTE_DELTA 768
38 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
42 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
46 0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
50 0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
54 { 0, 0 }, { -1, -43 }, { 6, -43 }, { -9, -42 }, { 13, -41 },
55 { -16, -40 }, { 19, -39 }, { -23, -36 }, { 26, -34 }, { -2, -33 },
56 { 4, -33 }, { -29, -32 }, { -9, -32 }, { 11, -31 }, { -16, -29 },
57 { 32, -29 }, { 18, -28 }, { -34, -26 }, { -22, -25 }, { -1, -25 },
58 { 3, -25 }, { -7, -24 }, { 8, -24 }, { 24, -23 }, { 36, -23 },
59 { -12, -22 }, { 13, -21 }, { -38, -20 }, { 0, -20 }, { -27, -19 },
60 { -4, -19 }, { 4, -19 }, { -17, -18 }, { -8, -17 }, { 8, -17 },
61 { 18, -17 }, { 28, -17 }, { 39, -17 }, { -12, -15 }, { 12, -15 },
62 { -21, -14 }, { -1, -14 }, { 1, -14 }, { -41, -13 }, { -5, -13 },
63 { 5, -13 }, { 21, -13 }, { -31, -12 }, { -15, -11 }, { -8, -11 },
64 { 8, -11 }, { 15, -11 }, { -2, -10 }, { 1, -10 }, { 31, -10 },
65 { -23, -9 }, { -11, -9 }, { -5, -9 }, { 4, -9 }, { 11, -9 },
66 { 42, -9 }, { 6, -8 }, { 24, -8 }, { -18, -7 }, { -7, -7 },
67 { -3, -7 }, { -1, -7 }, { 2, -7 }, { 18, -7 }, { -43, -6 },
68 { -13, -6 }, { -4, -6 }, { 4, -6 }, { 8, -6 }, { -33, -5 },
69 { -9, -5 }, { -2, -5 }, { 0, -5 }, { 2, -5 }, { 5, -5 },
70 { 13, -5 }, { -25, -4 }, { -6, -4 }, { -3, -4 }, { 3, -4 },
71 { 9, -4 }, { -19, -3 }, { -7, -3 }, { -4, -3 }, { -2, -3 },
72 { -1, -3 }, { 0, -3 }, { 1, -3 }, { 2, -3 }, { 4, -3 },
73 { 6, -3 }, { 33, -3 }, { -14, -2 }, { -10, -2 }, { -5, -2 },
74 { -3, -2 }, { -2, -2 }, { -1, -2 }, { 0, -2 }, { 1, -2 },
75 { 2, -2 }, { 3, -2 }, { 5, -2 }, { 7, -2 }, { 14, -2 },
76 { 19, -2 }, { 25, -2 }, { 43, -2 }, { -7, -1 }, { -3, -1 },
77 { -2, -1 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { 2, -1 },
78 { 3, -1 }, { 10, -1 }, { -5, 0 }, { -3, 0 }, { -2, 0 },
79 { -1, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 5, 0 },
80 { 7, 0 }, { -10, 1 }, { -7, 1 }, { -3, 1 }, { -2, 1 },
81 { -1, 1 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 },
82 { -43, 2 }, { -25, 2 }, { -19, 2 }, { -14, 2 }, { -5, 2 },
83 { -3, 2 }, { -2, 2 }, { -1, 2 }, { 0, 2 }, { 1, 2 },
84 { 2, 2 }, { 3, 2 }, { 5, 2 }, { 7, 2 }, { 10, 2 },
85 { 14, 2 }, { -33, 3 }, { -6, 3 }, { -4, 3 }, { -2, 3 },
86 { -1, 3 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 4, 3 },
87 { 19, 3 }, { -9, 4 }, { -3, 4 }, { 3, 4 }, { 7, 4 },
88 { 25, 4 }, { -13, 5 }, { -5, 5 }, { -2, 5 }, { 0, 5 },
89 { 2, 5 }, { 5, 5 }, { 9, 5 }, { 33, 5 }, { -8, 6 },
90 { -4, 6 }, { 4, 6 }, { 13, 6 }, { 43, 6 }, { -18, 7 },
91 { -2, 7 }, { 0, 7 }, { 2, 7 }, { 7, 7 }, { 18, 7 },
92 { -24, 8 }, { -6, 8 }, { -42, 9 }, { -11, 9 }, { -4, 9 },
93 { 5, 9 }, { 11, 9 }, { 23, 9 }, { -31, 10 }, { -1, 10 },
94 { 2, 10 }, { -15, 11 }, { -8, 11 }, { 8, 11 }, { 15, 11 },
95 { 31, 12 }, { -21, 13 }, { -5, 13 }, { 5, 13 }, { 41, 13 },
96 { -1, 14 }, { 1, 14 }, { 21, 14 }, { -12, 15 }, { 12, 15 },
97 { -39, 17 }, { -28, 17 }, { -18, 17 }, { -8, 17 }, { 8, 17 },
98 { 17, 18 }, { -4, 19 }, { 0, 19 }, { 4, 19 }, { 27, 19 },
99 { 38, 20 }, { -13, 21 }, { 12, 22 }, { -36, 23 }, { -24, 23 },
100 { -8, 24 }, { 7, 24 }, { -3, 25 }, { 1, 25 }, { 22, 25 },
101 { 34, 26 }, { -18, 28 }, { -32, 29 }, { 16, 29 }, { -11, 31 },
102 { 9, 32 }, { 29, 32 }, { -4, 33 }, { 2, 33 }, { -26, 34 },
103 { 23, 36 }, { -19, 39 }, { 16, 40 }, { -13, 41 }, { 9, 42 },
104 { -6, 43 }, { 1, 43 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
108 0, 0, 1, 0, 2, 0, 3, 0, 5, 0,
109 8, 0, 13, 0, 21, 0, -1, 0, -2, 0,
110 -3, 0, -5, 0, -8, 0, -13, 0, -17, 0,
111 -21, 0, 0, 1, 1, 1, 2, 1, 3, 1,
112 5, 1, 8, 1, 13, 1, 21, 1, -1, 1,
113 -2, 1, -3, 1, -5, 1, -8, 1, -13, 1,
114 -17, 1, -21, 1, 0, 2, 1, 2, 2, 2,
115 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
116 -1, 2, -2, 2, -3, 2, -5, 2, -8, 2,
117 -13, 2, -17, 2, -21, 2, 0, 3, 1, 3,
118 2, 3, 3, 3, 5, 3, 8, 3, 13, 3,
119 21, 3, -1, 3, -2, 3, -3, 3, -5, 3,
120 -8, 3, -13, 3, -17, 3, -21, 3, 0, 5,
121 1, 5, 2, 5, 3, 5, 5, 5, 8, 5,
122 13, 5, 21, 5, -1, 5, -2, 5, -3, 5,
123 -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
124 0, 8, 1, 8, 2, 8, 3, 8, 5, 8,
125 8, 8, 13, 8, 21, 8, -1, 8, -2, 8,
126 -3, 8, -5, 8, -8, 8, -13, 8, -17, 8,
127 -21, 8, 0, 13, 1, 13, 2, 13, 3, 13,
128 5, 13, 8, 13, 13, 13, 21, 13, -1, 13,
129 -2, 13, -3, 13, -5, 13, -8, 13, -13, 13,
130 -17, 13, -21, 13, 0, 21, 1, 21, 2, 21,
131 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
132 -1, 21, -2, 21, -3, 21, -5, 21, -8, 21,
133 -13, 21, -17, 21, -21, 21, 0, -1, 1, -1,
134 2, -1, 3, -1, 5, -1, 8, -1, 13, -1,
135 21, -1, -1, -1, -2, -1, -3, -1, -5, -1,
136 -8, -1, -13, -1, -17, -1, -21, -1, 0, -2,
137 1, -2, 2, -2, 3, -2, 5, -2, 8, -2,
138 13, -2, 21, -2, -1, -2, -2, -2, -3, -2,
139 -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
140 0, -3, 1, -3, 2, -3, 3, -3, 5, -3,
141 8, -3, 13, -3, 21, -3, -1, -3, -2, -3,
142 -3, -3, -5, -3, -8, -3, -13, -3, -17, -3,
143 -21, -3, 0, -5, 1, -5, 2, -5, 3, -5,
144 5, -5, 8, -5, 13, -5, 21, -5, -1, -5,
145 -2, -5, -3, -5, -5, -5, -8, -5, -13, -5,
146 -17, -5, -21, -5, 0, -8, 1, -8, 2, -8,
147 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
148 -1, -8, -2, -8, -3, -8, -5, -8, -8, -8,
149 -13, -8, -17, -8, -21, -8, 0, -13, 1, -13,
150 2, -13, 3, -13, 5, -13, 8, -13, 13, -13,
151 21, -13, -1, -13, -2, -13, -3, -13, -5, -13,
152 -8, -13, -13, -13, -17, -13, -21, -13, 0, -17,
153 1, -17, 2, -17, 3, -17, 5, -17, 8, -17,
154 13, -17, 21, -17, -1, -17, -2, -17, -3, -17,
155 -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
156 0, -21, 1, -21, 2, -21, 3, -21, 5, -21,
157 8, -21, 13, -21, 21, -21, -1, -21, -2, -21,
158 -3, -21, -5, -21, -8, -21, -13, -21, -17, -21,
159 0, 0, -8, -29, 8, -29, -18, -25, 17, -25,
160 0, -23, -6, -22, 6, -22, -13, -19, 12, -19,
161 0, -18, 25, -18, -25, -17, -5, -17, 5, -17,
162 -10, -15, 10, -15, 0, -14, -4, -13, 4, -13,
163 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
164 2, -11, 8, -11, -15, -10, -4, -10, 4, -10,
165 15, -10, -6, -9, -1, -9, 1, -9, 6, -9,
166 -29, -8, -11, -8, -8, -8, -3, -8, 3, -8,
167 8, -8, 11, -8, 29, -8, -5, -7, -2, -7,
168 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
169 -6, -6, -3, -6, -1, -6, 1, -6, 3, -6,
170 6, -6, 9, -6, 22, -6, -17, -5, -7, -5,
171 -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
172 7, -5, 17, -5, -13, -4, -10, -4, -5, -4,
173 -3, -4, -1, -4, 0, -4, 1, -4, 3, -4,
174 5, -4, 10, -4, 13, -4, -8, -3, -6, -3,
175 -4, -3, -3, -3, -2, -3, -1, -3, 0, -3,
176 1, -3, 2, -3, 4, -3, 6, -3, 8, -3,
177 -11, -2, -7, -2, -5, -2, -3, -2, -2, -2,
178 -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
179 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
180 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
181 1, -1, 2, -1, 3, -1, 4, -1, 6, -1,
182 9, -1, -31, 0, -23, 0, -18, 0, -14, 0,
183 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
184 -2, 0, -1, 0, 0, -31, 1, 0, 2, 0,
185 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
186 14, 0, 18, 0, 23, 0, 31, 0, -9, 1,
187 -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
188 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
189 6, 1, 9, 1, -11, 2, -7, 2, -5, 2,
190 -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
191 2, 2, 3, 2, 5, 2, 7, 2, 11, 2,
192 -8, 3, -6, 3, -4, 3, -2, 3, -1, 3,
193 0, 3, 1, 3, 2, 3, 3, 3, 4, 3,
194 6, 3, 8, 3, -13, 4, -10, 4, -5, 4,
195 -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
196 5, 4, 10, 4, 13, 4, -17, 5, -7, 5,
197 -4, 5, -2, 5, 0, 5, 2, 5, 4, 5,
198 7, 5, 17, 5, -22, 6, -9, 6, -6, 6,
199 -3, 6, -1, 6, 1, 6, 3, 6, 6, 6,
200 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
201 2, 7, 5, 7, -29, 8, -11, 8, -8, 8,
202 -3, 8, 3, 8, 8, 8, 11, 8, 29, 8,
203 -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
204 -4, 10, 4, 10, 15, 10, -8, 11, -2, 11,
205 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
206 -4, 13, 4, 13, 0, 14, -10, 15, 10, 15,
207 -5, 17, 5, 17, 25, 17, -25, 18, 0, 18,
208 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
209 -17, 25, 18, 25, -8, 29, 8, 29, 0, 31,
210 0, 0, -6, -22, 6, -22, -13, -19, 12, -19,
211 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
212 0, -14, -4, -13, 4, -13, 19, -13, -19, -12,
213 -8, -11, -2, -11, 0, -11, 2, -11, 8, -11,
214 -15, -10, -4, -10, 4, -10, 15, -10, -6, -9,
215 -1, -9, 1, -9, 6, -9, -11, -8, -8, -8,
216 -3, -8, 0, -8, 3, -8, 8, -8, 11, -8,
217 -5, -7, -2, -7, 0, -7, 2, -7, 5, -7,
218 -22, -6, -9, -6, -6, -6, -3, -6, -1, -6,
219 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
220 -17, -5, -7, -5, -4, -5, -2, -5, -1, -5,
221 0, -5, 1, -5, 2, -5, 4, -5, 7, -5,
222 17, -5, -13, -4, -10, -4, -5, -4, -3, -4,
223 -2, -4, -1, -4, 0, -4, 1, -4, 2, -4,
224 3, -4, 5, -4, 10, -4, 13, -4, -8, -3,
225 -6, -3, -4, -3, -3, -3, -2, -3, -1, -3,
226 0, -3, 1, -3, 2, -3, 3, -3, 4, -3,
227 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
228 -4, -2, -3, -2, -2, -2, -1, -2, 0, -2,
229 1, -2, 2, -2, 3, -2, 4, -2, 5, -2,
230 7, -2, 11, -2, -9, -1, -6, -1, -5, -1,
231 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1,
232 1, -1, 2, -1, 3, -1, 4, -1, 5, -1,
233 6, -1, 9, -1, -23, 0, -18, 0, -14, 0,
234 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0,
235 -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
236 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
237 14, 0, 18, 0, 23, 0, -9, 1, -6, 1,
238 -5, 1, -4, 1, -3, 1, -2, 1, -1, 1,
239 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
240 5, 1, 6, 1, 9, 1, -11, 2, -7, 2,
241 -5, 2, -4, 2, -3, 2, -2, 2, -1, 2,
242 0, 2, 1, 2, 2, 2, 3, 2, 4, 2,
243 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
244 -4, 3, -3, 3, -2, 3, -1, 3, 0, 3,
245 1, 3, 2, 3, 3, 3, 4, 3, 6, 3,
246 8, 3, -13, 4, -10, 4, -5, 4, -3, 4,
247 -2, 4, -1, 4, 0, 4, 1, 4, 2, 4,
248 3, 4, 5, 4, 10, 4, 13, 4, -17, 5,
249 -7, 5, -4, 5, -2, 5, -1, 5, 0, 5,
250 1, 5, 2, 5, 4, 5, 7, 5, 17, 5,
251 -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
252 1, 6, 3, 6, 6, 6, 9, 6, 22, 6,
253 -5, 7, -2, 7, 0, 7, 2, 7, 5, 7,
254 -11, 8, -8, 8, -3, 8, 0, 8, 3, 8,
255 8, 8, 11, 8, -6, 9, -1, 9, 1, 9,
256 6, 9, -15, 10, -4, 10, 4, 10, 15, 10,
257 -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
258 19, 12, -19, 13, -4, 13, 4, 13, 0, 14,
259 -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
260 -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
332 const int edge_max = edge_size - 1;
336 else if (y == edge_max)
340 else if (x == edge_max)
369 static void interp_point(int8_t *points,
int x0,
int y0,
int x1,
int y1,
370 int pos,
int npoints)
373 points[0] = (x0 *
pos + x1 * (npoints -
pos) + (npoints >> 1)) / npoints;
374 points[1] = (y0 *
pos + y1 * (npoints -
pos) + (npoints >> 1)) / npoints;
389 static void make_glyphs(int8_t *pglyphs,
const int8_t *xvec,
const int8_t *yvec,
390 const int side_length)
392 const int glyph_size = side_length * side_length;
393 int8_t *pglyph = pglyphs;
409 for (ipoint = 0; ipoint <= npoints; ipoint++) {
417 for (irow = point[1]; irow >= 0; irow--)
418 pglyph[point[0] + irow * side_length] = 1;
422 for (irow = point[1]; irow < side_length; irow++)
423 pglyph[point[0] + irow * side_length] = 1;
427 for (icol = point[0]; icol >= 0; icol--)
428 pglyph[icol + point[1] * side_length] = 1;
432 for (icol = point[0]; icol < side_length; icol++)
433 pglyph[icol + point[1] * side_length] = 1;
450 ctx->buf_size =
ctx->aligned_width *
ctx->aligned_height *
sizeof(
ctx->frm0[0]);
476 &
ctx->stored_frame_size,
ctx->buf_size);
478 if (!
ctx->frm0 || !
ctx->frm1 || !
ctx->frm2 ||
479 (!
ctx->stored_frame && !
ctx->version)) {
489 uint8_t *
dst = &(
ctx->c4tbl[0][0][0]);
490 int i, j, k, l, m, n, o, p;
492 for (
i = 0;
i < 8;
i++) {
493 for (k = 0; k < 8; k++) {
509 for (
i = 0;
i < 8;
i++) {
510 for (k = 0; k < 8; k++) {
523 for (
i = 0;
i < 8;
i++) {
524 for (k = 0; k < 8; k++) {
539 for (
i = 0;
i < 8;
i++) {
540 for (k = 0; k < 8; k++) {
556 uint8_t *
dst = &(
ctx->c4tbl[0][0][0]);
557 int i, j, k, l, m, n, o;
559 for (
i = 1;
i < 16;
i += 2) {
560 for (k = 0; k < 16; k++) {
566 if (j == m || l == m) {
580 for (
i = 0;
i < 16;
i += 2) {
581 for (k = 0; k < 16; k++) {
587 if (m == j || m == l) {
604 uint16_t param2, uint8_t clr)
606 uint8_t
c, *
dst = (uint8_t *)&(
ctx->c4tbl[1][0][0]);
607 uint32_t
loop = param2 * 8;
613 c = bytestream2_get_byteu(gb);
614 *
dst++ = (
c >> 4) + clr;
615 *
dst++ = (
c & 0xf) + clr;
623 if (rotate_code == 2)
657 if (
ctx->subversion < 2)
658 ctx->pal[0] = 0xFF
U << 24;
660 ctx->c4param = 0xffff;
675 int w,
int h, uint8_t param, uint16_t param2,
int codec)
677 const uint16_t p =
ctx->pitch;
678 const uint32_t maxpxo =
ctx->height * p;
683 if (
ctx->c4param != param) {
688 ctx->c4param = param;
699 for (j = 0; j <
w; j += 4) {
701 for (
i = 0;
i <
h;
i += 4) {
702 pxoff = j +
left + ((top +
i) * p);
707 mask = bytestream2_get_byteu(gb);
719 idx = bytestream2_get_byteu(gb);
720 if ((
bit == 0) && (idx == 0x80) && (codec != 5))
723 gs = &(
ctx->c4tbl[
bit][idx][0]);
725 for (k = 0; k < 4; k++) {
726 for (l = 0; l < 4; l++) {
727 if (pxo2 >= 0 && pxo2 < maxpxo) {
737 if (((pxoff - p + k) < 0) || ((pxoff - p + k) >= maxpxo)
738 || ((pxoff + 3 * p) < 0) || ((pxoff + 3 * p) >= maxpxo)
739 || (
i == 0) || (j == 0))
742 for (k = 0; k < 4; k++)
743 *(
dst + pxoff + k) = ((*(
dst + pxoff + k) + *(
dst + pxoff - p + k)) >> 1) | 0x80;
744 *(
dst + pxoff + 1 * p) = (*(
dst + pxoff + 1 * p) + *(
dst + pxoff + 1 * p - 1)) >> 1 | 0x80;
745 *(
dst + pxoff + 2 * p) = (*(
dst + pxoff + 2 * p) + *(
dst + pxoff + 2 * p - 1)) >> 1 | 0x80;
746 *(
dst + pxoff + 3 * p) = (*(
dst + pxoff + 3 * p) + *(
dst + pxoff + 3 * p - 1)) >> 1 | 0x80;
748 for (k = 0; k < 4; k++)
749 *(
dst + pxoff + k) = ((*(
dst + pxoff + k) + *(
dst + pxoff - p + k)) >> 1) & 0x7f;
750 *(
dst + pxoff + 1 * p) = (*(
dst + pxoff + 1 * p) + *(
dst + pxoff + 1 * p - 1)) >> 1;
751 *(
dst + pxoff + 2 * p) = (*(
dst + pxoff + 2 * p) + *(
dst + pxoff + 2 * p - 1)) >> 1;
752 *(
dst + pxoff + 3 * p) = (*(
dst + pxoff + 3 * p) + *(
dst + pxoff + 3 * p - 1)) >> 1;
764 opcode = bytestream2_get_byte(gb);
770 color = bytestream2_get_byte(gb);
786 int width,
int height, uint8_t param, uint16_t param2)
788 const uint32_t maxpxo =
ctx->height *
ctx->pitch;
789 uint8_t *
dst, lut[256],
c;
793 if (
ctx->subversion < 2) {
795 for (
i = 0;
i < 256;
i++)
796 lut[
i] = (
i + param + 0xd0) & 0xff;
797 }
else if (param2 == 256) {
801 }
else if (param2 < 256) {
802 for (
i = 0;
i < 256;
i++)
803 lut[
i] = (
i + param2) & 0xff;
805 memcpy(lut,
ctx->c23lut, 256);
810 dst = (uint8_t *)
ctx->fbuf;
814 pxoff =
left + ((top +
i) *
ctx->pitch);
815 k = bytestream2_get_le16u(gb);
818 while (k > 0 && pc <=
width) {
821 j = bytestream2_get_byteu(gb);
827 if (pxoff >=0 && pxoff < maxpxo) {
829 *(
dst + pxoff) = lut[
c];
844 const uint32_t maxpxo =
ctx->height *
ctx->pitch;
845 uint8_t *
dst = (uint8_t *)
ctx->fbuf,
c;
846 int i, j, k, pc, sk, pxoff;
848 dst = (uint8_t *)
ctx->fbuf;
852 pxoff =
left + ((top +
i) *
ctx->pitch);
853 k = bytestream2_get_le16u(gb);
856 while (k > 0 && pc <=
width) {
859 j = bytestream2_get_le16u(gb);
868 c = bytestream2_get_byteu(gb);
869 if (pxoff >=0 && pxoff < maxpxo) {
888 const int maxpxo =
ctx->height *
ctx->pitch;
889 uint8_t *
dst = (uint8_t *)
ctx->fbuf;
895 len = bytestream2_get_le16u(gb);
898 pxoff =
left + ((top +
i) *
ctx->pitch);
903 code = bytestream2_get_byteu(gb);
907 val = bytestream2_get_byteu(gb);
909 for (j = 0; j <
code; j++) {
910 if (pxoff >= 0 && pxoff < maxpxo)
920 for (j = 0; j <
code; j++) {
921 val = bytestream2_get_byteu(gb);
922 if ((pxoff >= 0) && (pxoff < maxpxo) && (
val || opaque))
929 ctx->rotate_code = 0;
937 uint8_t *
dst = (uint8_t *)
ctx->fbuf, col;
938 int16_t xpos =
left, ypos = top;
941 xpos += bytestream2_get_le16u(gb);
942 ypos += bytestream2_get_byteu(gb);
943 col = bytestream2_get_byteu(gb);
944 if (xpos >= 0 && ypos >= 0 &&
946 *(
dst + xpos + ypos *
ctx->pitch) = col;
954 uint8_t *
dst = (uint8_t *)
ctx->fbuf;
959 if (
w ==
ctx->pitch) {
962 for (
int i = 0;
i <
h;
i++) {
976 for (j = 0; j < 4; j++) {
977 for (
i = 0;
i < 4;
i++) {
991 int i, j, k, l, t,
run,
len,
code,
skip,
mx,
my;
995 int compr = bytestream2_get_byte(&
ctx->gb);
996 int mvoff = bytestream2_get_byte(&
ctx->gb);
997 int seq = bytestream2_get_le16(&
ctx->gb);
998 uint32_t decoded_size = bytestream2_get_le32(&
ctx->gb);
1002 flags = bytestream2_get_byte(&
ctx->gb);
1005 if (decoded_size >
ctx->height *
stride) {
1010 ctx->rotate_code = 0;
1012 if (((seq & 1) || !(
flags & 1)) && (compr && compr != 2)) {
1016 dst = ((uint8_t*)
ctx->frm0);
1017 prev = ((uint8_t*)
ctx->frm2);
1037 for (j = 0; j <
height; j += 4) {
1042 code = bytestream2_get_byte(&
ctx->gb);
1053 code = bytestream2_get_byte(&
ctx->gb);
1056 for (k = 0; k < 4; k++) {
1057 for (l = 0; l < 4; l++) {
1061 code = bytestream2_get_byte(&
ctx->gb);
1067 code = bytestream2_get_byte(&
ctx->gb);
1073 code = bytestream2_get_byte(&
ctx->gb);
1096 memset(
ctx->frm2, 0,
ctx->frm2_size);
1100 for (j = 0; j <
height; j += 4) {
1110 code = bytestream2_get_byteu(&
ctx->gb);
1114 for (k = 0; k < 4; k++)
1116 }
else if ((
flags & 4) && (
code == 0xFE)) {
1119 for (k = 0; k < 4; k++)
1120 memset(
dst +
i + k *
stride, bytestream2_get_byteu(&
ctx->gb), 4);
1121 }
else if ((
flags & 4) && (
code == 0xFD)) {
1124 t = bytestream2_get_byteu(&
ctx->gb);
1125 for (k = 0; k < 4; k++)
1133 if ((compr == 4) && (
code == 0)) {
1136 skip_run = bytestream2_get_byteu(&
ctx->gb);
1146 "Subcodec 37 compression %d", compr);
1154 uint8_t *prev2,
int stride,
int tbl,
int size)
1163 code = bytestream2_get_byteu(&
ctx->gb);
1170 dst[0] = bytestream2_get_byteu(&
ctx->gb);
1171 dst[1] = bytestream2_get_byteu(&
ctx->gb);
1195 t = bytestream2_get_byteu(&
ctx->gb);
1196 for (k = 0; k <
size; k++)
1203 code = bytestream2_get_byteu(&
ctx->gb);
1207 for (k = 0; k <
size; k++)
1208 for (t = 0; t <
size; t++)
1209 dst[t + k *
stride] = colors[!*pglyph++];
1212 for (k = 0; k <
size; k++)
1218 t = bytestream2_get_byte(&
ctx->gb);
1220 for (k = 0; k <
size; k++)
1226 int index = prev2 - (
const uint8_t *)
ctx->frm2;
1236 for (k = 0; k <
size; k++)
1245 uint8_t *p1, *p2, *itbl =
ctx->c47itbl;
1248 for (
i = 0;
i < 256;
i++) {
1250 for (j = 256 -
i; j; j--) {
1251 *p1 = *p2 = bytestream2_get_byte(&
ctx->gb);
1262 uint8_t p1, *
dst, *itbl =
ctx->c47itbl;
1268 p1 = bytestream2_get_byte(&
ctx->gb);
1272 for (j = 2; j <
width; j += 2) {
1273 p1 = bytestream2_get_byte(&
ctx->gb);
1274 px = (px << 8) | p1;
1284 for (j = 0; j <
width; j++) {
1294 uint32_t decoded_size;
1297 uint8_t *
dst = (uint8_t *)
ctx->frm0;
1298 uint8_t *prev1 = (uint8_t *)
ctx->frm1;
1299 uint8_t *prev2 = (uint8_t *)
ctx->frm2;
1302 int seq = bytestream2_get_le16(&
ctx->gb);
1303 int compr = bytestream2_get_byte(&
ctx->gb);
1304 int new_rot = bytestream2_get_byte(&
ctx->gb);
1305 int skip = bytestream2_get_byte(&
ctx->gb);
1308 auxcol[0] = bytestream2_get_byteu(&
ctx->gb);
1309 auxcol[1] = bytestream2_get_byteu(&
ctx->gb);
1310 decoded_size = bytestream2_get_le32(&
ctx->gb);
1313 if (decoded_size >
ctx->height *
stride) {
1325 memset(prev1, auxcol[0],
ctx->height *
stride);
1326 memset(prev2, auxcol[1],
ctx->height *
stride);
1333 for (j = 0; j <
height; j++) {
1344 if (seq ==
ctx->prev_seq + 1) {
1345 for (j = 0; j <
height; j += 8) {
1357 memcpy(
ctx->frm0,
ctx->frm2,
ctx->pitch *
ctx->height);
1360 memcpy(
ctx->frm0,
ctx->frm1,
ctx->pitch *
ctx->height);
1368 "Subcodec 47 compression %d", compr);
1371 if (seq ==
ctx->prev_seq + 1)
1372 ctx->rotate_code = new_rot;
1374 ctx->rotate_code = 0;
1375 ctx->prev_seq = seq;
1385 for (
int i = 0;
i < 4;
i++) {
1386 for (
int j = 0; j < 8; j += 2) {
1389 *((uint16_t *)(
dst +
w * 0 + j)) = p;
1390 *((uint16_t *)(
dst +
w * 1 + j)) = p;
1399 uint8_t opc, sb[16];
1407 opc = bytestream2_get_byteu(&
ctx->gb);
1413 opc = bytestream2_get_byteu(&
ctx->gb);
1414 for (
i = 0;
i < 16;
i++)
1421 mvofs = bytestream2_get_le16(&
ctx->gb);
1422 for (
i = 0;
i < 8;
i++) {
1424 for (k = 0; k < 8; k++)
1425 *(
dst + ofs + k) = *(db + ofs + k + mvofs);
1431 sb[ 5] = bytestream2_get_byteu(&
ctx->gb);
1432 sb[ 7] = bytestream2_get_byteu(&
ctx->gb);
1433 sb[13] = bytestream2_get_byteu(&
ctx->gb);
1434 sb[15] = bytestream2_get_byteu(&
ctx->gb);
1436 sb[0] = sb[1] = sb[4] = sb[5];
1437 sb[2] = sb[3] = sb[6] = sb[7];
1438 sb[8] = sb[9] = sb[12] = sb[13];
1439 sb[10] = sb[11] = sb[14] = sb[15];
1445 for (
i = 0;
i < 8;
i += 4) {
1446 for (k = 0; k < 8; k += 4) {
1447 opc = bytestream2_get_byteu(&
ctx->gb);
1449 for (j = 0; j < 4; j++) {
1450 ofs = (
w * (j +
i)) + k;
1451 for (l = 0; l < 4; l++)
1452 *(
dst + ofs + l) = *(db + ofs + l + mvofs);
1460 for (
i = 0;
i < 8;
i += 4) {
1461 for (k = 0; k < 8; k += 4) {
1462 mvofs = bytestream2_get_le16(&
ctx->gb);
1463 for (j = 0; j < 4; j++) {
1464 ofs = (
w * (j +
i)) + k;
1465 for (l = 0; l < 4; l++)
1466 *(
dst + ofs + l) = *(db + ofs + l + mvofs);
1480 for (
i = 0;
i < 8;
i += 2) {
1481 for (j = 0; j < 8; j += 2) {
1483 opc = bytestream2_get_byteu(&
ctx->gb);
1485 for (l = 0; l < 2; l++) {
1486 *(
dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
1487 *(
dst + ofs + l +
w) = *(db + ofs + l +
w + mvofs);
1495 for (
i = 0;
i < 8;
i += 2) {
1496 for (j = 0; j < 8; j += 2) {
1498 mvofs = bytestream2_get_le16(&
ctx->gb);
1499 for (l = 0; l < 2; l++) {
1500 *(
dst + ofs + l + 0) = *(db + ofs + l + 0 + mvofs);
1501 *(
dst + ofs + l +
w) = *(db + ofs + l +
w + mvofs);
1509 for (
i = 0;
i < 8;
i++) {
1511 for (l = 0; l < 8; l++)
1512 *(
dst + ofs + l) = bytestream2_get_byteu(&
ctx->gb);
1517 for (
i = 0;
i < 8;
i++) {
1519 for (l = 0; l < 8; l++)
1520 *(
dst + ofs + l) = *(db + ofs + l + mvofs);
1529 uint8_t *
dst, *prev;
1530 int compr = bytestream2_get_byte(&
ctx->gb);
1531 int mvidx = bytestream2_get_byte(&
ctx->gb);
1532 int seq = bytestream2_get_le16(&
ctx->gb);
1533 uint32_t decoded_size = bytestream2_get_le32(&
ctx->gb);
1543 flags = bytestream2_get_byte(&
ctx->gb);
1552 dst = (uint8_t*)
ctx->frm0;
1553 prev = (uint8_t*)
ctx->frm2;
1557 memset(prev, 0,
ctx->aligned_height *
width);
1564 for (j = 0; j <
height; j++) {
1574 if (seq ==
ctx->prev_seq + 1) {
1575 for (j = 0; j <
height; j += 8) {
1594 "Subcodec 48 compression %d", compr);
1597 ctx->rotate_code = 1;
1598 ctx->prev_seq = seq;
1604 uint16_t
w,
h, parm2;
1605 uint8_t codec, param;
1609 codec = bytestream2_get_byteu(gb);
1610 param = bytestream2_get_byteu(gb);
1611 left = bytestream2_get_le16u(gb);
1612 top = bytestream2_get_le16u(gb);
1613 w = bytestream2_get_le16u(gb);
1614 h = bytestream2_get_le16u(gb);
1616 parm2 = bytestream2_get_le16u(gb);
1618 if (
w < 1 || h < 1 || w > 800 ||
h > 600 ||
left > 800 || top > 600) {
1620 "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
1626 fsc = (codec == 37 || codec == 47 || codec == 48);
1629 sote = ((
w == 640) && (
h == 272) && (codec == 47));
1633 if (!
ctx->have_dimensions) {
1635 if (
ctx->subversion < 2) {
1639 ctx->have_dimensions = 1;
1640 }
else if (codec == 37 || codec == 47 || codec == 48) {
1644 ctx->have_dimensions = 1;
1655 ctx->have_dimensions = 1;
1656 }
else if (((xres == 424) && (yres == 260)) ||
1657 ((xres == 320) && (yres == 200)) ||
1658 ((xres == 640) && (yres == 480))) {
1659 ctx->have_dimensions = 1;
1666 if (
ctx->width < xres ||
ctx->height < yres) {
1677 if (((
left +
w >
ctx->width) || (top +
h >
ctx->height)) && fsc) {
1684 "resizing too large fobj: c%d %d %d @ %d %d\n", codec,
w,
h,
left, top);
1691 if (
ctx->first_fob) {
1694 memset(
ctx->fbuf, 0,
ctx->frm0_size);
1731 if ((
w ==
ctx->width) && (
h ==
ctx->height)) {
1732 memcpy(
ctx->fbuf,
ctx->frm0,
ctx->fbuf_size);
1734 uint8_t *
dst = (uint8_t *)
ctx->fbuf +
left + top *
ctx->pitch;
1735 const uint8_t *
src = (uint8_t *)
ctx->frm0;
1737 const int ch =
FFMIN(
h,
ctx->height - top);
1738 if ((cw > 0) && (ch > 0) && (
left >= 0) && (top >= 0)) {
1739 for (
int i = 0;
i < ch;
i++) {
1751 uint8_t *sf =
ctx->stored_frame;
1752 int xoff, yoff,
left, top,
ret;
1761 xoff = bytestream2_get_le16u(&
ctx->gb);
1762 yoff = bytestream2_get_le16u(&
ctx->gb);
1767 xoff = bytestream2_get_be32u(&
ctx->gb);
1768 yoff = bytestream2_get_be32u(&
ctx->gb);
1771 sz = *(uint32_t *)(sf + 0);
1772 if ((sz > 0) && (sz <=
ctx->stored_frame_size - 4)) {
1777 *(int16_t *)(sf + 4 + 4) =
av_le2ne16(top + yoff);
1800 int16_t *dp =
ctx->delta_pal;
1801 uint32_t *pal =
ctx->pal;
1807 cmd = bytestream2_get_be16(&
ctx->gb);
1811 c[0] = (*pal >> 16) & 0xFF;
1812 c[1] = (*pal >> 8) & 0xFF;
1813 c[2] = (*pal >> 0) & 0xFF;
1814 for (j = 0; j < 3; j++) {
1815 int cl = (
c[j] * 129) + *dp++;
1818 *pal++ = 0xFF
U << 24 |
c[0] << 16 |
c[1] << 8 |
c[2];
1820 }
else if (cmd == 2) {
1823 "Incorrect palette change block size %"PRIu32
".\n",
size);
1827 dp[
i] = bytestream2_get_le16u(&
ctx->gb);
1831 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
1832 if (
ctx->subversion < 2)
1833 ctx->pal[0] = 0xFF
U << 24;
1841 uint16_t *frm =
ctx->frm0;
1848 for (y = 0; y <
ctx->height; y++) {
1849 for (x = 0; x <
ctx->width; x++)
1850 frm[x] = bytestream2_get_le16u(&
ctx->gb);
1862 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size, ptrdiff_t pitch)
1864 uint8_t *
dst = (uint8_t *)pdest;
1865 uint8_t *
src = (uint8_t *)psrc;
1866 ptrdiff_t
stride = pitch * 2;
1868 switch (block_size) {
1885 pitch -= block_size;
1886 for (y = 0; y < block_size; y++, pdest += pitch)
1887 for (x = 0; x < block_size; x++)
1892 uint16_t fg_color, uint16_t bg_color,
int block_size,
1896 uint16_t colors[2] = { fg_color, bg_color };
1904 pglyph = block_size == 8 ?
ctx->p8x8glyphs[
index] :
ctx->p4x4glyphs[
index];
1905 pitch -= block_size;
1907 for (y = 0; y < block_size; y++,
dst += pitch)
1908 for (x = 0; x < block_size; x++)
1909 *
dst++ = colors[*pglyph++];
1915 uint16_t *
dst =
ctx->frm0 + cx + cy *
ctx->pitch;
1917 if (block_size == 2) {
1923 indices = bytestream2_get_le32u(&
ctx->gb);
1924 dst[0] =
ctx->codebook[indices & 0xFF];
1926 dst[1] =
ctx->codebook[indices & 0xFF];
1928 dst[pitch] =
ctx->codebook[indices & 0xFF];
1930 dst[pitch + 1] =
ctx->codebook[indices & 0xFF];
1932 uint16_t fgcolor, bgcolor;
1938 glyph = bytestream2_get_byteu(&
ctx->gb);
1939 bgcolor =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
1940 fgcolor =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
1949 uint16_t *
dst =
ctx->frm0 + cx + cy *
ctx->pitch;
1951 if (block_size == 2) {
1955 dst[0] = bytestream2_get_le16u(&
ctx->gb);
1956 dst[1] = bytestream2_get_le16u(&
ctx->gb);
1957 dst[pitch] = bytestream2_get_le16u(&
ctx->gb);
1958 dst[pitch + 1] = bytestream2_get_le16u(&
ctx->gb);
1960 uint16_t fgcolor, bgcolor;
1966 glyph = bytestream2_get_byteu(&
ctx->gb);
1967 bgcolor = bytestream2_get_le16u(&
ctx->gb);
1968 fgcolor = bytestream2_get_le16u(&
ctx->gb);
1978 int start_pos = cx +
mx + (cy +
my) *
ctx->pitch;
1979 int end_pos = start_pos + (block_size - 1) * (
ctx->pitch + 1);
1981 int good = start_pos >= 0 && end_pos < (
ctx->buf_size >> 1);
1985 "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
1986 cx +
mx, cy +
my, cx, cy, block_size);
1999 opcode = bytestream2_get_byteu(&
ctx->gb);
2008 ctx->frm2 + cx +
mx +
ctx->pitch * (cy +
my),
2009 blk_size,
ctx->pitch);
2015 index = bytestream2_get_le16u(&
ctx->gb);
2022 ctx->frm2 + cx +
mx +
ctx->pitch * (cy +
my),
2023 blk_size,
ctx->pitch);
2028 ctx->frm1 + cx +
ctx->pitch * cy,
2029 blk_size,
ctx->pitch);
2043 ctx->small_codebook[opcode - 0xf9], blk_size,
ctx->pitch);
2049 ctx->codebook[bytestream2_get_byteu(&
ctx->gb)], blk_size,
ctx->pitch);
2055 bytestream2_get_le16u(&
ctx->gb), blk_size,
ctx->pitch);
2058 if (blk_size == 2) {
2080 for (cy = 0; cy <
ctx->aligned_height; cy += 8)
2081 for (cx = 0; cx <
ctx->aligned_width; cx += 8)
2090 memcpy(
ctx->frm0,
ctx->frm2,
ctx->frm2_size);
2096 memcpy(
ctx->frm0,
ctx->frm1,
ctx->frm1_size);
2106 uint8_t *
dst = (uint8_t*)
ctx->frm0;
2112 npixels =
ctx->npixels;
2125 int npixels =
ctx->npixels;
2126 uint16_t *frm =
ctx->frm0;
2133 *frm++ =
ctx->codebook[bytestream2_get_byteu(&
ctx->gb)];
2140 uint16_t *pdest =
ctx->frm0;
2142 long npixels =
ctx->npixels;
2145 if (!
ctx->rle_buf) {
2149 rsrc =
ctx->rle_buf;
2155 *pdest++ =
ctx->codebook[*rsrc++];
2178 hdr->
width = bytestream2_get_le32u(&
ctx->gb);
2179 hdr->
height = bytestream2_get_le32u(&
ctx->gb);
2186 hdr->
seq_num = bytestream2_get_le16u(&
ctx->gb);
2187 hdr->
codec = bytestream2_get_byteu(&
ctx->gb);
2192 for (
i = 0;
i < 4;
i++)
2193 ctx->small_codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
2199 for (
i = 0;
i < 256;
i++)
2200 ctx->codebook[
i] = bytestream2_get_le16u(&
ctx->gb);
2218 const uint8_t *
src = hdr ? (uint8_t *)
ctx->frm0 : (uint8_t *)
ctx->fbuf;
2220 ptrdiff_t dstpitch, srcpitch =
ctx->pitch * (hdr ?
sizeof(
ctx->frm0[0]) : 1);
2225 dst =
ctx->frame->data[0];
2226 dstpitch =
ctx->frame->linesize[0];
2229 memcpy(
dst,
src, srcpitch);
2246 if (!
ctx->version) {
2247 int to_store = 0, have_img = 0;
2255 sig = bytestream2_get_be32u(&
ctx->gb);
2256 size = bytestream2_get_be32u(&
ctx->gb);
2264 case MKBETAG(
'N',
'P',
'A',
'L'):
2267 "Incorrect palette block size %"PRIu32
".\n",
size);
2271 ctx->pal[
i] = 0xFFU << 24 | bytestream2_get_be24u(&
ctx->gb);
2272 if (
ctx->subversion < 2)
2273 ctx->pal[0] = 0xFF
U << 24;
2275 case MKBETAG(
'F',
'O',
'B',
'J'):
2289 if (
ctx->subversion < 2) {
2290 if (
size + 4 <=
ctx->stored_frame_size) {
2293 *(uint32_t *)(
ctx->stored_frame) =
size;
2301 memcpy(
ctx->stored_frame,
ctx->fbuf,
ctx->buf_size);
2305 case MKBETAG(
'X',
'P',
'A',
'L'):
2309 case MKBETAG(
'S',
'T',
'O',
'R'):
2312 case MKBETAG(
'F',
'T',
'C',
'H'):
2313 if (
ctx->subversion < 2) {
2317 memcpy(
ctx->fbuf,
ctx->stored_frame,
ctx->buf_size);
2324 "Unknown/unsupported chunk %"PRIx32
".\n", sig);
2335 if (0 != bytestream2_get_byteu(&
ctx->gb))
2343 memcpy(
ctx->frame->data[1],
ctx->pal, 1024);
2366 "Subcodec %d: error decoding frame.\n",
header.codec);
2380 if (
ctx->rotate_code)