Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Nov 6, 2024
1 parent 17c3983 commit 3bc34f1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/image_editing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ impl ImageOperation {
let filter = match filter {
ScaleFilter::CatmullRom => imageops::FilterType::CatmullRom,
ScaleFilter::Lanczos3 => imageops::FilterType::Lanczos3,
_ => imageops::FilterType::Gaussian
_ => imageops::FilterType::Gaussian,
};
*dyn_img = dyn_img.resize(dimensions.0, dimensions.0, filter);
}
Expand Down
43 changes: 26 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ mod tests;
mod ui;
#[cfg(feature = "update")]
mod update;
use ui::*;
use crate::image_editing::EditState;
use ui::*;

mod image_editing;
pub mod paint;
Expand Down Expand Up @@ -161,13 +161,11 @@ fn main() -> Result<(), String> {
window_config.always_on_top = true;
window_config.max_size = None;


debug!("Starting oculante.");
notan::init_with(init)
.add_config(window_config)
.add_config(EguiConfig)
.add_config(DrawConfig)

.event(event)
.update(update)
.draw(drawe)
Expand Down Expand Up @@ -820,7 +818,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
if let Ok(frame) = state.texture_channel.1.try_recv() {
state.is_loaded = true;


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

match &frame {
Expand Down Expand Up @@ -948,17 +945,26 @@ 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);
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),
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);
state.current_texture.set_image(
&solo_channel(&img, state.persistent_settings.current_channel as usize),
gfx,
&state.persistent_settings,
);
}
}
state.current_image = Some(img);
Expand All @@ -968,13 +974,17 @@ 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(&state
.edit_state
.result_pixel_op, gfx, &state.persistent_settings)
state.current_texture.set_image(
&state.edit_state.result_pixel_op,
gfx,
&state.persistent_settings,
)
} else {
// update from image
if let Some(img) = &state.current_image {
state.current_texture.set_image(&img, gfx, &state.persistent_settings);
state
.current_texture
.set_image(&img, gfx, &state.persistent_settings);
}
}
}
Expand Down Expand Up @@ -1072,7 +1082,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
edit_ui(app, ctx, state, gfx);
}


if state.persistent_settings.info_enabled
&& !state.settings_enabled
&& !state.persistent_settings.zen_mode
Expand Down Expand Up @@ -1185,7 +1194,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
.scale(state.image_geometry.scale, state.image_geometry.scale)
.translate(aligned_offset_x, aligned_offset_y);
}

if state.persistent_settings.info_enabled {
// let offset_x = app.window().size().0 as f32 - state.dimensions.0 as f32;

Expand All @@ -1195,10 +1204,10 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
&mut zoom_image,
bbox_tl.x,
bbox_tl.y,
bbox_br.x-bbox_tl.x,
bbox_br.x - bbox_tl.x,
(state.cursor_relative.x, state.cursor_relative.y),
8.0
);
8.0,
);
}

