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 r = ptr[i]
|
||||||
let g = ptr[i + 1]
|
let g = ptr[i + 1]
|
||||||
let b = ptr[i + 2]
|
let b = ptr[i + 2]
|
||||||
|
let a = ptr[i + 3]
|
||||||
let luminance = (0.299 * Double(r) + 0.587 * Double(g) + 0.114 * Double(b))
|
let luminance = (0.299 * Double(r) + 0.587 * Double(g) + 0.114 * Double(b))
|
||||||
|
|
||||||
totalLuminance += luminance
|
if Double(a) > 0 {
|
||||||
pixelCount += 1
|
totalLuminance += luminance
|
||||||
|
pixelCount += 1
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let avgLuminance = totalLuminance / Double(pixelCount)
|
let avgLuminance = totalLuminance / Double(pixelCount)
|
||||||
return avgLuminance < 37.5
|
if totalLuminance == 0 {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return avgLuminance < 40
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue