Skip to content

Commit

Permalink
Merge branch 'master' into link_speedup_opt
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Feb 1, 2025
2 parents 7266338 + f7ba18c commit 6596eb5
Show file tree
Hide file tree
Showing 16 changed files with 560 additions and 391 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ dicom-pixeldata = { version = "0.8.0", features = ["image"] }
dicom-object = "0.8.0"
unicode-segmentation = "1.12.0"
font-kit = "0.14.2"
open = "5.3.2"

[features]
default = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Windows:
Install Nasm from https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/

Mac:
`brew install nasm`
`brew install nasm cmake`

## Updates

Expand Down
8 changes: 1 addition & 7 deletions src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub struct OculanteState {
/// Channel to load images from
pub load_channel: (Sender<PathBuf>, Receiver<PathBuf>),
pub extended_info_channel: (Sender<ExtendedImageInfo>, Receiver<ExtendedImageInfo>),
pub extended_info_loading: bool,
/// The Player, responsible for loading and sending Frames
pub player: Player,
//pub current_texture: Option<TexWrap>,
Expand Down Expand Up @@ -133,16 +132,11 @@ impl<'b> Default for OculanteState {
cursor: Default::default(),
cursor_relative: Default::default(),
sampled_color: [0., 0., 0., 0.],
player: Player::new(
tx_channel.0.clone(),
20,
msg_channel.0.clone(),
),
player: Player::new(tx_channel.0.clone(), 20, msg_channel.0.clone()),
texture_channel: tx_channel,
message_channel: msg_channel,
load_channel: mpsc::channel(),
extended_info_channel: meta_channel,
extended_info_loading: Default::default(),
mouse_delta: Default::default(),
current_texture: Default::default(),
current_image: Default::default(),
Expand Down
109 changes: 51 additions & 58 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn init(_app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins) -> OculanteSt
// Set up egui style / theme
plugins.egui(|ctx| {
// FIXME: Wait for https://github.com/Nazariglez/notan/issues/315 to close, then remove

let mut fonts = FontDefinitions::default();
egui_extras::install_image_loaders(ctx);

Expand Down Expand Up @@ -349,10 +349,8 @@ fn init(_app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins) -> OculanteSt
.unwrap()
.insert(0, "inter".to_owned());


let fonts = load_system_fonts(fonts);


debug!("Theme {:?}", state.persistent_settings.theme);
apply_theme(&mut state, ctx);
ctx.set_fonts(fonts);
Expand Down Expand Up @@ -792,38 +790,38 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O

debug!("Got frame: {}", frame.to_string());

match &frame {
Frame::AnimationStart(_) | Frame::Still(_) | Frame::ImageCollectionMember(_) => {
// Something new came in, update scrubber (index slider) and path
if let Some(path) = &state.current_path {
if state.scrubber.has_folder_changed(&path) {
debug!("Folder has changed, creating new scrubber");
state.scrubber = scrubber::Scrubber::new(path);
state.scrubber.wrap = state.persistent_settings.wrap_folder;
} else {
let index = state
.scrubber
.entries
.iter()
.position(|p| p == path)
.unwrap_or_default();
if index < state.scrubber.entries.len() {
state.scrubber.index = index;
}
if matches!(
&frame,
Frame::AnimationStart(_) | Frame::Still(_) | Frame::ImageCollectionMember(_)
) {
// Something new came in, update scrubber (index slider) and path
if let Some(path) = &state.current_path {
if state.scrubber.has_folder_changed(&path) {
debug!("Folder has changed, creating new scrubber");
state.scrubber = scrubber::Scrubber::new(path);
state.scrubber.wrap = state.persistent_settings.wrap_folder;
} else {
let index = state
.scrubber
.entries
.iter()
.position(|p| p == path)
.unwrap_or_default();
if index < state.scrubber.entries.len() {
state.scrubber.index = index;
}
}
}

if let Some(path) = &state.current_path {
if !state.volatile_settings.recent_images.contains(path) {
state
.volatile_settings
.recent_images
.insert(0, path.clone());
state.volatile_settings.recent_images.truncate(12);
}
if let Some(path) = &state.current_path {
if !state.volatile_settings.recent_images.contains(path) {
state
.volatile_settings
.recent_images
.insert(0, path.clone());
state.volatile_settings.recent_images.truncate(12);
}
}
_ => {}
}

match &frame {
Expand Down Expand Up @@ -939,6 +937,10 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
Frame::UpdateTexture => {}
}

if !matches!(frame, Frame::Animation(_, _)) {
state.image_metadata = None;
}

// Deal with everything that sends an image
match frame {
Frame::AnimationStart(img)
Expand All @@ -950,27 +952,12 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
debug!("Received image buffer: {:?}", img.dimensions(),);
state.image_geometry.dimensions = img.dimensions();

state
.current_texture
.set_image(&img, gfx, &state.persistent_settings);

match &state.persistent_settings.current_channel {
// Unpremultiply the image
ColorChannel::Rgb => state.current_texture.set_image(
&unpremult(&img),
gfx,
&state.persistent_settings,
),
// Do nuttin'
ColorChannel::Rgba => (),
// Display the channel
_ => {
state.current_texture.set_image(
&solo_channel(&img, state.persistent_settings.current_channel as usize),
gfx,
&state.persistent_settings,
);
}
if let Err(error) =
state
.current_texture
.set_image(&img, gfx, &state.persistent_settings)
{
state.send_message_warn(&format!("Error while displaying image: {error}"));
}
state.current_image = Some(img);
}
Expand All @@ -979,17 +966,25 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O

// Prefer the edit result, if present
if state.edit_state.result_pixel_op != Default::default() {
state.current_texture.set_image(
if let Err(error) = state.current_texture.set_image(
&state.edit_state.result_pixel_op,
gfx,
&state.persistent_settings,
)
) {
state.send_message_warn(&format!("Error while displaying image: {error}"));
}
} else {
// update from image
if let Some(img) = &state.current_image {
state
.current_texture
.set_image(&img, gfx, &state.persistent_settings);
if let Err(error) =
state
.current_texture
.set_image(&img, gfx, &state.persistent_settings)
{
state.send_message_warn(&format!(
"Error while displaying image: {error}"
));
}
}
}
}
Expand All @@ -1001,7 +996,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
// In those cases, we want the image to stay as it is.
// TODO: PERF: This copies the image buffer. This should also maybe not run for animation frames
// although it looks cool.
state.image_metadata = None;
send_extended_info(
&state.current_image,
&state.current_path,
Expand Down Expand Up @@ -1102,7 +1096,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
}

state.pointer_over_ui = ctx.is_pointer_over_area();
// ("using pointer {}", ctx.is_using_pointer());

// if there is interaction on the ui (dragging etc)
// we don't want zoom & pan to work, so we "grab" the pointer
Expand Down
Loading

0 comments on commit 6596eb5

Please sign in to comment.