Skip to content

Commit

Permalink
silvia-odwyer#145 - Convolution filters are not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley King committed Oct 21, 2023
1 parent 3e8a2a6 commit 52120d1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crate/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::helpers;
use crate::PhotonImage;
use image::{GenericImage, GenericImageView, Pixel};
use image::DynamicImage::ImageRgba8;
use std::cmp::min;

Expand All @@ -17,6 +18,17 @@ fn conv(photon_image: &mut PhotonImage, kernel: Kernel) {
let mut filtered_img = img.filter3x3(&kernel);
filtered_img = ImageRgba8(filtered_img.to_rgba8());

if filtered_img.pixels().all(|p| p.2[3] == 0 ) {
for x in 0..GenericImageView::width(&img) - 1 {
for y in 0..GenericImageView::height(&img) - 1 {
let mut pixel = GenericImageView::get_pixel(&filtered_img, x, y);
let original_alpha = GenericImageView::get_pixel(&img, x, y).channels()[3];
pixel.channels_mut()[3] = original_alpha;
filtered_img.put_pixel(x, y, pixel);
}
}
}

photon_image.raw_pixels = filtered_img.to_bytes();
}

Expand Down

0 comments on commit 52120d1

Please sign in to comment.