mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-21 15:14:38 +01:00
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:
parent
2df78f3cf1
commit
911d4ed248
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user