commit d98893d22e186dadfe4501489443477fc3caac1a
parent 15766ecbf3aa622b21e12133e019ffef7a06c407
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 30 Mar 2023 14:02:04 -0700
simplify code
Diffstat:
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs
@@ -436,22 +436,14 @@ fn has_red_in_center_area(letter_img: &DynamicImage) -> bool {
// Count pixels that are On (either white or red)
fn count_px_on(img: &DynamicImage) -> usize {
- img.pixels().fold(0, |acc, (_, _, c)| {
- if c == *ON_COLOR || c == *RED_COLOR {
- acc + 1
- } else {
- acc
- }
- })
+ img.pixels()
+ .filter(|(_, _, c)| *c == *ON_COLOR || *c == *RED_COLOR)
+ .count()
}
// Count pixels that are red
fn count_red_px(img: &DynamicImage) -> usize {
- img.pixels().fold(0, |acc, (_, _, c)| {
- if c == *RED_COLOR {
- acc + 1
- } else {
- acc
- }
- })
+ img.pixels()
+ .filter(|(_, _, c)| *c == *RED_COLOR)
+ .count()
}
\ No newline at end of file