Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to new peniko with color
Browse files Browse the repository at this point in the history
waywardmonkeys committed Nov 27, 2024
1 parent 64be9d9 commit e73431f
Showing 21 changed files with 248 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ env:
# If the compilation fails, then the version specified here needs to be bumped up to reality.
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.76"
RUST_MIN_VER: "1.82"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p vello -p vello_encoding -p vello_shaders"
20 changes: 14 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -99,7 +99,8 @@ bytemuck = { version = "1.18.0", features = ["derive"] }
skrifa = "0.22.3"
# The version of kurbo used below should be kept in sync
# with the version of kurbo used by peniko.
peniko = "0.2.0"
# peniko = "0.2.0"
peniko = { version = "0.2.0", git = "https://github.com/linebender/peniko.git", rev = "0fef133" }
# FIXME: This can be removed once peniko supports the schemars feature.
kurbo = "0.11.1"
futures-intrusive = "0.5.0"
11 changes: 5 additions & 6 deletions examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ mod simple_text;
mod svg;
pub mod test_scenes;

use anyhow::{anyhow, Result};
use clap::Args;
pub use images::ImageCache;
pub use simple_text::SimpleText;
@@ -42,7 +41,7 @@ pub use svg::{default_scene, scene_from_files};
use test_scenes::test_scenes;

use vello::kurbo::Vec2;
use vello::peniko::Color;
use vello::peniko::{color, Color};
use vello::Scene;

pub struct SceneParams<'a> {
@@ -94,15 +93,15 @@ pub struct Arguments {
/// The svg files paths to render
svgs: Option<Vec<PathBuf>>,
#[arg(help_heading = "Render Parameters")]
#[arg(long, global(false), value_parser = parse_color)]
#[arg(long, global(false), value_parser = parse_color_arg)]
/// The base color applied as the blend background to the rasterizer.
/// Format is CSS style hexadecimal (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) or
/// an SVG color name such as "aliceblue"
pub base_color: Option<Color>,
}

