Format vello_cpu/tests
These aren't picked up by `rustfmt --all` (also not in CI).
We could do the following.
```bash
cargo rustfmt --check -- ./**/*.rs
```
diff --git a/sparse_strips/vello_cpu/tests/basic.rs b/sparse_strips/vello_cpu/tests/basic.rs
index 1a0feab..75cb7f7 100644
--- a/sparse_strips/vello_cpu/tests/basic.rs
+++ b/sparse_strips/vello_cpu/tests/basic.rs
@@ -3,9 +3,7 @@
//! Tests for basic functionality.
-use crate::util::{
- check_ref, circular_star, crossed_line_star, get_ctx, miter_stroke_2,
-};
+use crate::util::{check_ref, circular_star, crossed_line_star, get_ctx, miter_stroke_2};
use std::f64::consts::PI;
use vello_common::color::palette::css::{
BEIGE, BLUE, DARK_BLUE, GREEN, LIME, MAROON, REBECCA_PURPLE, RED,
diff --git a/sparse_strips/vello_cpu/tests/compose.rs b/sparse_strips/vello_cpu/tests/compose.rs
index 83943c9..e744d0b 100644
--- a/sparse_strips/vello_cpu/tests/compose.rs
+++ b/sparse_strips/vello_cpu/tests/compose.rs
@@ -1,10 +1,10 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::util::{check_ref, get_ctx};
use vello_common::color::palette::css::{BLUE, YELLOW};
use vello_common::kurbo::Rect;
use vello_common::peniko::{BlendMode, Compose, Mix};
-use crate::util::{check_ref, get_ctx};
fn compose(name: &str, compose: Compose) {
let mut ctx = get_ctx(100, 100, false);
diff --git a/sparse_strips/vello_cpu/tests/gradient.rs b/sparse_strips/vello_cpu/tests/gradient.rs
index c870f85..da6e97e 100644
--- a/sparse_strips/vello_cpu/tests/gradient.rs
+++ b/sparse_strips/vello_cpu/tests/gradient.rs
@@ -1,13 +1,13 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::util::{check_ref, get_ctx, stops_blue_green_red_yellow, stops_green_blue};
use smallvec::smallvec;
-use vello_common::color::{ColorSpaceTag, DynamicColor};
use vello_common::color::palette::css::{BLACK, BLUE, WHITE, YELLOW};
+use vello_common::color::{ColorSpaceTag, DynamicColor};
use vello_common::kurbo::{Point, Rect};
use vello_common::paint::Gradient;
use vello_common::peniko::{ColorStop, ColorStops, GradientKind};
-use crate::util::{check_ref, get_ctx, stops_blue_green_red_yellow, stops_green_blue};
pub(crate) const fn tan_45() -> f64 {
1.0
@@ -45,7 +45,8 @@
},
stops: stops_blue_green_red_yellow(),
..Default::default()
- }.multiply_alpha(0.5);
+ }
+ .multiply_alpha(0.5);
ctx.set_paint(gradient);
ctx.fill_rect(&rect);
@@ -55,17 +56,17 @@
fn gradient_with_color_spaces(name: &str, stops: ColorStops) {
const COLOR_SPACES: &[ColorSpaceTag] = &[
- ColorSpaceTag::Srgb,
+ ColorSpaceTag::Srgb,
ColorSpaceTag::LinearSrgb,
ColorSpaceTag::Oklab,
];
-
+
const NUM_COLOR_SPACES: u16 = COLOR_SPACES.len() as u16;
let mut ctx = get_ctx(200, NUM_COLOR_SPACES * 40 + 10, false);
-
+
let mut cur_y = 10.0;
-
+
for cs in COLOR_SPACES {
let gradient = Gradient {
kind: GradientKind::Linear {
@@ -97,7 +98,7 @@
color: DynamicColor::from_alpha_color(WHITE),
},
]);
-
+
gradient_with_color_spaces("gradient_with_color_spaces_1", stops);
}
@@ -119,10 +120,14 @@
#[test]
fn gradient_with_color_spaces_3() {
- gradient_with_color_spaces("gradient_with_color_spaces_3", stops_blue_green_red_yellow());
+ gradient_with_color_spaces(
+ "gradient_with_color_spaces_3",
+ stops_blue_green_red_yellow(),
+ );
}
mod linear {
+ use crate::gradient::tan_45;
use crate::util::{
check_ref, crossed_line_star, get_ctx, stops_blue_green_red_yellow, stops_green_blue,
stops_green_blue_with_alpha,
@@ -131,7 +136,6 @@
use vello_common::kurbo::{Affine, Point, Rect};
use vello_common::paint::Gradient;
use vello_common::peniko::GradientKind;
- use crate::gradient::tan_45;
#[test]
fn gradient_linear_2_stops() {
@@ -172,12 +176,12 @@
check_ref(&ctx, "gradient_linear_2_stops_with_alpha");
}
-
+
macro_rules! directional {
($name:expr, $start:expr, $end:expr) => {
let mut ctx = get_ctx(100, 100, false);
let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
-
+
let gradient = Gradient {
kind: GradientKind::Linear {
start: $start,
@@ -186,32 +190,48 @@
stops: stops_green_blue(),
..Default::default()
};
-
+
ctx.set_paint(gradient);
ctx.fill_rect(&rect);
-
- check_ref(&ctx, $name);
+
+ check_ref(&ctx, $name);
};
}
#[test]
fn gradient_linear_negative_direction() {
- directional!("gradient_linear_negative_direction", Point::new(90.0, 0.0), Point::new(10.0, 0.0));
+ directional!(
+ "gradient_linear_negative_direction",
+ Point::new(90.0, 0.0),
+ Point::new(10.0, 0.0)
+ );
}
#[test]
fn gradient_linear_with_downward_y() {
- directional!("gradient_linear_with_downward_y", Point::new(20.0, 20.0), Point::new(80.0, 80.0));
+ directional!(
+ "gradient_linear_with_downward_y",
+ Point::new(20.0, 20.0),
+ Point::new(80.0, 80.0)
+ );
}
#[test]
fn gradient_linear_with_upward_y() {
- directional!("gradient_linear_with_upward_y", Point::new(20.0, 80.0), Point::new(80.0, 20.0));
+ directional!(
+ "gradient_linear_with_upward_y",
+ Point::new(20.0, 80.0),
+ Point::new(80.0, 20.0)
+ );
}
#[test]
fn gradient_linear_vertical() {
- directional!("gradient_linear_vertical", Point::new(0.0, 10.0), Point::new(0.0, 90.0));
+ directional!(
+ "gradient_linear_vertical",
+ Point::new(0.0, 10.0),
+ Point::new(0.0, 90.0)
+ );
}
macro_rules! gradient_pad {
@@ -514,15 +534,15 @@
}
mod radial {
+ use crate::gradient::tan_45;
use crate::util::{
check_ref, crossed_line_star, get_ctx, stops_blue_green_red_yellow, stops_green_blue,
stops_green_blue_with_alpha,
};
use std::f64::consts::PI;
use vello_common::kurbo::{Affine, Point, Rect};
- use vello_common::peniko::GradientKind::Radial;
use vello_common::paint::Gradient;
- use crate::gradient::tan_45;
+ use vello_common::peniko::GradientKind::Radial;
macro_rules! simple {
($stops:expr, $name:expr) => {
@@ -931,15 +951,15 @@
}
mod sweep {
+ use crate::gradient::tan_45;
use crate::util::{
check_ref, crossed_line_star, get_ctx, stops_blue_green_red_yellow, stops_green_blue,
stops_green_blue_with_alpha,
};
use std::f64::consts::PI;
use vello_common::kurbo::{Affine, Point, Rect};
- use vello_common::peniko::GradientKind;
use vello_common::paint::Gradient;
- use crate::gradient::tan_45;
+ use vello_common::peniko::GradientKind;
macro_rules! basic {
($stops:expr, $name:expr, $center:expr) => {
diff --git a/sparse_strips/vello_cpu/tests/image.rs b/sparse_strips/vello_cpu/tests/image.rs
index 9f3745b..b2f0c2f 100644
--- a/sparse_strips/vello_cpu/tests/image.rs
+++ b/sparse_strips/vello_cpu/tests/image.rs
@@ -1,15 +1,15 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::gradient::tan_45;
+use crate::util::{check_ref, crossed_line_star, get_ctx};
use std::f64::consts::PI;
use std::path::Path;
use std::sync::Arc;
use vello_common::kurbo::{Affine, Point, Rect};
use vello_common::paint::Image;
-use vello_common::pixmap::Pixmap;
use vello_common::peniko::{Extend, ImageQuality};
-use crate::gradient::tan_45;
-use crate::util::{check_ref, crossed_line_star, get_ctx};
+use vello_common::pixmap::Pixmap;
pub(crate) fn load_image(name: &str) -> Arc<Pixmap> {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("tests/assets/{name}.png"));
@@ -43,19 +43,19 @@
macro_rules! repeat {
($name:expr, $x_repeat:expr, $y_repeat:expr) => {
let mut ctx = get_ctx(100, 100, false);
- let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
- let im = rgb_img_10x10();
-
- ctx.set_paint(Image {
- pixmap: im,
- x_extend: $x_repeat,
- y_extend: $y_repeat,
- quality: ImageQuality::Low,
- transform: Affine::translate((45.0, 45.0)),
- });
- ctx.fill_rect(&rect);
+ let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
+ let im = rgb_img_10x10();
- check_ref(&ctx, $name);
+ ctx.set_paint(Image {
+ pixmap: im,
+ x_extend: $x_repeat,
+ y_extend: $y_repeat,
+ quality: ImageQuality::Low,
+ transform: Affine::translate((45.0, 45.0)),
+ });
+ ctx.fill_rect(&rect);
+
+ check_ref(&ctx, $name);
};
}
@@ -71,7 +71,11 @@
#[test]
fn image_reflect_x_reflect_y() {
- repeat!("image_reflect_x_reflect_y", Extend::Reflect, Extend::Reflect);
+ repeat!(
+ "image_reflect_x_reflect_y",
+ Extend::Reflect,
+ Extend::Reflect
+ );
}
#[test]
@@ -108,61 +112,61 @@
#[test]
fn image_with_transform_identity() {
transform!(
- "image_with_transform_identity",
- Affine::IDENTITY,
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_identity",
+ Affine::IDENTITY,
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
fn image_with_transform_translate() {
transform!(
- "image_with_transform_translate",
- Affine::translate((25.0, 25.0)),
- 0.0,
- 0.0,
- 50.0,
- 50.0
- );
+ "image_with_transform_translate",
+ Affine::translate((25.0, 25.0)),
+ 0.0,
+ 0.0,
+ 50.0,
+ 50.0
+ );
}
#[test]
fn image_with_transform_scale() {
transform!(
- "image_with_transform_scale",
- Affine::scale(2.0),
- 12.5,
- 12.5,
- 37.5,
- 37.5
- );
+ "image_with_transform_scale",
+ Affine::scale(2.0),
+ 12.5,
+ 12.5,
+ 37.5,
+ 37.5
+ );
}
#[test]
fn image_with_transform_negative_scale() {
transform!(
- "image_with_transform_negative_scale",
- Affine::translate((100.0, 100.0)) * Affine::scale(-2.0),
- 12.5,
- 12.5,
- 37.5,
- 37.5
- );
+ "image_with_transform_negative_scale",
+ Affine::translate((100.0, 100.0)) * Affine::scale(-2.0),
+ 12.5,
+ 12.5,
+ 37.5,
+ 37.5
+ );
}
#[test]
fn image_with_transform_scale_and_translate() {
transform!(
- "image_with_transform_scale_and_translate",
- Affine::new([2.0, 0.0, 0.0, 2.0, 25.0, 25.0]),
- 0.0,
- 0.0,
- 25.0,
- 25.0
- );
+ "image_with_transform_scale_and_translate",
+ Affine::new([2.0, 0.0, 0.0, 2.0, 25.0, 25.0]),
+ 0.0,
+ 0.0,
+ 25.0,
+ 25.0
+ );
}
// TODO: The below two test cases fail on Windows CI for some reason.
@@ -170,90 +174,90 @@
#[ignore]
fn image_with_transform_rotate_1() {
transform!(
- "image_with_transform_rotate_1",
- Affine::rotate_about(PI / 4.0, Point::new(50.0, 50.0)),
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_rotate_1",
+ Affine::rotate_about(PI / 4.0, Point::new(50.0, 50.0)),
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
#[ignore]
fn image_with_transform_rotate_2() {
transform!(
- "image_with_transform_rotate_2",
- Affine::rotate_about(-PI / 4.0, Point::new(50.0, 50.0)),
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_rotate_2",
+ Affine::rotate_about(-PI / 4.0, Point::new(50.0, 50.0)),
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
fn image_with_transform_scaling_non_uniform() {
transform!(
- "image_with_transform_scaling_non_uniform",
- Affine::scale_non_uniform(1.0, 2.0),
- 25.0,
- 12.5,
- 75.0,
- 37.5
- );
+ "image_with_transform_scaling_non_uniform",
+ Affine::scale_non_uniform(1.0, 2.0),
+ 25.0,
+ 12.5,
+ 75.0,
+ 37.5
+ );
}
#[test]
fn image_with_transform_skew_x_1() {
let transform = Affine::translate((-50.0, 0.0)) * Affine::skew(tan_45(), 0.0);
transform!(
- "image_with_transform_skew_x_1",
- transform,
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_skew_x_1",
+ transform,
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
fn image_with_transform_skew_x_2() {
let transform = Affine::translate((50.0, 0.0)) * Affine::skew(-tan_45(), 0.0);
transform!(
- "image_with_transform_skew_x_2",
- transform,
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_skew_x_2",
+ transform,
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
fn image_with_transform_skew_y_1() {
let transform = Affine::translate((0.0, 50.0)) * Affine::skew(0.0, -tan_45());
transform!(
- "image_with_transform_skew_y_1",
- transform,
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_skew_y_1",
+ transform,
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
fn image_with_transform_skew_y_2() {
let transform = Affine::translate((0.0, -50.0)) * Affine::skew(0.0, tan_45());
transform!(
- "image_with_transform_skew_y_2",
- transform,
- 25.0,
- 25.0,
- 75.0,
- 75.0
- );
+ "image_with_transform_skew_y_2",
+ transform,
+ 25.0,
+ 25.0,
+ 75.0,
+ 75.0
+ );
}
#[test]
@@ -278,8 +282,8 @@
#[test]
fn image_global_alpha() {
let mut ctx = get_ctx(100, 100, false);
- let rect = Rect::new(10.0, 10.0, 90.0 ,90.0);
-
+ let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
+
let mut pix = rgb_img_10x10();
Arc::make_mut(&mut pix).multiply_alpha(75);
@@ -300,8 +304,8 @@
macro_rules! image_format {
($name:expr, $image:expr) => {
let mut ctx = get_ctx(100, 100, false);
- let rect = Rect::new(10.0, 10.0, 90.0 ,90.0);
-
+ let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
+
let image = Image {
pixmap: $image,
x_extend: Extend::Repeat,
@@ -309,10 +313,10 @@
quality: ImageQuality::Low,
transform: Affine::IDENTITY,
};
-
+
ctx.set_paint(image);
ctx.fill_rect(&rect);
-
+
check_ref(&ctx, $name);
};
}
@@ -341,7 +345,7 @@
($name:expr, $transform:expr, $image:expr, $quality:expr, $extend:expr) => {
let mut ctx = get_ctx(100, 100, false);
let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
-
+
let image = Image {
pixmap: $image,
x_extend: $extend,
@@ -349,10 +353,10 @@
quality: $quality,
transform: $transform,
};
-
+
ctx.set_paint(image);
ctx.fill_rect(&rect);
-
+
check_ref(&ctx, $name);
};
}
@@ -361,37 +365,79 @@
#[test]
fn image_bilinear_identity() {
- quality!("image_bilinear_identity", Affine::IDENTITY, rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_identity",
+ Affine::IDENTITY,
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_2x_scale() {
- quality!("image_bilinear_2x_scale", Affine::scale(2.0), rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_2x_scale",
+ Affine::scale(2.0),
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_5x_scale() {
- quality!("image_bilinear_5x_scale", Affine::scale(5.0), rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_5x_scale",
+ Affine::scale(5.0),
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_10x_scale() {
- quality!("image_bilinear_10x_scale", Affine::scale(10.0), rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_10x_scale",
+ Affine::scale(10.0),
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_with_rotation() {
- quality!("image_bilinear_with_rotation", Affine::scale(5.0) * Affine::rotate(45.0_f64.to_radians()), rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_with_rotation",
+ Affine::scale(5.0) * Affine::rotate(45.0_f64.to_radians()),
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_with_translation() {
- quality!("image_bilinear_with_translation", Affine::scale(5.0) * Affine::translate((10.0, 10.0)), rgb_img_2x2(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_with_translation",
+ Affine::scale(5.0) * Affine::translate((10.0, 10.0)),
+ rgb_img_2x2(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
#[test]
fn image_bilinear_10x_scale_2() {
- quality!("image_bilinear_10x_scale_2", Affine::scale(10.0), rgb_img_2x3(), ImageQuality::Medium, Extend::Reflect);
+ quality!(
+ "image_bilinear_10x_scale_2",
+ Affine::scale(10.0),
+ rgb_img_2x3(),
+ ImageQuality::Medium,
+ Extend::Reflect
+ );
}
// This one looks slightly different from tiny-skia. In tiny-skia, it looks exactly the same as with
@@ -404,35 +450,77 @@
// either an outdated version or a slightly adapted one.
#[test]
fn image_bicubic_identity() {
- quality!("image_bicubic_identity", Affine::IDENTITY, rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_identity",
+ Affine::IDENTITY,
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_2x_scale() {
- quality!("image_bicubic_2x_scale", Affine::scale(2.0), rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_2x_scale",
+ Affine::scale(2.0),
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_5x_scale() {
- quality!("image_bicubic_5x_scale", Affine::scale(5.0), rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_5x_scale",
+ Affine::scale(5.0),
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_10x_scale() {
- quality!("image_bicubic_10x_scale", Affine::scale(10.0), rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_10x_scale",
+ Affine::scale(10.0),
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_with_rotation() {
- quality!("image_bicubic_with_rotation", Affine::scale(5.0) * Affine::rotate(45.0_f64.to_radians()), rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_with_rotation",
+ Affine::scale(5.0) * Affine::rotate(45.0_f64.to_radians()),
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_with_translation() {
- quality!("image_bicubic_with_translation", Affine::scale(5.0) * Affine::translate((10.0, 10.0)), rgb_img_2x2(), ImageQuality::High, Extend::Reflect);
+ quality!(
+ "image_bicubic_with_translation",
+ Affine::scale(5.0) * Affine::translate((10.0, 10.0)),
+ rgb_img_2x2(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
}
#[test]
fn image_bicubic_10x_scale_2() {
- quality!("image_bicubic_10x_scale_2", Affine::scale(10.0), rgb_img_2x3(), ImageQuality::High, Extend::Reflect);
-}
\ No newline at end of file
+ quality!(
+ "image_bicubic_10x_scale_2",
+ Affine::scale(10.0),
+ rgb_img_2x3(),
+ ImageQuality::High,
+ Extend::Reflect
+ );
+}
diff --git a/sparse_strips/vello_cpu/tests/layer.rs b/sparse_strips/vello_cpu/tests/layer.rs
index d5f9dbc..317cf96 100644
--- a/sparse_strips/vello_cpu/tests/layer.rs
+++ b/sparse_strips/vello_cpu/tests/layer.rs
@@ -1,11 +1,11 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::mask::example_mask;
+use crate::util::{check_ref, crossed_line_star, get_ctx};
use vello_common::color::palette::css::{BLUE, RED};
use vello_common::kurbo::Rect;
use vello_common::peniko::{BlendMode, Compose, Mix};
-use crate::mask::example_mask;
-use crate::util::{check_ref, crossed_line_star, get_ctx};
#[test]
fn layer_multiple_properties_1() {
@@ -16,7 +16,10 @@
ctx.set_paint(BLUE);
ctx.fill_rect(&Rect::new(10.0, 10.0, 90.0, 90.0));
ctx.push_layer(
- Some(&star), Some(BlendMode::new(Mix::Lighten, Compose::SrcOver)), Some(200), Some(mask)
+ Some(&star),
+ Some(BlendMode::new(Mix::Lighten, Compose::SrcOver)),
+ Some(200),
+ Some(mask),
);
ctx.set_paint(RED);
ctx.fill_rect(&Rect::new(10.0, 10.0, 90.0, 90.0));
diff --git a/sparse_strips/vello_cpu/tests/mask.rs b/sparse_strips/vello_cpu/tests/mask.rs
index cd64800..4503c70 100644
--- a/sparse_strips/vello_cpu/tests/mask.rs
+++ b/sparse_strips/vello_cpu/tests/mask.rs
@@ -1,6 +1,7 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::util::{check_ref, get_ctx};
use smallvec::smallvec;
use vello_common::color::DynamicColor;
use vello_common::color::palette::css::{BLACK, LIME, RED, YELLOW};
@@ -9,7 +10,6 @@
use vello_common::paint::Gradient;
use vello_common::peniko::{ColorStop, ColorStops, GradientKind};
use vello_cpu::{Pixmap, RenderContext};
-use crate::util::{check_ref, get_ctx};
pub(crate) fn example_mask(alpha_mask: bool) -> Mask {
let mut mask_pix = Pixmap::new(100, 100);
@@ -18,24 +18,22 @@
let grad = Gradient {
kind: GradientKind::Linear {
start: Point::new(10.0, 0.0),
- end: Point::new(90.0, 0.0)
+ end: Point::new(90.0, 0.0),
},
- stops: ColorStops(
- smallvec![
- ColorStop {
- offset: 0.0 ,
- color: DynamicColor::from_alpha_color(RED),
- },
- ColorStop {
- offset: 0.5,
- color: DynamicColor::from_alpha_color(YELLOW.with_alpha(0.5)),
- },
- ColorStop {
- offset: 1.0,
- color: DynamicColor::from_alpha_color(LIME.with_alpha(0.0)),
- },
- ]
- ),
+ stops: ColorStops(smallvec![
+ ColorStop {
+ offset: 0.0,
+ color: DynamicColor::from_alpha_color(RED),
+ },
+ ColorStop {
+ offset: 0.5,
+ color: DynamicColor::from_alpha_color(YELLOW.with_alpha(0.5)),
+ },
+ ColorStop {
+ offset: 1.0,
+ color: DynamicColor::from_alpha_color(LIME.with_alpha(0.0)),
+ },
+ ]),
..Default::default()
};
@@ -45,7 +43,7 @@
if alpha_mask {
Mask::new_alpha(&mask_pix)
- } else {
+ } else {
Mask::new_luminance(&mask_pix)
}
}
@@ -53,7 +51,7 @@
macro_rules! mask {
($name:expr, $mask:expr) => {
let mask = example_mask($mask);
-
+
let mut ctx = get_ctx(100, 100, false);
ctx.set_paint(BLACK);
ctx.fill_rect(&Rect::new(10.0, 10.0, 90.0, 90.0));
@@ -61,7 +59,7 @@
ctx.set_paint(RED);
ctx.fill_rect(&Rect::new(10.0, 10.0, 90.0, 90.0));
ctx.pop_layer();
-
+
check_ref(&ctx, $name);
};
}
diff --git a/sparse_strips/vello_cpu/tests/mix.rs b/sparse_strips/vello_cpu/tests/mix.rs
index f7e783a..f34e13c 100644
--- a/sparse_strips/vello_cpu/tests/mix.rs
+++ b/sparse_strips/vello_cpu/tests/mix.rs
@@ -1,15 +1,15 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
-use smallvec::smallvec;
-use vello_common::peniko::{ColorStop, ColorStops, GradientKind, ImageQuality};
-use vello_common::paint::{Gradient, Image};
-use vello_common::color::{AlphaColor, DynamicColor, Srgb};
-use vello_common::color::palette::css::{BLUE, LIME, MAGENTA, RED, YELLOW};
-use vello_common::kurbo::{Affine, Point, Rect};
-use vello_common::peniko::{BlendMode, Compose, Mix, Extend};
use crate::image::load_image;
use crate::util::{check_ref, get_ctx};
+use smallvec::smallvec;
+use vello_common::color::palette::css::{BLUE, LIME, MAGENTA, RED, YELLOW};
+use vello_common::color::{AlphaColor, DynamicColor, Srgb};
+use vello_common::kurbo::{Affine, Point, Rect};
+use vello_common::paint::{Gradient, Image};
+use vello_common::peniko::{BlendMode, Compose, Extend, Mix};
+use vello_common::peniko::{ColorStop, ColorStops, GradientKind, ImageQuality};
// The outputs have been compared visually with tiny-skia, and except for two cases (where tiny-skia
// is wrong), the overall visual effect looks the same.
@@ -20,30 +20,30 @@
let gradient = Gradient {
kind: GradientKind::Linear {
start: Point::new(0.0, 0.0),
- end: Point::new(80.0, 0.0)
+ end: Point::new(80.0, 0.0),
},
stops: ColorStops(smallvec![
- ColorStop {
- offset: 0.0,
- color: DynamicColor::from_alpha_color(BLUE.with_alpha(0.86)),
- },
- ColorStop {
- offset: 0.25,
- color: DynamicColor::from_alpha_color(MAGENTA.with_alpha(0.86)),
- },
- ColorStop {
- offset: 0.5,
- color: DynamicColor::from_alpha_color(RED.with_alpha(0.86)),
- },
- ColorStop {
- offset: 0.75,
- color: DynamicColor::from_alpha_color(YELLOW.with_alpha(0.86)),
- },
- ColorStop {
- offset: 1.0,
- color: DynamicColor::from_alpha_color(LIME.with_alpha(0.86)),
- },
- ]),
+ ColorStop {
+ offset: 0.0,
+ color: DynamicColor::from_alpha_color(BLUE.with_alpha(0.86)),
+ },
+ ColorStop {
+ offset: 0.25,
+ color: DynamicColor::from_alpha_color(MAGENTA.with_alpha(0.86)),
+ },
+ ColorStop {
+ offset: 0.5,
+ color: DynamicColor::from_alpha_color(RED.with_alpha(0.86)),
+ },
+ ColorStop {
+ offset: 0.75,
+ color: DynamicColor::from_alpha_color(YELLOW.with_alpha(0.86)),
+ },
+ ColorStop {
+ offset: 1.0,
+ color: DynamicColor::from_alpha_color(LIME.with_alpha(0.86)),
+ },
+ ]),
..Default::default()
};
@@ -68,13 +68,15 @@
#[test]
fn mix_normal() {
-
mix("mix_normal", BlendMode::new(Mix::Normal, Compose::SrcOver));
}
#[test]
fn mix_multiply() {
- mix("mix_multiply", BlendMode::new(Mix::Multiply, Compose::SrcOver));
+ mix(
+ "mix_multiply",
+ BlendMode::new(Mix::Multiply, Compose::SrcOver),
+ );
}
#[test]
@@ -89,42 +91,66 @@
#[test]
fn mix_lighten() {
- mix("mix_lighten", BlendMode::new(Mix::Lighten, Compose::SrcOver));
+ mix(
+ "mix_lighten",
+ BlendMode::new(Mix::Lighten, Compose::SrcOver),
+ );
}
#[test]
fn mix_color_dodge() {
- mix("mix_color_dodge", BlendMode::new(Mix::ColorDodge, Compose::SrcOver));
+ mix(
+ "mix_color_dodge",
+ BlendMode::new(Mix::ColorDodge, Compose::SrcOver),
+ );
}
#[test]
fn mix_color_burn() {
- mix("mix_color_burn", BlendMode::new(Mix::ColorBurn, Compose::SrcOver));
+ mix(
+ "mix_color_burn",
+ BlendMode::new(Mix::ColorBurn, Compose::SrcOver),
+ );
}
#[test]
fn mix_hard_light() {
- mix("mix_hard_light", BlendMode::new(Mix::HardLight, Compose::SrcOver));
+ mix(
+ "mix_hard_light",
+ BlendMode::new(Mix::HardLight, Compose::SrcOver),
+ );
}
#[test]
fn mix_soft_light() {
- mix("mix_soft_light", BlendMode::new(Mix::SoftLight, Compose::SrcOver));
+ mix(
+ "mix_soft_light",
+ BlendMode::new(Mix::SoftLight, Compose::SrcOver),
+ );
}
#[test]
fn mix_difference() {
- mix("mix_difference", BlendMode::new(Mix::Difference, Compose::SrcOver));
+ mix(
+ "mix_difference",
+ BlendMode::new(Mix::Difference, Compose::SrcOver),
+ );
}
#[test]
fn mix_exclusion() {
- mix("mix_exclusion", BlendMode::new(Mix::Exclusion, Compose::SrcOver));
+ mix(
+ "mix_exclusion",
+ BlendMode::new(Mix::Exclusion, Compose::SrcOver),
+ );
}
#[test]
fn mix_overlay() {
- mix("mix_overlay", BlendMode::new(Mix::Overlay, Compose::SrcOver));
+ mix(
+ "mix_overlay",
+ BlendMode::new(Mix::Overlay, Compose::SrcOver),
+ );
}
#[test]
@@ -134,7 +160,10 @@
#[test]
fn mix_saturation() {
- mix("mix_saturation", BlendMode::new(Mix::Saturation, Compose::SrcOver));
+ mix(
+ "mix_saturation",
+ BlendMode::new(Mix::Saturation, Compose::SrcOver),
+ );
}
#[test]
@@ -142,10 +171,12 @@
mix("mix_color", BlendMode::new(Mix::Color, Compose::SrcOver));
}
-
#[test]
fn mix_luminosity() {
- mix("mix_luminosity", BlendMode::new(Mix::Luminosity, Compose::SrcOver));
+ mix(
+ "mix_luminosity",
+ BlendMode::new(Mix::Luminosity, Compose::SrcOver),
+ );
}
macro_rules! mix_solid {
@@ -154,14 +185,14 @@
let rect = Rect::new(10.0, 10.0, 90.0, 90.0);
ctx.set_paint(AlphaColor::<Srgb>::from_rgba8(122, 85, 73, 255));
ctx.fill_rect(&rect);
-
+
ctx.push_blend_layer($mix_mode);
ctx.set_paint(AlphaColor::<Srgb>::from_rgba8(255, 255, 0, 255));
ctx.fill_rect(&rect);
ctx.pop_layer();
-
+
check_ref(&ctx, $name);
- }
+ };
}
#[test]
@@ -183,11 +214,17 @@
// Color of rectangle should be (106, 106, 0).
#[test]
fn mix_color_with_solid() {
- mix_solid!("mix_color_with_solid", BlendMode::new(Mix::Color, Compose::SrcOver));
+ mix_solid!(
+ "mix_color_with_solid",
+ BlendMode::new(Mix::Color, Compose::SrcOver)
+ );
}
// Color of rectangle should be (213, 52, 0).
#[test]
fn mix_color_with_saturation() {
- mix_solid!("mix_saturation_with_solid", BlendMode::new(Mix::Saturation, Compose::SrcOver));
+ mix_solid!(
+ "mix_saturation_with_solid",
+ BlendMode::new(Mix::Saturation, Compose::SrcOver)
+ );
}
diff --git a/sparse_strips/vello_cpu/tests/opacity.rs b/sparse_strips/vello_cpu/tests/opacity.rs
index e3d4c65..dbf76dd 100644
--- a/sparse_strips/vello_cpu/tests/opacity.rs
+++ b/sparse_strips/vello_cpu/tests/opacity.rs
@@ -1,9 +1,9 @@
// Copyright 2025 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
+use crate::util::{check_ref, get_ctx};
use vello_common::color::palette::css::{BLUE, GREEN, REBECCA_PURPLE, RED, YELLOW};
use vello_common::kurbo::{Circle, Rect, Shape};
-use crate::util::{check_ref, get_ctx};
#[test]
fn opacity_on_layer() {
@@ -15,7 +15,7 @@
ctx.set_paint(e.2);
ctx.fill_path(&circle.to_path(0.1));
}
-
+
ctx.pop_layer();
check_ref(&ctx, "opacity_on_layer");
@@ -24,7 +24,7 @@
#[test]
fn opacity_nested_on_layer() {
let mut ctx = get_ctx(100, 100, false);
-
+
ctx.set_paint(REBECCA_PURPLE);
ctx.fill_rect(&Rect::new(10.0, 10.0, 90.0, 90.0));
ctx.push_opacity_layer(128);
@@ -36,7 +36,5 @@
ctx.pop_layer();
ctx.pop_layer();
-
check_ref(&ctx, "opacity_nested_on_layer");
}
-
diff --git a/sparse_strips/vello_cpu/tests/util.rs b/sparse_strips/vello_cpu/tests/util.rs
index edaed92..17a3c86 100644
--- a/sparse_strips/vello_cpu/tests/util.rs
+++ b/sparse_strips/vello_cpu/tests/util.rs
@@ -7,11 +7,11 @@
use image::{ExtendedColorType, ImageEncoder, Rgba, RgbaImage, load_from_memory};
use skrifa::MetadataProvider;
use skrifa::raw::FileRef;
+use smallvec::smallvec;
use std::cmp::max;
use std::io::Cursor;
use std::path::PathBuf;
use std::sync::{Arc, LazyLock};
-use smallvec::smallvec;
use vello_common::color::DynamicColor;
use vello_common::color::palette::css::{BLUE, GREEN, RED, WHITE, YELLOW};
use vello_common::glyph::Glyph;
@@ -130,7 +130,6 @@
(font, glyphs)
}
-
pub(crate) fn stops_green_blue() -> ColorStops {
ColorStops(smallvec![
ColorStop {
@@ -178,7 +177,6 @@
])
}
-
pub(crate) fn check_ref(ctx: &RenderContext, name: &str) {
let mut pixmap = render_pixmap(ctx);
pixmap.unpremultiply();