forge
Explore
Log in

Don't you dare go Hollow

S8: one generic unscan<N> behind unzigzag, unfield and their 8x8 variants (same loop, same indices)

Browse files at this commit

e69b563bdd4cf8fa10e80bff81115477fa134c77Ahmet Kaan GümüşParent: ee455d5
crates/ec-h264/src/transform.rsmodified+9 -10
@@ -118,15 +118,18 @@ pub fn dequant_8x8(block: &mut [i32; 64], ls: &LevelScale8x8, qp: i32) {
118118 /// 8x8 zig-zag (Table 8-14).
119119 #[inline]
120120 pub fn unzigzag_8x8(scan: &[i32; 64], out: &mut [i32; 64]) {
121- for (s, &raster) in ZIGZAG_8X8.iter().enumerate() {
122- out[raster as usize] = scan[s];
123- }
121+ unscan(&ZIGZAG_8X8, scan, out);
124122 }
125123
126124 /// The same with the 8x8 field scan (Table 8-14), for field macroblocks.
127125 #[inline]
128126 pub fn unfield_8x8(scan: &[i32; 64], out: &mut [i32; 64]) {
129- for (s, &raster) in FIELD_8X8.iter().enumerate() {
127+ unscan(&FIELD_8X8, scan, out);
128+}
129+
130+#[inline]
131+pub fn unscan<const N: usize>(order: &[u8], scan: &[i32; N], out: &mut [i32; N]) {
132+ for (s, &raster) in order.iter().enumerate() {
130133 out[raster as usize] = scan[s];
131134 }
132135 }
@@ -197,17 +200,13 @@ pub fn inverse_transform_8x8(d: &[i32; 64], r: &mut [i32; 64]) {
197200 /// Place scan-order coefficients into raster order using the 4x4 zig-zag.
198201 #[inline]
199202 pub fn unzigzag(scan: &[i32; 16], out: &mut [i32; 16]) {
200- for (s, &raster) in ZIGZAG_4X4.iter().enumerate() {
201- out[raster as usize] = scan[s];
202- }
203+ unscan(&ZIGZAG_4X4, scan, out);
203204 }
204205
205206 /// The same with the 4x4 field scan (Table 8-13), for field macroblocks.
206207 #[inline]
207208 pub fn unfield(scan: &[i32; 16], out: &mut [i32; 16]) {
208- for (s, &raster) in FIELD_4X4.iter().enumerate() {
209- out[raster as usize] = scan[s];
210- }
209+ unscan(&FIELD_4X4, scan, out);
211210 }
212211
213212 /// Field-scan counterpart of [`unzigzag_ac15`].