impl Arguments {
pub fn select_scene_set(&self) -> Result<Option<SceneSet>> {
pub fn select_scene_set(&self) -> anyhow::Result<Option<SceneSet>> {
// There is no file access on WASM, and on Android we haven't set up the assets
// directory.
// TODO: Upload the assets directory on Android
@@ -121,6 +120,6 @@ impl Arguments {
}
}

fn parse_color(s: &str) -> Result<Color> {
Color::parse(s).ok_or(anyhow!("'{s}' is not a valid color"))
fn parse_color_arg(s: &str) -> Result<Color, color::ParseError> {
color::parse_color(s).map(|c| c.to_alpha_color())
}
14 changes: 7 additions & 7 deletions examples/scenes/src/mmark.rs
Original file line number Diff line number Diff line change
@@ -118,13 +118,13 @@ impl TestScene for MMark {
}

const COLORS: &[Color] = &[
Color::rgb8(0x10, 0x10, 0x10),
Color::rgb8(0x80, 0x80, 0x80),
Color::rgb8(0xc0, 0xc0, 0xc0),
Color::rgb8(0x10, 0x10, 0x10),
Color::rgb8(0x80, 0x80, 0x80),
Color::rgb8(0xc0, 0xc0, 0xc0),
Color::rgb8(0xe0, 0x10, 0x40),
Color::from_rgba8(0x10, 0x10, 0x10, 0xff),
Color::from_rgba8(0x80, 0x80, 0x80, 0xff),
Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff),
Color::from_rgba8(0x10, 0x10, 0x10, 0xff),
Color::from_rgba8(0x80, 0x80, 0x80, 0xff),
Color::from_rgba8(0xc0, 0xc0, 0xc0, 0xff),
Color::from_rgba8(0xe0, 0x10, 0x40, 0xff),
];

impl Element {
17 changes: 8 additions & 9 deletions examples/scenes/src/pico_svg.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use std::str::FromStr;
use roxmltree::{Document, Node};
use vello::{
kurbo::{Affine, BezPath, Point, Size, Vec2},
peniko::Color,
peniko::{color, Color},
};

pub struct PicoSvg {
@@ -260,30 +260,29 @@ fn parse_transform(transform: &str) -> Affine {

fn parse_color(color: &str) -> Color {
let color = color.trim();
if let Some(c) = Color::parse(color) {
c
if let Ok(c) = color::parse_color(color) {
c.to_alpha_color()
} else if let Some(s) = color.strip_prefix("rgb(").and_then(|s| s.strip_suffix(')')) {
let mut iter = s.split([',', ' ']).map(str::trim).map(u8::from_str);

let r = iter.next().unwrap().unwrap();
let g = iter.next().unwrap().unwrap();
let b = iter.next().unwrap().unwrap();
Color::rgb8(r, g, b)
Color::from_rgba8(r, g, b, 255)
} else {
Color::rgba8(255, 0, 255, 0x80)
Color::from_rgba8(255, 0, 255, 0x80)
}
}

fn modify_opacity(mut color: Color, attr_name: &str, node: Node<'_, '_>) -> Color {
fn modify_opacity(color: Color, attr_name: &str, node: Node<'_, '_>) -> Color {
if let Some(opacity) = node.attribute(attr_name) {
let alpha: f64 = if let Some(o) = opacity.strip_suffix('%') {
let alpha: f32 = if let Some(o) = opacity.strip_suffix('%') {
let pctg = o.parse().unwrap_or(100.0);
pctg * 0.01
} else {
opacity.parse().unwrap_or(1.0)
};
color.a = (alpha.clamp(0.0, 1.0) * 255.0).round() as u8;
color
color.with_alpha(alpha.clamp(0., 1.))
} else {
color
}
4 changes: 2 additions & 2 deletions examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use web_time::Instant;
use anyhow::Result;
use vello::{
kurbo::{Affine, Rect, Stroke, Vec2},
peniko::{Color, Fill},
peniko::{color::palette, Fill},
Scene,
};

@@ -124,7 +124,7 @@ pub fn svg_function_of<R: AsRef<str>>(
error_scene.fill(
Fill::NonZero,
Affine::IDENTITY,
Color::FUCHSIA,
palette::css::FUCHSIA,
None,
&Rect::new(0.0, 0.0, 1.0, 1.0),
);
246 changes: 139 additions & 107 deletions examples/scenes/src/test_scenes.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/simple/src/main.rs
Original file line number Diff line number Diff line change
@@ -210,12 +210,12 @@ fn add_shapes_to_scene(scene: &mut Scene) {
// Draw an outlined rectangle
let stroke = Stroke::new(6.0);
let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0);
let rect_stroke_color = Color::rgb(0.9804, 0.702, 0.5294);
let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]);
scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect);

// Draw a filled circle
let circle = Circle::new((420.0, 200.0), 120.0);
let circle_fill_color = Color::rgb(0.9529, 0.5451, 0.6588);
let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]);
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
@@ -226,7 +226,7 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a filled ellipse
let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0);
let ellipse_fill_color = Color::rgb(0.7961, 0.651, 0.9686);
let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]);
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
@@ -237,6 +237,6 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a straight line
let line = Line::new((260.0, 20.0), (620.0, 100.0));
let line_stroke_color = Color::rgb(0.5373, 0.7059, 0.9804);
let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]);
scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line);
}
8 changes: 4 additions & 4 deletions examples/simple_sdl2/src/main.rs
Original file line number Diff line number Diff line change
@@ -120,12 +120,12 @@ fn add_shapes_to_scene(scene: &mut Scene) {
// Draw an outlined rectangle
let stroke = Stroke::new(6.0);
let rect = RoundedRect::new(10.0, 10.0, 240.0, 240.0, 20.0);
let rect_stroke_color = Color::rgb(0.9804, 0.702, 0.5294);
let rect_stroke_color = Color::new([0.9804, 0.702, 0.5294, 1.]);
scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect);

