Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Filterpedia/components/HistogramDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HistogramDisplay: UIView
bitsPerPixel: 32,
colorSpace: nil,
bitmapInfo: CGBitmapInfo(
rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue),
rawValue: CGImageAlphaInfo.First.rawValue),
version: 0,
decode: nil,
renderingIntent: .RenderingIntentDefault)
Expand All @@ -57,9 +57,9 @@ class HistogramDisplay: UIView
let bluePtr = UnsafeMutablePointer<vImagePixelCount>(blue)
let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(alpha)

let rgba = [redPtr, greenPtr, bluePtr, alphaPtr]
let argb = [alphaPtr, redPtr, greenPtr, bluePtr]

let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(rgba)
let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(argb)

vImageHistogramCalculation_ARGB8888(&inBuffer, histogram, UInt32(kvImageNoFlags))

Expand Down
27 changes: 14 additions & 13 deletions Filterpedia/customFilters/VImageFilters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CircularBokeh: CIFilter, VImageFilter
probe!,
UInt(diameter),
UInt(diameter),
UInt32(kvImageEdgeExtend))
UInt32(kvImageEdgeExtend + kvImageLeaveAlphaUnchanged))

let outImage = CIImage(fromvImageBuffer: outBuffer)

Expand Down Expand Up @@ -218,7 +218,7 @@ class HistogramEqualization: CIFilter, VImageFilter
vImageEqualization_ARGB8888(
&imageBuffer,
&outBuffer,
UInt32(kvImageNoFlags))
UInt32(kvImageLeaveAlphaUnchanged))

let outImage = CIImage(fromvImageBuffer: outBuffer)

Expand Down Expand Up @@ -341,15 +341,15 @@ class EndsInContrastStretch: CIFilter, VImageFilter
width: UInt(CGImageGetWidth(imageRef)),
rowBytes: CGImageGetBytesPerRow(imageRef))

let low = [inputPercentLowRed, inputPercentLowGreen, inputPercentLowBlue, 0].map { return UInt32($0) }
let hi = [inputPercentHiRed, inputPercentHiGreen, inputPercentHiBlue, 0].map { return UInt32($0) }
let low = [0, inputPercentLowRed, inputPercentLowGreen, inputPercentLowBlue].map { return UInt32($0) }
let hi = [0, inputPercentHiRed, inputPercentHiGreen, inputPercentHiBlue].map { return UInt32($0) }

vImageEndsInContrastStretch_ARGB8888(
&imageBuffer,
&outBuffer,
low,
hi,
UInt32(kvImageNoFlags))
UInt32(kvImageLeaveAlphaUnchanged))

let outImage = CIImage(fromvImageBuffer: outBuffer)

Expand Down Expand Up @@ -413,7 +413,7 @@ class ContrastStretch: CIFilter, VImageFilter
vImageContrastStretch_ARGB8888(
&imageBuffer,
&outBuffer,
UInt32(kvImageNoFlags))
UInt32(kvImageLeaveAlphaUnchanged))

let outImage = CIImage(fromvImageBuffer: outBuffer)

Expand Down Expand Up @@ -476,11 +476,11 @@ class HistogramSpecification: CIFilter, VImageFilter
let greenMutablePointer = UnsafeMutablePointer<vImagePixelCount>(green)
let blueMutablePointer = UnsafeMutablePointer<vImagePixelCount>(blue)

let rgba = [redMutablePointer, greenMutablePointer, blueMutablePointer, alphaMutablePointer]
let argb = [alphaMutablePointer, redMutablePointer, greenMutablePointer, blueMutablePointer]

let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(rgba)
let histogram = UnsafeMutablePointer<UnsafeMutablePointer<vImagePixelCount>>(argb)

vImageHistogramCalculation_ARGB8888(&histogramSourceBuffer, histogram, UInt32(kvImageNoFlags))
vImageHistogramCalculation_ARGB8888(&histogramSourceBuffer, histogram, UInt32(kvImageLeaveAlphaUnchanged))

let pixelBuffer = malloc(CGImageGetBytesPerRow(imageRef) * CGImageGetHeight(imageRef))

Expand All @@ -495,9 +495,9 @@ class HistogramSpecification: CIFilter, VImageFilter
let greenPointer = UnsafePointer<vImagePixelCount>(green)
let bluePointer = UnsafePointer<vImagePixelCount>(blue)

let rgbaMutablePointer = UnsafeMutablePointer<UnsafePointer<vImagePixelCount>>([redPointer, greenPointer, bluePointer, alphaPointer])
let argbMutablePointer = UnsafeMutablePointer<UnsafePointer<vImagePixelCount>>([alphaPointer, redPointer, greenPointer, bluePointer])

vImageHistogramSpecification_ARGB8888(&imageBuffer, &outBuffer, rgbaMutablePointer, UInt32(kvImageNoFlags))
vImageHistogramSpecification_ARGB8888(&imageBuffer, &outBuffer, argbMutablePointer, UInt32(kvImageLeaveAlphaUnchanged))

let outImage = CIImage(fromvImageBuffer: outBuffer)

Expand All @@ -514,8 +514,9 @@ class HistogramSpecification: CIFilter, VImageFilter
protocol VImageFilter {
}

let bitmapInfo:CGBitmapInfo = CGBitmapInfo(
rawValue: CGImageAlphaInfo.Last.rawValue)
// The _ARGB8888 version of the vImage functions are used, so bitmapInfo should keep alpha channel before rgb channels (ARGB)
let bitmapInfo: CGBitmapInfo = CGBitmapInfo(
rawValue: CGImageAlphaInfo.First.rawValue)

var format = vImage_CGImageFormat(
bitsPerComponent: 8,
Expand Down