commit b4d035616a2bf147d9e81a18bd8323ebbd3c0c7c
parent b351efc72930c4c8292f2daabce32f04aa3545c0
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 30 Mar 2023 02:41:37 -0700
cleanup
Diffstat:
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs
@@ -491,14 +491,11 @@ fn count_px_on(img: &DynamicImage) -> usize {
// Count pixels that are red
fn count_red_px(img: &DynamicImage) -> usize {
- let mut count_on = 0;
- for y in 0..img.height() {
- for x in 0..img.width() {
- let c = img.get_pixel(x, y);
- if c == *RED_COLOR {
- count_on += 1
- }
+ img.pixels().fold(0, |acc, (_, _, c)| {
+ if c == *RED_COLOR {
+ acc + 1
+ } else {
+ acc
}
- }
- count_on
+ })
}
\ No newline at end of file