-
Notifications
You must be signed in to change notification settings - Fork 772
Image: data url support #7201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Image: data url support #7201
Conversation
|
Does dataurl I added depend on some old version of crates that didn't support no_std yet? In such case how do we solve it in general? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
This is an usefull feature to have.
I'm thinking the decoding could be done in the compiler instead. (and stored in EmbeddedData)
|
Thanks for your feedback. Does "in the compiler" mean decoding the image in from_at_image_url_node? In the current version, I wanted to use image::load_from_memory_with_format() as same place as image::open(). #[cfg(target_arch = "wasm32")]
return self.lookup_image_in_cache_or_create(cache_key, |_| {
return Some(ImageInner::HTMLImage(vtable::VRc::new(
super::htmlimage::HTMLImage::new(&str),
)));
}); |
|
It may be better not to introduce the DataUrl for ImageReference. Adding "data:/" block below the "builtin:/" block could be good enough. |
e7a931b to
6a138e9
Compare
I agree. This feature can most likely be handled entirely in the compiler, without introducing any additional functions and dependencies in the runtime. Is there a particular benefit to letting the browser do the data url decoding at runtime for wasm builds? |
I don't have any strong reason for that, it just looked cleaner for me. I'll move the logic in the compiler. |
|
I need more advise to make it right. As far as I checked, there is only one place that EmbeddedData is created.
The code here is called during compilation but if I use slint-viewer, it won't be called because embed_images returns immediately in the first if statement. pub async fn embed_images(
...
) {
if embed_files == EmbedResourcesKind::Nothing && resource_url_mapper.is_none() {
return;
}Is that correct? |
|
Indeed, it may need to be handled separately depending on the language.
I guess there could be an helper function in i_slint_compiler to share some of the decoding. |
Data url format is useful when one tries slintpad with images.
Image {
source: @image-url("data:image/png;base64,iV....=");
}
Fixes: slint-ui#4905
|
|
||
| #[cfg(feature = "image-decoders")] | ||
| /// Load an Image from a data url | ||
| pub fn load_from_data_url(data_url: &str) -> Result<Self, LoadImageError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is public API.
But I think we don't need this and should re-use the existing load_image_from_embedded_data that is already used by the generated code when the data is embedded. (and same in C++)
I wonder if we need this function call or if we could change
Data url format is useful when one tries slintpad with images.
Image {
source: @image-url("data:image/png;base64,iV....=");
}