objcio / functional-swift

Issue repository for the Functional Swift book
http://www.objc.io/books/fpinswift
927 stars 133 forks source link

Error in CoreImage Wrapper colorOverlay function #105

Closed karthikgs7 closed 8 years ago

karthikgs7 commented 9 years ago
screen shot 2015-10-03 at 1 24 25 pm

When, I call the colorGenerator and compositeSourceOver, separately, it works fine. I got error only, when I calling colorOverlay function.

pauluhn commented 9 years ago

Also getting an error... screen shot 2015-10-16 at 10 04 00 am

Based on https://github.com/objcio/functional-programming-in-swift/issues/77, I switched to a CIColor as the input color but still getting error. screen shot 2015-10-16 at 10 09 34 am

I notice that in https://github.com/objcio/issue-16-functional-apis/blob/master/FunctionalCoreImage/CoreImage.swift, you unwrap the CIColor but when I try to, it says its a non-optional.

huangsemao commented 8 years ago

To fix this problem need set size for output image in CIConstantColorGenerator filter, try this function

func colorGenerator(color: NSColor) -> Filter { return { image in guard let c = CIColor(color: color) else { fatalError() } let parameters = [kCIInputColorKey: c] guard let filter = CIFilter(name: "CIConstantColorGenerator", withInputParameters: parameters) else { fatalError() } guard let outputImage = filter.outputImage?.imageByCroppingToRect(image.extent) else { fatalError() } return outputImage } }

trozware commented 8 years ago

afterfriday's fix worked for me - thanks very much. This is really just applying the same crop as used in compositeSourceOverlay. I still had a problem due to my own typo in the filter name, so that is worth checking if things are going weird.

With the CIColor un-wrapping, if you are using an iOS playground with UIColor, the CIColor initialiser does not return an optional. If you are using an NSColor, it does.

chriseidhof commented 8 years ago

Thanks for all the comments everyone. Unfortunately, we can't do much about it until Apple fixes this =).