Merge branch 'simplify/s12' into simplify/w2
Browse files at this commit21 changed files +109 -106
- crates/ec-dnxhd/src/decoder.rs +2 -2
- crates/ec-dnxhd/src/idct.rs +1 -1
- crates/ec-dnxhd/src/lib.rs +0 -1
- crates/ec-dv/src/lib.rs +0 -1
- crates/ec-dv/src/video.rs +5 -5
- crates/ec-mjpeg/src/lib.rs +3 -7
- crates/ec-mpeg2/src/decoder.rs +63 -55
- crates/ec-mpeg2/src/header.rs +3 -3
- crates/ec-mpeg2/src/lib.rs +0 -1
- crates/ec-mpeg4/src/core.rs +3 -3
- crates/ec-mpeg4/src/dsp.rs +3 -0
- crates/ec-mpeg4/src/h263.rs +2 -2
- crates/ec-mpeg4/src/h263data.rs +2 -2
- crates/ec-mpeg4/src/header.rs +1 -0
- crates/ec-mpeg4/src/lib.rs +0 -5
- crates/ec-mpeg4/src/mb.rs +4 -4
- crates/ec-mpeg4/src/recon.rs +5 -2
- crates/ec-prores/src/encode.rs +6 -6
- crates/ec-prores/src/idct.rs +4 -3
- crates/ec-prores/src/lib.rs +0 -1
- crates/ec-prores/src/slice.rs +2 -2
crates/ec-dnxhd/src/decoder.rsmodified+2 -2
| @@ -575,7 +575,7 @@ pub(crate) fn to_picture(c: Canvas) -> Picture { | ||
| 575 | 575 | if c.bps == 1 { |
| 576 | 576 | out.extend(row.iter().map(|&v| u16::from(v))); |
| 577 | 577 | } else { |
| 578 | - out.extend(row.chunks_exact(2).map(|b| u16::from_le_bytes([b[0], b[1]]))); | |
| 578 | + out.extend(row.as_chunks::<2>().0.iter().map(|b| u16::from_le_bytes(*b))); | |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | out |
| @@ -596,7 +596,7 @@ pub(crate) fn to_video_frame(mut c: Canvas) -> Result<VideoFrame> { | ||
| 596 | 596 | }; |
| 597 | 597 | if info.bit_depth == 12 { |
| 598 | 598 | for p in &mut c.planes { |
| 599 | - for b in p.chunks_exact_mut(2) { | |
| 599 | + for b in p.as_chunks_mut::<2>().0 { | |
| 600 | 600 | let v = (u32::from(u16::from_le_bytes([b[0], b[1]])) + 2) >> 2; |
| 601 | 601 | b.copy_from_slice(&(v.min(1023) as u16).to_le_bytes()); |
| 602 | 602 | } |
crates/ec-dnxhd/src/idct.rsmodified+1 -1
| @@ -155,7 +155,7 @@ pub(crate) fn idct_put<const BD: u32>(blk: &mut Block, dst: &mut [u8], stride: u | ||
| 155 | 155 | } |
| 156 | 156 | } else { |
| 157 | 157 | for (row, o) in dst.chunks_mut(stride).zip(out.iter()) { |
| 158 | - for (d, &v) in row[..16].chunks_exact_mut(2).zip(o) { | |
| 158 | + for (d, &v) in row[..16].as_chunks_mut::<2>().0.iter_mut().zip(o) { | |
| 159 | 159 | d.copy_from_slice(&v.to_le_bytes()); |
| 160 | 160 | } |
| 161 | 161 | } |
crates/ec-dnxhd/src/lib.rsmodified+0 -1
| @@ -12,7 +12,6 @@ | ||
| 12 | 12 | //! ec-core has no 12-bit pixel formats, so [`DnxhdDecoder::decode`] narrows |
| 13 | 13 | //! 12-bit pictures to 10 bits (`(v + 2) >> 2`, clamped); [`DnxhdDecoder::decode_native`] |
| 14 | 14 | //! returns the samples at their coded depth. |
| 15 | -#![allow(clippy::chunks_exact_to_as_chunks, clippy::needless_range_loop)] | |
| 16 | 15 | #![forbid(unsafe_code)] |
| 17 | 16 | mod bits; |
| 18 | 17 | mod codec; |
crates/ec-dv/src/lib.rsmodified+0 -1
| @@ -14,7 +14,6 @@ | ||
| 14 | 14 | //! this crate as PCM, and [`DvDemuxer`] publishes it as `PcmS16Le` streams. |
| 15 | 15 | //! * [`DvDemuxer`], [`is_dv`] -- raw `.dv` / `.dif` files. |
| 16 | 16 | #![forbid(unsafe_code)] |
| 17 | -#![allow(clippy::needless_range_loop, clippy::too_many_arguments)] | |
| 18 | 17 | |
| 19 | 18 | mod audio; |
| 20 | 19 | mod decoder; |
crates/ec-dv/src/video.rsmodified+5 -5
| @@ -263,10 +263,10 @@ impl DvVideoDecoder { | ||
| 263 | 263 | let mut f1 = Vec::with_capacity(4096); |
| 264 | 264 | let mut f2 = Vec::with_capacity(4096); |
| 265 | 265 | for c in 0..4 { |
| 266 | - for s in 0..16 { | |
| 266 | + for q in QSTEP { | |
| 267 | 267 | for i in 0..64 { |
| 268 | - f1.push((QSTEP[s] << (c + 9)).wrapping_mul(u32::from(w1[i]))); | |
| 269 | - f2.push((QSTEP[s] << (c + 9)).wrapping_mul(u32::from(w2[i]))); | |
| 268 | + f1.push((q << (c + 9)).wrapping_mul(u32::from(w1[i]))); | |
| 269 | + f2.push((q << (c + 9)).wrapping_mul(u32::from(w2[i]))); | |
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | } |
| @@ -277,11 +277,11 @@ impl DvVideoDecoder { | ||
| 277 | 277 | let mut f1 = Vec::with_capacity(2816); |
| 278 | 278 | let mut f2 = Vec::with_capacity(2816); |
| 279 | 279 | for iw in [&IWEIGHT_88, &IWEIGHT_248] { |
| 280 | - for s in 0..22 { | |
| 280 | + for shifts in QUANT_SHIFTS { | |
| 281 | 281 | let mut i = 0; |
| 282 | 282 | for c in 0..4 { |
| 283 | 283 | while i < AREAS[c] { |
| 284 | - let v = u32::from(iw[i]) << (QUANT_SHIFTS[s][c] + 1); | |
| 284 | + let v = u32::from(iw[i]) << (shifts[c] + 1); | |
| 285 | 285 | f1.push(v); |
| 286 | 286 | f2.push(v << 1); |
| 287 | 287 | i += 1; |
crates/ec-mjpeg/src/lib.rsmodified+3 -7
| @@ -81,13 +81,9 @@ impl MjpegDecoder { | ||
| 81 | 81 | |
| 82 | 82 | /// Decode one packet to one frame. |
| 83 | 83 | pub fn decode(&mut self, data: &[u8], pts: Option<Timestamp>) -> Result<VideoFrame> { |
| 84 | - let container_height = match &self.params.media { | |
| 85 | - MediaParameters::Video(v) => v.height, | |
| 86 | - _ => 0, | |
| 87 | - }; | |
| 88 | - let container_color = match &self.params.media { | |
| 89 | - MediaParameters::Video(v) => v.color, | |
| 90 | - _ => ColorInfo::default(), | |
| 84 | + let (container_height, container_color) = match &self.params.media { | |
| 85 | + MediaParameters::Video(v) => (v.height, v.color), | |
| 86 | + _ => (0, ColorInfo::default()), | |
| 91 | 87 | }; |
| 92 | 88 | let mut frame = decode_frame(data, container_height, self.field_order, self.limits)?; |
| 93 | 89 | frame.pts = pts; |
crates/ec-mpeg2/src/decoder.rsmodified+63 -55
| @@ -14,6 +14,14 @@ use crate::idct::{idct_add, idct_add_dc, idct_put, idct_put_dc}; | ||
| 14 | 14 | use crate::mc::{Image, predict}; |
| 15 | 15 | use crate::tables::*; |
| 16 | 16 | |
| 17 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 18 | +enum SliceError { | |
| 19 | + Picture, | |
| 20 | + Address, | |
| 21 | + Quant, | |
| 22 | + Bitstream, | |
| 23 | +} | |
| 24 | + | |
| 17 | 25 | /// Facts about a decoded picture that [`VideoFrame`] cannot carry. |
| 18 | 26 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 19 | 27 | pub struct PictureInfo { |
| @@ -79,12 +87,16 @@ struct PicState { | ||
| 79 | 87 | second_field: bool, |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | -const MV_FRAME: u8 = 0; | |
| 83 | -const MV_FIELD_IN_FRAME: u8 = 1; | |
| 84 | -const MV_DUAL_FRAME: u8 = 2; | |
| 85 | -const MV_FIELD16: u8 = 3; | |
| 86 | -const MV_16X8: u8 = 4; | |
| 87 | -const MV_DUAL_FIELD: u8 = 5; | |
| 90 | +#[derive(Clone, Copy, Default, PartialEq, Eq)] | |
| 91 | +enum MotionKind { | |
| 92 | + #[default] | |
| 93 | + Frame, | |
| 94 | + FieldInFrame, | |
| 95 | + DualFrame, | |
| 96 | + Field16, | |
| 97 | + Mv16x8, | |
| 98 | + DualField, | |
| 99 | +} | |
| 88 | 100 | |
| 89 | 101 | #[derive(Clone, Copy, Default)] |
| 90 | 102 | struct Motion { |
| @@ -92,7 +104,7 @@ struct Motion { | ||
| 92 | 104 | mv: [[[i32; 2]; 2]; 2], |
| 93 | 105 | sel: [[u8; 2]; 2], |
| 94 | 106 | dmv: [i32; 2], |
| 95 | - kind: u8, | |
| 107 | + kind: MotionKind, | |
| 96 | 108 | fwd: bool, |
| 97 | 109 | bwd: bool, |
| 98 | 110 | } |
| @@ -659,10 +671,10 @@ impl Core { | ||
| 659 | 671 | } |
| 660 | 672 | |
| 661 | 673 | #[allow(clippy::too_many_lines)] |
| 662 | - fn decode_slice(&mut self, code: u8, data: &[u8]) -> std::result::Result<(), ()> { | |
| 663 | - let seq = self.seq.clone().ok_or(())?; | |
| 674 | + fn decode_slice(&mut self, code: u8, data: &[u8]) -> std::result::Result<(), SliceError> { | |
| 675 | + let seq = self.seq.clone().ok_or(SliceError::Picture)?; | |
| 664 | 676 | let t = tables(); |
| 665 | - let mut st = self.pic.take().ok_or(())?; | |
| 677 | + let mut st = self.pic.take().ok_or(SliceError::Picture)?; | |
| 666 | 678 | let r = self.slice_inner(&seq, t, &mut st, code, data); |
| 667 | 679 | self.pic = Some(st); |
| 668 | 680 | r |
| @@ -675,7 +687,7 @@ impl Core { | ||
| 675 | 687 | st: &mut PicState, |
| 676 | 688 | code: u8, |
| 677 | 689 | data: &[u8], |
| 678 | - ) -> std::result::Result<(), ()> { | |
| 690 | + ) -> std::result::Result<(), SliceError> { | |
| 679 | 691 | let hdr = st.hdr.clone(); |
| 680 | 692 | let mpeg1 = !seq.mpeg2; |
| 681 | 693 | let mut b = Bits::new(data); |
| @@ -685,19 +697,19 @@ impl Core { | ||
| 685 | 697 | } |
| 686 | 698 | let mw = seq.mb_width(); |
| 687 | 699 | if mb_row >= st.rows { |
| 688 | - return Err(()); | |
| 700 | + return Err(SliceError::Address); | |
| 689 | 701 | } |
| 690 | 702 | let qcode = b.read(5) as usize; |
| 691 | 703 | if qcode == 0 { |
| 692 | - return Err(()); | |
| 704 | + return Err(SliceError::Quant); | |
| 693 | 705 | } |
| 694 | 706 | while b.read1() { |
| 695 | 707 | b.skip(8); |
| 696 | 708 | } |
| 697 | - let cur_idx = self.cur.as_ref().ok_or(())?.idx; | |
| 709 | + let cur_idx = self.cur.as_ref().ok_or(SliceError::Picture)?.idx; | |
| 698 | 710 | // The picture must match this slice's geometry, or macroblock rows fall outside its planes. |
| 699 | 711 | if self.pool[cur_idx].height[0] != seq.mb_height() * 16 { |
| 700 | - return Err(()); | |
| 712 | + return Err(SliceError::Picture); | |
| 701 | 713 | } |
| 702 | 714 | let ptype = hdr.picture_type; |
| 703 | 715 | let field_pic = hdr.structure != Structure::Frame; |
| @@ -717,8 +729,7 @@ impl Core { | ||
| 717 | 729 | let dc_mult = if mpeg1 { 8 } else { 8 >> hdr.intra_dc_precision }; |
| 718 | 730 | let mut dc_pred = [dc_reset; 3]; |
| 719 | 731 | let mut pmv = [[[0i32; 2]; 2]; 2]; // [r][s][t] |
| 720 | - let mut motion = Motion::default(); | |
| 721 | - motion.fwd = true; | |
| 732 | + let mut motion = Motion { fwd: true, ..Motion::default() }; | |
| 722 | 733 | let mut addr: isize = (mb_row * mw) as isize - 1; |
| 723 | 734 | let mut first = true; |
| 724 | 735 | let nblocks = if seq.chroma_format == 1 { 6 } else { 8 }; |
| @@ -728,7 +739,7 @@ impl Core { | ||
| 728 | 739 | // macroblock_address_increment |
| 729 | 740 | let mut inc = 0usize; |
| 730 | 741 | loop { |
| 731 | - let v = b.vlc(&t.mba).ok_or(())?; | |
| 742 | + let v = b.vlc(&t.mba).ok_or(SliceError::Bitstream)?; | |
| 732 | 743 | if v == 34 { |
| 733 | 744 | inc += 33; |
| 734 | 745 | } else if v == 35 { |
| @@ -738,7 +749,7 @@ impl Core { | ||
| 738 | 749 | break; |
| 739 | 750 | } |
| 740 | 751 | if b.overrun() { |
| 741 | - return Err(()); | |
| 752 | + return Err(SliceError::Bitstream); | |
| 742 | 753 | } |
| 743 | 754 | } |
| 744 | 755 | if first { |
| @@ -749,7 +760,7 @@ impl Core { | ||
| 749 | 760 | for _ in 1..inc { |
| 750 | 761 | addr += 1; |
| 751 | 762 | if addr as usize >= total { |
| 752 | - return Err(()); | |
| 763 | + return Err(SliceError::Address); | |
| 753 | 764 | } |
| 754 | 765 | let a = addr as usize; |
| 755 | 766 | // Skipped macroblock. |
| @@ -759,7 +770,7 @@ impl Core { | ||
| 759 | 770 | // Same directions and vectors as the previous macroblock, |
| 760 | 771 | // predicted frame-wise (field-wise from the same-parity |
| 761 | 772 | // field in a field picture). |
| 762 | - m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME }; | |
| 773 | + m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame }; | |
| 763 | 774 | for s2 in 0..2 { |
| 764 | 775 | m.mv[s2][0] = pmv[0][s2]; |
| 765 | 776 | m.mv[s2][1] = pmv[0][s2]; |
| @@ -770,13 +781,13 @@ impl Core { | ||
| 770 | 781 | pmv = [[[0; 2]; 2]; 2]; |
| 771 | 782 | m = Motion::default(); |
| 772 | 783 | m.fwd = true; |
| 773 | - m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME }; | |
| 784 | + m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame }; | |
| 774 | 785 | let sel = st.parity as u8; |
| 775 | 786 | m.sel = [[sel; 2]; 2]; |
| 776 | 787 | motion = m; |
| 777 | 788 | } |
| 778 | 789 | if ptype == PictureType::I { |
| 779 | - return Err(()); | |
| 790 | + return Err(SliceError::Address); | |
| 780 | 791 | } |
| 781 | 792 | let info = MbInfo { intra: false, m, dct_field: false, cbp: 0, last: [0; 8] }; |
| 782 | 793 | self.recon_mb(seq, &hdr, st, cur_idx, a % mw, a / mw, &info, &mut blocks); |
| @@ -785,7 +796,7 @@ impl Core { | ||
| 785 | 796 | addr += 1; |
| 786 | 797 | } |
| 787 | 798 | if addr < 0 || addr as usize >= total { |
| 788 | - return Err(()); | |
| 799 | + return Err(SliceError::Bitstream); | |
| 789 | 800 | } |
| 790 | 801 | let a = addr as usize; |
| 791 | 802 | let mb_x = a % mw; |
| @@ -797,7 +808,7 @@ impl Core { | ||
| 797 | 808 | PictureType::P => 1, |
| 798 | 809 | PictureType::B => 2, |
| 799 | 810 | }; |
| 800 | - let flags = b.vlc(&t.mbtype[ti]).ok_or(())? as u16; | |
| 811 | + let flags = b.vlc(&t.mbtype[ti]).ok_or(SliceError::Bitstream)? as u16; | |
| 801 | 812 | let intra = flags & MB_INTRA != 0; |
| 802 | 813 | let mut m = Motion { fwd: flags & MB_FWD != 0, bwd: flags & MB_BWD != 0, ..Motion::default() }; |
| 803 | 814 | let mut dct_field = false; |
| @@ -808,7 +819,7 @@ impl Core { | ||
| 808 | 819 | } else { |
| 809 | 820 | kind_code = b.read(2); |
| 810 | 821 | if kind_code == 0 { |
| 811 | - return Err(()); | |
| 822 | + return Err(SliceError::Bitstream); | |
| 812 | 823 | } |
| 813 | 824 | } |
| 814 | 825 | } else if mpeg1 { |
| @@ -820,25 +831,25 @@ impl Core { | ||
| 820 | 831 | if flags & MB_QUANT != 0 { |
| 821 | 832 | let qc = b.read(5) as usize; |
| 822 | 833 | if qc == 0 { |
| 823 | - return Err(()); | |
| 834 | + return Err(SliceError::Quant); | |
| 824 | 835 | } |
| 825 | 836 | qscale = qscale_of(qc); |
| 826 | 837 | } |
| 827 | 838 | m.kind = if field_pic { |
| 828 | 839 | match kind_code { |
| 829 | - 1 => MV_FIELD16, | |
| 830 | - 2 => MV_16X8, | |
| 831 | - _ => MV_DUAL_FIELD, | |
| 840 | + 1 => MotionKind::Field16, | |
| 841 | + 2 => MotionKind::Mv16x8, | |
| 842 | + _ => MotionKind::DualField, | |
| 832 | 843 | } |
| 833 | 844 | } else { |
| 834 | 845 | match kind_code { |
| 835 | - 1 => MV_FIELD_IN_FRAME, | |
| 836 | - 2 => MV_FRAME, | |
| 837 | - _ => MV_DUAL_FRAME, | |
| 846 | + 1 => MotionKind::FieldInFrame, | |
| 847 | + 2 => MotionKind::Frame, | |
| 848 | + _ => MotionKind::DualFrame, | |
| 838 | 849 | } |
| 839 | 850 | }; |
| 840 | 851 | if intra && hdr.concealment_motion_vectors { |
| 841 | - m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME }; | |
| 852 | + m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame }; | |
| 842 | 853 | } |
| 843 | 854 | // Motion vectors. |
| 844 | 855 | if m.fwd || (intra && hdr.concealment_motion_vectors) { |
| @@ -861,7 +872,7 @@ impl Core { | ||
| 861 | 872 | // No motion compensation: zero vector. |
| 862 | 873 | pmv = [[[0; 2]; 2]; 2]; |
| 863 | 874 | m.fwd = true; |
| 864 | - m.kind = if field_pic { MV_FIELD16 } else { MV_FRAME }; | |
| 875 | + m.kind = if field_pic { MotionKind::Field16 } else { MotionKind::Frame }; | |
| 865 | 876 | m.sel = [[st.parity as u8; 2]; 2]; |
| 866 | 877 | m.mv = [[[0; 2]; 2]; 2]; |
| 867 | 878 | } |
| @@ -872,7 +883,7 @@ impl Core { | ||
| 872 | 883 | if intra { |
| 873 | 884 | cbp = (1 << nblocks) - 1; |
| 874 | 885 | } else if flags & MB_PAT != 0 { |
| 875 | - cbp = b.vlc(&t.cbp).ok_or(())?; | |
| 886 | + cbp = b.vlc(&t.cbp).ok_or(SliceError::Bitstream)?; | |
| 876 | 887 | if seq.chroma_format == 2 { |
| 877 | 888 | cbp = (cbp << 2) | b.read(2); |
| 878 | 889 | } |
| @@ -927,7 +938,7 @@ impl Core { | ||
| 927 | 938 | for blk in blocks.iter_mut() { |
| 928 | 939 | *blk = [0; 64]; |
| 929 | 940 | } |
| 930 | - return Err(()); | |
| 941 | + return Err(SliceError::Bitstream); | |
| 931 | 942 | } |
| 932 | 943 | let info = MbInfo { intra, m, dct_field, cbp, last }; |
| 933 | 944 | self.recon_mb(seq, &hdr, st, cur_idx, mb_x, mb_y, &info, &mut blocks); |
| @@ -939,7 +950,7 @@ impl Core { | ||
| 939 | 950 | motion = Motion { fwd: true, ..Motion::default() }; |
| 940 | 951 | } |
| 941 | 952 | if b.overrun() { |
| 942 | - return Err(()); | |
| 953 | + return Err(SliceError::Bitstream); | |
| 943 | 954 | } |
| 944 | 955 | if b.peek(23) == 0 { |
| 945 | 956 | break; |
| @@ -999,18 +1010,17 @@ impl Core { | ||
| 999 | 1010 | let mvv = |r: usize| (m.mv[s][r][0], m.mv[s][r][1]); |
| 1000 | 1011 | let ptype = hdr.picture_type; |
| 1001 | 1012 | match m.kind { |
| 1002 | - MV_FRAME => { | |
| 1013 | + MotionKind::Frame => { | |
| 1003 | 1014 | let (x, y) = mvv(0); |
| 1004 | 1015 | push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, None, st, cur), field: None, src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false }); |
| 1005 | 1016 | } |
| 1006 | - MV_FIELD_IN_FRAME => { | |
| 1007 | - for r in 0..2 { | |
| 1017 | + MotionKind::FieldInFrame => { | |
| 1018 | + for (r, &f) in m.sel[s].iter().enumerate() { | |
| 1008 | 1019 | let (x, y) = mvv(r); |
| 1009 | - let f = m.sel[s][r]; | |
| 1010 | 1020 | push(Part { dst0: r, step: 2, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 8) as i32, mvx: x, mvy: y, avg: false }); |
| 1011 | 1021 | } |
| 1012 | 1022 | } |
| 1013 | - MV_DUAL_FRAME => { | |
| 1023 | + MotionKind::DualFrame => { | |
| 1014 | 1024 | let (x, y) = mvv(0); |
| 1015 | 1025 | for p in 0..2usize { |
| 1016 | 1026 | let mm = if (p == 0) == hdr.top_field_first { 1 } else { 3 }; |
| @@ -1022,20 +1032,18 @@ impl Core { | ||
| 1022 | 1032 | push(Part { dst0: p, step: 2, rows: 8, src, field: Some(1 - p as u8), src_row: (mb_y * 8) as i32, mvx: ox, mvy: oy, avg: true }); |
| 1023 | 1033 | } |
| 1024 | 1034 | } |
| 1025 | - MV_FIELD16 => { | |
| 1035 | + MotionKind::Field16 => { | |
| 1026 | 1036 | let (x, y) = mvv(0); |
| 1027 | 1037 | let f = m.sel[s][0]; |
| 1028 | 1038 | push(Part { dst0: 0, step: 1, rows: 16, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16) as i32, mvx: x, mvy: y, avg: false }); |
| 1029 | 1039 | } |
| 1030 | - MV_16X8 => { | |
| 1031 | - for r in 0..2 { | |
| 1040 | + MotionKind::Mv16x8 => { | |
| 1041 | + for (r, &f) in m.sel[s].iter().enumerate() { | |
| 1032 | 1042 | let (x, y) = mvv(r); |
| 1033 | - let f = m.sel[s][r]; | |
| 1034 | 1043 | push(Part { dst0: 8 * r, step: 1, rows: 8, src: self.ref_for(ptype, s, Some(f), st, cur), field: Some(f), src_row: (mb_y * 16 + 8 * r) as i32, mvx: x, mvy: y, avg: false }); |
| 1035 | 1044 | } |
| 1036 | 1045 | } |
| 1037 | - _ => { | |
| 1038 | - // MV_DUAL_FIELD | |
| 1046 | + MotionKind::DualField => { | |
| 1039 | 1047 | let (x, y) = mvv(0); |
| 1040 | 1048 | let p = st.parity as u8; |
| 1041 | 1049 | let e = if p == 0 { -1 } else { 1 }; |
| @@ -1207,12 +1215,12 @@ fn read_motion( | ||
| 1207 | 1215 | m: &mut Motion, |
| 1208 | 1216 | pmv: &mut [[[i32; 2]; 2]; 2], |
| 1209 | 1217 | s: usize, |
| 1210 | -) -> std::result::Result<(), ()> { | |
| 1218 | +) -> std::result::Result<(), SliceError> { | |
| 1211 | 1219 | let field_pic = hdr.structure != Structure::Frame; |
| 1212 | - let dual = matches!(m.kind, MV_DUAL_FRAME | MV_DUAL_FIELD); | |
| 1213 | - let field_fmt = field_pic || m.kind != MV_FRAME; | |
| 1220 | + let dual = matches!(m.kind, MotionKind::DualFrame | MotionKind::DualField); | |
| 1221 | + let field_fmt = field_pic || m.kind != MotionKind::Frame; | |
| 1214 | 1222 | let frame_field = !field_pic && field_fmt; |
| 1215 | - let n = if matches!(m.kind, MV_FIELD_IN_FRAME | MV_16X8) { 2 } else { 1 }; | |
| 1223 | + let n = if matches!(m.kind, MotionKind::FieldInFrame | MotionKind::Mv16x8) { 2 } else { 1 }; | |
| 1216 | 1224 | let shift = if mpeg1 && hdr.full_pel[s] { 1 } else { 0 }; |
| 1217 | 1225 | for r in 0..n { |
| 1218 | 1226 | if field_fmt && !dual { |
| @@ -1223,7 +1231,7 @@ fn read_motion( | ||
| 1223 | 1231 | if tc == 1 && frame_field { |
| 1224 | 1232 | pred >>= 1; |
| 1225 | 1233 | } |
| 1226 | - let v = decode_component(b, t, hdr.f_code[s][tc], pred).ok_or(())?; | |
| 1234 | + let v = decode_component(b, t, hdr.f_code[s][tc], pred).ok_or(SliceError::Bitstream)?; | |
| 1227 | 1235 | pmv[r][s][tc] = if tc == 1 && frame_field { v << 1 } else { v }; |
| 1228 | 1236 | m.mv[s][r][tc] = v << shift; |
| 1229 | 1237 | if dual { |
| @@ -1236,7 +1244,7 @@ fn read_motion( | ||
| 1236 | 1244 | m.mv[s][1] = m.mv[s][0]; |
| 1237 | 1245 | m.sel[s][1] = m.sel[s][0]; |
| 1238 | 1246 | } |
| 1239 | - if b.overrun() { Err(()) } else { Ok(()) } | |
| 1247 | + if b.overrun() { Err(SliceError::Bitstream) } else { Ok(()) } | |
| 1240 | 1248 | } |
| 1241 | 1249 | |
| 1242 | 1250 | #[allow(clippy::too_many_arguments)] |
crates/ec-mpeg2/src/header.rsmodified+3 -3
| @@ -309,9 +309,9 @@ pub(crate) fn parse_picture_header(data: &[u8]) -> Result<PictureHeader> { | ||
| 309 | 309 | |
| 310 | 310 | pub(crate) fn parse_picture_coding_extension(b: &mut Bits, h: &mut PictureHeader) -> Result<()> { |
| 311 | 311 | let mut f_code = [[0u8; 2]; 2]; |
| 312 | - for s in 0..2 { | |
| 313 | - for t in 0..2 { | |
| 314 | - f_code[s][t] = b.read(4) as u8; | |
| 312 | + for row in f_code.iter_mut() { | |
| 313 | + for v in row.iter_mut() { | |
| 314 | + *v = b.read(4) as u8; | |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | let dc = b.read(2) as u8; |
crates/ec-mpeg2/src/lib.rsmodified+0 -1
| @@ -1,4 +1,3 @@ | ||
| 1 | -#![allow(clippy::needless_range_loop, clippy::field_reassign_with_default, clippy::too_many_arguments, clippy::type_complexity)] | |
| 2 | 1 | //! MPEG-1 and MPEG-2 video decoder. |
| 3 | 2 | #![forbid(unsafe_code)] |
| 4 | 3 | mod bits; |
crates/ec-mpeg4/src/core.rsmodified+3 -3
| @@ -364,12 +364,12 @@ impl Core { | ||
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | let wc = self.wc as isize; |
| 367 | - for p in 1..3 { | |
| 367 | + for ac in self.ac[1..3].iter_mut() { | |
| 368 | 368 | let start = (my - 1 + 1) * wc + (mx - 1 + 1); |
| 369 | 369 | for k in 0..(wc + 1) { |
| 370 | 370 | let i = (start + k) as usize; |
| 371 | - if i < self.ac[p].len() { | |
| 372 | - self.ac[p][i] = [0; 16]; | |
| 371 | + if i < ac.len() { | |
| 372 | + ac[i] = [0; 16]; | |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | } |
crates/ec-mpeg4/src/dsp.rsmodified+3 -0
| @@ -483,6 +483,7 @@ fn hpel_mode<const W: usize, const AVG: bool>( | ||
| 483 | 483 | /// the full (w+1)x(h+1). ffmpeg only has `put_no_rnd` tables for w = 16 and 8, so |
| 484 | 484 | /// `no_rnd` is ignored (rounding variant used) for w = 4 and 2. |
| 485 | 485 | /// Rounding: x2/y2 = (a+b+1)>>1 (no_rnd: (a+b)>>1); xy2 = (a+b+c+d+2)>>2 (no_rnd: +1). |
| 486 | +#[allow(clippy::too_many_arguments)] | |
| 486 | 487 | pub fn put_hpel( |
| 487 | 488 | dst: &mut [u8], |
| 488 | 489 | dst_stride: usize, |
| @@ -513,6 +514,7 @@ pub fn put_hpel( | ||
| 513 | 514 | /// is avg_pixels16). For w = 8/4/2 `no_rnd` is ignored. |
| 514 | 515 | /// Quirk reproduced from the C: `avg_pixels2_xy2_8_c` does NOT average with dst (it just |
| 515 | 516 | /// stores, like put) -- the hand-written 2-wide xy2 loop has `/* FIXME non put */`. |
| 517 | +#[allow(clippy::too_many_arguments)] | |
| 516 | 518 | pub fn avg_hpel( |
| 517 | 519 | dst: &mut [u8], |
| 518 | 520 | dst_stride: usize, |
| @@ -799,6 +801,7 @@ pub fn avg_qpel( | ||
| 799 | 801 | |
| 800 | 802 | /// gmc1_c: 8-wide, `h` rows. Reads 9 columns x (h+1) rows of `src` starting at src[0]. |
| 801 | 803 | /// dst = (A*s[0] + B*s[1] + C*s[stride] + D*s[stride+1] + rounder) >> 8 (truncated to u8). |
| 804 | +#[allow(clippy::too_many_arguments)] | |
| 802 | 805 | pub fn gmc1( |
| 803 | 806 | dst: &mut [u8], |
| 804 | 807 | dst_stride: usize, |
crates/ec-mpeg4/src/h263.rsmodified+2 -2
| @@ -290,11 +290,11 @@ impl Core { | ||
| 290 | 290 | } else { |
| 291 | 291 | kind = K_8X8; |
| 292 | 292 | w.mvt = Mvt::M8; |
| 293 | - for i in 0..4 { | |
| 293 | + for (i, mv) in w.mv[0].iter_mut().enumerate() { | |
| 294 | 294 | let (px, py) = self.pred_motion(i); |
| 295 | 295 | let mx = self.decode_motion(br, px, 1)?; |
| 296 | 296 | let my = self.decode_motion(br, py, 1)?; |
| 297 | - w.mv[0][i] = [mx, my]; | |
| 297 | + *mv = [mx, my]; | |
| 298 | 298 | let bx = 2 * self.mb_x as isize + (i & 1) as isize; |
| 299 | 299 | let by = 2 * self.mb_y as isize + (i >> 1) as isize; |
| 300 | 300 | let ci = self.mvi(bx, by); |
crates/ec-mpeg4/src/h263data.rsmodified+2 -2
| @@ -489,8 +489,8 @@ mod spec_tests { | ||
| 489 | 489 | (c, n) |
| 490 | 490 | ); |
| 491 | 491 | } |
| 492 | - for slot in 21..24 { | |
| 493 | - assert_eq!(H263_INTER_MCBPC_BITS[slot], 0); | |
| 492 | + for &bits in &H263_INTER_MCBPC_BITS[21..24] { | |
| 493 | + assert_eq!(bits, 0); | |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 |
crates/ec-mpeg4/src/header.rsmodified+1 -0
| @@ -700,6 +700,7 @@ pub fn parse_sprite_trajectory( | ||
| 700 | 700 | let vlc = &vlcs().sprite_traj; |
| 701 | 701 | let div500_413 = ident.divx_version == 500 && ident.divx_build == 413; |
| 702 | 702 | let mut d = [[0i64; 2]; 4]; |
| 703 | + #[allow(clippy::needless_range_loop)] | |
| 703 | 704 | for i in 0..npts { |
| 704 | 705 | let mut x = 0; |
| 705 | 706 | let mut y = 0; |
crates/ec-mpeg4/src/lib.rsmodified+0 -5
| @@ -1,8 +1,3 @@ | ||
| 1 | -#![allow( | |
| 2 | - clippy::needless_range_loop, | |
| 3 | - clippy::too_many_arguments, | |
| 4 | - clippy::type_complexity | |
| 5 | -)] | |
| 6 | 1 | #![forbid(unsafe_code)] |
| 7 | 2 | //! MPEG-4 Part 2 Visual (Simple and Advanced Simple profile) and H.263 baseline decoder. |
| 8 | 3 |
crates/ec-mpeg4/src/mb.rsmodified+4 -4
| @@ -775,10 +775,10 @@ impl Core { | ||
| 775 | 775 | w.field_select[0][0] = br.bit() as u8; |
| 776 | 776 | w.field_select[0][1] = br.bit() as u8; |
| 777 | 777 | let (px, py) = self.pred_motion(0); |
| 778 | - for i in 0..2 { | |
| 778 | + for mv in &mut w.mv[0][..2] { | |
| 779 | 779 | let mx = self.decode_motion(br, px, self.f_code)?; |
| 780 | 780 | let my = self.decode_motion(br, py / 2, self.f_code)?; |
| 781 | - w.mv[0][i] = [mx, my]; | |
| 781 | + *mv = [mx, my]; | |
| 782 | 782 | } |
| 783 | 783 | } else { |
| 784 | 784 | w.mvt = Mvt::M16; |
| @@ -790,11 +790,11 @@ impl Core { | ||
| 790 | 790 | } else { |
| 791 | 791 | kind = K_8X8; |
| 792 | 792 | w.mvt = Mvt::M8; |
| 793 | - for i in 0..4 { | |
| 793 | + for (i, mv) in w.mv[0].iter_mut().enumerate() { | |
| 794 | 794 | let (px, py) = self.pred_motion(i); |
| 795 | 795 | let mx = self.decode_motion(br, px, self.f_code)?; |
| 796 | 796 | let my = self.decode_motion(br, py, self.f_code)?; |
| 797 | - w.mv[0][i] = [mx, my]; | |
| 797 | + *mv = [mx, my]; | |
| 798 | 798 | let bx = 2 * self.mb_x as isize + (i & 1) as isize; |
| 799 | 799 | let by = 2 * self.mb_y as isize + (i >> 1) as isize; |
| 800 | 800 | let ci = self.mvi(bx, by); |
crates/ec-mpeg4/src/recon.rsmodified+5 -2
| @@ -25,6 +25,7 @@ struct Geo { | ||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /// A source window: either a view straight into the plane or a clamped copy. |
| 28 | +#[allow(clippy::too_many_arguments)] | |
| 28 | 29 | fn window<'a>( |
| 29 | 30 | plane: &'a [u8], |
| 30 | 31 | stride: usize, |
| @@ -54,6 +55,7 @@ fn window<'a>( | ||
| 54 | 55 | (&buf[..], WS) |
| 55 | 56 | } |
| 56 | 57 | |
| 58 | +#[allow(clippy::too_many_arguments)] | |
| 57 | 59 | fn put_or_avg_hpel( |
| 58 | 60 | avg: bool, |
| 59 | 61 | dst: &mut [u8], |
| @@ -72,6 +74,7 @@ fn put_or_avg_hpel( | ||
| 72 | 74 | } |
| 73 | 75 | } |
| 74 | 76 | |
| 77 | +#[allow(clippy::too_many_arguments)] | |
| 75 | 78 | fn put_or_avg_qpel( |
| 76 | 79 | avg: bool, |
| 77 | 80 | dst: &mut [u8], |
| @@ -351,8 +354,8 @@ fn apply_8x8( | ||
| 351 | 354 | ) { |
| 352 | 355 | let aw = g.aw; |
| 353 | 356 | let (mut sx, mut sy) = (0, 0); |
| 354 | - for i in 0..4 { | |
| 355 | - let (mx, my) = (mv[i][0], mv[i][1]); | |
| 357 | + for (i, m) in mv.iter().enumerate() { | |
| 358 | + let (mx, my) = (m[0], m[1]); | |
| 356 | 359 | let bx = (i & 1) as i32 * 8; |
| 357 | 360 | let by = (i >> 1) as i32 * 8; |
| 358 | 361 | let doff = (g.mb_y as usize * 16 + by as usize) * aw + g.mb_x as usize * 16 + bx as usize; |
crates/ec-prores/src/encode.rsmodified+6 -6
| @@ -214,15 +214,15 @@ fn tabs() -> &'static Tabs { | ||
| 214 | 214 | T.get_or_init(|| { |
| 215 | 215 | let mut t = Tabs { run: [[(0, 0); TAB]; 16], lvl: [[(0, 0); TAB]; 10] }; |
| 216 | 216 | for (i, &cb) in RUN_CB.iter().enumerate() { |
| 217 | - for v in 0..TAB { | |
| 217 | + for (v, slot) in t.run[i].iter_mut().enumerate() { | |
| 218 | 218 | let (c, l) = cw_code(cb, v as u32); |
| 219 | - t.run[i][v] = (c, l as u8); | |
| 219 | + *slot = (c, l as u8); | |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | for (i, &cb) in LEVEL_CB.iter().enumerate() { |
| 223 | - for v in 0..TAB { | |
| 223 | + for (v, slot) in t.lvl[i].iter_mut().enumerate() { | |
| 224 | 224 | let (c, l) = cw_code(cb, v as u32); |
| 225 | - t.lvl[i][v] = (c, l as u8); | |
| 225 | + *slot = (c, l as u8); | |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | t |
| @@ -322,8 +322,8 @@ fn code_component<S: Sink>(s: &mut S, q: &[i16], nb: usize) { | ||
| 322 | 322 | let mut prev = first; |
| 323 | 323 | let mut prev_neg = false; |
| 324 | 324 | let mut cbi = 5usize; |
| 325 | - for b in 1..nb { | |
| 326 | - let cur = i32::from(q[b]); | |
| 325 | + for &qb in q.iter().take(nb).skip(1) { | |
| 326 | + let cur = i32::from(qb); | |
| 327 | 327 | let d = cur - prev; |
| 328 | 328 | let neg = d < 0; |
| 329 | 329 | let code = if d == 0 { 0 } else { 2 * d.unsigned_abs() - u32::from(neg != prev_neg) }; |
crates/ec-prores/src/idct.rsmodified+4 -3
| @@ -28,7 +28,8 @@ pub mod reference { | ||
| 28 | 28 | pub col_shift: u32, |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - const fn k(w1: i32, w2: i32, w3: i32, w4: i32, w5: i32, w6: i32, w7: i32, row_shift: u32, col_shift: u32) -> K { | |
| 31 | + const fn k(w: [i32; 7], row_shift: u32, col_shift: u32) -> K { | |
| 32 | + let [w1, w2, w3, w4, w5, w6, w7] = w; | |
| 32 | 33 | K { |
| 33 | 34 | a2: [w2, w6, -w6, -w2], |
| 34 | 35 | a4: [w4, -w4, -w4, w4], |
| @@ -43,8 +44,8 @@ pub mod reference { | ||
| 43 | 44 | } |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | - pub static K10: K = k(22725, 21407, 19265, 16384, 12873, 8867, 4520, 13 + 2, 18); | |
| 47 | - pub static K12: K = k(45451, 42813, 38531, 32767, 25746, 17734, 9041, 16, 17); | |
| 47 | + pub static K10: K = k([22725, 21407, 19265, 16384, 12873, 8867, 4520], 13 + 2, 18); | |
| 48 | + pub static K12: K = k([45451, 42813, 38531, 32767, 25746, 17734, 9041], 16, 17); | |
| 48 | 49 | |
| 49 | 50 | #[inline(always)] |
| 50 | 51 | fn row_pass(k: &K, row: &mut [i16; 8]) { |
crates/ec-prores/src/lib.rsmodified+0 -1
| @@ -1,4 +1,3 @@ | ||
| 1 | -#![allow(clippy::needless_range_loop, clippy::too_many_arguments)] | |
| 2 | 1 | //! Apple ProRes video decoder (SMPTE RDD 36). |
| 3 | 2 | //! |
| 4 | 3 | //! Profiles 422 Proxy / LT / Standard / HQ (`apco`, `apcs`, `apcn`, `apch`) decode to |
crates/ec-prores/src/slice.rsmodified+2 -2
| @@ -105,10 +105,10 @@ fn luts() -> &'static Luts { | ||
| 105 | 105 | L.get_or_init(|| { |
| 106 | 106 | let mut l = Box::new(Luts { run: [0; 16 * 256], level: [0; 10 * 256], dc: [[0; 256]; 7] }); |
| 107 | 107 | for ctx in 0..7 { |
| 108 | - for i in 0..256usize { | |
| 108 | + for (i, slot) in l.dc[ctx].iter_mut().enumerate() { | |
| 109 | 109 | let (v, n) = Br::decode_w(DC_CB[ctx], (i as u64) << 56); |
| 110 | 110 | if n <= 8 && v < 4096 { |
| 111 | - l.dc[ctx][i] = (v as u16) << 4 | n as u16; | |
| 111 | + *slot = (v as u16) << 4 | n as u16; | |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | } |