Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Jan 7, 2025
1 parent e9bf1f3 commit 8ab1c1c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/texture_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ impl TexWrap {
return None
}
}
// TODO: we could just do .filter(|byte_count| img.as_bytes().len()< byte_count) here
// and have the function return an error

if img.as_bytes().len() < byte_count {
error!("Pixel buffer is smaller than expected!");
Expand All @@ -171,12 +173,12 @@ impl TexWrap {

fn image_bytes_slice(img: &DynamicImage) -> Option<&[u8]> {
Self::image_bytesize_expected(img).map(|byte_count| {
let byte_buffer = img.as_bytes();
if byte_count < byte_buffer.len() {
warn!("Image byte buffer is bigger than expected. Will truncate.");
}
let (buff, _) = byte_buffer.split_at(byte_count);
buff
let byte_buffer = img.as_bytes();
if byte_count < byte_buffer.len() {
warn!("Image byte buffer is bigger than expected. Will truncate.");
}
let (buff, _) = byte_buffer.split_at(byte_count);
buff
}
)
}
Expand Down Expand Up @@ -320,8 +322,7 @@ impl TexWrap {
);

if let Some(suba_img) = sub_img_opt {
let byte_slice = Self::image_bytes_slice(&suba_img);
if let Some(bt_slice) = byte_slice {
if let Some(bt_slice) = Self::image_bytes_slice(&suba_img) {
tex = texture_generator_function(
gfx,
bt_slice,
Expand All @@ -333,8 +334,7 @@ impl TexWrap {
);
}
} else {
let byte_slice = Self::image_bytes_slice(&image);
if let Some(bt_slice) = byte_slice {
if let Some(bt_slice) = Self::image_bytes_slice(&image) {
tex = texture_generator_function(
gfx,
bt_slice,
Expand Down Expand Up @@ -429,8 +429,8 @@ impl TexWrap {
center: (f32, f32),
scale: f32,
) {
self.add_draw_shader(draw);
self.add_draw_shader(draw);

let width_tex = (width / scale) as i32;

let xy_tex_size = ((width_tex) as i32, (width_tex) as i32);
Expand Down Expand Up @@ -507,7 +507,7 @@ impl TexWrap {
//Draw crosshair
//let stroke_width = 0.5;
let half_width = scale/4.0/*-stroke_width*/;

draw.rect(
(translation_x + width / 2.0 - half_width, translation_y),
(2.0 * half_width, width),
Expand Down

0 comments on commit 8ab1c1c

Please sign in to comment.