]> git.nihav.org Git - nihav.git/blob - nihav-duck/src/codecs/truemotion1.rs
remove trailing whitespaces
[nihav.git] / nihav-duck / src / codecs / truemotion1.rs
1 use nihav_core::codecs::*;
2 use nihav_core::io::byteio::*;
3
4 struct MaskState<'a> {
5 is_intra: bool,
6 pos: usize,
7 row_pos: usize,
8 row_size: usize,
9 mask: u8,
10 src: &'a [u8],
11 }
12
13 impl<'a> MaskState<'a> {
14 fn new(is_intra: bool, src: &'a [u8], row_size: usize) -> Self {
15 Self { is_intra, src, pos: 0, row_pos: 0, row_size, mask: 0x01 }
16 }
17 fn get_next(&mut self) -> bool {
18 if self.is_intra {
19 true
20 } else {
21 let res = (self.src[self.pos] & self.mask) == 0;
22 self.mask <<= 1;
23 if self.mask == 0 {
24 self.pos += 1;
25 self.mask = 0x01;
26 }
27 res
28 }
29 }
30 fn reset_row(&mut self) {
31 self.pos = self.row_pos;
32 self.mask = 0x01;
33 }
34 fn next_row(&mut self) {
35 self.row_pos += self.row_size;
36 self.reset_row();
37 }
38 }
39
40 struct IndexState<'a> {
41 src: &'a [u8],
42 pos: usize,
43 vec_idx: usize,
44 vec_subidx: usize,
45 }
46
47 impl<'a> IndexState<'a> {
48 fn new(src: &'a [u8]) -> Self {
49 Self { src, pos: 0, vec_idx: 0, vec_subidx: 0 }
50 }
51 fn get_next(&mut self) -> DecoderResult<()> {
52 validate!(self.pos < self.src.len());
53 self.vec_idx = self.src[self.pos] as usize;
54 self.vec_subidx = 0;
55 self.pos += 1;
56 Ok(())
57 }
58 fn get_pred(&self, dtab: &[[u32; 4]; 256]) -> u32 { dtab[self.vec_idx][self.vec_subidx] }
59 fn get_diff16(&mut self, dtab: &[[u32; 4]; 256]) -> DecoderResult<u32> {
60 let pred1 = self.get_pred(dtab);
61 let mut pred = pred1 >> 1;
62 if (pred1 & 1) != 0 {
63 self.get_next()?;
64 if self.vec_idx == 0 {
65 self.get_next()?;
66 let pred2 = self.get_pred(dtab);
67 pred = pred.wrapping_add((pred2 >> 1).wrapping_mul(5));
68 if (pred2 & 1) != 0 {
69 self.get_next()?;
70 } else {
71 self.vec_subidx += 1;
72 }
73 }
74 } else {
75 self.vec_subidx += 1;
76 }
77 Ok(pred)
78 }
79 fn get_diff16_noesc(&mut self, dtab: &[[u32; 4]; 256]) -> DecoderResult<u32> {
80 let pred1 = self.get_pred(dtab);
81 let pred = pred1 >> 1;
82 if (pred1 & 1) != 0 {
83 self.get_next()?;
84 } else {
85 self.vec_subidx += 1;
86 }
87 Ok(pred)
88 }
89 fn get_diff24(&mut self, dtab: &[[u32; 4]; 256], esctab: &[[u32; 4]; 256]) -> DecoderResult<u32> {
90 let pred1 = self.get_pred(dtab);
91 let mut pred = pred1 >> 1;
92 if (pred1 & 1) != 0 {
93 self.get_next()?;
94 if self.vec_idx == 0 {
95 self.get_next()?;
96 let pred2 = self.get_pred(esctab);
97 pred = pred.wrapping_add(pred2 >> 1);
98 if (pred2 & 1) != 0 {
99 self.get_next()?;
100 } else {
101 self.vec_subidx += 1;
102 }
103 }
104 } else {
105 self.vec_subidx += 1;
106 }
107 Ok(pred)
108 }
109 }
110
111 struct DeltaTables {
112 ydt: [[u32; 4]; 256],
113 cdt: [[u32; 4]; 256],
114 fat_ydt: [[u32; 4]; 256],
115 fat_cdt: [[u32; 4]; 256],
116 adt: [[u32; 4]; 256],
117 }
118
119 impl Default for DeltaTables {
120 fn default() -> Self {
121 Self {
122 ydt: [[0; 4]; 256],
123 cdt: [[0; 4]; 256],
124 fat_ydt: [[0; 4]; 256],
125 fat_cdt: [[0; 4]; 256],
126 adt: [[0; 4]; 256],
127 }
128 }
129 }
130
131 struct FrameBuf {
132 last16: Option<NAVideoBufferRef<u16>>,
133 last24: Option<NAVideoBufferRef<u8>>,
134 }
135
136 impl FrameBuf {
137 fn set16(&mut self, buf: NAVideoBufferRef<u16>) { self.last16 = Some(buf); }
138 fn set24(&mut self, buf: NAVideoBufferRef<u8>) { self.last24 = Some(buf); }
139 fn get16(&mut self) -> Option<NAVideoBufferRef<u16>> {
140 if let Some(ref mut frm) = self.last16 {
141 let newfrm = frm.copy_buffer();
142 *frm = newfrm.clone().into_ref();
143 Some(newfrm.into_ref())
144 } else {
145 None
146 }
147 }
148 fn get24(&mut self) -> Option<NAVideoBufferRef<u8>> {
149 if let Some(ref mut frm) = self.last24 {
150 let newfrm = frm.copy_buffer();
151 *frm = newfrm.clone().into_ref();
152 Some(newfrm.into_ref())
153 } else {
154 None
155 }
156 }
157 fn reset(&mut self) {
158 self.last16 = None;
159 self.last24 = None;
160 }
161 }
162
163 impl Default for FrameBuf {
164 fn default() -> Self {
165 Self { last16: None, last24: None }
166 }
167 }
168
169 #[derive(Default)]
170 struct TM1Decoder {
171 info: NACodecInfoRef,
172 last_delta_set: usize,
173 last_table_idx: usize,
174 delta_tables: DeltaTables,
175 blk_w: usize,
176 blk_h: usize,
177 vert_pred: Vec<u32>,
178 lastframe: FrameBuf,
179 }
180
181 const RGB555_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB(RGBSubmodel::RGB), components: 3,
182 comp_info: [
183 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 5, shift: 10, comp_offs: 0, next_elem: 2 }),
184 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 5, shift: 5, comp_offs: 0, next_elem: 2 }),
185 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 5, shift: 0, comp_offs: 0, next_elem: 2 }),
186 None, None],
187 elem_size: 2, be: false, alpha: false, palette: false };
188 const BGR0_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB(RGBSubmodel::RGB), components: 3,
189 comp_info: [
190 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 2, next_elem: 4 }),
191 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 1, next_elem: 4 }),
192 Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 0, next_elem: 4 }),
193 None, None],
194 elem_size: 4, be: false, alpha: false, palette: false };
195
196 impl TM1Decoder {
197 fn new() -> Self { Self::default() }
198 fn set_delta_tables(&mut self, delta_set: usize, table_idx: usize, is_24bit: bool) {
199 if (self.last_delta_set == delta_set) && (self.last_table_idx == table_idx) { return; }
200 let ydt = &DUCK_Y_DELTAS[delta_set];
201 let yfdt = DUCK_Y_FAT_DELTAS[delta_set];
202 let cdt = &DUCK_C_DELTAS[delta_set];
203 let cfdt = DUCK_C_FAT_DELTAS[delta_set];
204 let vec = DUCK_VECTABLES[table_idx - 1];
205
206 let mut vec_iter = vec.iter();
207 for i in 0..256 {
208 let len = (*vec_iter.next().unwrap() as usize) >> 1;
209 for j in 0..len {
210 let pair = vec_iter.next().unwrap();
211 let lo = (pair >> 4) as usize;
212 let hi = (pair & 0xF) as usize;
213 if !is_24bit {
214 let d_lo = ydt[lo] + (ydt[lo] << 5) + (ydt[lo] << 10);
215 let d_hi = ydt[hi] + (ydt[hi] << 5) + (ydt[hi] << 10);
216 self.delta_tables.ydt[i][j] = ((d_lo + (d_hi << 16)) << 1) as u32;
217 let d_c = cdt[hi] + (cdt[lo] << 10);
218 self.delta_tables.cdt[i][j] = ((d_c + (d_c << 16)) << 1) as u32;
219 let d_a = lo + hi * 5;
220 self.delta_tables.adt[i][j] = ((d_a << 16) << 1) as u32;
221 } else {
222 self.delta_tables.ydt[i][j] = ((ydt [lo] + (ydt [hi] << 8) + (ydt [hi] << 16)) << 1) as u32;
223 self.delta_tables.fat_ydt[i][j] = ((yfdt[lo] + (yfdt[hi] << 8) + (yfdt[hi] << 16)) << 1) as u32;
224 self.delta_tables.cdt[i][j] = ((cdt [hi] + (cdt [lo] << 16)) << 1) as u32;
225 self.delta_tables.fat_cdt[i][j] = ((cfdt[hi] + (cfdt[lo] << 16)) << 1) as u32;
226 }
227 }
228 self.delta_tables.ydt[i][len - 1] |= 1;
229 self.delta_tables.cdt[i][len - 1] |= 1;
230 self.delta_tables.adt[i][len - 1] |= 1;
231 self.delta_tables.fat_ydt[i][len - 1] |= 1;
232 self.delta_tables.fat_cdt[i][len - 1] |= 1;
233 }
234
235 self.last_delta_set = delta_set;
236 self.last_table_idx = table_idx;
237 }
238 fn decode_16bit(&mut self, dst: &mut [u16], stride: usize, width: usize, height: usize, mask: &mut MaskState<'_>, index: &mut IndexState<'_>) -> DecoderResult<()> {
239 let mut off = 0;
240 index.get_next()?;
241 for y in 0..height {
242 let mut hor_pred: u32 = 0;
243 for x in (0..width).step_by(4) {
244 if mask.get_next() {
245 match y & 3 {
246 0 => {
247 let dc0 = index.get_diff16(&self.delta_tables.cdt)?;
248 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
249 hor_pred = hor_pred.wrapping_add(dc0);
250 hor_pred = hor_pred.wrapping_add(dy0);
251 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
252 self.vert_pred[(x >> 1) + 0] = cur;
253 dst[off + x + 0] = cur as u16;
254 dst[off + x + 1] = (cur >> 16) as u16;
255 if self.blk_w == 2 {
256 let dc1 = index.get_diff16(&self.delta_tables.cdt)?;
257 hor_pred = hor_pred.wrapping_add(dc1);
258 }
259 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
260 hor_pred = hor_pred.wrapping_add(dy1);
261 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
262 self.vert_pred[(x >> 1) + 1] = cur;
263 dst[off + x + 2] = cur as u16;
264 dst[off + x + 3] = (cur >> 16) as u16;
265 },
266 1 | 3 => {
267 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
268 hor_pred = hor_pred.wrapping_add(dy0);
269 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
270 self.vert_pred[(x >> 1) + 0] = cur;
271 dst[off + x + 0] = cur as u16;
272 dst[off + x + 1] = (cur >> 16) as u16;
273 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
274 hor_pred = hor_pred.wrapping_add(dy1);
275 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
276 self.vert_pred[(x >> 1) + 1] = cur;
277 dst[off + x + 2] = cur as u16;
278 dst[off + x + 3] = (cur >> 16) as u16;
279 },
280 2 => {
281 if self.blk_h == 2 {
282 let dc0 = index.get_diff16(&self.delta_tables.cdt)?;
283 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
284 hor_pred = hor_pred.wrapping_add(dc0);
285 hor_pred = hor_pred.wrapping_add(dy0);
286 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
287 self.vert_pred[(x >> 1) + 0] = cur;
288 dst[off + x + 0] = cur as u16;
289 dst[off + x + 1] = (cur >> 16) as u16;
290 if self.blk_w == 2 {
291 let dc1 = index.get_diff16(&self.delta_tables.cdt)?;
292 hor_pred = hor_pred.wrapping_add(dc1);
293 }
294 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
295 hor_pred = hor_pred.wrapping_add(dy1);
296 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
297 self.vert_pred[(x >> 1) + 1] = cur;
298 dst[off + x + 2] = cur as u16;
299 dst[off + x + 3] = (cur >> 16) as u16;
300 } else {
301 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
302 hor_pred = hor_pred.wrapping_add(dy0);
303 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
304 self.vert_pred[(x >> 1) + 0] = cur;
305 dst[off + x + 0] = cur as u16;
306 dst[off + x + 1] = (cur >> 16) as u16;
307 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
308 hor_pred = hor_pred.wrapping_add(dy1);
309 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
310 self.vert_pred[(x >> 1) + 1] = cur;
311 dst[off + x + 2] = cur as u16;
312 dst[off + x + 3] = (cur >> 16) as u16;
313 }
314 },
315 _ => unreachable!(),
316 };
317 } else {
318 let cur = u32::from(dst[off + x + 0]) | (u32::from(dst[off + x + 1]) << 16);
319 self.vert_pred[(x >> 1) + 0] = cur;
320 let cur = u32::from(dst[off + x + 2]) | (u32::from(dst[off + x + 3]) << 16);
321 hor_pred = cur.wrapping_sub(self.vert_pred[(x >> 1) + 1]);
322 self.vert_pred[(x >> 1) + 1] = cur;
323 }
324 }
325 if (y & 3) != 3 {
326 mask.reset_row();
327 } else {
328 mask.next_row();
329 }
330 off += stride;
331 }
332 Ok(())
333 }
334 fn decode_sprite(&mut self, dst: &mut [u16], stride: usize, width: usize, height: usize, mask: &mut MaskState<'_>, index: &mut IndexState<'_>) -> DecoderResult<()> {
335 let mut off = 0;
336 let _ = index.get_next();
337 for y in 0..height {
338 let mut hor_pred: u32 = 0;
339 for x in (0..width).step_by(4) {
340 let is_tm = !mask.get_next();
341 let is_sprite = !mask.get_next();
342 if is_tm {
343 if (y & 3) == 0 {
344 let dc0 = index.get_diff16(&self.delta_tables.cdt)?;
345 hor_pred = hor_pred.wrapping_add(dc0);
346 }
347 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
348 hor_pred = hor_pred.wrapping_add(dy0);
349 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
350 self.vert_pred[(x >> 1) + 0] = cur;
351 dst[off + x + 0] = cur as u16;
352 dst[off + x + 1] = (cur >> 16) as u16;
353 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
354 hor_pred = hor_pred.wrapping_add(dy1);
355 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
356 self.vert_pred[(x >> 1) + 1] = cur;
357 dst[off + x + 2] = cur as u16;
358 dst[off + x + 3] = (cur >> 16) as u16;
359 } else if is_sprite {
360 if (y & 3) == 0 {
361 let dc0 = index.get_diff16(&self.delta_tables.cdt)?;
362 hor_pred = hor_pred.wrapping_add(dc0);
363 }
364 let dy0 = index.get_diff16(&self.delta_tables.ydt)?;
365 hor_pred = hor_pred.wrapping_add(dy0);
366 let _da0 = index.get_diff16_noesc(&self.delta_tables.adt)?;
367 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 0]);
368 self.vert_pred[(x >> 1) + 0] = cur;
369 dst[off + x + 0] = cur as u16;
370 dst[off + x + 1] = (cur >> 16) as u16;
371 let dy1 = index.get_diff16(&self.delta_tables.ydt)?;
372 hor_pred = hor_pred.wrapping_add(dy1);
373 let _da1 = index.get_diff16_noesc(&self.delta_tables.adt)?;
374 let cur = hor_pred.wrapping_add(self.vert_pred[(x >> 1) + 1]);
375 self.vert_pred[(x >> 1) + 1] = cur;
376 dst[off + x + 2] = cur as u16;
377 dst[off + x + 3] = (cur >> 16) as u16;
378 } else {
379 hor_pred = 0;
380 dst[off + x + 0] = 0;
381 dst[off + x + 1] = 0;
382 dst[off + x + 2] = 0;
383 dst[off + x + 3] = 0;
384 self.vert_pred[(x >> 1) + 0] = 0;
385 self.vert_pred[(x >> 1) + 1] = 0;
386 }
387 }
388 if (y & 3) != 3 {
389 mask.reset_row();
390 } else {
391 mask.next_row();
392 }
393 off += stride;
394 }
395 Ok(())
396 }
397 fn decode_24bit(&mut self, dst: &mut [u8], stride: usize, width: usize, height: usize, mask: &mut MaskState<'_>, index: &mut IndexState<'_>) -> DecoderResult<()> {
398 let mut off = 0;
399 index.get_next()?;
400 for y in 0..height {
401 let mut hor_pred: u32 = 0;
402 for x in (0..width).step_by(2) {
403 if mask.get_next() {
404 match y & 3 {
405 0 => {
406 let dc0 = index.get_diff24(&self.delta_tables.cdt, &self.delta_tables.fat_cdt)?;
407 let dy0 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
408 hor_pred = hor_pred.wrapping_add(dc0);
409 hor_pred = hor_pred.wrapping_add(dy0);
410 let cur = hor_pred.wrapping_add(self.vert_pred[x + 0]);
411 self.vert_pred[x + 0] = cur;
412 dst[off + x*4 + 0] = cur as u8;
413 dst[off + x*4 + 1] = (cur >> 8) as u8;
414 dst[off + x*4 + 2] = (cur >> 16) as u8;
415 dst[off + x*4 + 3] = 0;
416 if self.blk_w == 2 {
417 let dc1 = index.get_diff24(&self.delta_tables.cdt, &self.delta_tables.fat_cdt)?;
418 hor_pred = hor_pred.wrapping_add(dc1);
419 }
420 let dy1 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
421 hor_pred = hor_pred.wrapping_add(dy1);
422 let cur = hor_pred.wrapping_add(self.vert_pred[x + 1]);
423 self.vert_pred[x + 1] = cur;
424 dst[off + x*4 + 4] = cur as u8;
425 dst[off + x*4 + 5] = (cur >> 8) as u8;
426 dst[off + x*4 + 6] = (cur >> 16) as u8;
427 dst[off + x*4 + 7] = 0;
428 },
429 1 | 3 => {
430 let dy0 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
431 hor_pred = hor_pred.wrapping_add(dy0);
432 let cur = hor_pred.wrapping_add(self.vert_pred[x + 0]);
433 self.vert_pred[x + 0] = cur;
434 dst[off + x*4 + 0] = cur as u8;
435 dst[off + x*4 + 1] = (cur >> 8) as u8;
436 dst[off + x*4 + 2] = (cur >> 16) as u8;
437 dst[off + x*4 + 3] = 0;
438 let dy1 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
439 hor_pred = hor_pred.wrapping_add(dy1);
440 let cur = hor_pred.wrapping_add(self.vert_pred[x + 1]);
441 self.vert_pred[x + 1] = cur;
442 dst[off + x*4 + 4] = cur as u8;
443 dst[off + x*4 + 5] = (cur >> 8) as u8;
444 dst[off + x*4 + 6] = (cur >> 16) as u8;
445 dst[off + x*4 + 7] = 0;
446 },
447 2 => {
448 if self.blk_h == 2 {
449 let dc0 = index.get_diff24(&self.delta_tables.cdt, &self.delta_tables.fat_cdt)?;
450 let dy0 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
451 hor_pred = hor_pred.wrapping_add(dc0);
452 hor_pred = hor_pred.wrapping_add(dy0);
453 let cur = hor_pred.wrapping_add(self.vert_pred[x + 0]);
454 self.vert_pred[x + 0] = cur;
455 dst[off + x*4 + 0] = cur as u8;
456 dst[off + x*4 + 1] = (cur >> 8) as u8;
457 dst[off + x*4 + 2] = (cur >> 16) as u8;
458 dst[off + x*4 + 3] = 0;
459 if self.blk_w == 2 {
460 let dc1 = index.get_diff24(&self.delta_tables.cdt, &self.delta_tables.fat_cdt)?;
461 hor_pred = hor_pred.wrapping_add(dc1);
462 }
463 let dy1 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
464 hor_pred = hor_pred.wrapping_add(dy1);
465 let cur = hor_pred.wrapping_add(self.vert_pred[x + 1]);
466 self.vert_pred[x + 1] = cur;
467 dst[off + x*4 + 4] = cur as u8;
468 dst[off + x*4 + 5] = (cur >> 8) as u8;
469 dst[off + x*4 + 6] = (cur >> 16) as u8;
470 dst[off + x*4 + 7] = 0;
471 } else {
472 let dy0 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
473 hor_pred = hor_pred.wrapping_add(dy0);
474 let cur = hor_pred.wrapping_add(self.vert_pred[x + 0]);
475 self.vert_pred[x + 0] = cur;
476 dst[off + x*4 + 0] = cur as u8;
477 dst[off + x*4 + 1] = (cur >> 8) as u8;
478 dst[off + x*4 + 2] = (cur >> 16) as u8;
479 dst[off + x*4 + 3] = 0;
480 let dy1 = index.get_diff24(&self.delta_tables.ydt, &self.delta_tables.fat_ydt)?;
481 hor_pred = hor_pred.wrapping_add(dy1);
482 let cur = hor_pred.wrapping_add(self.vert_pred[x + 1]);
483 self.vert_pred[x + 1] = cur;
484 dst[off + x*4 + 4] = cur as u8;
485 dst[off + x*4 + 5] = (cur >> 8) as u8;
486 dst[off + x*4 + 6] = (cur >> 16) as u8;
487 dst[off + x*4 + 7] = 0;
488 }
489 },
490 _ => unreachable!(),
491 };
492 } else {
493 let cur = u32::from(dst[off + x*4 + 0])
494 | (u32::from(dst[off + x*4 + 1]) << 8)
495 | (u32::from(dst[off + x*4 + 2]) << 16)
496 | (u32::from(dst[off + x*4 + 3]) << 24);
497 self.vert_pred[x + 0] = cur;
498 let cur = u32::from(dst[off + x*4 + 4])
499 | (u32::from(dst[off + x*4 + 5]) << 8)
500 | (u32::from(dst[off + x*4 + 6]) << 16)
501 | (u32::from(dst[off + x*4 + 7]) << 24);
502 hor_pred = cur.wrapping_sub(self.vert_pred[x + 1]);
503 self.vert_pred[x + 1] = cur;
504 }
505 }
506 if (y & 3) != 3 {
507 mask.reset_row();
508 } else {
509 mask.next_row();
510 }
511 off += stride;
512 }
513 Ok(())
514 }
515 }
516
517 impl NADecoder for TM1Decoder {
518 fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
519 if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
520 let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT));
521 self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
522 Ok(())
523 } else {
524 Err(DecoderError::InvalidData)
525 }
526 }
527 fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
528 let src = pkt.get_buffer();
529 validate!(src.len() > 10);
530 let hdr_size = (src[0].rotate_left(3) & 0x7F) as usize;
531 validate!(hdr_size >= 12 && hdr_size < src.len());
532 let mut hdr: [u8; 127] = [0; 127];
533 for i in 1..hdr_size {
534 hdr[i - 1] = src[i] ^ src[i + 1];
535 }
536 let mut mr = MemoryReader::new_read(&hdr[0..hdr_size-1]);
537 let mut br = ByteReader::new(&mut mr);
538
539 let tm1type = br.read_byte()? as usize;
540 let delta_set = br.read_byte()? as usize;
541 let table_idx = br.read_byte()? as usize;
542 let height = br.read_u16le()? as usize;
543 let width = br.read_u16le()? as usize;
544 let _frameno = br.read_u16le()? as usize;
545 let version = br.read_byte()?;
546 let meta_type = br.read_byte()?;
547 validate!(width > 0 && height > 0);
548 let is_intra;
549 let mut is_sprite = false;
550 let mut spr_xoff = 0;
551 let mut spr_yoff = 0;
552 let mut spr_width = 0;
553 let mut spr_height = 0;
554 if version >= 2 {
555 validate!(meta_type <= 3);
556 if meta_type >= 2 {
557 let frameinfo = br.read_byte()?;
558 let _control = br.read_byte()?;
559
560 is_intra = ((frameinfo & 0x10) != 0) || ((frameinfo & 0x08) == 0);
561 } else {
562 is_intra = true;
563 }
564 if meta_type == 3 {
565 spr_xoff = br.read_u16le()? as usize;
566 spr_yoff = br.read_u16le()? as usize;
567 spr_width = br.read_u16le()? as usize;
568 spr_height = br.read_u16le()? as usize;
569 is_sprite = true;
570 }
571 } else {
572 is_intra = true;
573 }
574 validate!(tm1type < TM1_COMPR_TYPES.len());
575 let cinfo = TM1_COMPR_TYPES[tm1type];
576 if cinfo.is_none() {
577 //check for missing ref
578 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::None);
579 frm.set_keyframe(false);
580 frm.set_frame_type(FrameType::Skip);
581 return Ok(frm.into_ref());
582 }
583 let compr_info = cinfo.unwrap();
584 let is_24bit = !is_sprite && compr_info.is_24bit;
585
586 let vec_idx = if ((tm1type & 1) != 0) && (meta_type > 0) { 1 } else { table_idx };
587 validate!((delta_set < DUCK_Y_DELTAS.len()) && (vec_idx > 0) && (vec_idx <= DUCK_VECTABLES.len()));
588 self.set_delta_tables(delta_set, vec_idx, is_24bit);
589
590 let out_width = if is_24bit { width >> 1 } else { width };
591 let mask_row_size = if is_sprite {
592 ((spr_width >> 2) + 3) >> 2
593 } else if is_intra {
594 0
595 } else {
596 ((width >> 2) + 7) >> 3
597 };
598 let mask_size = mask_row_size * (if is_sprite { spr_height >> 2 } else { height >> 2 });
599 let mask_bits = &src[hdr_size..][..mask_size];
600 let index_bytes = &src[hdr_size+mask_size..];
601 validate!(src.len() >= hdr_size + mask_size);
602 self.vert_pred.truncate(0);
603 self.vert_pred.resize(out_width, 0);
604
605 if is_intra || is_sprite {
606 let fmt = if is_24bit { BGR0_FORMAT } else { RGB555_FORMAT };
607 let myinfo = NAVideoInfo::new(out_width, height, false, fmt);
608 let bufinfo = alloc_video_buffer(myinfo, 2)?;
609 self.lastframe.reset();
610 if !is_24bit {
611 self.lastframe.set16(bufinfo.get_vbuf16().unwrap());
612 } else {
613 self.lastframe.set24(bufinfo.get_vbuf().unwrap());
614 }
615 }
616
617 self.blk_w = compr_info.block_w;
618 self.blk_h = compr_info.block_h;
619 let mut mask = MaskState::new(is_intra && !is_sprite, &mask_bits, mask_row_size);
620 let mut index = IndexState::new(&index_bytes);
621 let bufinfo;
622 if !is_24bit {
623 if let Some(mut buf) = self.lastframe.get16() {
624 let stride = buf.get_stride(0);
625 {
626 let data = buf.get_data_mut().unwrap();
627 if !is_sprite {
628 self.decode_16bit(data.as_mut_slice(), stride, out_width, height, &mut mask, &mut index)?;
629 } else {
630 validate!(spr_xoff + spr_width <= out_width);
631 validate!(spr_yoff + spr_height <= height);
632 for el in data.iter_mut() { *el = 0; }
633 let dst = &mut data[spr_xoff + spr_yoff * stride..];
634 self.decode_sprite(dst, stride, spr_width, spr_height, &mut mask, &mut index)?;
635 }
636 }
637 bufinfo = NABufferType::Video16(buf);
638 } else {
639 return Err(DecoderError::MissingReference);
640 }
641 } else if let Some(mut buf) = self.lastframe.get24() {
642 let stride = buf.get_stride(0);
643 {
644 let data = buf.get_data_mut().unwrap();
645 self.decode_24bit(data.as_mut_slice(), stride, out_width, height, &mut mask, &mut index)?;
646 }
647 bufinfo = NABufferType::VideoPacked(buf);
648 } else {
649 return Err(DecoderError::MissingReference);
650 }
651
652 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
653 frm.set_keyframe(is_intra || is_sprite);
654 frm.set_frame_type(if is_intra { FrameType::I } else { FrameType::P });
655 Ok(frm.into_ref())
656 }
657 fn flush(&mut self) {
658 self.lastframe.reset();
659 }
660 }
661
662 impl NAOptionHandler for TM1Decoder {
663 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
664 fn set_options(&mut self, _options: &[NAOption]) { }
665 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
666 }
667
668 pub fn get_decoder() -> Box<dyn NADecoder + Send> {
669 Box::new(TM1Decoder::new())
670 }
671
672 #[cfg(test)]
673 mod test {
674 use nihav_core::codecs::RegisteredDecoders;
675 use nihav_core::demuxers::RegisteredDemuxers;
676 use nihav_codec_support::test::dec_video::*;
677 use crate::duck_register_all_decoders;
678 use nihav_commonfmt::generic_register_all_demuxers;
679 #[test]
680 fn test_tm1() {
681 let mut dmx_reg = RegisteredDemuxers::new();
682 generic_register_all_demuxers(&mut dmx_reg);
683 let mut dec_reg = RegisteredDecoders::new();
684 duck_register_all_decoders(&mut dec_reg);
685
686 test_decoding("avi", "truemotion1", "assets/Duck/phant2-940.duk", Some(12), &dmx_reg, &dec_reg,
687 ExpectedTestResult::MD5Frames(vec![
688 [0x989e62b8, 0x5d85c23c, 0x1cffba6d, 0xe599f1c4],
689 [0xc4231321, 0x25561487, 0x9db11f57, 0x4faeb9a5],
690 [0x36e3a831, 0xdbd21f89, 0x0a446071, 0xf6d31ee7],
691 [0x0af640af, 0x64bc2bac, 0x0e95dd72, 0x9e55360b],
692 [0xbc9c5f8b, 0x6c06f2bc, 0x216f4129, 0x3a421337],
693 [0xd8ea7297, 0xce5f79fc, 0x46071f4c, 0xaed7fb7a],
694 [0x87617060, 0x72ce8df8, 0xde42eaa6, 0x804a6f45],
695 [0xfd8c45b3, 0xf424b683, 0xb4d6a9bd, 0xc622d0b9],
696 [0x6c233746, 0xba8ed68e, 0xc0ed0e85, 0xc99e1dc0],
697 [0x5842aac0, 0xd3d78242, 0x5da21218, 0xea1ed0ad],
698 [0xdea0db20, 0xe2ce3586, 0xf7386649, 0xecc374f9],
699 [0xb80ae9cb, 0x04eb938e, 0xd8a337ee, 0x0054b5ed],
700 [0xf8b80e1d, 0xd8eb3d6c, 0xa99b23ff, 0x562851a1]]));
701 test_decoding("avi", "truemotion1", "assets/Duck/SPRITES.AVI", Some(2), &dmx_reg, &dec_reg,
702 ExpectedTestResult::MD5([0xb89a4275, 0xf9797f5f, 0xe53c1ccd, 0xfa163e02]));
703 //let file = "assets/Duck/AVI-DUCK-dk3.duk";
704 //let file = "assets/Duck/phant2-940.duk";
705 //let file = "assets/Duck/bugsampler-m01-16bit.avi";
706 //let file = "assets/Duck/sonic3dblast_intro.avi";
707 //let file = "assets/Duck/BUTTONS.AVI";
708 //let file = "assets/Duck/SPRITES.AVI";
709 //let file = "assets/Duck/TRICORD.AVI";
710 //test_file_decoding("avi", file, Some(42), true, false, None/*Some("tm1-")*/, &dmx_reg, &dec_reg);
711 }
712 }
713
714 #[derive(Clone,Copy)]
715 struct TM1ComprInfo {
716 is_24bit: bool,
717 block_w: usize,
718 block_h: usize,
719 }
720
721 const TM1_COMPR_TYPES: [Option<TM1ComprInfo>; 17] = [
722 None,
723 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 4 }),
724 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 4 }),
725 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 2 }),
726 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 2 }),
727 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 4 }),
728 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 4 }),
729 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 2 }),
730 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 2 }),
731 None,
732 Some(TM1ComprInfo { is_24bit: true, block_w: 4, block_h: 4 }),
733 None,
734 Some(TM1ComprInfo { is_24bit: true, block_w: 4, block_h: 2 }),
735 None,
736 Some(TM1ComprInfo { is_24bit: true, block_w: 2, block_h: 4 }),
737 None,
738 Some(TM1ComprInfo { is_24bit: true, block_w: 2, block_h: 2 }),
739 ];
740
741 const DUCK_Y_DELTAS: [[i32; 8]; 4] = [
742 [ 0, -1, 1, -3, 3, -6, 6, -6 ],
743 [ 0, -1, 2, -3, 4, -6, 6, -6 ],
744 [ 2, -3, 10, -10, 23, -23, 47, -47 ],
745 [ 0, -2, 2, -8, 8, -18, 18, -40 ]
746 ];
747 const DUCK_Y_FAT_DELTA3: [i32; 8] = [ 0, -15, 50, -50, 115, -115, 235, -235 ];
748 const DUCK_Y_FAT_DELTA4: [i32; 8] = [ 0, 40, 80, -76, 160, -154, 236, -236 ];
749 const DUCK_Y_FAT_DELTAS: [&[i32]; 4] = [
750 &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA4
751 ];
752
753 const DUCK_C_DELTAS: [[i32; 8]; 4] = [
754 [ 0, -1, 1, -2, 3, -4, 5, -4 ],
755 [ 0, -1, 1, -2, 3, -4, 5, -4 ],
756 [ 0, -4, 3, -16, 20, -32, 36, -32 ],
757 [ 0, -2, 2, -8, 8, -18, 18, -40 ]
758 ];
759 const DUCK_C_FAT_DELTA3: [i32; 8] = [ 0, -20, 15, -80, 100, -160, 180, -160 ];
760 const DUCK_C_FAT_DELTAS: [&[i32]; 4] = [
761 &DUCK_C_FAT_DELTA3, &DUCK_C_FAT_DELTA3, &DUCK_C_FAT_DELTA3, &DUCK_Y_FAT_DELTA4
762 ];
763
764 const DUCK_VECTBL2: &[u8] = &[
765 0x8,0x00,0x00,0x00,0x00,
766 0x8,0x00,0x00,0x00,0x00,
767 0x8,0x10,0x00,0x00,0x00,
768 0x8,0x01,0x00,0x00,0x00,
769 0x8,0x00,0x10,0x00,0x00,
770 0x8,0x00,0x01,0x00,0x00,
771 0x8,0x00,0x00,0x10,0x00,
772 0x8,0x00,0x00,0x01,0x00,
773 0x8,0x00,0x00,0x00,0x10,
774 0x8,0x00,0x00,0x00,0x01,
775 0x6,0x00,0x00,0x00,
776 0x6,0x10,0x00,0x00,
777 0x6,0x01,0x00,0x00,
778 0x6,0x00,0x10,0x00,
779 0x6,0x00,0x01,0x00,
780 0x6,0x00,0x00,0x01,
781 0x6,0x00,0x00,0x10,
782 0x6,0x00,0x00,0x02,
783 0x6,0x00,0x00,0x20,
784 0x6,0x20,0x10,0x00,
785 0x6,0x00,0x02,0x01,
786 0x6,0x00,0x20,0x10,
787 0x6,0x02,0x01,0x00,
788 0x6,0x11,0x00,0x00,
789 0x6,0x00,0x20,0x00,
790 0x6,0x00,0x02,0x00,
791 0x6,0x20,0x00,0x00,
792 0x6,0x01,0x10,0x00,
793 0x6,0x02,0x00,0x00,
794 0x6,0x01,0x00,0x02,
795 0x6,0x10,0x00,0x20,
796 0x6,0x00,0x01,0x02,
797 0x6,0x10,0x01,0x00,
798 0x6,0x00,0x10,0x20,
799 0x6,0x10,0x10,0x00,
800 0x6,0x10,0x00,0x01,
801 0x6,0x20,0x00,0x10,
802 0x6,0x02,0x00,0x01,
803 0x6,0x01,0x01,0x00,
804 0x6,0x01,0x00,0x10,
805 0x6,0x00,0x11,0x00,
806 0x6,0x10,0x00,0x02,
807 0x6,0x00,0x01,0x10,
808 0x6,0x00,0x00,0x11,
809 0x6,0x10,0x00,0x10,
810 0x6,0x01,0x00,0x01,
811 0x6,0x00,0x00,0x22,
812 0x6,0x02,0x01,0x01,
813 0x6,0x10,0x20,0x10,
814 0x6,0x01,0x02,0x01,
815 0x6,0x20,0x10,0x10,
816 0x6,0x01,0x00,0x20,
817 0x6,0x00,0x10,0x01,
818 0x6,0x21,0x10,0x00,
819 0x6,0x10,0x02,0x01,
820 0x6,0x12,0x01,0x00,
821 0x6,0x01,0x20,0x10,
822 0x6,0x01,0x02,0x00,
823 0x6,0x10,0x20,0x00,
824 0x6,0x00,0x10,0x02,
825 0x6,0x00,0x01,0x20,
826 0x6,0x00,0x02,0x21,
827 0x6,0x00,0x02,0x20,
828 0x6,0x00,0x00,0x12,
829 0x6,0x00,0x00,0x21,
830 0x6,0x20,0x11,0x00,
831 0x6,0x00,0x01,0x01,
832 0x6,0x11,0x10,0x00,
833 0x6,0x00,0x20,0x12,
834 0x6,0x00,0x20,0x11,
835 0x6,0x20,0x10,0x02,
836 0x6,0x02,0x01,0x20,
837 0x6,0x00,0x22,0x11,
838 0x6,0x00,0x10,0x10,
839 0x6,0x02,0x11,0x00,
840 0x6,0x00,0x21,0x10,
841 0x6,0x00,0x02,0x03,
842 0x6,0x20,0x10,0x01,
843 0x6,0x00,0x12,0x01,
844 0x4,0x11,0x00,
845 0x4,0x00,0x22,
846 0x4,0x20,0x00,
847 0x4,0x01,0x10,
848 0x4,0x02,0x20,
849 0x4,0x00,0x20,
850 0x4,0x02,0x00,
851 0x4,0x10,0x01,
852 0x4,0x00,0x11,
853 0x4,0x02,0x01,
854 0x4,0x02,0x21,
855 0x4,0x00,0x02,
856 0x4,0x20,0x02,
857 0x4,0x01,0x01,
858 0x4,0x10,0x10,
859 0x4,0x10,0x02,
860 0x4,0x22,0x00,
861 0x4,0x10,0x00,
862 0x4,0x01,0x00,
863 0x4,0x21,0x00,
864 0x4,0x12,0x00,
865 0x4,0x00,0x10,
866 0x4,0x20,0x12,
867 0x4,0x01,0x11,
868 0x4,0x00,0x01,
869 0x4,0x01,0x02,
870 0x4,0x11,0x02,
871 0x4,0x11,0x01,
872 0x4,0x10,0x20,
873 0x4,0x20,0x01,
874 0x4,0x22,0x11,
875 0x4,0x00,0x12,
876 0x4,0x20,0x10,
877 0x4,0x22,0x01,
878 0x4,0x01,0x20,
879 0x4,0x00,0x21,
880 0x4,0x10,0x11,
881 0x4,0x21,0x10,
882 0x4,0x10,0x22,
883 0x4,0x02,0x03,
884 0x4,0x12,0x01,
885 0x4,0x20,0x11,
886 0x4,0x11,0x10,
887 0x4,0x20,0x30,
888 0x4,0x11,0x20,
889 0x4,0x02,0x10,
890 0x4,0x22,0x10,
891 0x4,0x11,0x11,
892 0x4,0x30,0x20,
893 0x4,0x30,0x00,
894 0x4,0x01,0x22,
895 0x4,0x01,0x12,
896 0x4,0x02,0x11,
897 0x4,0x03,0x02,
898 0x4,0x03,0x00,
899 0x4,0x10,0x21,
900 0x4,0x12,0x20,
901 0x4,0x00,0x00,
902 0x4,0x12,0x21,
903 0x4,0x21,0x11,
904 0x4,0x02,0x22,
905 0x4,0x10,0x12,
906 0x4,0x31,0x00,
907 0x4,0x20,0x20,
908 0x4,0x00,0x03,
909 0x4,0x02,0x02,
910 0x4,0x22,0x20,
911 0x4,0x01,0x21,
912 0x4,0x21,0x02,
913 0x4,0x21,0x12,
914 0x4,0x11,0x22,
915 0x4,0x00,0x30,
916 0x4,0x12,0x11,
917 0x4,0x20,0x22,
918 0x4,0x31,0x20,
919 0x4,0x21,0x30,
920 0x4,0x22,0x02,
921 0x4,0x22,0x22,
922 0x4,0x20,0x31,
923 0x4,0x13,0x02,
924 0x4,0x03,0x10,
925 0x4,0x11,0x12,
926 0x4,0x00,0x13,
927 0x4,0x21,0x01,
928 0x4,0x12,0x03,
929 0x4,0x13,0x00,
930 0x4,0x13,0x10,
931 0x4,0x02,0x13,
932 0x4,0x30,0x01,
933 0x4,0x12,0x10,
934 0x4,0x22,0x13,
935 0x4,0x03,0x12,
936 0x4,0x31,0x01,
937 0x4,0x30,0x22,
938 0x4,0x00,0x31,
939 0x4,0x01,0x31,
940 0x4,0x02,0x23,
941 0x4,0x01,0x30,
942 0x4,0x11,0x21,
943 0x4,0x22,0x21,
944 0x4,0x01,0x13,
945 0x4,0x10,0x03,
946 0x4,0x22,0x03,
947 0x4,0x30,0x21,
948 0x4,0x21,0x31,
949 0x4,0x33,0x00,
950 0x4,0x13,0x12,
951 0x4,0x11,0x31,
952 0x4,0x30,0x02,
953 0x4,0x12,0x02,
954 0x4,0x11,0x13,
955 0x4,0x12,0x22,
956 0x4,0x20,0x32,
957 0x4,0x10,0x13,
958 0x4,0x22,0x31,
959 0x4,0x21,0x20,
960 0x4,0x01,0x33,
961 0x4,0x33,0x10,
962 0x4,0x20,0x13,
963 0x4,0x31,0x22,
964 0x4,0x13,0x30,
965 0x4,0x01,0x03,
966 0x4,0x11,0x33,
967 0x4,0x20,0x21,
968 0x4,0x13,0x31,
969 0x4,0x03,0x22,
970 0x4,0x31,0x02,
971 0x4,0x00,0x24,
972 0x2,0x00,
973 0x2,0x10,
974 0x2,0x20,
975 0x2,0x30,
976 0x2,0x40,
977 0x2,0x50,
978 0x2,0x60,
979 0x2,0x01,
980 0x2,0x11,
981 0x2,0x21,
982 0x2,0x31,
983 0x2,0x41,
984 0x2,0x51,
985 0x2,0x61,
986 0x2,0x02,
987 0x2,0x12,
988 0x2,0x22,
989 0x2,0x32,
990 0x2,0x42,
991 0x2,0x52,
992 0x2,0x62,
993 0x2,0x03,
994 0x2,0x13,
995 0x2,0x23,
996 0x2,0x33,
997 0x2,0x43,
998 0x2,0x53,
999 0x2,0x63,
1000 0x2,0x04,
1001 0x2,0x14,
1002 0x2,0x24,
1003 0x2,0x34,
1004 0x2,0x44,
1005 0x2,0x54,
1006 0x2,0x64,
1007 0x2,0x05,
1008 0x2,0x15,
1009 0x2,0x25,
1010 0x2,0x35,
1011 0x2,0x45,
1012 0x2,0x55,
1013 0x2,0x65,
1014 0x2,0x06,
1015 0x2,0x16,
1016 0x2,0x26,
1017 0x2,0x36,
1018 0x2,0x46,
1019 0x2,0x56,
1020 0x2,0x66
1021 ];
1022
1023 const DUCK_VECTBL3: &[u8] = &[
1024 0x6,0x00,0x00,0x00,
1025 0x6,0x00,0x00,0x00,
1026 0x6,0x00,0x00,0x01,
1027 0x6,0x00,0x00,0x10,
1028 0x6,0x00,0x00,0x11,
1029 0x6,0x00,0x01,0x00,
1030 0x6,0x00,0x01,0x01,
1031 0x6,0x00,0x01,0x10,
1032 0x6,0x00,0x01,0x11,
1033 0x6,0x00,0x10,0x00,
1034 0x6,0x00,0x10,0x01,
1035 0x6,0x00,0x10,0x10,
1036 0x6,0x00,0x10,0x11,
1037 0x6,0x00,0x11,0x00,
1038 0x6,0x00,0x11,0x01,
1039 0x6,0x00,0x11,0x10,
1040 0x6,0x00,0x11,0x11,
1041 0x6,0x01,0x00,0x00,
1042 0x6,0x01,0x00,0x01,
1043 0x6,0x01,0x00,0x10,
1044 0x6,0x01,0x00,0x11,
1045 0x6,0x01,0x01,0x00,
1046 0x6,0x01,0x01,0x01,
1047 0x6,0x01,0x01,0x10,
1048 0x6,0x01,0x01,0x11,
1049 0x6,0x01,0x10,0x00,
1050 0x6,0x01,0x10,0x01,
1051 0x6,0x01,0x10,0x10,
1052 0x6,0x01,0x10,0x11,
1053 0x6,0x01,0x11,0x00,
1054 0x6,0x01,0x11,0x01,
1055 0x6,0x01,0x11,0x10,
1056 0x6,0x01,0x11,0x11,
1057 0x6,0x10,0x00,0x00,
1058 0x6,0x10,0x00,0x01,
1059 0x6,0x10,0x00,0x10,
1060 0x6,0x10,0x00,0x11,
1061 0x6,0x10,0x01,0x00,
1062 0x6,0x10,0x01,0x01,
1063 0x6,0x10,0x01,0x10,
1064 0x6,0x10,0x01,0x11,
1065 0x6,0x10,0x10,0x00,
1066 0x6,0x10,0x10,0x01,
1067 0x6,0x10,0x10,0x10,
1068 0x6,0x10,0x10,0x11,
1069 0x6,0x10,0x11,0x00,
1070 0x6,0x10,0x11,0x01,
1071 0x6,0x10,0x11,0x10,
1072 0x6,0x10,0x11,0x11,
1073 0x6,0x11,0x00,0x00,
1074 0x6,0x11,0x00,0x01,
1075 0x6,0x11,0x00,0x10,
1076 0x6,0x11,0x00,0x11,
1077 0x6,0x11,0x01,0x00,
1078 0x6,0x11,0x01,0x01,
1079 0x6,0x11,0x01,0x10,
1080 0x6,0x11,0x01,0x11,
1081 0x6,0x11,0x10,0x00,
1082 0x6,0x11,0x10,0x01,
1083 0x6,0x11,0x10,0x10,
1084 0x6,0x11,0x10,0x11,
1085 0x6,0x11,0x11,0x00,
1086 0x6,0x11,0x11,0x01,
1087 0x6,0x11,0x11,0x10,
1088 0x4,0x00,0x00,
1089 0x4,0x00,0x01,
1090 0x4,0x00,0x02,
1091 0x4,0x00,0x03,
1092 0x4,0x00,0x10,
1093 0x4,0x00,0x11,
1094 0x4,0x00,0x12,
1095 0x4,0x00,0x13,
1096 0x4,0x00,0x20,
1097 0x4,0x00,0x21,
1098 0x4,0x00,0x22,
1099 0x4,0x00,0x23,
1100 0x4,0x00,0x30,
1101 0x4,0x00,0x31,
1102 0x4,0x00,0x32,
1103 0x4,0x00,0x33,
1104 0x4,0x01,0x00,
1105 0x4,0x01,0x01,
1106 0x4,0x01,0x02,
1107 0x4,0x01,0x03,
1108 0x4,0x01,0x10,
1109 0x4,0x01,0x11,
1110 0x4,0x01,0x12,
1111 0x4,0x01,0x13,
1112 0x4,0x01,0x20,
1113 0x4,0x01,0x21,
1114 0x4,0x01,0x22,
1115 0x4,0x01,0x23,
1116 0x4,0x01,0x30,
1117 0x4,0x01,0x31,
1118 0x4,0x01,0x32,
1119 0x4,0x01,0x33,
1120 0x4,0x02,0x00,
1121 0x4,0x02,0x01,
1122 0x4,0x02,0x02,
1123 0x4,0x02,0x03,
1124 0x4,0x02,0x10,
1125 0x4,0x02,0x11,
1126 0x4,0x02,0x12,
1127 0x4,0x02,0x13,
1128 0x4,0x02,0x20,
1129 0x4,0x02,0x21,
1130 0x4,0x02,0x22,
1131 0x4,0x02,0x23,
1132 0x4,0x02,0x30,
1133 0x4,0x02,0x31,
1134 0x4,0x02,0x32,
1135 0x4,0x02,0x33,
1136 0x4,0x03,0x00,
1137 0x4,0x03,0x01,
1138 0x4,0x03,0x02,
1139 0x4,0x03,0x03,
1140 0x4,0x03,0x10,
1141 0x4,0x03,0x11,
1142 0x4,0x03,0x12,
1143 0x4,0x03,0x13,
1144 0x4,0x03,0x20,
1145 0x4,0x03,0x21,
1146 0x4,0x03,0x22,
1147 0x4,0x03,0x23,
1148 0x4,0x03,0x30,
1149 0x4,0x03,0x31,
1150 0x4,0x03,0x32,
1151 0x4,0x03,0x33,
1152 0x4,0x10,0x00,
1153 0x4,0x10,0x01,
1154 0x4,0x10,0x02,
1155 0x4,0x10,0x03,
1156 0x4,0x10,0x10,
1157 0x4,0x10,0x11,
1158 0x4,0x10,0x12,
1159 0x4,0x10,0x13,
1160 0x4,0x10,0x20,
1161 0x4,0x10,0x21,
1162 0x4,0x10,0x22,
1163 0x4,0x10,0x23,
1164 0x4,0x10,0x30,
1165 0x4,0x10,0x31,
1166 0x4,0x10,0x32,
1167 0x4,0x10,0x33,
1168 0x4,0x11,0x00,
1169 0x4,0x11,0x01,
1170 0x4,0x11,0x02,
1171 0x4,0x11,0x03,
1172 0x4,0x11,0x10,
1173 0x4,0x11,0x11,
1174 0x4,0x11,0x12,
1175 0x4,0x11,0x13,
1176 0x4,0x11,0x20,
1177 0x4,0x11,0x21,
1178 0x4,0x11,0x22,
1179 0x4,0x11,0x23,
1180 0x4,0x11,0x30,
1181 0x4,0x11,0x31,
1182 0x4,0x11,0x32,
1183 0x4,0x11,0x33,
1184 0x4,0x12,0x00,
1185 0x4,0x12,0x01,
1186 0x4,0x12,0x02,
1187 0x4,0x12,0x03,
1188 0x4,0x12,0x10,
1189 0x4,0x12,0x11,
1190 0x4,0x12,0x12,
1191 0x4,0x12,0x13,
1192 0x4,0x12,0x20,
1193 0x4,0x12,0x21,
1194 0x4,0x12,0x22,
1195 0x4,0x12,0x23,
1196 0x4,0x12,0x30,
1197 0x4,0x12,0x31,
1198 0x4,0x12,0x32,
1199 0x4,0x12,0x33,
1200 0x4,0x13,0x00,
1201 0x4,0x13,0x01,
1202 0x4,0x13,0x02,
1203 0x4,0x13,0x03,
1204 0x4,0x13,0x10,
1205 0x4,0x13,0x11,
1206 0x4,0x13,0x12,
1207 0x4,0x13,0x13,
1208 0x4,0x13,0x20,
1209 0x4,0x13,0x21,
1210 0x4,0x13,0x22,
1211 0x4,0x13,0x23,
1212 0x4,0x13,0x30,
1213 0x4,0x13,0x31,
1214 0x4,0x13,0x32,
1215 0x4,0x13,0x33,
1216 0x2,0x00,
1217 0x2,0x10,
1218 0x2,0x20,
1219 0x2,0x30,
1220 0x2,0x40,
1221 0x2,0x50,
1222 0x2,0x60,
1223 0x2,0x70,
1224 0x2,0x01,
1225 0x2,0x11,
1226 0x2,0x21,
1227 0x2,0x31,
1228 0x2,0x41,
1229 0x2,0x51,
1230 0x2,0x61,
1231 0x2,0x71,
1232 0x2,0x02,
1233 0x2,0x12,
1234 0x2,0x22,
1235 0x2,0x32,
1236 0x2,0x42,
1237 0x2,0x52,
1238 0x2,0x62,
1239 0x2,0x72,
1240 0x2,0x03,
1241 0x2,0x13,
1242 0x2,0x23,
1243 0x2,0x33,
1244 0x2,0x43,
1245 0x2,0x53,
1246 0x2,0x63,
1247 0x2,0x73,
1248 0x2,0x04,
1249 0x2,0x14,
1250 0x2,0x24,
1251 0x2,0x34,
1252 0x2,0x44,
1253 0x2,0x54,
1254 0x2,0x64,
1255 0x2,0x74,
1256 0x2,0x05,
1257 0x2,0x15,
1258 0x2,0x25,
1259 0x2,0x35,
1260 0x2,0x45,
1261 0x2,0x55,
1262 0x2,0x65,
1263 0x2,0x75,
1264 0x2,0x06,
1265 0x2,0x16,
1266 0x2,0x26,
1267 0x2,0x36,
1268 0x2,0x46,
1269 0x2,0x56,
1270 0x2,0x66,
1271 0x2,0x76,
1272 0x2,0x07,
1273 0x2,0x17,
1274 0x2,0x27,
1275 0x2,0x37,
1276 0x2,0x47,
1277 0x2,0x57,
1278 0x2,0x67,
1279 0x2,0x77
1280 ];
1281
1282 const DUCK_VECTBL4: &[u8] = &[
1283 0x8,0x00,0x00,0x00,0x00,
1284 0x8,0x00,0x00,0x00,0x00,
1285 0x8,0x20,0x00,0x00,0x00,
1286 0x8,0x00,0x00,0x00,0x01,
1287 0x8,0x10,0x00,0x00,0x00,
1288 0x8,0x00,0x00,0x00,0x02,
1289 0x8,0x01,0x00,0x00,0x00,
1290 0x8,0x00,0x00,0x00,0x10,
1291 0x8,0x02,0x00,0x00,0x00,
1292 0x6,0x00,0x00,0x00,
1293 0x6,0x20,0x00,0x00,
1294 0x6,0x00,0x00,0x01,
1295 0x6,0x10,0x00,0x00,
1296 0x6,0x00,0x00,0x02,
1297 0x6,0x00,0x10,0x00,
1298 0x6,0x00,0x20,0x00,
1299 0x6,0x00,0x02,0x00,
1300 0x6,0x00,0x01,0x00,
1301 0x6,0x01,0x00,0x00,
1302 0x6,0x00,0x00,0x20,
1303 0x6,0x02,0x00,0x00,
1304 0x6,0x00,0x00,0x10,
1305 0x6,0x10,0x00,0x20,
1306 0x6,0x01,0x00,0x02,
1307 0x6,0x20,0x00,0x10,
1308 0x6,0x02,0x00,0x01,
1309 0x6,0x20,0x10,0x00,
1310 0x6,0x00,0x12,0x00,
1311 0x6,0x00,0x02,0x01,
1312 0x6,0x02,0x01,0x00,
1313 0x6,0x00,0x21,0x00,
1314 0x6,0x00,0x01,0x02,
1315 0x6,0x00,0x20,0x10,
1316 0x6,0x00,0x00,0x21,
1317 0x6,0x00,0x00,0x12,
1318 0x6,0x00,0x01,0x20,
1319 0x6,0x12,0x00,0x00,
1320 0x6,0x00,0x10,0x20,
1321 0x6,0x01,0x20,0x00,
1322 0x6,0x02,0x10,0x00,
1323 0x6,0x10,0x20,0x00,
1324 0x6,0x01,0x02,0x00,
1325 0x6,0x21,0x00,0x00,
1326 0x6,0x00,0x02,0x10,
1327 0x6,0x20,0x01,0x00,
1328 0x6,0x00,0x22,0x00,
1329 0x6,0x10,0x02,0x00,
1330 0x6,0x00,0x10,0x02,
1331 0x6,0x11,0x00,0x00,
1332 0x6,0x00,0x11,0x00,
1333 0x6,0x22,0x00,0x00,
1334 0x6,0x20,0x00,0x02,
1335 0x6,0x10,0x00,0x01,
1336 0x6,0x00,0x20,0x01,
1337 0x6,0x02,0x20,0x00,
1338 0x6,0x01,0x10,0x00,
1339 0x6,0x01,0x00,0x20,
1340 0x6,0x00,0x20,0x02,
1341 0x6,0x01,0x20,0x02,
1342 0x6,0x10,0x01,0x00,
1343 0x6,0x02,0x00,0x10,
1344 0x6,0x00,0x10,0x01,
1345 0x6,0x10,0x01,0x20,
1346 0x6,0x20,0x02,0x10,
1347 0x6,0x00,0x00,0x22,
1348 0x6,0x10,0x00,0x02,
1349 0x6,0x00,0x02,0x20,
1350 0x6,0x20,0x02,0x00,
1351 0x6,0x00,0x00,0x11,
1352 0x6,0x02,0x10,0x01,
1353 0x6,0x00,0x01,0x10,
1354 0x6,0x00,0x02,0x11,
1355 0x4,0x01,0x02,
1356 0x4,0x02,0x01,
1357 0x4,0x01,0x00,
1358 0x4,0x10,0x20,
1359 0x4,0x20,0x10,
1360 0x4,0x20,0x00,
1361 0x4,0x11,0x00,
1362 0x4,0x02,0x00,
1363 0x4,0x12,0x00,
1364 0x4,0x00,0x21,
1365 0x4,0x22,0x00,
1366 0x4,0x00,0x12,
1367 0x4,0x21,0x00,
1368 0x4,0x02,0x11,
1369 0x4,0x00,0x01,
1370 0x4,0x10,0x02,
1371 0x4,0x02,0x20,
1372 0x4,0x20,0x11,
1373 0x4,0x01,0x10,
1374 0x4,0x21,0x10,
1375 0x4,0x10,0x00,
1376 0x4,0x10,0x22,
1377 0x4,0x20,0x20,
1378 0x4,0x00,0x22,
1379 0x4,0x01,0x22,
1380 0x4,0x20,0x01,
1381 0x4,0x02,0x02,
1382 0x4,0x00,0x20,
1383 0x4,0x00,0x10,
1384 0x4,0x00,0x11,
1385 0x4,0x22,0x01,
1386 0x4,0x11,0x20,
1387 0x4,0x12,0x01,
1388 0x4,0x12,0x20,
1389 0x4,0x11,0x02,
1390 0x4,0x10,0x10,
1391 0x4,0x01,0x01,
1392 0x4,0x02,0x21,
1393 0x4,0x20,0x12,
1394 0x4,0x01,0x12,
1395 0x4,0x22,0x11,
1396 0x4,0x21,0x12,
1397 0x4,0x22,0x10,
1398 0x4,0x21,0x02,
1399 0x4,0x20,0x02,
1400 0x4,0x10,0x01,
1401 0x4,0x00,0x02,
1402 0x4,0x10,0x21,
1403 0x4,0x01,0x20,
1404 0x4,0x11,0x22,
1405 0x4,0x12,0x21,
1406 0x4,0x22,0x20,
1407 0x4,0x02,0x10,
1408 0x4,0x02,0x22,
1409 0x4,0x11,0x10,
1410 0x4,0x22,0x02,
1411 0x4,0x20,0x21,
1412 0x4,0x01,0x11,
1413 0x4,0x11,0x01,
1414 0x4,0x10,0x12,
1415 0x4,0x02,0x12,
1416 0x4,0x20,0x22,
1417 0x4,0x21,0x20,
1418 0x4,0x01,0x21,
1419 0x4,0x12,0x02,
1420 0x4,0x21,0x11,
1421 0x4,0x12,0x22,
1422 0x4,0x12,0x10,
1423 0x4,0x22,0x21,
1424 0x4,0x10,0x11,
1425 0x4,0x21,0x01,
1426 0x4,0x11,0x12,
1427 0x4,0x12,0x11,
1428 0x4,0x66,0x66,
1429 0x4,0x22,0x22,
1430 0x4,0x11,0x21,
1431 0x4,0x11,0x11,
1432 0x4,0x21,0x22,
1433 0x4,0x00,0x00,
1434 0x4,0x22,0x12,
1435 0x4,0x12,0x12,
1436 0x4,0x21,0x21,
1437 0x4,0x42,0x00,
1438 0x4,0x00,0x04,
1439 0x4,0x40,0x00,
1440 0x4,0x30,0x00,
1441 0x4,0x31,0x00,
1442 0x4,0x00,0x03,
1443 0x4,0x00,0x14,
1444 0x4,0x00,0x13,
1445 0x4,0x01,0x24,
1446 0x4,0x20,0x13,
1447 0x4,0x01,0x42,
1448 0x4,0x14,0x20,
1449 0x4,0x42,0x02,
1450 0x4,0x13,0x00,
1451 0x4,0x00,0x24,
1452 0x4,0x31,0x20,
1453 0x4,0x22,0x13,
1454 0x4,0x11,0x24,
1455 0x4,0x12,0x66,
1456 0x4,0x30,0x01,
1457 0x4,0x02,0x13,
1458 0x4,0x12,0x42,
1459 0x4,0x40,0x10,
1460 0x4,0x40,0x02,
1461 0x4,0x01,0x04,
1462 0x4,0x24,0x00,
1463 0x4,0x42,0x10,
1464 0x4,0x21,0x13,
1465 0x4,0x13,0x12,
1466 0x4,0x31,0x21,
1467 0x4,0x21,0x24,
1468 0x4,0x00,0x40,
1469 0x4,0x10,0x24,
1470 0x4,0x10,0x42,
1471 0x4,0x32,0x01,
1472 0x4,0x11,0x42,
1473 0x4,0x20,0x31,
1474 0x4,0x12,0x40,
1475 0x2,0x00,
1476 0x2,0x10,
1477 0x2,0x20,
1478 0x2,0x30,
1479 0x2,0x40,
1480 0x2,0x50,
1481 0x2,0x60,
1482 0x2,0x70,
1483 0x2,0x01,
1484 0x2,0x11,
1485 0x2,0x21,
1486 0x2,0x31,
1487 0x2,0x41,
1488 0x2,0x51,
1489 0x2,0x61,
1490 0x2,0x71,
1491 0x2,0x02,
1492 0x2,0x12,
1493 0x2,0x22,
1494 0x2,0x32,
1495 0x2,0x42,
1496 0x2,0x52,
1497 0x2,0x62,
1498 0x2,0x72,
1499 0x2,0x03,
1500 0x2,0x13,
1501 0x2,0x23,
1502 0x2,0x33,
1503 0x2,0x43,
1504 0x2,0x53,
1505 0x2,0x63,
1506 0x2,0x73,
1507 0x2,0x04,
1508 0x2,0x14,
1509 0x2,0x24,
1510 0x2,0x34,
1511 0x2,0x44,
1512 0x2,0x54,
1513 0x2,0x64,
1514 0x2,0x74,
1515 0x2,0x05,
1516 0x2,0x15,
1517 0x2,0x25,
1518 0x2,0x35,
1519 0x2,0x45,
1520 0x2,0x55,
1521 0x2,0x65,
1522 0x2,0x75,
1523 0x2,0x06,
1524 0x2,0x16,
1525 0x2,0x26,
1526 0x2,0x36,
1527 0x2,0x46,
1528 0x2,0x56,
1529 0x2,0x66,
1530 0x2,0x76,
1531 0x2,0x07,
1532 0x2,0x17,
1533 0x2,0x27,
1534 0x2,0x37,
1535 0x2,0x47,
1536 0x2,0x57,
1537 0x2,0x67,
1538 0x2,0x77
1539 ];
1540
1541 const DUCK_VECTABLES: [&[u8]; 3] = [ DUCK_VECTBL2, DUCK_VECTBL3, DUCK_VECTBL4 ];