Skip to content

Commit

Permalink
Update Peniko
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Dec 18, 2024
1 parent a6a6da0 commit e53d2d9
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 36 deletions.
18 changes: 10 additions & 8 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ bytemuck = { version = "1.20.0", features = ["derive"] }
skrifa = "0.26.0"
# The version of kurbo used below should be kept in sync
# with the version of kurbo used by peniko.
# peniko = "0.2.0"
peniko = { version = "0.2.0", git = "https://github.com/linebender/peniko.git", rev = "3462e19" }
peniko = "0.3.0"
# FIXME: This can be removed once peniko supports the schemars feature.
kurbo = "0.11.1"
futures-intrusive = "0.5.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;

use vello::peniko::{Blob, Format, Image};
use vello::peniko::{Blob, Image, ImageFormat};

/// Simple hack to support loading images for examples.
#[derive(Default)]
Expand Down Expand Up @@ -50,5 +50,5 @@ fn decode_image(data: &[u8]) -> anyhow::Result<Image> {
let height = image.height();
let data = Arc::new(image.into_rgba8().into_vec());
let blob = Blob::new(data);
Ok(Image::new(blob, Format::Rgba8, width, height))
Ok(Image::new(blob, ImageFormat::Rgba8, width, height))
}
4 changes: 2 additions & 2 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ mod impls {
blob.extend(c.premultiply().to_rgba8().to_u8_array());
});
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);
let image = Image::new(data, ImageFormat::Rgba8, 2, 2);

