Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ mod tests {
// Solid variant text is always white — probe for white ink
// specifically, since the pill background paints regardless.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 200 && p[1] > 200 && p[2] > 200)
.count();
assert!(
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/callout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ mod tests {
// for near-white ink specifically, since the bubble background
// paints regardless of font-size.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 200 && p[1] > 200 && p[2] > 200)
.count();
assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ mod tests {
skia_safe::image::CachingHint::Disallow,
);
assert!(ok, "pixel read should succeed");
let lit = buf.chunks_exact(4).filter(|p| p[3] > 0).count();
let lit = buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count();
assert!(
lit > 20,
"counter at font-size: 2rem must paint visible ink, got {lit} lit pixels"
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/kbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ mod tests {
// face — probe for near-white ink specifically, since the face/
// border/shadow paint regardless of font-size.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 180 && p[1] > 180 && p[2] > 180)
.count();
assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ mod tests {
skia_safe::image::CachingHint::Disallow,
);
assert!(ok, "pixel read should succeed");
let lit = buf.chunks_exact(4).filter(|p| p[3] > 0).count();
let lit = buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count();
assert!(
lit > 20,
"list at font-size: 2rem must paint visible ink, got {lit} lit pixels"
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/lottie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ mod tests {

let mut red_sum: u64 = 0;
let mut blue_sum: u64 = 0;
for px in buf.chunks_exact(4) {
for px in buf.as_chunks::<4>().0.iter() {
let r = px[0] as u64;
let _g = px[1] as u64;
let b = px[2] as u64;
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/marquee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ mod tests {
skia_safe::image::CachingHint::Disallow,
);
assert!(ok, "pixel read should succeed");
let lit = buf.chunks_exact(4).filter(|p| p[3] > 0).count();
let lit = buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count();
assert!(
lit > 20,
"marquee at font-size: 2rem must paint visible ink, got {lit} lit pixels"
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ mod tests {
// Title text is white (#FFFFFF default) on a dark #1E293B card —
// probe for near-white ink specifically.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 200 && p[1] > 200 && p[2] > 200)
.count();
assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/src/pill_nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mod tests {
skia_safe::image::CachingHint::Disallow,
);
assert!(ok, "pixel read should succeed");
let lit = buf.chunks_exact(4).filter(|p| p[3] > 0).count();
let lit = buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count();
assert!(
lit > 20,
"pill_nav at font-size: 2rem must paint visible ink, got {lit} lit pixels"
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ mod tests {
// probe specifically for near-white text ink rather than any lit
// pixel (the header/row backgrounds paint regardless of font-size).
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 200 && p[1] > 200 && p[2] > 200)
.count();
assert!(
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ mod tests {
// specifically: pixels that are not the dark theme background color
// (#1E1E1E) and not fully transparent.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && !(p[0] < 40 && p[1] < 40 && p[2] < 40))
.count();
assert!(
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/src/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ mod tests {
// Text is near-white (#E2E8F0 default) on a dark #1E293B body —
// probe for near-white ink specifically.
let text_ink = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > 180 && p[1] > 180 && p[2] > 180)
.count();
assert!(
Expand Down
6 changes: 5 additions & 1 deletion crates/rustmotion-components/tests/caption_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ fn render_caption_at(json: serde_json::Value, time: f64, y: f32) -> Vec<u8> {
}

fn count_pixels(buf: &[u8], pred: impl Fn(&[u8]) -> bool) -> usize {
buf.chunks_exact(4).filter(|p| pred(p)).count()
buf.as_chunks::<4>()
.0
.iter()
.filter(|p| pred(p.as_slice()))
.count()
}

fn lit_pixels(buf: &[u8]) -> usize {
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-components/tests/codeblock_auto_scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ fn text_ink_pixels(buf: &[u8]) -> usize {
// Background is #2b303b ~ (43, 48, 59). Count pixels that deviate from
// that by a wide margin in any channel — syntect's theme colors are all
// much brighter than the near-black background.
buf.chunks_exact(4)
buf.as_chunks::<4>()
.0
.iter()
.filter(|p| {
let (r, g, b, a) = (p[0] as i32, p[1] as i32, p[2] as i32, p[3] as i32);
a > 200 && ((r - 43).abs() > 40 || (g - 48).abs() > 40 || (b - 59).abs() > 40)
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-components/tests/relative_font_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn render(json: serde_json::Value) -> Vec<u8> {
}

fn lit_pixels(buf: &[u8]) -> usize {
buf.chunks_exact(4).filter(|p| p[3] > 0).count()
buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count()
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmotion-core/src/engine/renderer/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ mod emoji_presentation_tests {
surface.read_pixels(&info, &mut buf, (W * 4) as usize, (0, 0));

let (mut n, mut sr, mut sg, mut sb) = (0usize, 0f64, 0f64, 0f64);
for px in buf.chunks_exact(4) {
for px in buf.as_chunks::<4>().0.iter() {
if px[3] > 40 {
n += 1;
sr += px[0] as f64;
Expand Down
4 changes: 2 additions & 2 deletions crates/rustmotion-core/src/engine/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ mod camera_pan_tests {
);

// blend_fade(10, 200, 0.5) = (10*0.5 + 200*0.5 + 0.5) as u8 = 105.
for px in out.chunks_exact(4) {
for px in out.as_chunks::<4>().0.iter() {
assert_eq!(
px,
*px,
[105, 105, 105, 255],
"mid-pan Static frame must be a blend of bg_a and bg_b, not a copy of either"
);
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-studio/src/editor/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ pub fn prepare(scenario: Arc<ResolvedScenario>, total_duration: f64) {
match mixed {
Ok(Some(pcm_bytes)) => {
let pcm: Vec<f32> = pcm_bytes
.chunks_exact(2)
.as_chunks::<2>()
.0
.iter()
.map(|b| i16::from_le_bytes([b[0], b[1]]) as f32 / 32768.0)
.collect();
let _ = tx.send(Cmd::Load(Arc::new(pcm), SAMPLE_RATE));
Expand Down
4 changes: 3 additions & 1 deletion crates/rustmotion-studio/src/scenario/optimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ mod tests {
.expect("render")
};
let count_red = |rgba: &[u8]| {
rgba.chunks_exact(4)
rgba.as_chunks::<4>()
.0
.iter()
.filter(|p| p[0] > 180 && p[1] < 90 && p[2] < 90)
.count()
};
Expand Down
49 changes: 36 additions & 13 deletions crates/rustmotion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod component_smoke {

/// Counts non-transparent pixels in an RGBA buffer (alpha > 0).
fn nonzero_pixels(buf: &[u8]) -> usize {
buf.chunks_exact(4).filter(|p| p[3] > 0).count()
buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count()
}

#[test]
Expand Down Expand Up @@ -605,7 +605,8 @@ mod component_smoke {
let late = render_new_at(&scene, 400, 300, 0.95, 1.0);
// Total red intensity (sum of red channel) — alpha-attenuated pixels
// contribute less to this sum even when premul keeps the count up.
let red_sum: fn(&[u8]) -> u64 = |buf| buf.chunks_exact(4).map(|p| p[0] as u64).sum();
let red_sum: fn(&[u8]) -> u64 =
|buf| buf.as_chunks::<4>().0.iter().map(|p| p[0] as u64).sum();
let early_red = red_sum(&early);
let late_red = red_sum(&late);
assert!(
Expand Down Expand Up @@ -638,7 +639,7 @@ mod component_smoke {
}

fn red_sum(buf: &[u8]) -> u64 {
buf.chunks_exact(4).map(|p| p[0] as u64).sum()
buf.as_chunks::<4>().0.iter().map(|p| p[0] as u64).sum()
}

#[test]
Expand Down Expand Up @@ -718,7 +719,9 @@ mod component_smoke {
}
}));
let count_mid = |buf: &[u8]| {
buf.chunks_exact(4)
buf.as_chunks::<4>()
.0
.iter()
.filter(|p| p[0] > 20 && p[0] < 220)
.count()
};
Expand All @@ -744,7 +747,9 @@ mod component_smoke {
}));
let buf = render_new_at(&inverted, 400, 300, 0.5, 1.0);
let flipped = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[0] < 50 && p[1] > 150)
.count();
assert!(
Expand Down Expand Up @@ -873,7 +878,8 @@ mod component_smoke {
bleed: false,
};
let scene = vec![child];
let blue_sum = |buf: &[u8]| -> u64 { buf.chunks_exact(4).map(|p| p[2] as u64).sum() };
let blue_sum =
|buf: &[u8]| -> u64 { buf.as_chunks::<4>().0.iter().map(|p| p[2] as u64).sum() };
let before = render_new_at(&scene, 400, 300, 0.5, 4.0);
let mid = render_new_at(&scene, 400, 300, 1.5, 4.0);
let after = render_new_at(&scene, 400, 300, 2.5, 4.0);
Expand Down Expand Up @@ -936,7 +942,7 @@ mod component_smoke {
fn red_centroid_x(buf: &[u8], width: u32) -> Option<f64> {
let mut sum_wx = 0.0_f64;
let mut sum_w = 0.0_f64;
for (i, p) in buf.chunks_exact(4).enumerate() {
for (i, p) in buf.as_chunks::<4>().0.iter().enumerate() {
let x = (i as u32 % width) as f64;
let w = p[0] as f64;
sum_wx += w * x;
Expand Down Expand Up @@ -1665,7 +1671,7 @@ mod svg_draw_on_tests {

/// Count non-transparent pixels in RGBA buffer.
fn lit(buf: &[u8]) -> usize {
buf.chunks_exact(4).filter(|p| p[3] > 0).count()
buf.as_chunks::<4>().0.iter().filter(|p| p[3] > 0).count()
}

/// Count non-transparent pixels in horizontal band [y0, y1) of a 100-wide canvas.
Expand Down Expand Up @@ -1831,7 +1837,9 @@ mod svg_draw_on_tests {
);
// resvg fills the rect red. Count red-dominant pixels.
let red_pixels = buf
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[3] > 0 && p[0] > p[2] && p[0] > p[1])
.count();
assert!(
Expand Down Expand Up @@ -2232,7 +2240,9 @@ mod audio_tests {
let lit_at = |frame: usize| {
crate::encode::video::render_frame_task(&scenario.video, &scenario, &tasks[frame])
.expect("render")
.chunks_exact(4)
.as_chunks::<4>()
.0
.iter()
.filter(|p| p[0] > 40)
.count()
};
Expand Down Expand Up @@ -2556,7 +2566,14 @@ mod audio_tests {
}
}))
};
let red_sum = |pixels: &[u8]| pixels.chunks_exact(4).map(|p| p[0] as u64).sum::<u64>();
let red_sum = |pixels: &[u8]| {
pixels
.as_chunks::<4>()
.0
.iter()
.map(|p| p[0] as u64)
.sum::<u64>()
};

let loud = paint_scene(make_child(), 200, 200, 0.0, 30);
let quiet = paint_scene(make_child(), 200, 200, 0.5, 30);
Expand Down Expand Up @@ -2658,7 +2675,13 @@ mod motion_blur_trail {

/// Find the maximum red channel value across all pixels.
fn max_red(pixels: &[u8]) -> u8 {
pixels.chunks_exact(4).map(|p| p[0]).max().unwrap_or(0)
pixels
.as_chunks::<4>()
.0
.iter()
.map(|p| p[0])
.max()
.unwrap_or(0)
}

/// Make a red Shape with slide_in_left + motion_blur, positioned at the center.
Expand Down Expand Up @@ -3385,7 +3408,7 @@ mod world_view_regressions {
fn avg_luma(buf: &[u8]) -> f64 {
let mut sum = 0u64;
let mut n = 0u64;
for px in buf.chunks_exact(4) {
for px in buf.as_chunks::<4>().0.iter() {
sum += px[0] as u64 + px[1] as u64 + px[2] as u64;
n += 3;
}
Expand Down
Loading