Hemera Photo Objects

Great Stock Objects

Excellent source libraries of photographic stock images are sold by Hemera, under the product name Hemera Photo Objects. I recommend purchasing them at software stores or from online retailers, even if your platform is not supported by the Hemera software.

There are two volumes available currently. Each volume is an eight CD-ROM set, containing 50,000 photographic stock images. Each image is on the order of 600x600 pixels, clipped with an alpha channel mask to make compositing the objects into artwork projects very easy.

The box comes with eight CDROMs, a user guide, and a great full-color catalogue showing thumbnails for all of the 50,000 images in the volume. The catalogue is organized into clear categories such as "art" or "kitchen" or "sports", in several languages. Finding an image with the catalogue alone is (usually) sufficient, but some details may be hard to see in the small thumbnail size.

The software included gives a nice keyword-driven search to find just the right image for a given project. Browsing through the thumbnails is quick and easy, and a full-scale preview is available if the proper disc is loaded. The software then converts the image file from its highly compressed HPI format to any number of other formats, on the Windows clipboard or to one of several industry standard formats such as TIFF or PNG. For applications which cannot handle transparency, a solid background color can be chosen instead, and Hemera's exporter application will composite the object on that background color.

The HPI File Format

Hemera has stated a preference to not include the HPI file format in third-party applications. This is a shame, because interoperability opens new markets and firms up the file format as an industry standard.

However, a very simple examination of the HPI file format led to a clear and simple solution for people who would like to buy and use Hemera's product on other platforms.

Any HPI file consists of a fixed 32-byte header which resembles the header used in PNG (Portable Network Graphics) files. Following this header, the color image information is presented in JPEG format. Following the main image, the grayscale mask information is presented in PNG format. This achieves good (albeit lossy) compression on the image data, and excellent compression on the grayscale mask data which is usually dominated by pure white and pure black pixels.

Incidentally, the JNG format is quite similar in concept, using separate compression methods for color image and alpha channel data.

Typically, the PNG mask data can be found by its distinctive "\211 P N G" four byte magic number, and the JPEG image data can be assumed to start immediately after the 32-byte HPI header information.

A more rigorous investigation of the 32-byte header reveals the following fields, which make working with HPI files even more predictable.

$ hexdump -C gnu.hpi | head -2
00000000  89 48 50 49 0d 0a 1a 0a  64 00 00 00 20 00 00 00  |.HPI....d... ...|
00000010  e8 f3 00 00 08 f4 00 00  25 42 00 00 00 00 00 00  |........%B......|

With this analysis, it becomes straightforward to extract any HPI image to a format that interoperates with existing software on those platforms which Hemera doesn't support, such as Linux or SGI IRIX or others.

Manual Conversions

The key to using HPI files on unsupported platforms is to extract the two data components, image and mask. Once extracted, most modern image processing programs can use the mask data as an alpha channel. Make a simple converter which does this job automatically. A very simple Perl script can separate the two data components.

This blurb of Perl will extract the two components. It uses a simple regular expression to find the PNG header, rather than parse the data in the header.

open(I, "$name") || die;
binmode(I);
$_ = <I>;
close(I);

($j, $p) = m|^.{32}(.*)(\211PNG.*)$|s;
open(J, ">$name.jpg") &&
    do { binmode(J); print J $j; close J; };
open(P, ">$name.png") &&
    do { binmode(P); print P $p; close P; };

To recombine the JPEG and PNG elements into another format, a graphics utility such as ImageMagick's tool suite is useful. The methods and command-line switches vary from version to version, but this blurb calls upon the ImageMagick command-line tools to do the job. Newer versions may be written with fewer steps.

convert $name.png -negate negated.$name.png
convert $name.jpg -type truecolormatte matted.$name.png
composite -compose copyopacity matted.$name.png matted.$name.png \
          negated.$name.png final.$name.png

This analysis is for interoperability purposes only. Honor all product licenses and pricing.
Contact Ed Halley by email at ed@halley.cc.
Text, code, layout and artwork are Copyright © 1996-2002 Ed Halley.
Copying in whole or in part, with author attribution, is expressly allowed.
Any references to trademarks are illustrative and are controlled by their respective owners.