scene.draw_image(
&image,
Expand Down Expand Up @@ -1822,7 +1822,7 @@ mod impls {
blob.extend(c.premultiply().to_rgba8().to_u8_array());
});
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);
let image = Image::new(data, ImageFormat::Rgba8, 2, 2);
let image = image.with_extend(Extend::Pad);
// Pad extend mode
scene.fill(
Expand Down
10 changes: 5 additions & 5 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl<'a> DrawGlyphs<'a> {
Image::new(
// TODO: The design of the Blob type forces the double boxing
Blob::new(Arc::new(data)),
peniko::Format::Rgba8,
peniko::ImageFormat::Rgba8,
bitmap.width,
bitmap.height,
)
Expand Down Expand Up @@ -583,7 +583,7 @@ impl<'a> DrawGlyphs<'a> {
Image::new(
// TODO: The design of the Blob type forces the double boxing
Blob::new(Arc::new(buf)),
peniko::Format::Rgba8,
peniko::ImageFormat::Rgba8,
bitmap.width,
bitmap.height,
)
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<'a> DrawGlyphs<'a> {
Image::new(
// TODO: The design of the Blob type forces the double boxing
Blob::new(Arc::new(data)),
peniko::Format::Rgba8,
peniko::ImageFormat::Rgba8,
bitmap.width,
bitmap.height,
)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fn conv_extend(extend: skrifa::color::Extend) -> Extend {
struct ColorStopsConverter<'a>(&'a [skrifa::color::ColorStop], &'a Cpal<'a>, BrushRef<'a>);

impl ColorStopsSource for ColorStopsConverter<'_> {
fn collect_stops(&self, vec: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
for item in self.0 {
let color = color_index(self.1, item.palette_index);
let color = match color {
Expand All @@ -1036,7 +1036,7 @@ impl ColorStopsSource for ColorStopsConverter<'_> {
},
};
let color = color.multiply_alpha(item.alpha);
vec.push(ColorStop {
stops.push(ColorStop {
color: DynamicColor::from_alpha_color(color),
offset: item.offset,
});
Expand Down
11 changes: 6 additions & 5 deletions vello_encoding/src/ramp_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::collections::HashMap;

use peniko::color::cache_key::CacheKey;
use peniko::color::{HueDirection, Srgb};
use peniko::{ColorStop, ColorStops};

Expand All @@ -20,7 +21,7 @@ pub struct Ramps<'a> {
#[derive(Default)]
pub(crate) struct RampCache {
epoch: u64,
map: HashMap<ColorStops, (u32, u64)>,
map: HashMap<CacheKey<ColorStops>, (u32, u64)>,
data: Vec<u32>,
}

Expand All @@ -35,13 +36,13 @@ impl RampCache {
}

pub(crate) fn add(&mut self, stops: &[ColorStop]) -> u32 {
if let Some(entry) = self.map.get_mut(stops) {
if let Some(entry) = self.map.get_mut(&CacheKey(stops.into())) {
entry.1 = self.epoch;
entry.0
} else if self.map.len() < RETAINED_COUNT {
let id = (self.data.len() / N_SAMPLES) as u32;
self.data.extend(make_ramp(stops));
self.map.insert(stops.into(), (id, self.epoch));
self.map.insert(CacheKey(stops.into()), (id, self.epoch));
id
} else {
let mut reuse = None;
Expand All @@ -60,12 +61,12 @@ impl RampCache {
{
*dst = src;
}
self.map.insert(stops.into(), (id, self.epoch));
self.map.insert(CacheKey(stops.into()), (id, self.epoch));
id
} else {
let id = (self.data.len() / N_SAMPLES) as u32;
self.data.extend(make_ramp(stops));
self.map.insert(stops.into(), (id, self.epoch));
self.map.insert(CacheKey(stops.into()), (id, self.epoch));
id
}
}
Expand Down
6 changes: 3 additions & 3 deletions vello_tests/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::{anyhow, bail, Result};
use image::DynamicImage;
use nv_flip::FlipPool;
use vello::{
peniko::{Format, Image},
peniko::{Image, ImageFormat},
Scene,
};

Expand Down Expand Up @@ -105,8 +105,8 @@ pub async fn compare_gpu_cpu(scene: Scene, mut params: TestParams) -> Result<Gpu
assert!(gpu_rendered.width == cpu_rendered.width && gpu_rendered.height == cpu_rendered.height,);

// Compare the images using nv-flip
assert_eq!(cpu_rendered.format, Format::Rgba8);
assert_eq!(gpu_rendered.format, Format::Rgba8);
assert_eq!(cpu_rendered.format, ImageFormat::Rgba8);
assert_eq!(gpu_rendered.format, ImageFormat::Rgba8);
let gpu_rendered_data: DynamicImage = image::RgbaImage::from_raw(
cpu_rendered.width,
cpu_rendered.height,
Expand Down
4 changes: 2 additions & 2 deletions vello_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::sync::Arc;
use anyhow::{anyhow, bail, Result};
use scenes::{ExampleScene, ImageCache, SceneParams, SimpleText};
use vello::kurbo::{Affine, Vec2};
use vello::peniko::{color::palette, Blob, Color, Format, Image};
use vello::peniko::{color::palette, Blob, Color, Image, ImageFormat};
use vello::wgpu::{
self, BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer,
TextureDescriptor, TextureFormat, TextureUsages,
Expand Down Expand Up @@ -188,7 +188,7 @@ pub async fn get_scene_image(params: &TestParams, scene: &Scene) -> Result<Image
result_unpadded.extend(&data[start..start + (width * 4) as usize]);
}
let data = Blob::new(Arc::new(result_unpadded));
let image = Image::new(data, Format::Rgba8, width, height);
let image = Image::new(data, ImageFormat::Rgba8, width, height);
Ok(image)
}

Expand Down
4 changes: 2 additions & 2 deletions vello_tests/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use image::{DynamicImage, ImageError};
use nv_flip::FlipPool;
use vello::{
peniko::{Format, Image},
peniko::{Image, ImageFormat},
Scene,
};

Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn snapshot_test_image(
unreachable!();
}
// Compare the images using nv-flip
assert_eq!(raw_rendered.format, Format::Rgba8);
assert_eq!(raw_rendered.format, ImageFormat::Rgba8);
let rendered_data: DynamicImage = image::RgbaImage::from_raw(
raw_rendered.width,
raw_rendered.height,
Expand Down
4 changes: 2 additions & 2 deletions vello_tests/tests/known_issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use vello::{
kurbo::{Affine, Rect},
peniko::{color::palette, Format},
peniko::{color::palette, ImageFormat},
Scene,
};
use vello_tests::TestParams;
Expand All @@ -35,7 +35,7 @@ fn many_bins(use_cpu: bool) {
};
// To view, use VELLO_DEBUG_TEST=many_bins
let image = vello_tests::render_then_debug_sync(&scene, &params).unwrap();
assert_eq!(image.format, Format::Rgba8);
assert_eq!(image.format, ImageFormat::Rgba8);
let mut red_count = 0;
let mut black_count = 0;
for pixel in image.data.data().chunks_exact(4) {
Expand Down
6 changes: 3 additions & 3 deletions vello_tests/tests/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)]

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

Expand All @@ -30,7 +30,7 @@ fn simple_square(use_cpu: bool) {
..TestParams::new("simple_square", 150, 150)
};
let image = vello_tests::render_then_debug_sync(&scene, &params).unwrap();
assert_eq!(image.format, Format::Rgba8);
assert_eq!(image.format, ImageFormat::Rgba8);
let mut red_count = 0;
let mut black_count = 0;
for pixel in image.data.data().chunks_exact(4) {
Expand Down Expand Up @@ -64,7 +64,7 @@ fn empty_scene(use_cpu: bool) {
..TestParams::new("simple_square", 150, 150)
};
let image = vello_tests::render_then_debug_sync(&scene, &params).unwrap();
assert_eq!(image.format, Format::Rgba8);
assert_eq!(image.format, ImageFormat::Rgba8);
for pixel in image.data.data().chunks_exact(4) {
let &[r, g, b, a] = pixel else { unreachable!() };
let image_color = Color::from_rgba8(r, g, b, a);
Expand Down

0 comments on commit e53d2d9

Please sign in to comment.