HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Adding a New Image Format Using FBio

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).

Use of the GEOio table is still supported but has been deprecated in favour of using the GEOio.json format (Binding Command Line Geometry Converters).

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)
{
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)