h264: update test hashes after the changes
[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.clear();
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 // sample: https://samples.mplayerhq.hu/V-codecs/DUCK/phant2-940.duk
687 test_decoding("avi", "truemotion1", "assets/Duck/phant2-940.duk", Some(12), &dmx_reg, &dec_reg,
688 ExpectedTestResult::MD5Frames(vec![
689 [0x989e62b8, 0x5d85c23c, 0x1cffba6d, 0xe599f1c4],
690 [0xc4231321, 0x25561487, 0x9db11f57, 0x4faeb9a5],
691 [0x36e3a831, 0xdbd21f89, 0x0a446071, 0xf6d31ee7],
692 [0x0af640af, 0x64bc2bac, 0x0e95dd72, 0x9e55360b],
693 [0xbc9c5f8b, 0x6c06f2bc, 0x216f4129, 0x3a421337],
694 [0xd8ea7297, 0xce5f79fc, 0x46071f4c, 0xaed7fb7a],
695 [0x87617060, 0x72ce8df8, 0xde42eaa6, 0x804a6f45],
696 [0xfd8c45b3, 0xf424b683, 0xb4d6a9bd, 0xc622d0b9],
697 [0x6c233746, 0xba8ed68e, 0xc0ed0e85, 0xc99e1dc0],
698 [0x5842aac0, 0xd3d78242, 0x5da21218, 0xea1ed0ad],
699 [0xdea0db20, 0xe2ce3586, 0xf7386649, 0xecc374f9],
700 [0xb80ae9cb, 0x04eb938e, 0xd8a337ee, 0x0054b5ed],
701 [0xf8b80e1d, 0xd8eb3d6c, 0xa99b23ff, 0x562851a1]]));
702 test_decoding("avi", "truemotion1", "assets/Duck/SPRITES.AVI", Some(2), &dmx_reg, &dec_reg,
703 ExpectedTestResult::MD5([0xb89a4275, 0xf9797f5f, 0xe53c1ccd, 0xfa163e02]));
704 //let file = "assets/Duck/AVI-DUCK-dk3.duk";
705 //let file = "assets/Duck/phant2-940.duk";
706 //let file = "assets/Duck/bugsampler-m01-16bit.avi";
707 //let file = "assets/Duck/sonic3dblast_intro.avi";
708 //let file = "assets/Duck/BUTTONS.AVI";
709 //let file = "assets/Duck/SPRITES.AVI";
710 //let file = "assets/Duck/TRICORD.AVI";
711 //test_file_decoding("avi", file, Some(42), true, false, None/*Some("tm1-")*/, &dmx_reg, &dec_reg);
712 }
713 }
714
715 #[derive(Clone,Copy)]
716 struct TM1ComprInfo {
717 is_24bit: bool,
718 block_w: usize,
719 block_h: usize,
720 }
721
722 const TM1_COMPR_TYPES: [Option<TM1ComprInfo>; 17] = [
723 None,
724 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 4 }),
725 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 4 }),
726 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 2 }),
727 Some(TM1ComprInfo { is_24bit: false, block_w: 4, block_h: 2 }),
728 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 4 }),
729 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 4 }),
730 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 2 }),
731 Some(TM1ComprInfo { is_24bit: false, block_w: 2, block_h: 2 }),
732 None,
733 Some(TM1ComprInfo { is_24bit: true, block_w: 4, block_h: 4 }),
734 None,
735 Some(TM1ComprInfo { is_24bit: true, block_w: 4, block_h: 2 }),
736 None,
737 Some(TM1ComprInfo { is_24bit: true, block_w: 2, block_h: 4 }),
738 None,
739 Some(TM1ComprInfo { is_24bit: true, block_w: 2, block_h: 2 }),
740 ];
741
742 const DUCK_Y_DELTAS: [[i32; 8]; 4] = [
743 [ 0, -1, 1, -3, 3, -6, 6, -6 ],
744 [ 0, -1, 2, -3, 4, -6, 6, -6 ],
745 [ 2, -3, 10, -10, 23, -23, 47, -47 ],
746 [ 0, -2, 2, -8, 8, -18, 18, -40 ]
747 ];
748 const DUCK_Y_FAT_DELTA3: [i32; 8] = [ 0, -15, 50, -50, 115, -115, 235, -235 ];
749 const DUCK_Y_FAT_DELTA4: [i32; 8] = [ 0, 40, 80, -76, 160, -154, 236, -236 ];
750 const DUCK_Y_FAT_DELTAS: [&[i32]; 4] = [
751 &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA3, &DUCK_Y_FAT_DELTA4
752 ];
753
754 const DUCK_C_DELTAS: [[i32; 8]; 4] = [
755 [ 0, -1, 1, -2, 3, -4, 5, -4 ],
756 [ 0, -1, 1, -2, 3, -4, 5, -4 ],
757 [ 0, -4, 3, -16, 20, -32, 36, -32 ],
758 [ 0, -2, 2, -8, 8, -18, 18, -40 ]
759 ];
760 const DUCK_C_FAT_DELTA3: [i32; 8] = [ 0, -20, 15, -80, 100, -160, 180, -160 ];
761 const DUCK_C_FAT_DELTAS: [&[i32]; 4] = [
762 &DUCK_C_FAT_DELTA3, &DUCK_C_FAT_DELTA3, &DUCK_C_FAT_DELTA3, &DUCK_Y_FAT_DELTA4
763 ];
764
765 const DUCK_VECTBL2: &[u8] = &[
766 0x8,0x00,0x00,0x00,0x00,
767 0x8,0x00,0x00,0x00,0x00,
768 0x8,0x10,0x00,0x00,0x00,
769 0x8,0x01,0x00,0x00,0x00,
770 0x8,0x00,0x10,0x00,0x00,
771 0x8,0x00,0x01,0x00,0x00,
772 0x8,0x00,0x00,0x10,0x00,
773 0x8,0x00,0x00,0x01,0x00,
774 0x8,0x00,0x00,0x00,0x10,
775 0x8,0x00,0x00,0x00,0x01,
776 0x6,0x00,0x00,0x00,
777 0x6,0x10,0x00,0x00,
778 0x6,0x01,0x00,0x00,
779 0x6,0x00,0x10,0x00,
780 0x6,0x00,0x01,0x00,
781 0x6,0x00,0x00,0x01,
782 0x6,0x00,0x00,0x10,
783 0x6,0x00,0x00,0x02,
784 0x6,0x00,0x00,0x20,
785 0x6,0x20,0x10,0x00,
786 0x6,0x00,0x02,0x01,
787 0x6,0x00,0x20,0x10,
788 0x6,0x02,0x01,0x00,
789 0x6,0x11,0x00,0x00,
790 0x6,0x00,0x20,0x00,
791 0x6,0x00,0x02,0x00,
792 0x6,0x20,0x00,0x00,
793 0x6,0x01,0x10,0x00,
794 0x6,0x02,0x00,0x00,
795 0x6,0x01,0x00,0x02,
796 0x6,0x10,0x00,0x20,
797 0x6,0x00,0x01,0x02,
798 0x6,0x10,0x01,0x00,
799 0x6,0x00,0x10,0x20,
800 0x6,0x10,0x10,0x00,
801 0x6,0x10,0x00,0x01,
802 0x6,0x20,0x00,0x10,
803 0x6,0x02,0x00,0x01,
804 0x6,0x01,0x01,0x00,
805 0x6,0x01,0x00,0x10,
806 0x6,0x00,0x11,0x00,
807 0x6,0x10,0x00,0x02,
808 0x6,0x00,0x01,0x10,
809 0x6,0x00,0x00,0x11,
810 0x6,0x10,0x00,0x10,
811 0x6,0x01,0x00,0x01,
812 0x6,0x00,0x00,0x22,
813 0x6,0x02,0x01,0x01,
814 0x6,0x10,0x20,0x10,
815 0x6,0x01,0x02,0x01,
816 0x6,0x20,0x10,0x10,
817 0x6,0x01,0x00,0x20,
818 0x6,0x00,0x10,0x01,
819 0x6,0x21,0x10,0x00,
820 0x6,0x10,0x02,0x01,
821 0x6,0x12,0x01,0x00,
822 0x6,0x01,0x20,0x10,
823 0x6,0x01,0x02,0x00,
824 0x6,0x10,0x20,0x00,
825 0x6,0x00,0x10,0x02,
826 0x6,0x00,0x01,0x20,
827 0x6,0x00,0x02,0x21,
828 0x6,0x00,0x02,0x20,
829 0x6,0x00,0x00,0x12,
830 0x6,0x00,0x00,0x21,
831 0x6,0x20,0x11,0x00,
832 0x6,0x00,0x01,0x01,
833 0x6,0x11,0x10,0x00,
834 0x6,0x00,0x20,0x12,
835 0x6,0x00,0x20,0x11,
836 0x6,0x20,0x10,0x02,
837 0x6,0x02,0x01,0x20,
838 0x6,0x00,0x22,0x11,
839 0x6,0x00,0x10,0x10,
840 0x6,0x02,0x11,0x00,
841 0x6,0x00,0x21,0x10,
842 0x6,0x00,0x02,0x03,
843 0x6,0x20,0x10,0x01,
844 0x6,0x00,0x12,0x01,
845 0x4,0x11,0x00,
846 0x4,0x00,0x22,
847 0x4,0x20,0x00,
848 0x4,0x01,0x10,
849 0x4,0x02,0x20,
850 0x4,0x00,0x20,
851 0x4,0x02,0x00,
852 0x4,0x10,0x01,
853 0x4,0x00,0x11,
854 0x4,0x02,0x01,
855 0x4,0x02,0x21,
856 0x4,0x00,0x02,
857 0x4,0x20,0x02,
858 0x4,0x01,0x01,
859 0x4,0x10,0x10,
860 0x4,0x10,0x02,
861 0x4,0x22,0x00,
862 0x4,0x10,0x00,
863 0x4,0x01,0x00,
864 0x4,0x21,0x00,
865 0x4,0x12,0x00,
866 0x4,0x00,0x10,
867 0x4,0x20,0x12,
868 0x4,0x01,0x11,
869 0x4,0x00,0x01,
870 0x4,0x01,0x02,
871 0x4,0x11,0x02,
872 0x4,0x11,0x01,
873 0x4,0x10,0x20,
874 0x4,0x20,0x01,
875 0x4,0x22,0x11,
876 0x4,0x00,0x12,
877 0x4,0x20,0x10,
878 0x4,0x22,0x01,
879 0x4,0x01,0x20,
880 0x4,0x00,0x21,
881 0x4,0x10,0x11,
882 0x4,0x21,0x10,
883 0x4,0x10,0x22,
884 0x4,0x02,0x03,
885 0x4,0x12,0x01,
886 0x4,0x20,0x11,
887 0x4,0x11,0x10,
888 0x4,0x20,0x30,
889 0x4,0x11,0x20,
890 0x4,0x02,0x10,
891 0x4,0x22,0x10,
892 0x4,0x11,0x11,
893 0x4,0x30,0x20,
894 0x4,0x30,0x00,
895 0x4,0x01,0x22,
896 0x4,0x01,0x12,
897 0x4,0x02,0x11,
898 0x4,0x03,0x02,
899 0x4,0x03,0x00,
900 0x4,0x10,0x21,
901 0x4,0x12,0x20,
902 0x4,0x00,0x00,
903 0x4,0x12,0x21,
904 0x4,0x21,0x11,
905 0x4,0x02,0x22,
906 0x4,0x10,0x12,
907 0x4,0x31,0x00,
908 0x4,0x20,0x20,
909 0x4,0x00,0x03,
910 0x4,0x02,0x02,
911 0x4,0x22,0x20,
912 0x4,0x01,0x21,
913 0x4,0x21,0x02,
914 0x4,0x21,0x12,
915 0x4,0x11,0x22,
916 0x4,0x00,0x30,
917 0x4,0x12,0x11,
918 0x4,0x20,0x22,
919 0x4,0x31,0x20,
920 0x4,0x21,0x30,
921 0x4,0x22,0x02,
922 0x4,0x22,0x22,
923 0x4,0x20,0x31,
924 0x4,0x13,0x02,
925 0x4,0x03,0x10,
926 0x4,0x11,0x12,
927 0x4,0x00,0x13,
928 0x4,0x21,0x01,
929 0x4,0x12,0x03,
930 0x4,0x13,0x00,
931 0x4,0x13,0x10,
932 0x4,0x02,0x13,
933 0x4,0x30,0x01,
934 0x4,0x12,0x10,
935 0x4,0x22,0x13,
936 0x4,0x03,0x12,
937 0x4,0x31,0x01,
938 0x4,0x30,0x22,
939 0x4,0x00,0x31,
940 0x4,0x01,0x31,
941 0x4,0x02,0x23,
942 0x4,0x01,0x30,
943 0x4,0x11,0x21,
944 0x4,0x22,0x21,
945 0x4,0x01,0x13,
946 0x4,0x10,0x03,
947 0x4,0x22,0x03,
948 0x4,0x30,0x21,
949 0x4,0x21,0x31,
950 0x4,0x33,0x00,
951 0x4,0x13,0x12,
952 0x4,0x11,0x31,
953 0x4,0x30,0x02,
954 0x4,0x12,0x02,
955 0x4,0x11,0x13,
956 0x4,0x12,0x22,
957 0x4,0x20,0x32,
958 0x4,0x10,0x13,
959 0x4,0x22,0x31,
960 0x4,0x21,0x20,
961 0x4,0x01,0x33,
962 0x4,0x33,0x10,
963 0x4,0x20,0x13,
964 0x4,0x31,0x22,
965 0x4,0x13,0x30,
966 0x4,0x01,0x03,
967 0x4,0x11,0x33,
968 0x4,0x20,0x21,
969 0x4,0x13,0x31,
970 0x4,0x03,0x22,
971 0x4,0x31,0x02,
972 0x4,0x00,0x24,
973 0x2,0x00,
974 0x2,0x10,
975 0x2,0x20,
976 0x2,0x30,
977 0x2,0x40,
978 0x2,0x50,
979 0x2,0x60,
980 0x2,0x01,
981 0x2,0x11,
982 0x2,0x21,
983 0x2,0x31,
984 0x2,0x41,
985 0x2,0x51,
986 0x2,0x61,
987 0x2,0x02,
988 0x2,0x12,
989 0x2,0x22,
990 0x2,0x32,
991 0x2,0x42,
992 0x2,0x52,
993 0x2,0x62,
994 0x2,0x03,
995 0x2,0x13,
996 0x2,0x23,
997 0x2,0x33,
998 0x2,0x43,
999 0x2,0x53,
1000 0x2,0x63,
1001 0x2,0x04,
1002 0x2,0x14,
1003 0x2,0x24,
1004 0x2,0x34,
1005 0x2,0x44,
1006 0x2,0x54,
1007 0x2,0x64,
1008 0x2,0x05,
1009 0x2,0x15,
1010 0x2,0x25,
1011 0x2,0x35,
1012 0x2,0x45,
1013 0x2,0x55,
1014 0x2,0x65,
1015 0x2,0x06,
1016 0x2,0x16,
1017 0x2,0x26,
1018 0x2,0x36,
1019 0x2,0x46,
1020 0x2,0x56,
1021 0x2,0x66
1022 ];
1023
1024 const DUCK_VECTBL3: &[u8] = &[
1025 0x6,0x00,0x00,0x00,
1026 0x6,0x00,0x00,0x00,
1027 0x6,0x00,0x00,0x01,
1028 0x6,0x00,0x00,0x10,
1029 0x6,0x00,0x00,0x11,
1030 0x6,0x00,0x01,0x00,
1031 0x6,0x00,0x01,0x01,
1032 0x6,0x00,0x01,0x10,
1033 0x6,0x00,0x01,0x11,
1034 0x6,0x00,0x10,0x00,
1035 0x6,0x00,0x10,0x01,
1036 0x6,0x00,0x10,0x10,
1037 0x6,0x00,0x10,0x11,
1038 0x6,0x00,0x11,0x00,
1039 0x6,0x00,0x11,0x01,
1040 0x6,0x00,0x11,0x10,
1041 0x6,0x00,0x11,0x11,
1042 0x6,0x01,0x00,0x00,
1043 0x6,0x01,0x00,0x01,
1044 0x6,0x01,0x00,0x10,
1045 0x6,0x01,0x00,0x11,
1046 0x6,0x01,0x01,0x00,
1047 0x6,0x01,0x01,0x01,
1048 0x6,0x01,0x01,0x10,
1049 0x6,0x01,0x01,0x11,
1050 0x6,0x01,0x10,0x00,
1051 0x6,0x01,0x10,0x01,
1052 0x6,0x01,0x10,0x10,
1053 0x6,0x01,0x10,0x11,
1054 0x6,0x01,0x11,0x00,
1055 0x6,0x01,0x11,0x01,
1056 0x6,0x01,0x11,0x10,
1057 0x6,0x01,0x11,0x11,
1058 0x6,0x10,0x00,0x00,
1059 0x6,0x10,0x00,0x01,
1060 0x6,0x10,0x00,0x10,
1061 0x6,0x10,0x00,0x11,
1062 0x6,0x10,0x01,0x00,
1063 0x6,0x10,0x01,0x01,
1064 0x6,0x10,0x01,0x10,
1065 0x6,0x10,0x01,0x11,
1066 0x6,0x10,0x10,0x00,
1067 0x6,0x10,0x10,0x01,
1068 0x6,0x10,0x10,0x10,
1069 0x6,0x10,0x10,0x11,
1070 0x6,0x10,0x11,0x00,
1071 0x6,0x10,0x11,0x01,
1072 0x6,0x10,0x11,0x10,
1073 0x6,0x10,0x11,0x11,
1074 0x6,0x11,0x00,0x00,
1075 0x6,0x11,0x00,0x01,
1076 0x6,0x11,0x00,0x10,
1077 0x6,0x11,0x00,0x11,
1078 0x6,0x11,0x01,0x00,
1079 0x6,0x11,0x01,0x01,
1080 0x6,0x11,0x01,0x10,
1081 0x6,0x11,0x01,0x11,
1082 0x6,0x11,0x10,0x00,
1083 0x6,0x11,0x10,0x01,
1084 0x6,0x11,0x10,0x10,
1085 0x6,0x11,0x10,0x11,
1086 0x6,0x11,0x11,0x00,
1087 0x6,0x11,0x11,0x01,
1088 0x6,0x11,0x11,0x10,
1089 0x4,0x00,0x00,
1090 0x4,0x00,0x01,
1091 0x4,0x00,0x02,
1092 0x4,0x00,0x03,
1093 0x4,0x00,0x10,
1094 0x4,0x00,0x11,
1095 0x4,0x00,0x12,
1096 0x4,0x00,0x13,
1097 0x4,0x00,0x20,
1098 0x4,0x00,0x21,
1099 0x4,0x00,0x22,
1100 0x4,0x00,0x23,
1101 0x4,0x00,0x30,
1102 0x4,0x00,0x31,
1103 0x4,0x00,0x32,
1104 0x4,0x00,0x33,
1105 0x4,0x01,0x00,
1106 0x4,0x01,0x01,
1107 0x4,0x01,0x02,
1108 0x4,0x01,0x03,
1109 0x4,0x01,0x10,
1110 0x4,0x01,0x11,
1111 0x4,0x01,0x12,
1112 0x4,0x01,0x13,
1113 0x4,0x01,0x20,
1114 0x4,0x01,0x21,
1115 0x4,0x01,0x22,
1116 0x4,0x01,0x23,
1117 0x4,0x01,0x30,
1118 0x4,0x01,0x31,
1119 0x4,0x01,0x32,
1120 0x4,0x01,0x33,
1121 0x4,0x02,0x00,
1122 0x4,0x02,0x01,
1123 0x4,0x02,0x02,
1124 0x4,0x02,0x03,
1125 0x4,0x02,0x10,
1126 0x4,0x02,0x11,
1127 0x4,0x02,0x12,
1128 0x4,0x02,0x13,
1129 0x4,0x02,0x20,
1130 0x4,0x02,0x21,
1131 0x4,0x02,0x22,
1132 0x4,0x02,0x23,
1133 0x4,0x02,0x30,
1134 0x4,0x02,0x31,
1135 0x4,0x02,0x32,
1136 0x4,0x02,0x33,
1137 0x4,0x03,0x00,
1138 0x4,0x03,0x01,
1139 0x4,0x03,0x02,
1140 0x4,0x03,0x03,
1141 0x4,0x03,0x10,
1142 0x4,0x03,0x11,
1143 0x4,0x03,0x12,
1144 0x4,0x03,0x13,
1145 0x4,0x03,0x20,
1146 0x4,0x03,0x21,
1147 0x4,0x03,0x22,
1148 0x4,0x03,0x23,
1149 0x4,0x03,0x30,
1150 0x4,0x03,0x31,
1151 0x4,0x03,0x32,
1152 0x4,0x03,0x33,
1153 0x4,0x10,0x00,
1154 0x4,0x10,0x01,
1155 0x4,0x10,0x02,
1156 0x4,0x10,0x03,
1157 0x4,0x10,0x10,
1158 0x4,0x10,0x11,
1159 0x4,0x10,0x12,
1160 0x4,0x10,0x13,
1161 0x4,0x10,0x20,
1162 0x4,0x10,0x21,
1163 0x4,0x10,0x22,
1164 0x4,0x10,0x23,
1165 0x4,0x10,0x30,
1166 0x4,0x10,0x31,
1167 0x4,0x10,0x32,
1168 0x4,0x10,0x33,
1169 0x4,0x11,0x00,
1170 0x4,0x11,0x01,
1171 0x4,0x11,0x02,
1172 0x4,0x11,0x03,
1173 0x4,0x11,0x10,
1174 0x4,0x11,0x11,
1175 0x4,0x11,0x12,
1176 0x4,0x11,0x13,
1177 0x4,0x11,0x20,
1178 0x4,0x11,0x21,
1179 0x4,0x11,0x22,
1180 0x4,0x11,0x23,
1181 0x4,0x11,0x30,
1182 0x4,0x11,0x31,
1183 0x4,0x11,0x32,
1184 0x4,0x11,0x33,
1185 0x4,0x12,0x00,
1186 0x4,0x12,0x01,
1187 0x4,0x12,0x02,
1188 0x4,0x12,0x03,
1189 0x4,0x12,0x10,
1190 0x4,0x12,0x11,
1191 0x4,0x12,0x12,
1192 0x4,0x12,0x13,
1193 0x4,0x12,0x20,
1194 0x4,0x12,0x21,
1195 0x4,0x12,0x22,
1196 0x4,0x12,0x23,
1197 0x4,0x12,0x30,
1198 0x4,0x12,0x31,
1199 0x4,0x12,0x32,
1200 0x4,0x12,0x33,
1201 0x4,0x13,0x00,
1202 0x4,0x13,0x01,
1203 0x4,0x13,0x02,
1204 0x4,0x13,0x03,
1205 0x4,0x13,0x10,
1206 0x4,0x13,0x11,
1207 0x4,0x13,0x12,
1208 0x4,0x13,0x13,
1209 0x4,0x13,0x20,
1210 0x4,0x13,0x21,
1211 0x4,0x13,0x22,
1212 0x4,0x13,0x23,
1213 0x4,0x13,0x30,
1214 0x4,0x13,0x31,
1215 0x4,0x13,0x32,
1216 0x4,0x13,0x33,
1217 0x2,0x00,
1218 0x2,0x10,
1219 0x2,0x20,
1220 0x2,0x30,
1221 0x2,0x40,
1222 0x2,0x50,
1223 0x2,0x60,
1224 0x2,0x70,
1225 0x2,0x01,
1226 0x2,0x11,
1227 0x2,0x21,
1228 0x2,0x31,
1229 0x2,0x41,
1230 0x2,0x51,
1231 0x2,0x61,
1232 0x2,0x71,
1233 0x2,0x02,
1234 0x2,0x12,
1235 0x2,0x22,
1236 0x2,0x32,
1237 0x2,0x42,
1238 0x2,0x52,
1239 0x2,0x62,
1240 0x2,0x72,
1241 0x2,0x03,
1242 0x2,0x13,
1243 0x2,0x23,
1244 0x2,0x33,
1245 0x2,0x43,
1246 0x2,0x53,
1247 0x2,0x63,
1248 0x2,0x73,
1249 0x2,0x04,
1250 0x2,0x14,
1251 0x2,0x24,
1252 0x2,0x34,
1253 0x2,0x44,
1254 0x2,0x54,
1255 0x2,0x64,
1256 0x2,0x74,
1257 0x2,0x05,
1258 0x2,0x15,
1259 0x2,0x25,
1260 0x2,0x35,
1261 0x2,0x45,
1262 0x2,0x55,
1263 0x2,0x65,
1264 0x2,0x75,
1265 0x2,0x06,
1266 0x2,0x16,
1267 0x2,0x26,
1268 0x2,0x36,
1269 0x2,0x46,
1270 0x2,0x56,
1271 0x2,0x66,
1272 0x2,0x76,
1273 0x2,0x07,
1274 0x2,0x17,
1275 0x2,0x27,
1276 0x2,0x37,
1277 0x2,0x47,
1278 0x2,0x57,
1279 0x2,0x67,
1280 0x2,0x77
1281 ];
1282
1283 const DUCK_VECTBL4: &[u8] = &[
1284 0x8,0x00,0x00,0x00,0x00,
1285 0x8,0x00,0x00,0x00,0x00,
1286 0x8,0x20,0x00,0x00,0x00,
1287 0x8,0x00,0x00,0x00,0x01,
1288 0x8,0x10,0x00,0x00,0x00,
1289 0x8,0x00,0x00,0x00,0x02,
1290 0x8,0x01,0x00,0x00,0x00,
1291 0x8,0x00,0x00,0x00,0x10,
1292 0x8,0x02,0x00,0x00,0x00,
1293 0x6,0x00,0x00,0x00,
1294 0x6,0x20,0x00,0x00,
1295 0x6,0x00,0x00,0x01,
1296 0x6,0x10,0x00,0x00,
1297 0x6,0x00,0x00,0x02,
1298 0x6,0x00,0x10,0x00,
1299 0x6,0x00,0x20,0x00,
1300 0x6,0x00,0x02,0x00,
1301 0x6,0x00,0x01,0x00,
1302 0x6,0x01,0x00,0x00,
1303 0x6,0x00,0x00,0x20,
1304 0x6,0x02,0x00,0x00,
1305 0x6,0x00,0x00,0x10,
1306 0x6,0x10,0x00,0x20,
1307 0x6,0x01,0x00,0x02,
1308 0x6,0x20,0x00,0x10,
1309 0x6,0x02,0x00,0x01,
1310 0x6,0x20,0x10,0x00,
1311 0x6,0x00,0x12,0x00,
1312 0x6,0x00,0x02,0x01,
1313 0x6,0x02,0x01,0x00,
1314 0x6,0x00,0x21,0x00,
1315 0x6,0x00,0x01,0x02,
1316 0x6,0x00,0x20,0x10,
1317 0x6,0x00,0x00,0x21,
1318 0x6,0x00,0x00,0x12,
1319 0x6,0x00,0x01,0x20,
1320 0x6,0x12,0x00,0x00,
1321 0x6,0x00,0x10,0x20,
1322 0x6,0x01,0x20,0x00,
1323 0x6,0x02,0x10,0x00,
1324 0x6,0x10,0x20,0x00,
1325 0x6,0x01,0x02,0x00,
1326 0x6,0x21,0x00,0x00,
1327 0x6,0x00,0x02,0x10,
1328 0x6,0x20,0x01,0x00,
1329 0x6,0x00,0x22,0x00,
1330 0x6,0x10,0x02,0x00,
1331 0x6,0x00,0x10,0x02,
1332 0x6,0x11,0x00,0x00,
1333 0x6,0x00,0x11,0x00,
1334 0x6,0x22,0x00,0x00,
1335 0x6,0x20,0x00,0x02,
1336 0x6,0x10,0x00,0x01,
1337 0x6,0x00,0x20,0x01,
1338 0x6,0x02,0x20,0x00,
1339 0x6,0x01,0x10,0x00,
1340 0x6,0x01,0x00,0x20,
1341 0x6,0x00,0x20,0x02,
1342 0x6,0x01,0x20,0x02,
1343 0x6,0x10,0x01,0x00,
1344 0x6,0x02,0x00,0x10,
1345 0x6,0x00,0x10,0x01,
1346 0x6,0x10,0x01,0x20,
1347 0x6,0x20,0x02,0x10,
1348 0x6,0x00,0x00,0x22,
1349 0x6,0x10,0x00,0x02,
1350 0x6,0x00,0x02,0x20,
1351 0x6,0x20,0x02,0x00,
1352 0x6,0x00,0x00,0x11,
1353 0x6,0x02,0x10,0x01,
1354 0x6,0x00,0x01,0x10,
1355 0x6,0x00,0x02,0x11,
1356 0x4,0x01,0x02,
1357 0x4,0x02,0x01,
1358 0x4,0x01,0x00,
1359 0x4,0x10,0x20,
1360 0x4,0x20,0x10,
1361 0x4,0x20,0x00,
1362 0x4,0x11,0x00,
1363 0x4,0x02,0x00,
1364 0x4,0x12,0x00,
1365 0x4,0x00,0x21,
1366 0x4,0x22,0x00,
1367 0x4,0x00,0x12,
1368 0x4,0x21,0x00,
1369 0x4,0x02,0x11,
1370 0x4,0x00,0x01,
1371 0x4,0x10,0x02,
1372 0x4,0x02,0x20,
1373 0x4,0x20,0x11,
1374 0x4,0x01,0x10,
1375 0x4,0x21,0x10,
1376 0x4,0x10,0x00,
1377 0x4,0x10,0x22,
1378 0x4,0x20,0x20,
1379 0x4,0x00,0x22,
1380 0x4,0x01,0x22,
1381 0x4,0x20,0x01,
1382 0x4,0x02,0x02,
1383 0x4,0x00,0x20,
1384 0x4,0x00,0x10,
1385 0x4,0x00,0x11,
1386 0x4,0x22,0x01,
1387 0x4,0x11,0x20,
1388 0x4,0x12,0x01,
1389 0x4,0x12,0x20,
1390 0x4,0x11,0x02,
1391 0x4,0x10,0x10,
1392 0x4,0x01,0x01,
1393 0x4,0x02,0x21,
1394 0x4,0x20,0x12,
1395 0x4,0x01,0x12,
1396 0x4,0x22,0x11,
1397 0x4,0x21,0x12,
1398 0x4,0x22,0x10,
1399 0x4,0x21,0x02,
1400 0x4,0x20,0x02,
1401 0x4,0x10,0x01,
1402 0x4,0x00,0x02,
1403 0x4,0x10,0x21,
1404 0x4,0x01,0x20,
1405 0x4,0x11,0x22,
1406 0x4,0x12,0x21,
1407 0x4,0x22,0x20,
1408 0x4,0x02,0x10,
1409 0x4,0x02,0x22,
1410 0x4,0x11,0x10,
1411 0x4,0x22,0x02,
1412 0x4,0x20,0x21,
1413 0x4,0x01,0x11,
1414 0x4,0x11,0x01,
1415 0x4,0x10,0x12,
1416 0x4,0x02,0x12,
1417 0x4,0x20,0x22,
1418 0x4,0x21,0x20,
1419 0x4,0x01,0x21,
1420 0x4,0x12,0x02,
1421 0x4,0x21,0x11,
1422 0x4,0x12,0x22,
1423 0x4,0x12,0x10,
1424 0x4,0x22,0x21,
1425 0x4,0x10,0x11,
1426 0x4,0x21,0x01,
1427 0x4,0x11,0x12,
1428 0x4,0x12,0x11,
1429 0x4,0x66,0x66,
1430 0x4,0x22,0x22,
1431 0x4,0x11,0x21,
1432 0x4,0x11,0x11,
1433 0x4,0x21,0x22,
1434 0x4,0x00,0x00,
1435 0x4,0x22,0x12,
1436 0x4,0x12,0x12,
1437 0x4,0x21,0x21,
1438 0x4,0x42,0x00,
1439 0x4,0x00,0x04,
1440 0x4,0x40,0x00,
1441 0x4,0x30,0x00,
1442 0x4,0x31,0x00,
1443 0x4,0x00,0x03,
1444 0x4,0x00,0x14,
1445 0x4,0x00,0x13,
1446 0x4,0x01,0x24,
1447 0x4,0x20,0x13,
1448 0x4,0x01,0x42,
1449 0x4,0x14,0x20,
1450 0x4,0x42,0x02,
1451 0x4,0x13,0x00,
1452 0x4,0x00,0x24,
1453 0x4,0x31,0x20,
1454 0x4,0x22,0x13,
1455 0x4,0x11,0x24,
1456 0x4,0x12,0x66,
1457 0x4,0x30,0x01,
1458 0x4,0x02,0x13,
1459 0x4,0x12,0x42,
1460 0x4,0x40,0x10,
1461 0x4,0x40,0x02,
1462 0x4,0x01,0x04,
1463 0x4,0x24,0x00,
1464 0x4,0x42,0x10,
1465 0x4,0x21,0x13,
1466 0x4,0x13,0x12,
1467 0x4,0x31,0x21,
1468 0x4,0x21,0x24,
1469 0x4,0x00,0x40,
1470 0x4,0x10,0x24,
1471 0x4,0x10,0x42,
1472 0x4,0x32,0x01,
1473 0x4,0x11,0x42,
1474 0x4,0x20,0x31,
1475 0x4,0x12,0x40,
1476 0x2,0x00,
1477 0x2,0x10,
1478 0x2,0x20,
1479 0x2,0x30,
1480 0x2,0x40,
1481 0x2,0x50,
1482 0x2,0x60,
1483 0x2,0x70,
1484 0x2,0x01,
1485 0x2,0x11,
1486 0x2,0x21,
1487 0x2,0x31,
1488 0x2,0x41,
1489 0x2,0x51,
1490 0x2,0x61,
1491 0x2,0x71,
1492 0x2,0x02,
1493 0x2,0x12,
1494 0x2,0x22,
1495 0x2,0x32,
1496 0x2,0x42,
1497 0x2,0x52,
1498 0x2,0x62,
1499 0x2,0x72,
1500 0x2,0x03,
1501 0x2,0x13,
1502 0x2,0x23,
1503 0x2,0x33,
1504 0x2,0x43,
1505 0x2,0x53,
1506 0x2,0x63,
1507 0x2,0x73,
1508 0x2,0x04,
1509 0x2,0x14,
1510 0x2,0x24,
1511 0x2,0x34,
1512 0x2,0x44,
1513 0x2,0x54,
1514 0x2,0x64,
1515 0x2,0x74,
1516 0x2,0x05,
1517 0x2,0x15,
1518 0x2,0x25,
1519 0x2,0x35,
1520 0x2,0x45,
1521 0x2,0x55,
1522 0x2,0x65,
1523 0x2,0x75,
1524 0x2,0x06,
1525 0x2,0x16,
1526 0x2,0x26,
1527 0x2,0x36,
1528 0x2,0x46,
1529 0x2,0x56,
1530 0x2,0x66,
1531 0x2,0x76,
1532 0x2,0x07,
1533 0x2,0x17,
1534 0x2,0x27,
1535 0x2,0x37,
1536 0x2,0x47,
1537 0x2,0x57,
1538 0x2,0x67,
1539 0x2,0x77
1540 ];
1541
1542 const DUCK_VECTABLES: [&[u8]; 3] = [ DUCK_VECTBL2, DUCK_VECTBL3, DUCK_VECTBL4 ];