Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirrus
Submodule cirrus updated 1 files
+32 −6 theming/src/v1/mod.rs
19 changes: 13 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cirrus_theming::v1::{Colour, Theme};
use eframe::egui::{self, Align, Color32, Context, CursorIcon, Frame, Layout, Margin, Rect, Stroke, Vec2};
use egui_notify::ToastLevel;

use crate::{config::config::Config, files, image_handler::ImageHandler, magnification_panel::MagnificationPanel, monitor_size::MonitorSize, notifier::{self, NotifierAPI}, window_scaling::WindowScaling, windows::{about::AboutWindow, info::InfoWindow}, zoom_pan::ZoomPan};
use crate::{config::config::Config, files, image_handler::ImageHandler, magnification_panel::MagnificationPanel, monitor_size::MonitorSize, notifier::NotifierAPI, window_scaling::WindowScaling, windows::{about::AboutWindow, info::InfoWindow}, zoom_pan::ZoomPan};

pub struct Roseate<'a> {
theme: Theme,
Expand All @@ -24,7 +24,8 @@ impl<'a> Roseate<'a> {
pub fn new(mut image_handler: ImageHandler, monitor_size: MonitorSize, mut notifier: NotifierAPI, theme: Theme, config: Config) -> Self {
if image_handler.image.is_some() {
image_handler.load_image(
config.image.loading.initial.lazy_loading,
config.image.loading.initial.lazy_loading,
false,
&mut notifier,
&monitor_size,
config.misc.experimental.use_fast_roseate_backend
Expand Down Expand Up @@ -58,8 +59,7 @@ impl<'a> Roseate<'a> {
Stroke {
width: 2.0,
color: Color32::from_hex(
&self.theme.accent_colour.as_ref()
.unwrap_or(&Colour {hex_code: "e05f78".into()}).hex_code
&self.theme.accent_colour.hex_code
).unwrap()
},
10.0,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl eframe::App for Roseate<'_> {
.as_ref()
.unwrap(); // gotta love rust ~ ananas

let result = self.image_handler.init_image(path, &self.monitor_size);
let result = self.image_handler.init_image(path);

if let Err(error) = result {
self.notifier.toasts.lock().unwrap().toast_and_log(
Expand All @@ -116,6 +116,7 @@ impl eframe::App for Roseate<'_> {

self.image_handler.load_image(
true,
false,
&mut self.notifier,
&self.monitor_size,
self.config.misc.experimental.use_fast_roseate_backend
Expand Down Expand Up @@ -161,6 +162,7 @@ impl eframe::App for Roseate<'_> {
Ok(_) => {
self.image_handler.load_image(
self.config.image.loading.gui.lazy_loading,
false,
&mut self.notifier,
&self.monitor_size,
self.config.misc.experimental.use_fast_roseate_backend
Expand Down Expand Up @@ -198,7 +200,12 @@ impl eframe::App for Roseate<'_> {

self.info_box.update(ctx);
self.zoom_pan.update(ctx);
self.image_handler.update(&self.zoom_pan, &self.monitor_size);
self.image_handler.update(
&self.zoom_pan,
&self.monitor_size,
&mut self.notifier,
self.config.misc.experimental.use_fast_roseate_backend
);
self.magnification_panel.update(ctx, &mut self.zoom_pan);

let image = self.image_handler.image.clone().unwrap();
Expand Down
44 changes: 19 additions & 25 deletions src/image/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ use image::{codecs::{gif::GifDecoder, jpeg::JpegDecoder, png::PngDecoder, webp::

use crate::{error::{Error, Result}, monitor_size::MonitorSize, notifier::NotifierAPI};

use super::{backends::ImageProcessingBackend, image_formats::ImageFormat, optimization::ImageOptimizations};
use super::{backends::ImageProcessingBackend, image_formats::ImageFormat, modifications::ImageModifications};

pub type ImageSizeT = (u32, u32);

#[derive(Clone)]
pub struct Image {
pub image_size: ImageSize,
pub image_size: ImageSize, // TODO: change this to ImageSizeT
pub image_format: ImageFormat,
pub image_path: Arc<PathBuf>,
/// Currently applied optimizations.
pub optimizations: HashSet<ImageOptimizations>,
pub image_bytes: Arc<Mutex<Option<Arc<[u8]>>>>,
// Look! I know you see that type above me but just
// so you know, I'm NOT crazy... well not yet at least...
Expand Down Expand Up @@ -104,7 +102,6 @@ impl Image {
image_format,
image_path: Arc::new(path.to_owned()),
image_bytes: Arc::new(Mutex::new(None)),
optimizations: HashSet::new(),
}
)
}
Expand Down Expand Up @@ -137,13 +134,16 @@ impl Image {
&mut self,
notifier: &mut NotifierAPI,
monitor_size: &MonitorSize,
modifications: HashSet<ImageModifications>,
image_processing_backend: &ImageProcessingBackend
) -> Result<()> {
if !self.contains_initial_optimization() {
debug!("No optimizations were set so loading with fs::read instead...");
if modifications.is_empty() {
debug!("No modifications were set so we're loading with fs::read instead...");

let mut image_bytes_lock = self.image_bytes.lock().unwrap();

notifier.set_loading(Some("Opening file...".into()));

// TODO: return Error instead of panic.
*image_bytes_lock = Some(
Arc::from(fs::read(self.image_path.as_ref()).expect("Failed to read image with fs::read!"))
Expand All @@ -166,15 +166,15 @@ impl Image {

let image_decoder = self.get_image_decoder(image_buf_reader);

let mut optimized_image_buffer: Vec<u8> = Vec::new();
let mut modified_image_buffer: Vec<u8> = Vec::new();

notifier.set_loading(Some("Decoding image...".into()));

let image_result = self.optimize_and_decode_image_to_buffer(
let image_result = self.modify_and_decode_image_to_buffer(
image_processing_backend,
image_decoder,
&mut optimized_image_buffer,
monitor_size,
modifications,
&mut modified_image_buffer,
notifier
);

Expand All @@ -189,17 +189,21 @@ impl Image {
.toast_and_log(error.into(), egui_notify::ToastLevel::Error);

// load image without optimizations
self.optimizations.clear();
let result = self.load_image(notifier, monitor_size, image_processing_backend);
let result = self.load_image(
notifier,
monitor_size,
HashSet::new(),
image_processing_backend
);

match result {
Ok(_) => return Ok(()),
Err(error) => return Err(error),
}
}

// NOTE: At this point "optimized_image_buffer" should definitely have the image.
*self.image_bytes.lock().unwrap() = Some(Arc::from(optimized_image_buffer));
// NOTE: At this point "modified_image_buffer" should definitely have the image.
*self.image_bytes.lock().unwrap() = Some(Arc::from(modified_image_buffer));

Ok(())
}
Expand Down Expand Up @@ -234,16 +238,6 @@ impl Image {
}
}

fn contains_initial_optimization(&self) -> bool {
for optimization in &self.optimizations {
if let ImageOptimizations::Initial(_) = optimization {
return true;
}
}

false
}

// fn required_optimizations(&self, optimizations: &[ImageOptimization]) -> Vec<ImageOptimization> {
// let optimizations_wanted = optimizations.to_owned();

Expand Down
4 changes: 2 additions & 2 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod image;
pub mod optimization;
pub mod image_formats;
pub mod backends;
pub mod image_formats;
pub mod modifications;

mod fast_downsample;
Loading