More stuff done for the Image Filter Chain reference documentation. authored by Kevin Meaney's avatar Kevin Meaney
...@@ -29,6 +29,24 @@ CICategoryStylyize ...@@ -29,6 +29,24 @@ CICategoryStylyize
CICategoryTileEffect CICategoryTileEffect
CICategoryTransition CICategoryTransition
### Getting the attributes of a CoreImage filter
To be able to create a property list dictionary or json object for setting up a core image filter in a filter chain, you need to know what the properties are for each filter and for each property key what the range of allowed values is that can be assigned to the filter. To get the filter description you ask for the "imagefilterattribute" property from the "imagefilterchain" type. The information can be returned in one of 3 ways. Either as a json string or saved to a json or a plist file (-jsonfile, -plistfile). If saving to a file then after the (-jsonfile, -propertyfile) option you need to provide a file path.
The following shows you how to get the properties about the CIDroste filter as a json string.
smig getproperty -type imagefilterchain -property imagefilterattributes -filtername CIDroste -jsonstring
Alternatively you can save the result to a file as a json object or a plist dictionary. You do this by replacing the "-jsonstring" switch with a "-jsonfile" or "-propertyfile" option on the command line followed by a path to a file.
smig getproperty -type imagefilterchain -property imagefilterattributes -filtername CIDroste -jsonfile "~/Desktop/CIDrosteFilterAttributes.json"
In the case of the "-jsonfile" option the text saved to the json file will be in a more human readable form than that returned using the "-jsonstring" option.
The property list file version:
smig getproperty -type imagefilterchain -property imagefilterattributes -filtername CIDroste -propertyfile "~/Desktop/CIDrosteFilterAttributes.plist"
### Creating an image filter chain json object/plist dictionary ### Creating an image filter chain json object/plist dictionary
The chaining filters together is achieved by making the output image of a filter earlier in the filter chain an input image to a later filter. When the "imagefilterchain" object receives the render filter chain message the object renders the output image of the last filter in the filter list to the render destination. The chaining filters together is achieved by making the output image of a filter earlier in the filter chain an input image to a later filter. When the "imagefilterchain" object receives the render filter chain message the object renders the output image of the last filter in the filter list to the render destination.
...@@ -131,6 +149,15 @@ An example demonstrating the creation of a filter chain: ...@@ -131,6 +149,15 @@ An example demonstrating the creation of a filter chain:
] ]
} }
In the above in the "cifiltervalue" property where the value is an object with property "mifiltername" then the value is a name identifier for a filter earlier defined in the filter chain. Alternatively an earlier filter can be specified by its filter index. So instead of in the above example where the "mifiltername" property has a value of "photoeffectprocess" we could have the "cifilterindex" property with a value of 0.
"cifilterkey": "inputImage",
"cifiltervalueclass": "CIImage",
"cifiltervalue":
{
"cifilterindex": 0
}
If one of the filter properties took a value that needed to be converted to a CIVector object then the filter property json object would like: If one of the filter properties took a value that needed to be converted to a CIVector object then the filter property json object would like:
{ {
...@@ -210,22 +237,61 @@ These are both boolean values. When requesting the property value for both of th ...@@ -210,22 +237,61 @@ These are both boolean values. When requesting the property value for both of th
#### Rendering the image filter chain object #### Rendering the image filter chain object
To draw to the bitmap graphic context you use the "-drawelement" option for the doaction subcommand. The "-drawelement" option takes one of the options: "-jsonstring", "-jsonfile" or "-plistfile". If the option is "-jsonstring" then the string that immediately follows the option is a json object which describes the drawing, otherwise if the option is "-jsonfile" then the string that follows is a path to a file which is a text file containing a json object which describes the drawing, else if the option is "-plistfile" the the string that follows is a path to a file which is a plist file containing a dictionary object which describes the drawing. The image filter chain object is rendered by sending the image filter chain object a render message. The render destination was specified when the image filter chain object was created so there is no need to respecify the render destination.
In its simplest form the render command looks like:
smig doaction -renderfilterchain -object $IMFCR
Which will render the filter chain in its current state.
If you wish to render the same filter chain more than once, then to produce different output, either the input image must change or the input values for the filters must change. To update a filter chain input image, the input image must come from a bitmap context object. By changing the contents of the bitmap context before rendering the filter chain the filter chain object will pull a new image from the bitmap context before rendering.
To update properties of filters in the filter chain the render filter chain action needs a json object or a plist dictionary. The json object or plist dictionary is supplied either via a json string on the command line or a path to a file containing the json object or a plist dictionary.
For example the following will draw the contents of the plist file if it is correctly formed. The top level json object can take three properties. All of the properties are optional. The keys for these properties are:
smig doaction -drawelement -object $BMCR -plistfile "~/Desktop/liondrawing.plist" sourcerectangle
destinationrectangle
cifilterproperties
To view a description of the drawing commands please see the [Drawing Shapes Images and Text Documentation](DrawingShapesImagesAndText) The source rectangle is defined in the coordinate system of the image filter chain and can be used to crop the image filter chain output. Filters like any of the blur filters extend the bounds of the output image of a filter chain beyond that of the input image, you can use the source rectangle property to crop the extended edges from the output image.
#### Getting pixel data from a graphic context The destination rectangle is defined in the coordinate system of the render destination, currently a bitmap context. You can use the destination rectangle property to specify where in the bitmap context the image filter chain render should draw to.
To get pixel data from a bitmap context you use the "-getpixeldata" option. This command can easily produce a lot of data and is currently limited to getting data from 65536 pixels or less in one command. The "-getpixeldata" option takes a "-jsonstring" option that defines the rectangle within which it will get the pixel data from. The "-getpixeldata" also takes one of "-jsonfile" or "-plistfile" which specifies the data type (plist or json) and where the data should be saved. The property with key "cifilterproperties" has as its value a list of json objects each representing a filter property.
The "-getpixeldata" option determines the type of bitmap context, depending on whether the context is grayscale, rgb, cmyk, whether the context has an alpha channel and whether the components of the context is represented by floating point values, or integers and returns the appropriate data. The "-getpixeldata" option also returns a list of column titles and the first two titles are always x and y representing the location of the pixel from which the pixel data comes from. The three properties keys in the object returned by "-getpixeldata" are "columnNames", "contextInfo" and "pixelData". The "contextInfo" property contains some basic information about the context the data was obtained from. If we wanted to vary the inputAngle property of the motion blur filter in the image filter chain defined above each time the image filter chain is rendered then we would do:
For example, if we had a bitmap context with name "nightingale" and we wanted to get the pixel data from a rectangle starting at position x = 100, y = 50 with width 2048 and height 32 then we would do as demonstrated below: {
"sourcerectangle":
{
"origin":
{
"x": 0,
"y": 0
}
"size":
{
"width": 512,
"height":342
}
}
"cifilterproperties":
[
{
"cifilterkey": "inputImage",
"cifiltervaleclass": "CIImage",
"cifiltervalue":
{
"mifiltername": "motionblur0",
"cifilterkey": "inputAngle",
"cifiltervalue": 1.57
}
}
]
}
smig doaction -getpixeldata -name "nightingale" -type bitmapcontext -jsonstring '{ "origin" : { "x" : 100, "y" : 50 }, "size" : { "width" : 2048, "height" : "32" } }' -jsonfile "~/Desktop/pixeldata.json" Like during the creation of a filter chain, a filter in the filter chain can be referred to by its filter index, not just by its name identifier.
[Home](Home) | [Contents](Contents) | [Previous - Bitmap Graphic Context](BitmapGraphicContext) | [Next - Drawing Shapes Images and Text](DrawingShapesImagesAndText) [Home](Home) | [Contents](Contents) | [Previous - Bitmap Graphic Context](BitmapGraphicContext) | [Next - Drawing Shapes Images and Text](DrawingShapesImagesAndText)
\ No newline at end of file