The IceMan Scripting Environment |
To script image processing operations within It requires writing expressions in the IceMan scripting environment. The IceMan scripting environment uses the Io language. The decision to write somethingin Tcl or IceMan is fairly simple. If you script needs access to the application objects then you must use tcl. IceMan scripts know nothing of the tcl application object or catalogs or sessions. If you script needs to perform mathematical or image processing then it should be written as an IceMan script. Of course it is very easy for you tcl scripts to compose IceMan scripts on the fly and execute them and for you to develop libraries of IceMan or tcl scripts that can be automatically loaded by "It" and executed as desired directly or by other scripts.
Every image in 'it' is represented by a tcl side Image object. Over in the IceMan environment each image is also represented by an object. There images are represented by a type called IceImage. This is a more direct representation of an image than the tcl side has. You can add two IceImages togther, use any of over one hundred image processing methods IceImage has to transform and create new IceImages. The environment has a more natural support for numbers (unlike tcl).
One extremely useful and interesting aspect of the IceMan scripting environment is how easy it is to extend existing objects. At this point it is worth introducing the colleciton of files used to implement It's environment that are included in their source form. You can find them under $RMSTREE/lib/it/. As an example of extending an object's behavior it is particularly common to want to add, subtract, multiply and divide images. IceImage of course has those operators and in their native form and you can type at the "It" console window:
it IceExpr "e0 Sum(e1)"
The IceMan script is the part between inside the quotes. It will be evaluate the moment you press enter. You can read the expression as "send the image e0 the Sum message with the argmument of image e1. Not exactly a natural way of adding two things. Now open in a text editor the file $RMSTREE/lib/it/IceImage.io. This file is read in automatically by it on start up. You can see how we've added four new methods to the IceImage object to make it possible to write the following:
it IceExpr "e0 + e1"
That is a bit more obvious and easy to remember. Adding two images together is one thing you might type directly but you'll often want to collect together more complex expressions and put them in a library routine. In the Io language that's called a method. It might also be helpful to look through IoUtils.io for a simple example of how to declare a new method in the Io langauge.
There is a relationship between 'it's tcl side Catalog object and a construct on the IceMan side called a namespace. For each catalog in "it" there exists a namespace on the IceMan side. Namespaces are kept track of by the IceRegistry object. When you execute an IceMan script it runs within one namespace and any images that are ceated from an expression are added to that namespace and therefore to the same catalog.
Also worth mentioning is the IceRegistry object also performs another important function. 'It' will start to stash least recently used images to a scratch directory if you open or create more than a set number of images. That threshold is set in the Preferences window. The operation of this tempory swapping to disk can be completely ignored by the script writer but for the mortally curious it is completely implemented within IceRegistry object which you can find in $RMSTREE/lib/it/IceRegistry.io
An IceImage represents an array of pixels. Pixels are composed of 1 or more channels like red green and blue. The number of channels an image has is referred to as it's ply. IceImage supports 4 different image types (8 bit, float, double and fixed point) but within one IceImage all the channels are of the same type. Expressions can freely mix types as promotion is performed automatically.
The Ice object holds the entire state of the "It" application. It uses the IceRegistry to keep track of images that fall into one of two camps. The first camp is the obvious one, the images you have render, loaded or created via a script. The second is used by "It" to perform display functions such as tone mapping. For the most part you can ignore this second group and it is not intended for these images to take part in normal scripting activities.s
The Ice object also provides the context that scripts run in. This context provides the grouping represented by a catalog in the GUI. As a convinience to the script user if you type in an expression without an assigment such as:
it IceExpr "e0 Blur(6,6)"
the Ice object will collect the result of that script and create an image called "_result" for you. So if you are just trying things out you don't have to keep coming up with a variable name. The alternative would be assign the result directly to a variable of you choice as in:
it IceExpr "fuzzy := e0 Blur(20,20)"
The IceRegistry provides a mapping between handles (names) and the actual images. It also implements a "virtual image" scheme by swapping images out to disk if the total number of images exceed a threshold. Images can be 'locked' to prevent them from be swapped out but this is not something the usual script writer should do. 'It' uses the IceRegistry for both your regular images that you can see in the catalogs and for it's own purposes for displays and so forth
As mentioned above 'It' uses the IceMan environment itself to produce the actual display images. The IceRamp object and it's subclasses perform define each of the tone mapping operators.
If you use the "Save Image..." dialog from 'It' you will see there is a drop down menu to choose the format the image is saved in. The format is defined by the IceSave object and its related classes. In effect a "save" is actually just the result of an arbitrary IceMan script. A script writer could insert anything here for any evil purposes he or she desires.
You can extend or modify the IceMan scripting environment by loading your own .tcl files on 'it' startup. In your local copy of it.ini place:
LoadExtension io /my/extensionpath/MyIceManExtensions.io
Pixar Animation Studios
|