Skip to content

Commit be155fd

Browse files
committed
WIP glow image rendering support
#674 This works, but duplicates code from `iced_wgpu` that should ideally be shared, and the cache never evicts. The next step here is to work on an API design to move some of the image loading and caching logic from the backend to `iced_graphics` (or elsewhere?).
1 parent 8221794 commit be155fd

7 files changed

Lines changed: 437 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ resolver = "2"
1515
[features]
1616
default = ["wgpu"]
1717
# Enables the `Image` widget
18-
image = ["iced_wgpu/image", "image_rs"]
18+
image = ["iced_wgpu/image", "iced_glow/image", "image_rs"]
1919
# Enables the `Svg` widget
2020
svg = ["iced_wgpu/svg"]
2121
# Enables the `Canvas` widget

glow/Cargo.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@ license = "MIT AND OFL-1.1"
88
repository = "https://github.com/iced-rs/iced"
99

1010
[features]
11+
image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"]
12+
png = ["image_rs/png"]
13+
jpeg = ["image_rs/jpeg"]
14+
jpeg_rayon = ["image_rs/jpeg_rayon"]
15+
gif = ["image_rs/gif"]
16+
webp = ["image_rs/webp"]
17+
pnm = ["image_rs/pnm"]
18+
ico = ["image_rs/ico"]
19+
bmp = ["image_rs/bmp"]
20+
hdr = ["image_rs/hdr"]
21+
dds = ["image_rs/dds"]
22+
farbfeld = ["image_rs/farbfeld"]
1123
canvas = ["iced_graphics/canvas"]
1224
qr_code = ["iced_graphics/qr_code"]
1325
default_system_font = ["iced_graphics/font-source"]
1426
# Not supported yet!
15-
image = []
1627
svg = []
1728

1829
[dependencies]
@@ -22,6 +33,8 @@ glyph_brush = "0.7"
2233
euclid = "0.22"
2334
bytemuck = "1.4"
2435
log = "0.4"
36+
kamadak-exif = "0.5"
37+
bitflags = "1.2"
2538

2639
[dependencies.iced_native]
2740
version = "0.5"
@@ -32,6 +45,12 @@ version = "0.3"
3245
path = "../graphics"
3346
features = ["font-fallback", "font-icons", "opengl"]
3447

48+
[dependencies.image_rs]
49+
version = "0.23"
50+
package = "image"
51+
default-features = false
52+
optional = true
53+
3554
[package.metadata.docs.rs]
3655
rustdoc-args = ["--cfg", "docsrs"]
3756
all-features = true

glow/src/backend.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::image;
12
use crate::program;
23
use crate::quad;
34
use crate::text;
@@ -16,6 +17,7 @@ use iced_native::{Font, Size};
1617
/// [`iced`]: https://github.com/iced-rs/iced
1718
#[derive(Debug)]
1819
pub struct Backend {
20+
image_pipeline: image::Pipeline,
1921
quad_pipeline: quad::Pipeline,
2022
text_pipeline: text::Pipeline,
2123
triangle_pipeline: triangle::Pipeline,
@@ -33,10 +35,12 @@ impl Backend {
3335

3436
let shader_version = program::Version::new(gl);
3537

38+
let image_pipeline = image::Pipeline::new(gl, &shader_version);
3639
let quad_pipeline = quad::Pipeline::new(gl, &shader_version);
3740
let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version);
3841

3942
Self {
43+
image_pipeline,
4044
quad_pipeline,
4145
text_pipeline,
4246
triangle_pipeline,
@@ -113,6 +117,20 @@ impl Backend {
113117
);
114118
}
115119

120+
#[cfg(feature = "image")]
121+
if !layer.images.is_empty() {
122+
let scaled = transformation
123+
* Transformation::scale(scale_factor, scale_factor);
124+
125+
self.image_pipeline.draw(
126+
gl,
127+
target_height,
128+
scaled,
129+
scale_factor,
130+
&layer.images,
131+
);
132+
}
133+
116134
if !layer.text.is_empty() {
117135
for text in layer.text.iter() {
118136
// Target physical coordinates directly to avoid blurry text
@@ -239,8 +257,8 @@ impl backend::Text for Backend {
239257

240258
#[cfg(feature = "image")]
241259
impl backend::Image for Backend {
242-
fn dimensions(&self, _handle: &iced_native::image::Handle) -> (u32, u32) {
243-
(50, 50)
260+
fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) {
261+
self.image_pipeline.dimensions(handle)
244262
}
245263
}
246264

0 commit comments

Comments
 (0)