[SESI logo]

Houdini Development Toolkit - Version 6.5

Side Effects Software Inc. 2004

Image

Loading and Saving Raster Images

The preferred method of saving and loading a raster image is to use the methods in IMG_Raster.
  • stat(const char *filename, short *xres, short *yres)
  • load(const char *filename, int xres, int yres, ...)
  • load(const char *filename...)
  • save(const char *filename)
  • The reason that these methods are preferred is that they handle both 8 and 16 bit color channels. Currently only two file formats support 16 bit color channels, Cineon (suffix .cin or .kdk) and TIFF (suffix .tif16).

    On success, the above methods will return 1. If they fail, the return value will be 0.

    The load methods will determine the correct format type by looking at the extension of the filename. Any format supported by Houdini may be saved or loaded. If the extension doesn't map to any known suffix, Alias format is used for saving (this does not include an alpha channel).

    An alternative method of saving and loading rasters is to use the raw Frame Buffer Library (libFB.h). However, this is antique C code and only handles 8 bit rasters.


    Adding a new format using FBio

    The FBio table (usually found in $HFS/houdini) allows the extension of the formats that the raster library understands. The FBio file contains a list of file extensions along with programs which can read/write the new file format (as well as Houdini .pic files). The format of the GEOio table is really quite straight-forward. The extension for the format is specified, then a program to read the external format, then a program to save to the external format.

    Here is an example program which uses the SGI image buffer libraries to save a raster out.

    // This is based of sample source in /usr/people/4Dgifts #include <stdlib.h> #include <IMG/IMG_Raster.h> #include "image.h" unsigned short rbuf[8192]; unsigned short gbuf[8192]; unsigned short bbuf[8192]; static void stripRow(IMG_RGBA *pix, int xres) { int i; for (i = 0; i < xres; i++) { rbuf[i] = pix[i].r; gbuf[i] = pix[i].g; bbuf[i] = pix[i].b; } } int main(int argc, char **argv) { IMAGE *image; IMG_Raster raster; int xres, yres; int y; if (argc != 2) { fprintf(stderr,"Usage: savesgi outimage.rgb\n"); exit(1); } if (!raster.load("stdin")) { fprintf(stderr, "Unable to load image stdin\r\n"); exit(1); } xres = raster.Xres(); yres = raster.Yres(); image = iopen(argv[1], "w", RLE(1), 3, xres, yres, 3); for (y=0; y < yres; y++) { stripRow(raster.getPixel(0, y), xres); putrow(image, rbuf, y, 0); putrow(image, gbuf, y, 1); putrow(image, bbuf, y, 2); } iclose(image); return 0; } The corresponding entry in the FBio table would look something like this:
    .sgi "" "savesgi %s" .rgb "" "savesgi %s" To complete this file format, we would want to create a program to read SGI format images and fill out the reader portion of the table entry. The %s will get replaced with the filename to be saved.

    In addition to setting up the FBio table, it is also important to extend the FBfiles file to include your new file extension. If this is not done, several programs will not display the new format type in the file prompters.

    Tip: The external file format does not actually have to be a disk file format. It is also possible to drive output devices (or scanners) using the FBio table technique. For example, to add an "ipaste" file format, simply add the following line to the FBio table:
    .ip "icp stdin /tmp/$$.sgi ; ipaste /tmp/$$.sgi ; rm -f /tmp/$$.sgi" "" Then, when you save an image to a file name ending in ".ip", ipaste will be run (i.e. icp $HH/pic/Mandril.pic test.ip)


    Table of Contents
    Operators | Surface Operations | Particle Operations | Composite Operators | Channel Operators
    Material & Texture | Objects | Command and Expression | Render Output |
    Mantra Shaders | Utility Classes | Geometry Library | Image Library | Clip Library
    Customizing UI | Questions & Answers

    Copyright © 2004 Side Effects Software Inc.
    477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7