AlternativeUniversity.net
Alternative University

Computer Science

Raster Image Storage

Higher Precision Extended Range

XRH File Format 3.0

Channels (Image Planes)

The rest of an XRH file, following the Channel Names block, is pixel data stored as image planes (channels). All image planes are the same width and height (have the same number of scanlines and the same number of samples per scanline).

Subsampling of channels is not supported. Instead of subsampling channels, applying different compression rates (or different types of compression) for different channels is supported.

All samples in a channel use the same compression, but different channels can each have a different compression type or rate.

Each channel is stored as a block of bytes, referred to as a Channel Block. Channel Blocks are stored one after the other, to the end of the file.


Figure 1:  XRH 3.0 file with three Channel Blocks: the first Channel Block storing red intensity values (samples), the second Channel Block storing green samples, and the third Channel Block storing blue samples.

Each Channel Block begins with a 4-byte start-of-channel-block marker,

followed with a 64-bit Size integer,

followed with a 32-bit Channel Number integer,

followed with a 32-bit integer that stores the Image Width (must be same as the file header Image Width),

followed with a 32-bit integer that stores the Image Height (same as the file header Image Height),

followed with a 32-bit Sample Type and Stride integer,

followed with 20 bytes that are reserved for future use and must store zero,

followed with a 64-bit Compression Type integer,

followed with a 64-bit Size of Data,

followed with the Data (samples) for that channel,

followed with a 4-byte end-of-channel-block marker,

which is followed with the next Channel Block if there is a next Channel Block.


Figure 2:  Channel Block (image plane) of an XRH 3.0 file. The Data (Samples of the channel) are yellow in this diagram. The byte offset (number of bytes) from the beginning of the Channel Block to the beginning of the Data (Samples) is 64 bytes.

The first four bytes of a Channel Block store the value 0x53434200 (ASCII string SCB\0) which marks the start-of-channel-block.

Start of Channel Block Marker:  SCB\0


The next 8 bytes of a Channel Block are a Size integer that specifies the total size (number of bytes) of the entire Channel Block including the Size integer and the start and end markers. The entire block may be skipped by offsetting that many bytes from the beginning of the Channel Block (to the next Channel Block).

Note that the Size integer of a Channel Block is 8 bytes, not 4 bytes. It is a 64-bit integer. And keep in mind that all multi-byte numbers, including this Size integer, are stored in Big Endian format (network byte order).


Immediately after the Size integer, the next 4 bytes store an integer that specifies the Channel Number of this channel in the XRH file.  Channel Numbers are sequential, 1-based:  The first channel stored in the file is Channel Number 1, the next channel stored in the file is Channel Number 2, etc.


Following the Channel Number, the next 4 bytes store the Image Width, and the next 4 bytes after that store the Image Height, which must be the same as the file header Image Width and Height respectively.


Following the Image Height, the next 4 bytes store the Sample Type and Stride, which is an integer that specifies the type of number of each channel sample, and number of bytes (stride) of each channel sample. The Sample Type is stored in the upper 16 bits (upper 2 bytes), and the Sample Stride is stored in the lower 16 bits.

Sample Type is one (1) for floating point, or two (2) for unsigned integer:

Floating Point Type = 1
Unsigned Integer Type = 2

Sample Stride is 1 through 8 for unsigned integer (Sample Type 2).

For floating point (Sample Type 1), Sample Stride is 4 for 32-bit floating point, or 8 for 64-bit floating point.


After the Sample Type and Stride, the next 20 bytes are reserved for future use and must store zero in all 20 bytes.


Following the 20 Reserved Bytes, the next 8 bytes is an unsigned 64-bit integer that specifies the Compression Type of the Channel Block, which must be one of the following values:


Zebra  : 
SZMOD  : 
 0x 5A4252 00030000
 0x 535A4D 00030000
Channel Compression Type
(unsigned 64-bit integer)

Other Compression Type numbers are reserved for compression methods that are not yet supported. (Technical Note: To specify a private custom compression method, for your own applications only, set the high order bit. This official file format will never set the high order bit).

If the Compression Type integer is 0x5A425200030000 (Zebra), the Data of the Channel Block consists of a lossless Zebra Compression Stream. That will be discussed in the Zebra Compression page.

If the Compression Type integer is 0x535A4D00030000 (SZMOD), the Data of the Channel Block is a lossy SZMod Compression Stream. That will be discussed in the SZMOD page.


The next 8 bytes after the Compression Type is an unsigned 64-bit integer that specifies the size of the Data which immediately follows.


Immediately after the Data (after the compressed data stream), the last 4 bytes of the Channel Block store 0x45434200 (ASCII string ECB\0) as the end-of-channel-block marker.

End of Channel Block Marker:  ECB\0


Default Value

If the samples of a color channel are all the same value, that value may be stored instead of a compression code stream. We refer to that value as the Default Value of the channel. In that case, store the Sample Stride (without Sample Type) in the Data Size, and store the Default Value in place of the data compression stream.

For example, say the Sample Type and Stride is 0x10004, which is Float32, and all the samples of the channel are 1.0f. After the Compression Type (which will not actually be used), store 4 as the Data Size, then store 1.0f as the Data (instead of storing a compression stream as the Data), after which the end-of-channel-block value is stored.


Technical Notes

Colors are linear. Color channel samples are not usually premultiplied with alpha.


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