Change dark image detection to only consider non-clear pixels and not fail on images with no luminescence. Issue #1607

This commit is contained in:
Maurice Parker 2020-01-11 12:25:31 -07:00
parent 2df78f3cf1
commit 911d4ed248

View File

@ -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
}
}
}