Skip to content

Commit

Permalink
Merge pull request #452 from woelper/big_images
Browse files Browse the repository at this point in the history
Big images
  • Loading branch information
woelper authored Oct 21, 2024
2 parents 8c43088 + ef9c5f7 commit 792ad31
Show file tree
Hide file tree
Showing 11 changed files with 644 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ opt-level = 3
panic = "abort"

[profile.dev]
debug = false
debug = true
incremental = true
opt-level = 1
opt-level = 0
11 changes: 7 additions & 4 deletions src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use crate::{
image_editing::EditState,
scrubber::Scrubber,
settings::{PersistentSettings, VolatileSettings},
texture_wrapper::TextureWrapperManager,
utils::{ExtendedImageInfo, Frame, Player},
};

use egui_notify::Toasts;
use image::RgbaImage;
use nalgebra::Vector2;
Expand Down Expand Up @@ -65,7 +67,8 @@ pub struct OculanteState {
pub extended_info_loading: bool,
/// The Player, responsible for loading and sending Frames
pub player: Player,
pub current_texture: Option<Texture>,
//pub current_texture: Option<TexWrap>,
pub current_texture: TextureWrapperManager,
pub current_path: Option<PathBuf>,
pub current_image: Option<RgbaImage>,
pub settings_enabled: bool,
Expand All @@ -92,7 +95,7 @@ pub struct OculanteState {
pub filebrowser_id: Option<String>,
}

impl OculanteState {
impl<'b> OculanteState {
pub fn send_message_info(&self, msg: &str) {
_ = self.message_channel.0.send(Message::info(msg));
}
Expand All @@ -106,7 +109,7 @@ impl OculanteState {
}
}

impl Default for OculanteState {
impl<'b> Default for OculanteState {
fn default() -> OculanteState {
let tx_channel = mpsc::channel();
OculanteState {
Expand All @@ -122,7 +125,7 @@ impl Default for OculanteState {
cursor: Default::default(),
cursor_relative: Default::default(),
sampled_color: [0., 0., 0., 0.],
player: Player::new(tx_channel.0.clone(), 20, 16384),
player: Player::new(tx_channel.0.clone(), 20),
texture_channel: tx_channel,
message_channel: mpsc::channel(),
load_channel: mpsc::channel(),
Expand Down
4 changes: 2 additions & 2 deletions src/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ pub fn open_image(
let mut decoder = PngDecoder::new(ZCursor::new(contents));
decoder.set_options(
DecoderOptions::new_fast()
.set_max_height(50000)
.set_max_width(50000),
.set_max_height(128000)
.set_max_width(128000),
);

//animation
Expand Down
75 changes: 46 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod image_loader;
use appstate::*;
#[cfg(not(feature = "file_open"))]
mod filebrowser;
mod texture_wrapper;

pub mod ktx2_loader;
// mod events;
Expand Down Expand Up @@ -207,7 +208,6 @@ fn init(_app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins) -> OculanteSt
state.player = Player::new(
state.texture_channel.0.clone(),
state.persistent_settings.max_cache,
gfx.limits().max_texture_size,
);

debug!("matches {:?}", matches);
Expand Down Expand Up @@ -759,7 +759,7 @@ fn update(app: &mut App, state: &mut OculanteState) {
state.toasts.error(e);
state.current_image = None;
state.is_loaded = true;
state.current_texture = None;
state.current_texture.clear();
}
Message::Info(m) => {
state
Expand Down Expand Up @@ -866,7 +866,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
}
}
// always reset if first image
if state.current_texture.is_none() {
if state.current_texture.get().is_none() {
state.reset_image = true;
}

Expand Down Expand Up @@ -923,37 +923,44 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
debug!("Received compare result");

// always reset if first image
if state.current_texture.is_none() {
if state.current_texture.get().is_none() {
state.reset_image = true;
}

state.redraw = false;
}
}

if let Some(tex) = &mut state.current_texture {
if let Some(tex) = &mut state.current_texture.get() {
if tex.width() as u32 == img.width() && tex.height() as u32 == img.height() {
img.update_texture(gfx, tex);
img.update_texture_with_texwrap(gfx, tex);
} else {
state.current_texture = img.to_texture(gfx, &state.persistent_settings);
state
.current_texture
.set(img.to_texture_with_texwrap(gfx, &state.persistent_settings), gfx);
}
} else {
debug!("Setting texture");
state.current_texture = img.to_texture(gfx, &state.persistent_settings);
state
.current_texture
.set(img.to_texture_with_texwrap(gfx, &state.persistent_settings), gfx);
}

match &state.persistent_settings.current_channel {
// Unpremultiply the image
ColorChannel::Rgb => {
state.current_texture = unpremult(&img).to_texture(gfx, &state.persistent_settings)
}
ColorChannel::Rgb => state.current_texture.set(
unpremult(&img).to_texture_with_texwrap(gfx, &state.persistent_settings),
gfx,
),
// Do nuttin'
ColorChannel::Rgba => (),
// Display the channel
_ => {
state.current_texture =
state.current_texture.set(
solo_channel(&img, state.persistent_settings.current_channel as usize)
.to_texture(gfx, &state.persistent_settings)
.to_texture_with_texwrap(gfx, &state.persistent_settings),
gfx,
);
}
}
state.current_image = Some(img);
Expand Down Expand Up @@ -1097,7 +1104,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
settings_ui(app, ctx, state, gfx);
});

if let Some(texture) = &state.current_texture {
if let Some(texture) = &state.current_texture.get() {
// align to pixel to prevent distortion
let aligned_offset_x = state.image_geometry.offset.x.trunc();
let aligned_offset_y = state.image_geometry.offset.y.trunc();
Expand All @@ -1114,18 +1121,31 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
}
}
if state.tiling < 2 {
draw.image(texture)
.blend_mode(BlendMode::NORMAL)
.scale(state.image_geometry.scale, state.image_geometry.scale)
.translate(aligned_offset_x, aligned_offset_y);
texture.draw_textures(
&mut draw,
aligned_offset_x,
aligned_offset_y,
state.image_geometry.scale,
);
} else {
draw.pattern(texture)
.scale(state.image_geometry.scale, state.image_geometry.scale)
.translate(aligned_offset_x, aligned_offset_y)
.size(
texture.width() * state.tiling as f32,
texture.height() * state.tiling as f32,
);
for yi in 0..state.tiling {
for xi in 0..state.tiling {
//The "old" version used only a static offset, is this correct?
let translate_x = (xi as f32 * texture.width() * state.image_geometry.scale
+ state.image_geometry.offset.x)
.trunc();
let translate_y = (yi as f32 * texture.height() * state.image_geometry.scale
+ state.image_geometry.offset.y)
.trunc();

texture.draw_textures(
&mut draw,
translate_x,
translate_y,
state.image_geometry.scale,
);
}
}
}

if state.persistent_settings.show_frame {
Expand All @@ -1152,10 +1172,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
> app.window().size().0 as f32;

if show_minimap {
draw.image(texture)
.blend_mode(BlendMode::NORMAL)
.translate(offset_x, 100.)
.scale(scale, scale);
texture.draw_textures(&mut draw, offset_x, 100., scale);
}
}

Expand Down
Loading

0 comments on commit 792ad31

Please sign in to comment.