// Draw a filled circle
let circle = Circle::new((420.0, 200.0), 120.0);
let circle_fill_color = Color::rgb(0.9529, 0.5451, 0.6588);
let circle_fill_color = Color::new([0.9529, 0.5451, 0.6588, 1.]);
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
@@ -136,7 +136,7 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a filled ellipse
let ellipse = Ellipse::new((250.0, 420.0), (100.0, 160.0), -90.0);
let ellipse_fill_color = Color::rgb(0.7961, 0.651, 0.9686);
let ellipse_fill_color = Color::new([0.7961, 0.651, 0.9686, 1.]);
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
@@ -147,6 +147,6 @@ fn add_shapes_to_scene(scene: &mut Scene) {

// Draw a straight line
let line = Line::new((260.0, 20.0), (620.0, 100.0));
let line_stroke_color = Color::rgb(0.5373, 0.7059, 0.9804);
let line_stroke_color = Color::new([0.5373, 0.7059, 0.9804, 1.]);
scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line);
}
44 changes: 22 additions & 22 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use std::collections::VecDeque;
#[cfg(feature = "wgpu-profiler")]
use vello::kurbo::Line;
use vello::kurbo::{Affine, PathEl, Rect, Stroke};
use vello::peniko::{Brush, Color, Fill};
use vello::peniko::{color::palette, Brush, Color, Fill};
use vello::{low_level::BumpAllocators, AaConfig, Scene};

