From c5cf2e88be2f58cca83fccbb6c7016f680803f1b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 7 Mar 2023 12:52:34 +0400 Subject: [PATCH] Fix warning --- .../Sources/ImageTransparency.swift | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/submodules/ImageTransparency/Sources/ImageTransparency.swift b/submodules/ImageTransparency/Sources/ImageTransparency.swift index 54277c8e66..8c8c17f4af 100644 --- a/submodules/ImageTransparency/Sources/ImageTransparency.swift +++ b/submodules/ImageTransparency/Sources/ImageTransparency.swift @@ -29,17 +29,31 @@ private func generateHistogram(cgImage: CGImage) -> ([[vImagePixelCount]], Int)? } assert(error == kvImageNoError) - let histogramBins: [[vImagePixelCount]] = (0...3).map { _ in - return [vImagePixelCount](repeating: 0, count: 256) + var histogramBinZero = [vImagePixelCount](repeating: 0, count: 256) + var histogramBinOne = [vImagePixelCount](repeating: 0, count: 256) + var histogramBinTwo = [vImagePixelCount](repeating: 0, count: 256) + var histogramBinThree = [vImagePixelCount](repeating: 0, count: 256) + + histogramBinZero.withUnsafeMutableBufferPointer { zeroPtr in + histogramBinOne.withUnsafeMutableBufferPointer { onePtr in + histogramBinTwo.withUnsafeMutableBufferPointer { twoPtr in + histogramBinThree.withUnsafeMutableBufferPointer { threePtr in + var histogramBins = [zeroPtr.baseAddress, onePtr.baseAddress, twoPtr.baseAddress, threePtr.baseAddress] + histogramBins.withUnsafeMutableBufferPointer { histogramBinsPtr in + let error = vImageHistogramCalculation_ARGB8888( + &sourceBuffer, + histogramBinsPtr.baseAddress!, + noFlags + ) + assert(error == kvImageNoError) + } + } + } + } } - var mutableHistogram: [UnsafeMutablePointer?] = histogramBins.map { - return UnsafeMutablePointer(mutating: $0) - } - error = vImageHistogramCalculation_ARGB8888(&sourceBuffer, &mutableHistogram, noFlags) - assert(error == kvImageNoError) let alphaBinIndex = [.last, .premultipliedLast].contains(cgImage.alphaInfo) ? 3 : 0 - return (histogramBins, alphaBinIndex) + return ([histogramBinZero, histogramBinOne, histogramBinTwo, histogramBinThree], alphaBinIndex) } public func imageHasTransparency(_ cgImage: CGImage) -> Bool {