Upgrade resvg to 0.34 and tiny_skia to 0.10
This commit is contained in:
parent
9f2be29a28
commit
af386fd0a3
7 changed files with 85 additions and 51 deletions
|
|
@ -11,7 +11,7 @@ geometry = ["iced_graphics/geometry"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
raw-window-handle = "0.5"
|
raw-window-handle = "0.5"
|
||||||
softbuffer = "0.2"
|
softbuffer = "0.2"
|
||||||
tiny-skia = "0.9"
|
tiny-skia = "0.10"
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
rustc-hash = "1.1"
|
rustc-hash = "1.1"
|
||||||
kurbo = "0.9"
|
kurbo = "0.9"
|
||||||
|
|
@ -34,5 +34,5 @@ version = "1.6.1"
|
||||||
features = ["std"]
|
features = ["std"]
|
||||||
|
|
||||||
[dependencies.resvg]
|
[dependencies.resvg]
|
||||||
version = "0.32"
|
version = "0.34"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
||||||
|
|
@ -753,7 +753,15 @@ fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {
|
||||||
|
|
||||||
let path = {
|
let path = {
|
||||||
let mut builder = tiny_skia::PathBuilder::new();
|
let mut builder = tiny_skia::PathBuilder::new();
|
||||||
builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height);
|
builder.push_rect(
|
||||||
|
tiny_skia::Rect::from_xywh(
|
||||||
|
bounds.x,
|
||||||
|
bounds.y,
|
||||||
|
bounds.width,
|
||||||
|
bounds.height,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
builder.finish().unwrap()
|
builder.finish().unwrap()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::core::image as raster;
|
||||||
use crate::core::{Rectangle, Size};
|
use crate::core::{Rectangle, Size};
|
||||||
use crate::graphics;
|
use crate::graphics;
|
||||||
|
|
||||||
|
use bytemuck::cast;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::hash_map;
|
use std::collections::hash_map;
|
||||||
|
|
@ -80,9 +81,8 @@ impl Cache {
|
||||||
for (i, pixel) in image.pixels().enumerate() {
|
for (i, pixel) in image.pixels().enumerate() {
|
||||||
let [r, g, b, a] = pixel.0;
|
let [r, g, b, a] = pixel.0;
|
||||||
|
|
||||||
buffer[i] = tiny_skia::ColorU8::from_rgba(b, g, r, a)
|
buffer[i] = cast(tiny_skia::ColorU8::from_rgba(b, g, r, a)
|
||||||
.premultiply()
|
.premultiply());
|
||||||
.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.insert(Some(Entry {
|
entry.insert(Some(Entry {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use crate::core::font::{self, Font};
|
||||||
use crate::core::text::{Hit, LineHeight, Shaping};
|
use crate::core::text::{Hit, LineHeight, Shaping};
|
||||||
use crate::core::{Color, Pixels, Point, Rectangle, Size};
|
use crate::core::{Color, Pixels, Point, Rectangle, Size};
|
||||||
|
|
||||||
|
use bytemuck::cast;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
@ -288,14 +289,15 @@ impl GlyphCache {
|
||||||
|
|
||||||
for _y in 0..image.placement.height {
|
for _y in 0..image.placement.height {
|
||||||
for _x in 0..image.placement.width {
|
for _x in 0..image.placement.width {
|
||||||
buffer[i] = tiny_skia::ColorU8::from_rgba(
|
buffer[i] = cast(
|
||||||
b,
|
tiny_skia::ColorU8::from_rgba(
|
||||||
g,
|
b,
|
||||||
r,
|
g,
|
||||||
image.data[i],
|
r,
|
||||||
)
|
image.data[i],
|
||||||
.premultiply()
|
)
|
||||||
.get();
|
.premultiply(),
|
||||||
|
);
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -307,14 +309,15 @@ impl GlyphCache {
|
||||||
for _y in 0..image.placement.height {
|
for _y in 0..image.placement.height {
|
||||||
for _x in 0..image.placement.width {
|
for _x in 0..image.placement.width {
|
||||||
// TODO: Blend alpha
|
// TODO: Blend alpha
|
||||||
buffer[i >> 2] = tiny_skia::ColorU8::from_rgba(
|
buffer[i >> 2] = cast(
|
||||||
image.data[i + 2],
|
tiny_skia::ColorU8::from_rgba(
|
||||||
image.data[i + 1],
|
image.data[i + 2],
|
||||||
image.data[i],
|
image.data[i + 1],
|
||||||
image.data[i + 3],
|
image.data[i],
|
||||||
)
|
image.data[i + 3],
|
||||||
.premultiply()
|
)
|
||||||
.get();
|
.premultiply(),
|
||||||
|
);
|
||||||
|
|
||||||
i += 4;
|
i += 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::core::svg::{Data, Handle};
|
use crate::core::svg::{Data, Handle};
|
||||||
use crate::core::{Color, Rectangle, Size};
|
use crate::core::{Color, Rectangle, Size};
|
||||||
|
|
||||||
|
use bytemuck::cast;
|
||||||
use resvg::usvg;
|
use resvg::usvg;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
|
||||||
|
|
@ -130,30 +131,41 @@ impl Cache {
|
||||||
|
|
||||||
let mut image = tiny_skia::Pixmap::new(size.width, size.height)?;
|
let mut image = tiny_skia::Pixmap::new(size.width, size.height)?;
|
||||||
|
|
||||||
resvg::render(
|
let tree_size = tree.size.to_int_size();
|
||||||
tree,
|
let target_size;
|
||||||
if size.width > size.height {
|
if size.width > size.height {
|
||||||
resvg::FitTo::Width(size.width)
|
target_size = tree_size.scale_to_width(size.width);
|
||||||
} else {
|
} else {
|
||||||
resvg::FitTo::Height(size.height)
|
target_size = tree_size.scale_to_height(size.height);
|
||||||
},
|
}
|
||||||
tiny_skia::Transform::default(),
|
let transform;
|
||||||
image.as_mut(),
|
if let Some(target_size) = target_size {
|
||||||
)?;
|
let tree_size = tree_size.to_size();
|
||||||
|
let target_size = target_size.to_size();
|
||||||
|
transform = tiny_skia::Transform::from_scale(
|
||||||
|
target_size.width() / tree_size.width(),
|
||||||
|
target_size.height() / tree_size.height(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
transform = tiny_skia::Transform::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
resvg::Tree::from_usvg(tree).render(transform, &mut image.as_mut());
|
||||||
|
|
||||||
if let Some([r, g, b, _]) = key.color {
|
if let Some([r, g, b, _]) = key.color {
|
||||||
// Apply color filter
|
// Apply color filter
|
||||||
for pixel in
|
for pixel in
|
||||||
bytemuck::cast_slice_mut::<u8, u32>(image.data_mut())
|
bytemuck::cast_slice_mut::<u8, u32>(image.data_mut())
|
||||||
{
|
{
|
||||||
*pixel = tiny_skia::ColorU8::from_rgba(
|
*pixel = cast(
|
||||||
b,
|
tiny_skia::ColorU8::from_rgba(
|
||||||
g,
|
b,
|
||||||
r,
|
g,
|
||||||
(*pixel >> 24) as u8,
|
r,
|
||||||
)
|
(*pixel >> 24) as u8,
|
||||||
.premultiply()
|
)
|
||||||
.get();
|
.premultiply(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Swap R and B channels for `softbuffer` presentation
|
// Swap R and B channels for `softbuffer` presentation
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ version = "1.0"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.resvg]
|
[dependencies.resvg]
|
||||||
version = "0.32"
|
version = "0.34"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.tracing]
|
[dependencies.tracing]
|
||||||
|
|
|
||||||
|
|
@ -114,16 +114,27 @@ impl Cache {
|
||||||
// It would be cool to be able to smooth resize the `svg` example.
|
// It would be cool to be able to smooth resize the `svg` example.
|
||||||
let mut img = tiny_skia::Pixmap::new(width, height)?;
|
let mut img = tiny_skia::Pixmap::new(width, height)?;
|
||||||
|
|
||||||
resvg::render(
|
let tree_size = tree.size.to_int_size();
|
||||||
tree,
|
let target_size;
|
||||||
if width > height {
|
if width > height {
|
||||||
resvg::FitTo::Width(width)
|
target_size = tree_size.scale_to_width(width);
|
||||||
} else {
|
} else {
|
||||||
resvg::FitTo::Height(height)
|
target_size = tree_size.scale_to_height(height);
|
||||||
},
|
}
|
||||||
tiny_skia::Transform::default(),
|
let transform;
|
||||||
img.as_mut(),
|
if let Some(target_size) = target_size {
|
||||||
)?;
|
let tree_size = tree_size.to_size();
|
||||||
|
let target_size = target_size.to_size();
|
||||||
|
transform = tiny_skia::Transform::from_scale(
|
||||||
|
target_size.width() / tree_size.width(),
|
||||||
|
target_size.height() / tree_size.height(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
transform = tiny_skia::Transform::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
resvg::Tree::from_usvg(tree)
|
||||||
|
.render(transform, &mut img.as_mut());
|
||||||
|
|
||||||
let mut rgba = img.take();
|
let mut rgba = img.take();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue