remage74a9b56
Use as_chunks for constant chunk sizes (clippy 1.99)
+27 −9
4 files changed
- M src/decode/color.rs +10 −4
- M src/decode/mod.rs +7 −1
- M src/render/mod.rs +1 −1
- M src/thumbs.rs +9 −3
| @@ -92,7 +92,9 @@ fn aces(x: f32) -> f32 { | |||
| 92 | 92 | /// within 0..1 are only encoded; brighter ones are tone-mapped. | |
| 93 | 93 | pub fn tonemap(rgba: &[f32]) -> Vec<u8> { | |
| 94 | 94 | let peak = rgba | |
| 95 | − | .chunks_exact(4) | |
| 95 | + | .as_chunks::<4>() | |
| 96 | + | .0 | |
| 97 | + | .iter() | |
| 96 | 98 | .flat_map(|p| &p[..3]) | |
| 97 | 99 | .copied() | |
| 98 | 100 | .filter(|v| v.is_finite()) | |
| @@ -100,7 +102,7 @@ pub fn tonemap(rgba: &[f32]) -> Vec<u8> { | |||
| 100 | 102 | let hdr = peak > 1.0; | |
| 101 | 103 | let to8 = |v: f32| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8; | |
| 102 | 104 | let mut out = Vec::with_capacity(rgba.len()); | |
| 103 | − | for p in rgba.chunks_exact(4) { | |
| 105 | + | for p in rgba.as_chunks::<4>().0.iter() { | |
| 104 | 106 | for &c in &p[..3] { | |
| 105 | 107 | let c = if c.is_finite() { c.max(0.0) } else { 0.0 }; | |
| 106 | 108 | let c = if hdr { aces(c) } else { c }; | |
| @@ -149,11 +151,15 @@ pub fn expand(samples: &[u8], channels: usize) -> Vec<u8> { | |||
| 149 | 151 | match channels { | |
| 150 | 152 | 4 => samples.to_vec(), | |
| 151 | 153 | 3 => samples | |
| 152 | − | .chunks_exact(3) | |
| 154 | + | .as_chunks::<3>() | |
| 155 | + | .0 | |
| 156 | + | .iter() | |
| 153 | 157 | .flat_map(|p| [p[0], p[1], p[2], 255]) | |
| 154 | 158 | .collect(), | |
| 155 | 159 | 2 => samples | |
| 156 | − | .chunks_exact(2) | |
| 160 | + | .as_chunks::<2>() | |
| 161 | + | .0 | |
| 162 | + | .iter() | |
| 157 | 163 | .flat_map(|p| [p[0], p[0], p[0], p[1]]) | |
| 158 | 164 | .collect(), | |
| 159 | 165 | _ => samples.iter().flat_map(|&g| [g, g, g, 255]).collect(), | |
| @@ -228,7 +228,13 @@ fn ftyp_brands(head: &[u8]) -> Vec<&[u8]> { | |||
| 228 | 228 | let len = u32::from_be_bytes([head[0], head[1], head[2], head[3]]) as usize; | |
| 229 | 229 | let end = len.clamp(16, head.len()); | |
| 230 | 230 | let mut brands = vec![&head[8..12]]; | |
| 231 | − | brands.extend(head[16..end].chunks_exact(4)); | |
| 231 | + | brands.extend( | |
| 232 | + | head[16..end] | |
| 233 | + | .as_chunks::<4>() | |
| 234 | + | .0 | |
| 235 | + | .iter() | |
| 236 | + | .map(|b| b.as_slice()), | |
| 237 | + | ); | |
| 232 | 238 | brands | |
| 233 | 239 | } | |
| 234 | 240 | ||
| @@ -412,7 +412,7 @@ impl Renderer { | |||
| 412 | 412 | let mut pixels = Vec::with_capacity((size[0] * size[1] * 4) as usize); | |
| 413 | 413 | for y in 0..size[1] as usize { | |
| 414 | 414 | let line = &data[y * row as usize..][..size[0] as usize * 4]; | |
| 415 | − | for px in line.chunks_exact(4) { | |
| 415 | + | for px in line.as_chunks::<4>().0.iter() { | |
| 416 | 416 | let rgb = if bgra { | |
| 417 | 417 | [px[2], px[1], px[0]] | |
| 418 | 418 | } else { | |
| @@ -178,12 +178,16 @@ fn to_rgba(buf: Vec<u8>, color: png::ColorType) -> Option<Vec<u8>> { | |||
| 178 | 178 | Some(match color { | |
| 179 | 179 | Rgba => buf, | |
| 180 | 180 | Rgb => buf | |
| 181 | − | .chunks_exact(3) | |
| 181 | + | .as_chunks::<3>() | |
| 182 | + | .0 | |
| 183 | + | .iter() | |
| 182 | 184 | .flat_map(|p| [p[0], p[1], p[2], 255]) | |
| 183 | 185 | .collect(), | |
| 184 | 186 | Grayscale => buf.iter().flat_map(|&g| [g, g, g, 255]).collect(), | |
| 185 | 187 | GrayscaleAlpha => buf | |
| 186 | − | .chunks_exact(2) | |
| 188 | + | .as_chunks::<2>() | |
| 189 | + | .0 | |
| 190 | + | .iter() | |
| 187 | 191 | .flat_map(|p| [p[0], p[0], p[0], p[1]]) | |
| 188 | 192 | .collect(), | |
| 189 | 193 | Indexed => return None, | |
| @@ -443,7 +447,9 @@ fn jpeg_scaled(path: &Path, max: u32) -> anyhow::Result<Option<Generated>> { | |||
| 443 | 447 | let pixels: Vec<u8> = match info.pixel_format { | |
| 444 | 448 | L8 => data.iter().flat_map(|&g| [g, g, g, 255]).collect(), | |
| 445 | 449 | _ => data | |
| 446 | − | .chunks_exact(3) | |
| 450 | + | .as_chunks::<3>() | |
| 451 | + | .0 | |
| 452 | + | .iter() | |
| 447 | 453 | .flat_map(|p| [p[0], p[1], p[2], 255]) | |
| 448 | 454 | .collect(), | |
| 449 | 455 | }; | |