From 911d4ed24883d09db33875da6d43ceebb21c3021 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 11 Jan 2020 12:25:31 -0700 Subject: [PATCH] Change dark image detection to only consider non-clear pixels and not fail on images with no luminescence. Issue #1607 --- Shared/Extensions/IconImage.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Shared/Extensions/IconImage.swift b/Shared/Extensions/IconImage.swift index 9d82daad1..83f9ff118 100644 --- a/Shared/Extensions/IconImage.swift +++ b/Shared/Extensions/IconImage.swift @@ -52,15 +52,22 @@ extension CGImage { let r = ptr[i] let g = ptr[i + 1] let b = ptr[i + 2] + let a = ptr[i + 3] let luminance = (0.299 * Double(r) + 0.587 * Double(g) + 0.114 * Double(b)) - totalLuminance += luminance - pixelCount += 1 + if Double(a) > 0 { + totalLuminance += luminance + pixelCount += 1 + } } let avgLuminance = totalLuminance / Double(pixelCount) - return avgLuminance < 37.5 + if totalLuminance == 0 { + return true + } else { + return avgLuminance < 40 + } } }