#[cfg(all(feature = "wgpu-profiler", not(target_arch = "wasm32")))]
@@ -49,7 +49,7 @@ impl Snapshot {
scene.fill(
Fill::NonZero,
offset,
&Brush::Solid(Color::rgba8(0, 0, 0, 200)),
&Brush::Solid(Color::from_rgba8(0, 0, 0, 200)),
None,
&Rect::new(0., 0., width, height),
);
@@ -89,7 +89,7 @@ impl Snapshot {
scene,
None,
text_size,
Some(&Brush::Solid(Color::WHITE)),
Some(&Brush::Solid(palette::css::WHITE)),
offset * Affine::translate((left_margin, (i + 1) as f64 * text_height)),
label,
);
@@ -98,7 +98,7 @@ impl Snapshot {
scene,
None,
text_size,
Some(&Brush::Solid(Color::WHITE)),
Some(&Brush::Solid(palette::css::WHITE)),
offset * Affine::translate((width * 0.67, text_height)),
&format!("FPS: {:.2}", self.fps),
);
@@ -136,9 +136,9 @@ impl Snapshot {
let s = Affine::scale_non_uniform(1., -h);
#[allow(clippy::match_overlapping_arm)]
let color = match *sample {
..=16_667 => Color::rgb8(100, 143, 255),
..=33_334 => Color::rgb8(255, 176, 0),
_ => Color::rgb8(220, 38, 127),
..=16_667 => Color::from_rgba8(100, 143, 255, 255),
..=33_334 => Color::from_rgba8(255, 176, 0, 255),
_ => Color::from_rgba8(220, 38, 127, 255),
};
scene.fill(
Fill::NonZero,
@@ -165,7 +165,7 @@ impl Snapshot {
scene,
None,
thres_text_height as f32,
Some(&Brush::Solid(Color::WHITE)),
Some(&Brush::Solid(palette::css::WHITE)),
offset
* Affine::translate((
left_margin,
@@ -176,7 +176,7 @@ impl Snapshot {
scene.stroke(
&Stroke::new(graph_max_height * 0.01),
offset * Affine::translate((left_margin_padding, (1. - y) * graph_max_height)),
Color::WHITE,
palette::css::WHITE,
None,
&marker,
);
@@ -290,14 +290,14 @@ pub fn draw_gpu_profiling(
profiles: &[GpuTimerQueryResult],
) {
const COLORS: &[Color] = &[
Color::AQUA,
Color::RED,
Color::ALICE_BLUE,
Color::YELLOW,
Color::GREEN,
Color::BLUE,
Color::ORANGE,
Color::WHITE,
palette::css::AQUA,
palette::css::RED,
palette::css::ALICE_BLUE,
palette::css::YELLOW,
palette::css::GREEN,
palette::css::BLUE,
palette::css::ORANGE,
palette::css::WHITE,
];
if profiles_are_empty(profiles) {
return;
@@ -311,7 +311,7 @@ pub fn draw_gpu_profiling(
scene.fill(
Fill::NonZero,
offset,
&Brush::Solid(Color::rgba8(0, 0, 0, 200)),
&Brush::Solid(Color::from_rgba8(0, 0, 0, 200)),
None,
&Rect::new(0., 0., width, height),
);
@@ -352,7 +352,7 @@ pub fn draw_gpu_profiling(
scene,
None,
text_size,
Some(&Brush::Solid(Color::WHITE)),
Some(&Brush::Solid(palette::css::WHITE)),
offset * Affine::translate((left_margin, (i + 1) as f64 * text_height)),
label,
);
@@ -364,7 +364,7 @@ pub fn draw_gpu_profiling(
scene,
None,
text_size,
Some(&Brush::Solid(Color::WHITE)),
Some(&Brush::Solid(palette::css::WHITE)),
offset * Affine::translate((left_margin, (i + 1) as f64 * text_height)),
label,
);
@@ -416,9 +416,9 @@ pub fn draw_gpu_profiling(
// Ensure that all remaining items can fit
.min(timeline_range_end - (count - cur_index) as f64 * text_height);
let (text_height, text_color) = if slow {
(text_height, Color::WHITE)
(text_height, palette::css::WHITE)
} else {
(text_height * 0.6, Color::LIGHT_GRAY)
(text_height * 0.6, palette::css::LIGHT_GRAY)
};
let text_size = (text_height * 0.9) as f32;
// Text is specified by the baseline, but the y positions all refer to the top of the text
13 changes: 5 additions & 8 deletions vello/src/debug/renderer.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ use crate::{

use {
bytemuck::{offset_of, Pod, Zeroable},
peniko::Color,
peniko::{color::palette, Color},
vello_encoding::{BumpAllocators, LineSoup, PathBbox},
};
pub(crate) struct DebugRenderer {
@@ -255,8 +255,8 @@ impl DebugRenderer {
);

let linepoints_uniforms = [
LinepointsUniforms::new(Color::DARK_CYAN, 10.),
LinepointsUniforms::new(Color::RED, 80.),
LinepointsUniforms::new(palette::css::DARK_CYAN, 10.),
LinepointsUniforms::new(palette::css::RED, 80.),
];
let linepoints_uniforms_buf = recording.upload_uniform(
"vello.debug.linepoints_uniforms",
@@ -358,12 +358,9 @@ struct LinepointsUniforms {

impl LinepointsUniforms {
fn new(color: Color, point_size: f32) -> Self {
let point_color = color.discard_alpha().components;
Self {
point_color: [
color.r as f32 / 255.,
color.g as f32 / 255.,
color.b as f32 / 255.,
],
point_color,
point_size,
_pad0: [0; 30],
_pad1: [0; 30],
7 changes: 4 additions & 3 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ mod bitmap;
use std::sync::Arc;

use peniko::{
color::{DynamicColor, Srgb},
kurbo::{Affine, BezPath, Point, Rect, Shape, Stroke, Vec2},
BlendMode, Blob, Brush, BrushRef, Color, ColorStop, ColorStops, ColorStopsSource, Compose,
Extend, Fill, Font, Gradient, Image, Mix, StyleRef,
@@ -987,7 +988,7 @@ fn color_index(cpal: &'_ Cpal<'_>, palette_index: u16) -> Option<Color> {
let actual_colors = cpal.color_records_array().unwrap().unwrap();
// TODO: Error reporting in the `None` case
let color = actual_colors.get(usize::from(palette_index))?;
Some(Color::rgba8(
Some(Color::from_rgba8(
color.red,
color.green,
color.blue,
@@ -1027,14 +1028,14 @@ impl ColorStopsSource for ColorStopsConverter<'_> {
BrushRef::Gradient(grad) => grad
.stops
.first()
.map(|it| it.color)
.map(|it| it.color.to_alpha_color::<Srgb>())
.unwrap_or(Color::TRANSPARENT),
BrushRef::Image(_) => Color::BLACK,
},
};
let color = color.multiply_alpha(item.alpha);
vec.push(ColorStop {
color,
color: DynamicColor::from_alpha_color(color),
offset: item.offset,
});
}
2 changes: 1 addition & 1 deletion vello_encoding/src/config.rs
Original file line number Diff line number Diff line change
@@ -184,7 +184,7 @@ impl RenderConfig {
height_in_tiles,
target_width: width,
target_height: height,
base_color: base_color.to_premul_u32(),
base_color: base_color.premultiply().to_rgba8().to_u32(),
lines_size: buffer_sizes.lines.len(),
binning_size: buffer_sizes.bin_data.len() - layout.bin_data_start,
tiles_size: buffer_sizes.tiles.len(),
2 changes: 1 addition & 1 deletion vello_encoding/src/draw.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ impl DrawColor {
/// Creates new solid color draw data.
pub fn new(color: Color) -> Self {
Self {
rgba: color.to_premul_u32(),
rgba: color.premultiply().to_rgba8().to_u32(),
}
}
}
15 changes: 11 additions & 4 deletions vello_encoding/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ use {
DrawImage, DrawLinearGradient, DrawRadialGradient, DrawSweepGradient, Glyph, GlyphRun,
Patch,
},
peniko::color::{DynamicColor, Srgb},
peniko::{ColorStop, Extend, GradientKind, Image},
skrifa::instance::NormalizedCoord,
};
@@ -355,7 +356,9 @@ impl Encoding {
) {
match self.add_ramp(color_stops, alpha, extend) {
RampStops::Empty => self.encode_color(DrawColor::new(Color::TRANSPARENT)),
RampStops::One(color) => self.encode_color(DrawColor::new(color)),
RampStops::One(color) => {
self.encode_color(DrawColor::new(color.to_alpha_color::<Srgb>()));
}
_ => {
self.draw_tags.push(DrawTag::LINEAR_GRADIENT);
self.draw_data
@@ -381,7 +384,9 @@ impl Encoding {
}
match self.add_ramp(color_stops, alpha, extend) {
RampStops::Empty => self.encode_color(DrawColor::new(Color::TRANSPARENT)),
RampStops::One(color) => self.encode_color(DrawColor::new(color)),
RampStops::One(color) => {
self.encode_color(DrawColor::new(color.to_alpha_color::<Srgb>()));
}
_ => {
self.draw_tags.push(DrawTag::RADIAL_GRADIENT);
self.draw_data
@@ -406,7 +411,9 @@ impl Encoding {
}
match self.add_ramp(color_stops, alpha, extend) {
RampStops::Empty => self.encode_color(DrawColor::new(Color::TRANSPARENT)),
RampStops::One(color) => self.encode_color(DrawColor::new(color)),
RampStops::One(color) => {
self.encode_color(DrawColor::new(color.to_alpha_color::<Srgb>()));
}
_ => {
self.draw_tags.push(DrawTag::SWEEP_GRADIENT);
self.draw_data
@@ -527,7 +534,7 @@ enum RampStops {
/// Color stop sequence was empty.
Empty,
/// Contained a single color stop.
One(Color),
One(DynamicColor),
/// More than one color stop.
Many,
}
13 changes: 5 additions & 8 deletions vello_encoding/src/ramp_cache.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

use std::collections::HashMap;

use peniko::color::Srgb;
use peniko::{Color, ColorStop, ColorStops};

const N_SAMPLES: usize = 512;
@@ -81,7 +82,7 @@ impl RampCache {

fn make_ramp(stops: &[ColorStop]) -> impl Iterator<Item = u32> + '_ {
let mut last_u = 0.0;
let mut last_c = ColorF64::from_color(stops[0].color);
let mut last_c = ColorF64::from_color(stops[0].color.to_alpha_color::<Srgb>());
let mut this_u = last_u;
let mut this_c = last_c;
let mut j = 0;
@@ -92,7 +93,7 @@ fn make_ramp(stops: &[ColorStop]) -> impl Iterator<Item = u32> + '_ {
last_c = this_c;
if let Some(s) = stops.get(j + 1) {
this_u = s.offset as f64;
this_c = ColorF64::from_color(s.color);
this_c = ColorF64::from_color(s.color.to_alpha_color::<Srgb>());
j += 1;
} else {
break;
@@ -113,12 +114,8 @@ struct ColorF64([f64; 4]);

impl ColorF64 {
fn from_color(color: Color) -> Self {
Self([
color.r as f64 / 255.0,
color.g as f64 / 255.0,
color.b as f64 / 255.0,
color.a as f64 / 255.0,
])
let [r, g, b, a] = color.components;
Self([r as f64, g as f64, b as f64, a as f64])
}

fn lerp(&self, other: &Self, a: f64) -> Self {
4 changes: 2 additions & 2 deletions vello_tests/snapshots/many_clips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/tests/known_issues.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

use vello::{
kurbo::{Affine, Rect},
peniko::{Color, Format},
peniko::{color::palette, Format},
Scene,
};
use vello_tests::TestParams;
@@ -25,7 +25,7 @@ fn many_bins(use_cpu: bool) {
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
Color::RED,
palette::css::RED,
None,
&Rect::new(-5., -5., 256. * 20., 256. * 20.),
);
12 changes: 6 additions & 6 deletions vello_tests/tests/property.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
)]

use vello::kurbo::{Affine, Rect};
use vello::peniko::{Brush, Color, Format};
use vello::peniko::{color::palette, Brush, Color, Format};
use vello::Scene;
use vello_tests::TestParams;

@@ -19,7 +19,7 @@ fn simple_square(use_cpu: bool) {
scene.fill(
vello::peniko::Fill::NonZero,
Affine::IDENTITY,
&Brush::Solid(Color::RED),
&Brush::Solid(palette::css::RED),
None,
&Rect::from_center_size((100., 100.), (50., 50.)),
);
@@ -55,7 +55,7 @@ fn empty_scene(use_cpu: bool) {
// Adding an alpha factor here changes the resulting colour *slightly*,
// presumably due to pre-multiplied alpha.
// We just assume that alpha scenarios work fine
let color = Color::PLUM;
let color = palette::css::PLUM;
let params = TestParams {
use_cpu,
base_colour: Some(color),
@@ -65,9 +65,9 @@ fn empty_scene(use_cpu: bool) {
assert_eq!(image.format, Format::Rgba8);
for pixel in image.data.data().chunks_exact(4) {
let &[r, g, b, a] = pixel else { unreachable!() };
let image_color = Color::rgba8(r, g, b, a);
if image_color != color {
panic!("Got {image_color:?}, expected clear colour {color:?}");
let image_color = Color::from_rgba8(r, g, b, a);
if image_color.premultiply().difference(color.premultiply()) > 1e-4 {
panic!("Got {image_color:?}, expected clear color {color:?}");
}
}
}
6 changes: 3 additions & 3 deletions vello_tests/tests/smoke_snapshots.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
use scenes::SimpleText;
use vello::{
kurbo::{Affine, Circle, Rect},
peniko::{Brush, Color, Fill},
peniko::{color::palette, Brush, Fill},
Scene,
};
use vello_tests::{smoke_snapshot_test_sync, TestParams};
@@ -16,7 +16,7 @@ fn filled_square(use_cpu: bool) {
scene.fill(
Fill::NonZero,
Affine::IDENTITY,
&Brush::Solid(Color::BLUE),
&Brush::Solid(palette::css::BLUE),
None,
&Rect::from_center_size((10., 10.), (6., 6.)),
);
@@ -34,7 +34,7 @@ fn filled_circle(use_cpu: bool) {
scene.fill(
Fill::NonZero,
Affine::IDENTITY,
&Brush::Solid(Color::BLUE),
&Brush::Solid(palette::css::BLUE),
None,
&Circle::new((10., 10.), 7.),
);

0 comments on commit e73431f

Please sign in to comment.