-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
adds a image loader for DynamicImage/rgba8/gif #3951
Conversation
the use case I intended for it is to display gifs. an example for that would be:
use egui::ImageSource;
use image::codecs::gif::GifDecoder;
use image::{AnimationDecoder, EncodableLayout, ImageDecoder};
use std::borrow::Cow;
use std::fs::File;
use std::time::Duration;
pub fn gif(uri: &str) -> Vec<(ImageSource<'static>, Duration)> {
let file_in = File::open("test.gif").unwrap();
let decoder = GifDecoder::new(file_in).unwrap();
let (width, height) = decoder.dimensions();
let mut res = vec![];
for (index, frame) in decoder.into_frames().enumerate() {
let frame = frame.unwrap();
let img = frame.buffer();
let mut bytes = vec![];
bytes.extend_from_slice(&(width as usize).to_le_bytes());
bytes.extend_from_slice(&(height as usize).to_le_bytes());
bytes.extend_from_slice(img.as_bytes());
let delay: Duration = frame.delay().into();
res.push((
ImageSource::Bytes {
uri: Cow::Owned(format!("rgba8://{}-{}", uri, index)),
bytes: bytes.into(),
},
delay,
));
}
res
} I would like to ask what you would prefer. a custom GifImage component or Image with the ability to display gifs. I have modified the Image component. It seems to be mostly working. the only issue is that |
@emilk is this fine? |
examples/images/src/main.rs
Outdated
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
egui::ScrollArea::both().show(ui, |ui| { | ||
ui.add(self.gif.clone()); |
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.
Would this work too?
ui.add(self.gif.clone()); | |
ui.image(egui_extras::include_gif!("ferris.gif")); |
That is, will this work without reloading the gif each frame? This is how we want it to work for it to be consistent with all other image formats
* Previous PR: #3951 * Closes #4489 --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
* Previous PR: emilk#3951 * Closes emilk#4489 --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
The macro converts the dynamic_image to rgba8 bytes and the rest is handled by the new image loader(only processes Uris that start with "rgba8://"