What to do if Core Image is ignoring your slider attributes
Wednesday, February 27th, 2008So you’re writing an Image Unit, and it has a couple of numeric parameters. You expect that Core Image Fun House will show a slider for each of them, and it does—but no matter what you do, the slider’s minimum and maximum are both 0. Furthermore, Core Image Fun House doesn’t show your parameters’ real display names; it simply makes them up from the parameters’ KVC keys.
The problem is that you are specifying those attributes in the wrong place in your Description.plist. And yes, I know you’re specifying them where the project template had them—so was I. The template has it wrong.
One of the filter attributes that Core Image recognizes is CIInputs
. The value for this key is an array of dictionaries; each dictionary represents one parameter to the filter. The template has all the parameter attributes in these dictionaries. That makes sense, but it’s not where Core Image looks for them.
In reality, Core Image only looks for three keys in those dictionaries:
CIAttributeName
CIAttributeClass
CIAttributeDefault
Anything else, it simply ignores.
The correct place to put all those other keys (including CIAttributeSliderMin
, CIAttributeSliderMax
, and CIAttributeDisplayName
) is in another dictionary—one for each parameter. These dictionaries go inside the CIFilterAttributes
dictionary. In other words, the CIFilterAttributes
dictionary should contain:
CIInputs
=> Aforementioned array of (now very small) dictionariesinputFoo
=> Dictionary fully describing theinputFoo
parameter, including slider attributes and display nameinputBar
=> Dictionary fully describing theinputBar
parameter, including slider attributes and display nameinputBaz
=> Dictionary fully describing theinputBaz
parameter, including slider attributes and display name
Finally, an example:
<key>CIFilterAttributes</key> <dict> ⋮ <key>CIInputs</key> <array> <dict> <key>CIAttributeClass</key> <string>CIImage</string> <key>CIAttributeName</key> <string>inputImage</string> </dict> <dict> <key>CIAttributeClass</key> <string>NSNumber</string> <key>CIAttributeDefault</key> <real>1.0</real> <key>CIAttributeName</key> <string>inputWhitePoint</string> </dict> <dict> <key>CIAttributeClass</key> <string>NSNumber</string> <key>CIAttributeDefault</key> <real>0.0</real> <key>CIAttributeName</key> <string>inputBlackPoint</string> </dict> </array> <key>inputWhitePoint</key> <dict> <key>CIAttributeClass</key> <string>NSNumber</string> <key>CIAttributeDefault</key> <real>1.0</real> <key>CIAttributeDisplayName</key> <string>White point</string> <key>CIAttributeIdentity</key> <real>1.0</real> <key>CIAttributeMin</key> <real>0.0</real> <key>CIAttributeMax</key> <real>1.0</real> <key>CIAttributeName</key> <string>inputWhitePoint</string> <key>CIAttributeSliderMin</key> <real>0.0</real> <key>CIAttributeSliderMax</key> <real>1.0</real> <key>CIAttributeType</key> <string>CIAttributeTypeScalar</string> </dict> <key>inputBlackPoint</key> <dict> <key>CIAttributeClass</key> <string>NSNumber</string> <key>CIAttributeDefault</key> <real>0.0</real> <key>CIAttributeDisplayName</key> <string>Black point</string> <key>CIAttributeIdentity</key> <real>0.0</real> <key>CIAttributeMin</key> <real>0.0</real> <key>CIAttributeMax</key> <real>1.0</real> <key>CIAttributeName</key> <string>inputBlackPoint</string> <key>CIAttributeSliderMin</key> <real>0.0</real> <key>CIAttributeSliderMax</key> <real>1.0</real> <key>CIAttributeType</key> <string>CIAttributeTypeScalar</string> </dict> </dict>
You can see how the descriptions under CIInputs
are as terse as possible; everything besides the absolute necessities is specified in the outer dictionaries.