"it" Scriptlets

"it" Scriptlets

Find herein a collection of simple commands and scripts that you can run in the "it" console to do all manner of useful and funky stuff...


SCRIPTLET #1: GIMME AN "A"

There are times in a person's life when one finds one's self confronted with the unthinkable, staring at a source image that one could have sworn was rgba but is, in fact, merely rgb. At these times, the weak go out for coffee and ask a co-worker for help, while the strong will turn to "it" and find succor...

The following is a relatively simple way of a creating a four-channel, rgba image that includes a simple "pseudo-alpha" that could serve to get you back in black, as it were.

  1. Lo and behold! An image, what has but three channels, r, g, and b! You can find a similar TIFF image (logo.tif) in the sourceimages directory of the rfm_project included with the documentation.

    images/logo.jpg

    The RenderMan Logo

  2. Open "it" and load logo.tif (it loads as e0 in your catalog). Just for grins, right-click on the image and select View > Alpha. Marvel at the sheer nothingness before your eyes. Select View > RGB to return to normal viewing.

  3. Once again, right-click in the "it" Catalog window and select Windows > Console.... This will open the Console window, which you might be familiar with from the Introduction to "it" Scripting tutorial.

  4. Now we'll run a few simple commands to give us an rgba version of our logo. Essentially, what we want to do is create an inverse of the r channel. We're going to do this by subtracting r from a base, "1.0", image.

    • First, we'll create an image (a card) whose pixel value is 1.0:

      it IceExpr "one := IceImage Card(IceComponentType Float, 1.0)"

      This creates an entry one in your catalog that is labeled <script result> and rivals the alpha view of our logo image in its sheer nothingness.

    • Next, we'll create a single-channel "alpha" image from the inverse of the red channel (1 - red) of logo.tif:

      it IceExpr "a := one - e0 Shuffle(1)"

      This creates an image in our catalog named a, and it looks a little something like this:

      images/logo_a.jpg

      Our Single-Channel "Alpha"

      Now, in all honesty, that's the long way of doing things, but those steps do a nice, explicit job of showing what we're doing. As it happens, IceMan gives us the same result in a single step, thusly:

      it IceExpr "a := IceColor(1.0) - e0 Shuffle(1)"

    • Finally, we'll merge our three-channel source image with the first (and only) channel of our new "alpha" image to create a four-channel rgba TIFF file:

      it IceExpr "witha := e0 Interleave(a, list(-1,-2,-3,1))"

      This will create an image in our catalog that looks like our logo, but if we right-click on the image and select View > Alpha... Presto! You got alpha.

  5. And that's that.

For more information on the IceMan Operators that we used here, check out the Creation and Channel Manipulation sections of the "it" documentation.


Scriptlet #2: Custom Save Scripts

Saving images can get very complex, so to keep 'it' simple we provide a system for you to define your own file saving policies and do not try to cover every possible situation ourselves.

Your policy can pretty much do anything, as file saving is actually the result of executing a script - the details of which you can read all about in the comments of $RMSTREE/lib/it/IceSave.io.

In this example, we are burning a gamma value into our pixels. We're going to compose a script and load it in any appropriate .ini file (it.ini or RMSProduction.ini or ...) using the following line:

LoadExtension io /path/to/MyJpeg.io

Our script, MyJpeg.io, will look like this:

// IceSaver is defined for use in $RMSTREE/lib/it/IceSave.io here we make
// another sub-class and register it as new saver script

SaveMyJpeg := IceSaver clone do (
   FormatName := "My JPEG with gamma"
   FormatExtension := "jpg"
   SaveFile := method(fileName, image,

       // Enforce the extension we want.
       if (fileName pathExtension == "",
           fileName := fileName .. "."
       ,
           fileName := fileName asMutable removeSuffix(fileName pathExtension)
       )
       fileName := fileName .. FormatExtension

       // now get down to the business of gamma and file writing
       writeln("saving gamma'd jpeg to ", fileName)
       image Gamma(list(2.2)) Save(fileName, IceOutputType Jpeg)
   )
)

SaveMyJpeg register(SaveMyJpeg)

When you re-start 'it' and do a "Save Image", you'll see a new entry on the format menu called My JPEG with gamma. Note this script also can be used to manipulate the file name.