Alternative University

Computer Science

Raster Image Storage

Higher Precision Extended Range

XRH File Format 3.0

File Layout

An XRH file stores a rectangular raster image of one or more channels. A channel is also called an image plane or component.

Each channel is stored as scanlines in raster order (top-down, left-to-right). All samples in a channel are of the same type and length. The type of each sample in a channel is either floating point (Sample Type 1) or unsigned integer (Sample Type 2).

The length of each sample in a channel, referred to as Sample Stride, is the number of bytes of each sample (how many bytes from the beginning of a sample to the beginning of the next sample). All samples of a channel have the same length (are the same Sample Stride).

Different channels can have different Sample Strides, but all the samples within a channel have the same Sample Stride.

If the samples of a channel are floating point (Sample Type 1), the Sample Stride can be 4 or 8 (for 32-bit or 64-bit floating point numbers respectively).

If the samples of a channel are unsigned integer (Sample Type 2), the Sample Stride must be at least 1 and not greater than 8. Any number of bytes within that range is allowed, and all samples in the channel are each that length.

Note: Zebra compression supports Sample Types 1 and 2; SZ compression only supports Sample Type 1.

Reminder: All multi-byte numbers in an XRH file are stored in Big Endian format (network byte order).

XRH files have a  “.xrh”  file name extension. Each file begins with a File Header, followed with Comments, followed with Custom Properties, followed with optional Channel Names, and followed with the Image Planes (channels of pixel samples) to the end of the file.

Figure 1:  XRH file layout.

File Header

The first 128 bytes of an XRH file are the file header:

Figure 2:  XRH file header.

File Signature

The first 16 bytes of an XRH file (beginning of the file header) is the following ASCII text string including the single quote marks and terminating null:


These first 16 bytes of an XRH file (bytes 0−15) are the bytes 0x27, 0x58, 0x52, 0x48, 0x27, 0x66, 0x69, 0x6C, 0x65, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x00 in that order.

File Version

The next four bytes of the file (bytes 16−19) store the file version number. The current version number is 0x00030000. Remember that this number, and all other multi-byte numbers in an XRH file, are stored in Big Endian format (network byte order).

Image Width and Height

The next four bytes (20−23) store the number of samples (pixels) per scanline (Image Width), followed with four bytes (bytes 24−27) that store the number of image scanlines (Image Height). Each channel has this many scanlines and this many samples per scanline.

Number of Channels

The next four bytes (28−31) specify the number of channels (image planes).


The next 16 bytes (32−47) specify an optional viewport. If these bytes are all zero (the default), then the viewport is the entire image. Otherwise 4 unsigned integers specify the minimum x, minimum y, x width and y height of the viewport in that order; x and y are measured left-to-right and top-down respectively.

A viewport is the intended final image. Having extra pixels outside of the viewport may be useful for image processing of intermediate images.


The next 64 bytes (48−111) specify optional chromaticites for ITU-R BT.709 color transformation, in case color transformation is performed. If these bytes are all zero (the default), then default chromaticites are used. Otherwise 8 Float64 numbers specify custom red X, red Y, green X, green Y, blue X, blue Y, white X and white Y chromaticities in that order.

Color Transformation Type

Following the Chromaticities, the next 4 bytes store the Color Transformation Type: Zero (0) if there is no built-in color transformation; or One (1) which specifies ITU-R BT.709. Future XRH versions may support other built-in color transformation types.

If Color Transformation Type is 1, Compression Type of color channels must be lossy. In that case, the first channel of the file is the Y Channel of a set of YCbCr channels, and the next two channels are the Cb and Cr channels respectively.

End of Header

The next 12 bytes (116−127) are the last 12 bytes of the file header and must store the ASCII text string  EndOfHeader\0  (including the terminating null character). This ASCII text string is stored without storing a count of how many characters it has (since it is fixed width and known to be 12 bytes including the terminating null character).

That marks the end of the header of a version 3.0 XRH file.

New Version Available

Newer XRH version recommended for new applications:

XRH version 4.0

< Previous: Introduction    
    Next Page: Comments >
XRH 3.0 File Format
Page 1 : 
Page 2 : 
Page 3 : 
Page 4 : 
Page 5 : 
Page 6 : 
Page 7 : 
Page 8 : 
Page 9 : 
Page 10 : 
File Layout & Header (this page)
Custom Properties
Channel Names
Zebra Compression
SZMOD Compression
Color Transformations
Sample Files