// Draw a brush preview when paint mode is on
Expand Down
9 changes: 5 additions & 4 deletions src/texture_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,18 @@ impl TexWrap {

match image {
DynamicImage::ImageLuma8(luma8_image) => {

// Creating luma 8 sub image
let mut buff: Vec<u8> = vec![0; tex_width as usize * tex_height as usize];
let bytes_src = luma8_image.as_bytes();
let mut dst_idx_start = 0 as usize;
let mut src_idx_start = tex_start_x as usize + tex_start_y as usize * im_w as usize;
let mut src_idx_start =
tex_start_x as usize + tex_start_y as usize * im_w as usize;

for _y in 0..tex_height {
for _y in 0..tex_height {
let dst_idx_end = dst_idx_start + tex_width as usize;
let src_idx_end = src_idx_start + tex_width as usize;
buff[dst_idx_start..dst_idx_end].copy_from_slice(&bytes_src[src_idx_start..src_idx_end]);
buff[dst_idx_start..dst_idx_end]
.copy_from_slice(&bytes_src[src_idx_start..src_idx_end]);
dst_idx_start = dst_idx_end;
src_idx_start += im_w as usize;
}
Expand Down
39 changes: 25 additions & 14 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use crate::{
clear_image, clipboard_to_image, delete_file,
file_encoder::FileEncoder,
get_pixel_checked,
image_editing::{process_pixels, Channel, ColorTypeExt, GradientStop, ImageOperation, ScaleFilter},
image_editing::{
process_pixels, Channel, ColorTypeExt, GradientStop, ImageOperation, ScaleFilter,
},
paint::PaintStroke,
set_zoom,
settings::{set_system_theme, ColorTheme, PersistentSettings, VolatileSettings},
Expand Down Expand Up @@ -31,7 +33,7 @@ use log::{debug, error, info};
use mouse_position::mouse_position::Mouse;
use notan::{
egui::{self, *},
prelude::{App, Graphics}
prelude::{App, Graphics},
};
use std::{
collections::BTreeSet,
Expand Down Expand Up @@ -508,13 +510,12 @@ pub fn image_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) {
// .rect;
}


pub fn info_ui(ctx: &Context, state: &mut OculanteState, _gfx: &mut Graphics) -> (Pos2, Pos2) {
let mut color_type = ColorType::Rgba8;
let mut bbox_tl: Pos2 = Default::default();
let mut bbox_br: Pos2 = Default::default();
let mut uv_center: (f64, f64)= Default::default();
let mut uv_size: (f64, f64)= Default::default();
let mut uv_center: (f64, f64) = Default::default();
let mut uv_size: (f64, f64) = Default::default();

if let Some(img) = &state.current_image {
color_type = img.color();
Expand Down Expand Up @@ -619,10 +620,10 @@ pub fn info_ui(ctx: &Context, state: &mut OculanteState, _gfx: &mut Graphics) ->
let preview_rect = egui::Rect::from_min_size(ui.cursor().left_top(), egui::Vec2::splat(desired_width as f32));

//Rendering a placeholder rectangle
ui.painter().rect(preview_rect, ROUNDING, egui::Color32::from_rgba_premultiplied(0, 0, 0, 0), egui::Stroke::new(0.0, egui::Color32::default()));
ui.painter().rect(preview_rect, ROUNDING, egui::Color32::from_rgba_premultiplied(0, 0, 0, 0), egui::Stroke::new(0.0, egui::Color32::default()));
bbox_tl = preview_rect.left_top();
bbox_br = preview_rect.right_bottom();
bbox_br = preview_rect.right_bottom();

let preview_rect = egui::Rect::from_min_max(bbox_tl, bbox_br);
ui.advance_cursor_after_rect(preview_rect);
}
Expand Down Expand Up @@ -1426,7 +1427,7 @@ pub fn edit_ui(app: &mut App, ctx: &Context, state: &mut OculanteState, gfx: &mu
if let Err(e) = process_pixels(&mut state.edit_state.result_pixel_op, ops) {
state.send_message_warn(&format!("{e}"));
message = Some(e.to_string())

}
}

Expand Down Expand Up @@ -2252,18 +2253,28 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu
}

// TODO: remove redundancy
if changed_channels { //TODO: Make this dependent of DynamicImage's type
if changed_channels {
//TODO: Make this dependent of DynamicImage's type
if let Some(img) = &state.current_image {
match &state.persistent_settings.current_channel {
ColorChannel::Rgb => {
state.current_texture.set_image(&unpremult(img), gfx, &state.persistent_settings);
state.current_texture.set_image(
&unpremult(img),
gfx,
&state.persistent_settings,
);
}
ColorChannel::Rgba => {
state.current_texture.set_image(img, gfx, &state.persistent_settings);
state
.current_texture
.set_image(img, gfx, &state.persistent_settings);
}
_ => {
let solo_im = solo_channel(img, state.persistent_settings.current_channel as usize);
state.current_texture.set_image(&solo_im, gfx, &state.persistent_settings);
let solo_im =
solo_channel(img, state.persistent_settings.current_channel as usize);
state
.current_texture
.set_image(&solo_im, gfx, &state.persistent_settings);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,6 @@ impl ImageExt for RgbaImage {
Vector2::new(self.width() as f32, self.height() as f32)
}



fn to_texture_premult(&self, gfx: &mut Graphics) -> Option<Texture> {
gfx.clean();

Expand All @@ -713,13 +711,13 @@ impl ImageExt for RgbaImage {
if let Err(e) = gfx.update_texture(texture).with_data(self).update() {
error!("{e}");
}
}
}
}

impl ImageExt for DynamicImage {
fn size_vec(&self) -> Vector2<f32> {
Vector2::new(self.width() as f32, self.height() as f32)
}
}

fn to_texture_premult(&self, gfx: &mut Graphics) -> Option<Texture> {
gfx.clean();
Expand Down

0 comments on commit 3bc34f1

Please sign in to comment.