From 9127d8dc51de2d693e4ed1561c473166409d5fdc Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Wed, 30 Sep 2026 13:21:10 +0200 Subject: [PATCH] vello_common: Exercise image sampling in probe --- vello_common/assets/probe_image_bilinear.png | Bin 82 -> 138 bytes vello_common/assets/probe_image_bilinear.rgba | Bin 784 -> 784 bytes vello_common/assets/probe_image_nearest.png | Bin 82 -> 87 bytes vello_common/assets/probe_image_nearest.rgba | Bin 784 -> 784 bytes vello_common/src/probe.rs | 32 ++++++++---------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/vello_common/assets/probe_image_bilinear.png b/vello_common/assets/probe_image_bilinear.png index 8b6fc59cd0577e6afffafdd10fc68c7d29ae549f..9769a32c8bfab7eeb74714119a3602e2b3bf550d 100644 GIT binary patch delta 120 zcmWIQVw@mR#KO$L!0`9Ft*q%)szpY_aBa}unNWPGv@Bb=> wP!tRj1Igji2eJpG2d)6B5F`eY8|wPV4Ht6b0Ty0_X!Q6aq#h;@(?<>s0N1?kAOHXW delta 40 ZcmbQhHi2z|%|z?Ui8U6u(Bw5t$pA^x5KjOA diff --git a/vello_common/assets/probe_image_nearest.png b/vello_common/assets/probe_image_nearest.png index 8b6fc59cd0577e6afffafdd10fc68c7d29ae549f..b4bde15d9e0528b9d96c282226588441c5c10fb9 100644 GIT binary patch delta 56 zcmWFvpP*ta=jq}YQgJK!hrdYzLn2#Kho6_>)EFMGaQgJK!hrdYzgD?-v#TAzl*G&2Ggo%N1oz@e Pixmap { let mut pixmap = Pixmap::new(IMAGE_SOURCE_SIZE as u16, IMAGE_SOURCE_SIZE as u16); for y in 0..pixmap.height() { for x in 0..pixmap.width() { - pixmap.set_pixel( - x, - y, - AlphaColor::from_rgba8(255, 0, 0, 255) - .premultiply() - .to_rgba8(), - ); + let color = if (1..3).contains(&x) && (1..3).contains(&y) { + css::RED + } else { + css::BLUE + }; + pixmap.set_pixel(x, y, color.premultiply().to_rgba8()); } } pixmap.set_may_have_transparency(false); @@ -381,11 +380,11 @@ fn draw_probe_element( ctx.set_paint(linear_gradient(&rect).into()); ctx.fill_rect(&rect); } - ProbeFeature::ImageNearest => draw_centered_padded_image(ctx, cell, image_nearest), + ProbeFeature::ImageNearest => draw_centered_image(ctx, cell, image_nearest), ProbeFeature::Filter => { draw_blurred_rect(ctx, centered_rect(cell, 10.0, 10.0)); } - ProbeFeature::ImageBilinear => draw_centered_padded_image(ctx, cell, image_bilinear), + ProbeFeature::ImageBilinear => draw_centered_image(ctx, cell, image_bilinear), ProbeFeature::OpacityLayer => { draw_opacity_layer_rect(ctx, centered_rect(cell, RECT_SIZE, RECT_SIZE)); } @@ -404,14 +403,13 @@ fn centered_rect(cell: Rect, width: f64, height: f64) -> Rect { ) } -fn draw_centered_padded_image(ctx: &mut impl ProbeRenderer, cell: Rect, image_paint: &PaintType) { +fn draw_centered_image(ctx: &mut impl ProbeRenderer, cell: Rect, image_paint: &PaintType) { let dst_rect = centered_rect(cell, RECT_SIZE, RECT_SIZE); - let image_origin = ( - dst_rect.x0 + (RECT_SIZE - IMAGE_SOURCE_SIZE) * 0.5, - dst_rect.y0 + (RECT_SIZE - IMAGE_SOURCE_SIZE) * 0.5, - ); ctx.set_paint(image_paint.clone()); - ctx.set_paint_transform(Affine::translate(image_origin)); + ctx.set_paint_transform( + Affine::translate((dst_rect.x0, dst_rect.y0)) + * Affine::scale(RECT_SIZE / IMAGE_SOURCE_SIZE), + ); ctx.fill_rect(&dst_rect); ctx.reset_paint_transform(); }