mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Sticker cut out for iOS < 17
This commit is contained in:
@@ -56,6 +56,21 @@ private func generateHistogram(cgImage: CGImage) -> ([[vImagePixelCount]], Int)?
|
||||
return ([histogramBinZero, histogramBinOne, histogramBinTwo, histogramBinThree], alphaBinIndex)
|
||||
}
|
||||
|
||||
public func imageHasSubject(_ image: UIImage) -> Bool {
|
||||
guard let cgImage = image.cgImage, cgImage.bitsPerComponent == 8, cgImage.bitsPerPixel == 32 else {
|
||||
return false
|
||||
}
|
||||
if let (histogramBins, _) = generateHistogram(cgImage: cgImage) {
|
||||
var totalCount: vImagePixelCount = 0
|
||||
for i in 0 ..< 255 {
|
||||
totalCount += histogramBins[1][i]
|
||||
}
|
||||
let opaqueCount: vImagePixelCount = histogramBins[1][255]
|
||||
return Double(opaqueCount) / Double(totalCount) > 0.05
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public func imageHasTransparency(_ image: UIImage) -> Bool {
|
||||
guard let cgImage = image.cgImage, cgImage.bitsPerComponent == 8, cgImage.bitsPerPixel == 32 else {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user