Krolyxon
Commit 74a9b56

Branches

Tags

Refs →

remage74a9b56

Use as_chunks for constant chunk sizes (clippy 1.99)

Author
krolyxon
Date
2026-11-05 00:25 +0530
Parent
4654f72
Commit
74a9b56ca9557251304eafaf382a481c311b6406

+27 −9

4 files changed

  1. M src/decode/color.rs +10 −4
  2. M src/decode/mod.rs +7 −1
  3. M src/render/mod.rs +1 −1
  4. M src/thumbs.rs +9 −3
M src/decode/color.rs View
@@ -92,7 +92,9 @@ fn aces(x: f32) -> f32 {
9292 /// within 0..1 are only encoded; brighter ones are tone-mapped.
9393 pub fn tonemap(rgba: &[f32]) -> Vec<u8> {
9494 let peak = rgba
95− .chunks_exact(4)
95+ .as_chunks::<4>()
96+ .0
97+ .iter()
9698 .flat_map(|p| &p[..3])
9799 .copied()
98100 .filter(|v| v.is_finite())
@@ -100,7 +102,7 @@ pub fn tonemap(rgba: &[f32]) -> Vec<u8> {
100102 let hdr = peak > 1.0;
101103 let to8 = |v: f32| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
102104 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() {
104106 for &c in &p[..3] {
105107 let c = if c.is_finite() { c.max(0.0) } else { 0.0 };
106108 let c = if hdr { aces(c) } else { c };
@@ -149,11 +151,15 @@ pub fn expand(samples: &[u8], channels: usize) -> Vec<u8> {
149151 match channels {
150152 4 => samples.to_vec(),
151153 3 => samples
152− .chunks_exact(3)
154+ .as_chunks::<3>()
155+ .0
156+ .iter()
153157 .flat_map(|p| [p[0], p[1], p[2], 255])
154158 .collect(),
155159 2 => samples
156− .chunks_exact(2)
160+ .as_chunks::<2>()
161+ .0
162+ .iter()
157163 .flat_map(|p| [p[0], p[0], p[0], p[1]])
158164 .collect(),
159165 _ => samples.iter().flat_map(|&g| [g, g, g, 255]).collect(),
M src/decode/mod.rs View
@@ -228,7 +228,13 @@ fn ftyp_brands(head: &[u8]) -> Vec<&[u8]> {
228228 let len = u32::from_be_bytes([head[0], head[1], head[2], head[3]]) as usize;
229229 let end = len.clamp(16, head.len());
230230 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+ );
232238 brands
233239 }
234240
M src/render/mod.rs View
@@ -412,7 +412,7 @@ impl Renderer {
412412 let mut pixels = Vec::with_capacity((size[0] * size[1] * 4) as usize);
413413 for y in 0..size[1] as usize {
414414 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() {
416416 let rgb = if bgra {
417417 [px[2], px[1], px[0]]
418418 } else {
M src/thumbs.rs View
@@ -178,12 +178,16 @@ fn to_rgba(buf: Vec<u8>, color: png::ColorType) -> Option<Vec<u8>> {
178178 Some(match color {
179179 Rgba => buf,
180180 Rgb => buf
181− .chunks_exact(3)
181+ .as_chunks::<3>()
182+ .0
183+ .iter()
182184 .flat_map(|p| [p[0], p[1], p[2], 255])
183185 .collect(),
184186 Grayscale => buf.iter().flat_map(|&g| [g, g, g, 255]).collect(),
185187 GrayscaleAlpha => buf
186− .chunks_exact(2)
188+ .as_chunks::<2>()
189+ .0
190+ .iter()
187191 .flat_map(|p| [p[0], p[0], p[0], p[1]])
188192 .collect(),
189193 Indexed => return None,
@@ -443,7 +447,9 @@ fn jpeg_scaled(path: &Path, max: u32) -> anyhow::Result<Option<Generated>> {
443447 let pixels: Vec<u8> = match info.pixel_format {
444448 L8 => data.iter().flat_map(|&g| [g, g, g, 255]).collect(),
445449 _ => data
446− .chunks_exact(3)
450+ .as_chunks::<3>()
451+ .0
452+ .iter()
447453 .flat_map(|p| [p[0], p[1], p[2], 255])
448454 .collect(),
449455 };