Added notes to image filter chain documentation about using images from an...
authored
byKevin Meaney
Added notes to image filter chain documentation about using images from an image collection. Also about using the ruby gem convenience methods for setting points and rectangles as values for filter properties.
@@ -33,7 +33,7 @@ To obtain a list of CoreImage filters belonging to the blur category:
### Getting the Attributes of a CoreImage Filter
To be able to create a property list dictionary or json object that you use to setup a core image filter in a filter chain, you need to know what the list of keys are for each filter are and for each key what the range of allowed values is that can be assigned to the filter. To get the filter description you can get the "imagefilterattribute" property from the "imagefilterchain" type. The information can be returned in one of 3 ways. Either as a json string (see the example below) or saved to a json or a plist file (-jsonfile, -plistfile). If saving to a file then after the (-jsonfile, -plistfile) option you need to provide a file path.
To be able to create a property list dictionary or json object that you use to setup a core image filter in a filter chain, you need to know what the list of keys are for each filter and for each key what the range of allowed values is that can be assigned to the filter. To get the filter description you can get the "imagefilterattribute" property from the "imagefilterchain" type. The information can be returned in one of 3 ways. Either as a json string (see the example below) or saved to a json or a plist file (-jsonfile, -plistfile). If saving to a file then after the (-jsonfile, -plistfile) option you need to provide a file path.
To view the CIDroste filter attributes using ruby:
...
...
@@ -74,7 +74,19 @@ Each filter in a filter chain, is described by the filter name, a name identifie
In the above json example, the core image filter to be created is a Core Image Unsharp Mask filter. The filter is given the identifier "com.yvs.documentation.renderingfilterchain.unsharpmask" and the filter takes three inputs. These are the input radius, which takes a numeric value, the input intensity which also takes a numeric value and an input image which takes a dictionary/json object which describes how to obtain the image.
When an input is an image, then the input value is a way to obtain the image and is a json object. The image can be sourced as the output image of a previous filter in the filter chain and if that was the case then the key in the object would be "cifilterindex" and the value is an index to an earlier filter in the filter chain or a key "mifiltername" and the value would be a string which is the name identifier of the earlier filter. If the image is sourced from a bitmap context then the key in the object would be "objectreference" as in the above example which refers to a base object with reference 0. The image can also come from an image importer object in which case the "objectreference" key is also used but that a "imageindex" key should also be supplied specifying the index of the image in the image file. If "imageindex" is not specified and the object reference refers to an image importer object then "imageindex" defaults to 0.
When an input is an image, then the input value is a way to obtain the image and is a json object. The image can be sourced as the output image of a previous filter in the filter chain and if that was the case then the key in the object would be "cifilterindex" and the value is an index to an earlier filter in the filter chain or a key "mifiltername" and the value would be a string which is the name identifier of the earlier filter. If the image is sourced from a bitmap context then the key in the object would be "objectreference" as in the above example which refers to a base object with reference 0. The image can also come from an image importer object in which case the "objectreference" key is also used but that a "imageindex" key should also be supplied specifying the index of the image in the image file. If "imageindex" is not specified and the object reference refers to an image importer object then "imageindex" defaults to 0. When obtaining an image from an object like an image importer, bitmap context, or movie importer the objecttype/objectname combination can be used in place of objectreference to obtain the object to obtain the image from.
Alternately the input image can be sourced from an image in the image collection. Unlike the other image sources the image in the collection does not have to exist at the time the filter chain is created, as long as the image is available when the image filter chain is sent the render message then the filter chain will be able to render.
To source an image from an image in the image collection you refer to the image by its identifier.
When a filter takes a numeric input, then the "cifiltervalueclass" key is not needed but for all other input types specifying the value class is required and in the above example "CIImage" is demonstrated. Other "cifiltervalueclass" keys are "CIVector", "CIColor", "NSString". In the case of both CIVector and CIColor the type of the value for the key "cifiltervalue" is a string, the purpose of the "cifiltervalueclass" key is to inform Moving Images what object type the string needs to be converted into before it can be assigned to the filter.
CoreImage filter properties like inputExtent and inputCenter have convenience methods in the ruby gem added so that you can assign hash values generated from the methods MIShapes.make_point and MIShapes.make_rectangle. The JSON generated from using these methods when adding filter properties for a point is:
The following json object is everything needed to define the filter chain managed by a "imagefilterchain" base object. The render destination is specified using the "cirenderdestination" key. The value for the "cifilterlist" key is a list of filter objects each one describing one filter in the filter list. The order of the filters in this list is important, for a few reasons. The outputImage of the last filter in the filter chain is the the one that renders to the render destination. Since you can refer to an earlier filter in the filter chain by its filter index "cifilterindex" then the order needs to be correct or alternatively if you refer to filters by their name identifier you can only refer to filters earlier in the list of filters.