S8: one generic unscan<N> behind unzigzag, unfield and their 8x8 variants (same loop, same indices)
Browse files at this commite69b563bdd4cf8fa10e80bff81115477fa134c77Parent: ee455d51 changed file +9 -10
crates/ec-h264/src/transform.rsmodified+9 -10
| @@ -118,15 +118,18 @@ pub fn dequant_8x8(block: &mut [i32; 64], ls: &LevelScale8x8, qp: i32) { | |||
| 118 | /// 8x8 zig-zag (Table 8-14). | 118 | /// 8x8 zig-zag (Table 8-14). |
| 119 | #[inline] | 119 | #[inline] |
| 120 | pub fn unzigzag_8x8(scan: &[i32; 64], out: &mut [i32; 64]) { | 120 | pub fn unzigzag_8x8(scan: &[i32; 64], out: &mut [i32; 64]) { |
| 121 | - for (s, &raster) in ZIGZAG_8X8.iter().enumerate() { | 121 | + unscan(&ZIGZAG_8X8, scan, out); |
| 122 | - out[raster as usize] = scan[s]; | ||
| 123 | - } | ||
| 124 | } | 122 | } |
| 125 | 123 | ||
| 126 | /// The same with the 8x8 field scan (Table 8-14), for field macroblocks. | 124 | /// The same with the 8x8 field scan (Table 8-14), for field macroblocks. |
| 127 | #[inline] | 125 | #[inline] |
| 128 | pub fn unfield_8x8(scan: &[i32; 64], out: &mut [i32; 64]) { | 126 | 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() { | ||
| 130 | out[raster as usize] = scan[s]; | 133 | out[raster as usize] = scan[s]; |
| 131 | } | 134 | } |
| 132 | } | 135 | } |
| @@ -197,17 +200,13 @@ pub fn inverse_transform_8x8(d: &[i32; 64], r: &mut [i32; 64]) { | |||
| 197 | /// Place scan-order coefficients into raster order using the 4x4 zig-zag. | 200 | /// Place scan-order coefficients into raster order using the 4x4 zig-zag. |
| 198 | #[inline] | 201 | #[inline] |
| 199 | pub fn unzigzag(scan: &[i32; 16], out: &mut [i32; 16]) { | 202 | pub fn unzigzag(scan: &[i32; 16], out: &mut [i32; 16]) { |
| 200 | - for (s, &raster) in ZIGZAG_4X4.iter().enumerate() { | 203 | + unscan(&ZIGZAG_4X4, scan, out); |
| 201 | - out[raster as usize] = scan[s]; | ||
| 202 | - } | ||
| 203 | } | 204 | } |
| 204 | 205 | ||
| 205 | /// The same with the 4x4 field scan (Table 8-13), for field macroblocks. | 206 | /// The same with the 4x4 field scan (Table 8-13), for field macroblocks. |
| 206 | #[inline] | 207 | #[inline] |
| 207 | pub fn unfield(scan: &[i32; 16], out: &mut [i32; 16]) { | 208 | pub fn unfield(scan: &[i32; 16], out: &mut [i32; 16]) { |
| 208 | - for (s, &raster) in FIELD_4X4.iter().enumerate() { | 209 | + unscan(&FIELD_4X4, scan, out); |
| 209 | - out[raster as usize] = scan[s]; | ||
| 210 | - } | ||
| 211 | } | 210 | } |
| 212 | 211 | ||
| 213 | /// Field-scan counterpart of [`unzigzag_ac15`]. | 212 | /// Field-scan counterpart of [`unzigzag_ac15`]. |