Load fixes
This commit is contained in:
parent
ec879c31b1
commit
2d73b89df0
29
src/app.rs
29
src/app.rs
@ -227,6 +227,7 @@ pub struct AppState {
|
|||||||
pub transform_data: TransformData,
|
pub transform_data: TransformData,
|
||||||
pub filters: FileFilters,
|
pub filters: FileFilters,
|
||||||
pub selected_image: ImageData,
|
pub selected_image: ImageData,
|
||||||
|
pub loaded_thumbnail: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
@ -298,7 +299,6 @@ impl AppState {
|
|||||||
let scale_factor = 1.0;
|
let scale_factor = 1.0;
|
||||||
|
|
||||||
let (image_texture, bind_group, render_pipeline, transform_buffer) =
|
let (image_texture, bind_group, render_pipeline, transform_buffer) =
|
||||||
// setup_texture(&device, surface_config.clone(), 6000, 4000);
|
|
||||||
setup_texture(&device, surface_config.clone(), 8192, 8192);
|
setup_texture(&device, surface_config.clone(), 8192, 8192);
|
||||||
|
|
||||||
let transform_data = TransformData {
|
let transform_data = TransformData {
|
||||||
@ -325,6 +325,7 @@ impl AppState {
|
|||||||
transform_data,
|
transform_data,
|
||||||
filters: FileFilters::default(),
|
filters: FileFilters::default(),
|
||||||
selected_image,
|
selected_image,
|
||||||
|
loaded_thumbnail: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +384,7 @@ impl App {
|
|||||||
self.state.get_or_insert(state);
|
self.state.get_or_insert(state);
|
||||||
|
|
||||||
self.reset_transform();
|
self.reset_transform();
|
||||||
self.update_texture();
|
self.update_texture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_resized(&mut self, width: u32, height: u32) {
|
fn handle_resized(&mut self, width: u32, height: u32) {
|
||||||
@ -393,20 +394,30 @@ impl App {
|
|||||||
self.pan_zoom(0.0, 0.0, 0.0);
|
self.pan_zoom(0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_texture(&mut self) {
|
pub fn update_texture(&mut self, force: bool) {
|
||||||
let state = self.state.as_mut().unwrap();
|
let state = self.state.as_mut().unwrap();
|
||||||
|
if !force
|
||||||
{
|
{
|
||||||
let store = state.store.read().unwrap();
|
let mut store = state.store.write().unwrap();
|
||||||
if state.selected_image == store.current_image_path {
|
store.check_loaded_images();
|
||||||
|
let current_image_selected = state.selected_image == store.current_image_path;
|
||||||
|
let current_quality_loaded =
|
||||||
|
state.loaded_thumbnail == store.get_current_image().is_none();
|
||||||
|
println!(
|
||||||
|
"check {} {}",
|
||||||
|
current_quality_loaded, current_image_selected
|
||||||
|
);
|
||||||
|
if current_image_selected && current_quality_loaded {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut store = state.store.write().unwrap();
|
let mut store = state.store.write().unwrap();
|
||||||
store.check_loaded_images();
|
|
||||||
let imbuf = if let Some(full) = store.get_current_image() {
|
let imbuf = if let Some(full) = store.get_current_image() {
|
||||||
|
state.loaded_thumbnail = false;
|
||||||
full
|
full
|
||||||
} else {
|
} else {
|
||||||
|
state.loaded_thumbnail = true;
|
||||||
store.get_thumbnail()
|
store.get_thumbnail()
|
||||||
};
|
};
|
||||||
let width = imbuf.width as u32;
|
let width = imbuf.width as u32;
|
||||||
@ -441,6 +452,7 @@ impl App {
|
|||||||
depth_or_array_layers: 1,
|
depth_or_array_layers: 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
state.selected_image = store.current_image_path.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_transform();
|
self.update_transform();
|
||||||
@ -710,6 +722,7 @@ impl App {
|
|||||||
image_widget.scroll_to_me(Some(Align::Center));
|
image_widget.scroll_to_me(Some(Align::Center));
|
||||||
}
|
}
|
||||||
if image_widget.clicked() {
|
if image_widget.clicked() {
|
||||||
|
println!("{}", image.get_hash_str());
|
||||||
selected_image = Some(image);
|
selected_image = Some(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,7 +759,7 @@ impl App {
|
|||||||
state.queue.submit(Some(encoder.finish()));
|
state.queue.submit(Some(encoder.finish()));
|
||||||
surface_texture.present();
|
surface_texture.present();
|
||||||
|
|
||||||
self.update_texture();
|
self.update_texture(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,7 +856,7 @@ impl ApplicationHandler for App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if updated_image {
|
if updated_image {
|
||||||
self.update_texture();
|
self.update_texture(false);
|
||||||
}
|
}
|
||||||
if reset_transform {
|
if reset_transform {
|
||||||
self.reset_transform();
|
self.reset_transform();
|
||||||
|
20
src/image.rs
20
src/image.rs
@ -30,6 +30,8 @@ use std::io::Read;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd)]
|
#[derive(Clone, Eq, Hash, PartialEq, PartialOrd)]
|
||||||
@ -145,6 +147,7 @@ fn get_format(path: &PathBuf) -> Option<ImageFormat> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_image(image: &ImageData) -> ImflowImageBuffer {
|
pub fn load_image(image: &ImageData) -> ImflowImageBuffer {
|
||||||
|
// sleep(Duration::from_millis(500));
|
||||||
let total_start = Instant::now();
|
let total_start = Instant::now();
|
||||||
|
|
||||||
match image.format {
|
match image.format {
|
||||||
@ -291,11 +294,18 @@ pub fn check_embedded_thumbnail(path: &PathBuf) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_embedded_thumbnail(image: &ImageData) -> Option<Vec<u8>> {
|
pub fn get_embedded_thumbnail(image: &ImageData) -> Option<Vec<u8>> {
|
||||||
Metadata::new_from_path(&image.path)
|
let meta = Metadata::new_from_path(&image.path).ok()?;
|
||||||
.ok()?
|
|
||||||
.get_preview_images()?
|
let width = meta.get_pixel_width();
|
||||||
.first()
|
let height = meta.get_pixel_height();
|
||||||
.and_then(|preview| preview.get_data().ok())
|
println!("image: {}", width as f32 / height as f32);
|
||||||
|
|
||||||
|
meta.get_preview_images()?.first().and_then(|preview| {
|
||||||
|
let width = preview.get_width();
|
||||||
|
let height = preview.get_height();
|
||||||
|
println!("thumbnail: {}", width as f32 / height as f32);
|
||||||
|
preview.get_data().ok()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_thumbnail(path: &ImageData) -> ImflowImageBuffer {
|
pub fn load_thumbnail(path: &ImageData) -> ImflowImageBuffer {
|
||||||
|
15
src/store.rs
15
src/store.rs
@ -56,11 +56,11 @@ impl ImageStore {
|
|||||||
|
|
||||||
let currently_loading = HashSet::new();
|
let currently_loading = HashSet::new();
|
||||||
|
|
||||||
let first_image_path = available_images[0].clone();
|
// let first_image_path = available_images[0].clone();
|
||||||
let first_image_thread = std::thread::spawn(move || {
|
// let first_image_thread = std::thread::spawn(move || {
|
||||||
let image = load_image(&first_image_path);
|
// let image = load_image(&first_image_path);
|
||||||
(first_image_path, image)
|
// (first_image_path, image)
|
||||||
});
|
// });
|
||||||
|
|
||||||
let total_start = Instant::now();
|
let total_start = Instant::now();
|
||||||
let (sender, receiver) = unbounded();
|
let (sender, receiver) = unbounded();
|
||||||
@ -80,8 +80,9 @@ impl ImageStore {
|
|||||||
loaded_thumbnails.len()
|
loaded_thumbnails.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
let (path, image) = first_image_thread.join().unwrap();
|
let image = load_image(&new_path.clone());
|
||||||
loaded_images.insert(path, image);
|
// let (path, image) = first_image_thread.join().unwrap();
|
||||||
|
loaded_images.insert(new_path.clone(), image);
|
||||||
let mut state = Self {
|
let mut state = Self {
|
||||||
current_image_id,
|
current_image_id,
|
||||||
loaded_images,
|
loaded_images,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user