bhcli

A TUI for chatting on LE PHP Chats (onion)
git clone https://git.dasho.dev/n0tr1v/bhcli.git
Log | Files | Refs | README

commit c3f89c32a394a3820cfe4226f95f3f2672fcee26
parent f5c285719945714b2620faf1b6985a1da24ad248
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 30 Mar 2023 21:00:17 -0700

simplify code

Diffstat:
Msrc/lechatphp/mod.rs | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs @@ -307,25 +307,19 @@ impl From<Point> for bresenham::Point { } } -fn get_pixel_in_bound(img: &DynamicImage, x: u32, y: u32) -> Option<Rgba<u8>> { - if !img.in_bounds(x, y) { - return None; - } - Some(img.get_pixel(x, y)) -} - // give an image and a valid letter image, return either or not the letter is in that image. fn img_contains_letter(img: &DynamicImage, letter_img: &DynamicImage) -> bool { + if letter_img.dimensions() != img.dimensions() { + return false; + } for y in 0..LETTER_HEIGHT { for x in 0..LETTER_WIDTH { - if let Some(good_letter_color) = get_pixel_in_bound(letter_img, x, y) { - if let Some(letter_img_color) = get_pixel_in_bound(img, x, y) { - // If we find an Off pixel where it's supposed to be On, skip that letter - if good_letter_color == *ON_COLOR && - (letter_img_color != *ON_COLOR && letter_img_color != *RED_COLOR) { - return false; - } - } + let good_letter_color = letter_img.get_pixel(x, y); + let letter_img_color = img.get_pixel(x, y); + // If we find an Off pixel where it's supposed to be On, skip that letter + if good_letter_color == *ON_COLOR && + (letter_img_color != *ON_COLOR && letter_img_color != *RED_COLOR) { + return false; } } }