Skip to content

Instantly share code, notes, and snippets.

@josephjoeljo
Last active November 1, 2019 19:35

Revisions

  1. josephjoeljo revised this gist Nov 1, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions blackandwhite
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ guard let monoFormat = vImage_CGImageFormat(
    }

    let result = try? destinationBuffer.createCGImage(format: monoFormat)

    if let result = result {
    imageView.image = UIImage(cgImage: result)
    }
  2. josephjoeljo renamed this gist Nov 1, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. josephjoeljo revised this gist Nov 1, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // vim: syntax=Swift

    Swift Color matrix

    let redCoefficient: Float = 0.2126
  4. josephjoeljo revised this gist Nov 1, 2019. 1 changed file with 31 additions and 1 deletion.
    32 changes: 31 additions & 1 deletion Swift
    Original file line number Diff line number Diff line change
    @@ -1 +1,31 @@
    Swift Color matrix
    Swift Color matrix

    let redCoefficient: Float = 0.2126
    let greenCoefficient: Float = 0.7152
    let blueCoefficient: Float = 0.0722

    let divisor: Int32 = 0x1000
    let fDivisor = Float(divisor)

    var coefficientsMatrix = [
    Int16(redCoefficient * fDivisor),
    Int16(greenCoefficient * fDivisor),
    Int16(blueCoefficient * fDivisor)
    ]

    let preBias: [Int16] = [0, 0, 0, 0]
    let postBias: Int32 = 0

    guard let monoFormat = vImage_CGImageFormat(
    bitsPerComponent: 8,
    bitsPerPixel: 8,
    colorSpace: CGColorSpaceCreateDeviceGray(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue),
    renderingIntent: .defaultIntent) else {
    return
    }

    let result = try? destinationBuffer.createCGImage(format: monoFormat)
    if let result = result {
    imageView.image = UIImage(cgImage: result)
    }
  5. josephjoeljo created this gist Nov 1, 2019.
    1 change: 1 addition & 0 deletions Swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Swift Color matrix