This commit is contained in:
Chris Tsang
2024-05-30 10:04:23 +01:00
parent 36b16de17a
commit f6cf3e8705
2 changed files with 6 additions and 6 deletions

View File

@@ -73,7 +73,7 @@ fn should_key_image(img: &ColorImage) -> bool {
// Check for transparency at several scanlines // Check for transparency at several scanlines
let threshold = ((img.width * 2) as f32 * KEYING_THRESHOLD) as usize; let threshold = ((img.width * 2) as f32 * KEYING_THRESHOLD) as usize;
let mut num_transparent_boundary_pixels = 0; let mut num_transparent_pixels = 0;
let y_positions = [ let y_positions = [
0, 0,
img.height / 4, img.height / 4,
@@ -84,9 +84,9 @@ fn should_key_image(img: &ColorImage) -> bool {
for y in y_positions { for y in y_positions {
for x in 0..img.width { for x in 0..img.width {
if img.get_pixel(x, y).a == 0 { if img.get_pixel(x, y).a == 0 {
num_transparent_boundary_pixels += 1; num_transparent_pixels += 1;
} }
if num_transparent_boundary_pixels >= threshold { if num_transparent_pixels >= threshold {
return true; return true;
} }
} }

View File

@@ -233,14 +233,14 @@ impl ColorImageConverter {
// Check for transparency at several scanlines // Check for transparency at several scanlines
let threshold = ((img.width * 2) as f32 * KEYING_THRESHOLD) as usize; let threshold = ((img.width * 2) as f32 * KEYING_THRESHOLD) as usize;
let mut num_transparent_boundary_pixels = 0; let mut num_transparent_pixels = 0;
let y_positions = [0, img.height / 4, img.height / 2, 3 * img.height / 4, img.height - 1]; let y_positions = [0, img.height / 4, img.height / 2, 3 * img.height / 4, img.height - 1];
for y in y_positions { for y in y_positions {
for x in 0..img.width { for x in 0..img.width {
if img.get_pixel(x, y).a == 0 { if img.get_pixel(x, y).a == 0 {
num_transparent_boundary_pixels += 1; num_transparent_pixels += 1;
} }
if num_transparent_boundary_pixels >= threshold { if num_transparent_pixels >= threshold {
return true; return true;
} }
} }