Skip to content

Commit

Permalink
fix(image-generation): correct pixel placement to prevent out-of-boun…
Browse files Browse the repository at this point in the history
…ds error

Fix pixel placement calculation to prevent out-of-bounds error

Adjust pixel placement calculation based on image resolution.
  • Loading branch information
jabibamman committed Feb 23, 2024
1 parent 9fcdc69 commit 7a11c61
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/src/messages/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn handle_client(mut stream: TcpStream) -> io::Result<()> {
}
};

let img_path: String = match get_file_path("tondaronla", dir_path_buf, get_extension_str(FileExtension::PNG)) {
let img_path: String = match get_file_path("test-23_02_23", dir_path_buf, get_extension_str(FileExtension::PNG)) {
Ok(img_path) => img_path,
Err(e) => {
error!("Error getting file path: {:?}", e);
Expand Down
5 changes: 2 additions & 3 deletions shared/src/utils/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ pub fn image_from_pixel_intensity(pixel_intensity: Vec<PixelIntensity>) -> Resul
let resolution = Resolution::new(width, height);
let mut img = ImageBuffer::new(resolution.nx.into(), resolution.ny.into());
for (i, pixel_intensity) in pixel_intensity.iter().enumerate() {
let x = (i % 250 as usize) as u32;
let y = (i / 250 as usize) as u32;

let x = (i as u32) % resolution.nx as u32;
let y = (i as u32) / resolution.nx as u32;
img.put_pixel(x, y, Rgb(color(*pixel_intensity)));
}

Expand Down

0 comments on commit 7a11c61

Please sign in to comment.