If the Compression Type integer of a Channel Block is 0x5A425200040000 (Zebra), the Channel Block Data is a Zebra Compression Stream, after which the end-of-channel-block marker follows the Zebra Compression Stream.
Zebra is a simple lossless compression scheme for compressing floating point or integer numbers. It consists of splitting up number samples into bytes, and storing the corresponding bytes of the different samples together: the most significant byte of all the samples are stored together, the next most significant byte of the samples are stored together, etc.
Each such group of bytes is called a Byte Channel.
If the samples are
Byte Channels are stored in Big Endian format: most significant Byte Channel first, next most significant Byte Channel next, etc.; the least significant byte of all the image channel samples are the last Byte Channel, the second least significant byte is the second-to-last Byte Channel, etc.
The Zebra Compression Stream begins with a
followed with a
followed with a 64-bit Compression Type integer (0x5A425200040000),
followed with a
followed with a
followed with a
followed with a 32-bit IEEE floating point number that stores the bias that is added to make all numbers of the channel non-negative (zero if no bias is needed or if the samples will not be STOR_U_FLOAT24 encoded),
followed with
followed with Byte Channels, one byte channel per byte of
Sample Width (which is defined in the lower 16 bits of Sample Definition),
e.g., 4 Byte Channels for
followed with the end-of-zebra marker (ASCII string EZB\0) that marks the end of the Zebra stream.
The Zebra Compression Stream is self-contained and may be used in any file format (not just in an XRH file).
The first four bytes of a Zebra Compression Stream
store the value 0x535A4200
(ASCII string
SZB\0)
which marks the
Start of Zebra Stream Marker: SZB\0
The last 4 bytes of a Zebra Compression Stream
store the value 0x455A4200 (ASCII string
EZB\0)
which marks the
End of Zebra Stream Marker: EZB\0
Sample Definition is a
Sample Type must be STOR_UINT, STOR_IEEE_FILT, or STOR_U_FLOAT24. See the Data Types page of this specification.
If Sample Type is STOR_UINT, then Sample Width must be multiples of 8, and Sample Padding must be either zero or the number of bits that causes sample stride to be multiples of 1, 4 or 8 bytes (stride is the number of bytes from the beginning of a sample to the beginning of the next sample).
If Sample Type is STOR_IEEE_FILT, then Sample Width must be 32 and Sample Padding must be zero.
If Sample Type is STOR_U_FLOAT24, then Sample Width must be 24 and Sample Padding must be 8.
The data bytes of a Byte Channel are compressed using ZST (a lossless compressor, also called Zstandard).
Each Byte Channel consists of a
followed with a 64-bit integer that specifies the size of the ZST code stream that stores the data bytes of the Byte Channel,
followed with that ZST code stream (the compressed data generated by ZST),
followed with an
The first four bytes of a Byte Channel
store the value 0x53424300
(ASCII string
SBC\0)
which marks the
Start of Byte Channel Marker: SBC\0
The last 4 bytes of a Byte Channel
store the value 0x45424300 (ASCII string
EBC\0)
which marks the
End of Byte Channel Marker: EBC\0
The ZST code stream of each Byte Channel is a compressed byte stream that when uncompressed provides the sample bytes of the Byte Channel in raster order.
For example, to reconstruct the 5th sample of a Channel Block: the 5th data byte of the first Byte Channel becomes the high order byte of the 5th sample of the Channel Block, the 5th data byte of the second Byte Channel becomes the next most significant byte of the 5th sample of the Channel Block, etc.
If all of the bytes of a Byte Channel are the same,
then a Default Value (one byte) may be stored
that specifies the value of all the bytes of the Byte Channel.
In that case,