Alternative University

Computer Science

Raster Image Storage

Higher Precision Extended Range

XRH File Format 2.0

Porcupine (PPN) Compression

If the Compression Type integer of a Channel Block is 0x50504E00020000 (Porcupine), a Porcupine (PPN) Compression Stream immediately follows the Compression Type integer, after which the end-of-channel-block marker follows the Porcupine Compression Stream.

Figure 1:  Channel Block of an XRH 2.0 file, with Compression Type set to 0x50504E00020000, stores a Porcupine Compression Stream as the Channel Block Data (yellow in this diagram).

Porcupine (PPN) is a simple lossless compression scheme for compressing bit masks (bit planes). A set of uncompressed bit planes is stored as an array of unsigned integers: the first sample of the first bit plane is the low order bit of the first integer, the first sample of the second bit plane is the second lowest order bit of the first integer, etc.

To compress the bit planes, they are demarcated (split off) from the integers (like marks on porcupine quills as transverse stripes), then each stripe is compressed with ZST.

Conceptually, this is like Zebra compression, except it is bit-level instead of byte-level: instead of 4 Byte Channels per 4 byte sample, there are up to 32 Bit Channels; and instead of 8 Byte Channels per 8 byte sample, there are up to 64 Bit Channels.

Sample Stride specifies the number of bytes of each unsigned integer (must be 4 or 8). The integers are filled from the lowest bit up, and do not have to be fully stored: an array of 32-bit integers can store up to 32 bit planes, but can store less then 32 bit planes; an array of 64-bit integers can store up to 64 bit planes, but can store less than 64 bit planes.

The Number of Bit Planes specifies how many bit planes are stored and compressed. Each bit plane is called a Bit Channel.


Porcupine Compression Stream

The Porcupine Compression Stream begins with a start-of-porcupine marker, followed with a 64-bit Size integer that stores the Size of the Porcupine (PPN) Compression Stream (including the start-of-porcupine marker and this Size integer), followed with a 64-bit Compression Type integer (0x50504E00020000), followed with a 32-bit integer that stores the Sample Stride (must equal the Channel Block Sample Stride), followed with a 32-bit integer that stores the Image Width (must equal the File Header Image Width), followed with a 32-bit integer that stores the Image Height (same as File Header Image Height), followed with a 32-bit integer that stores the Encoding Type (must be 1), followed with a 32-bit integer that stores the Number of Bit Planes, followed with Bit Channels (one Bit Channel per Bit Plane), followed with the end-of-porcupine marker that marks the end of the Porcupine stream.

Figure 2:  Porcupine Compression Stream as the Data of a Channel Block.

Note: The Porcupine 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 Porcupine Compression Stream store the value 0x53505000 (ASCII string SPP\0) which marks the start-of-porcupine.

Start of Porcupine Stream Marker:  SPP\0

The last 4 bytes of a Porcupine Compression Stream store the value 0x45505000 (ASCII string EPP\0) which marks the end-of-porcupine (the last 4 bytes of the Porcupine Compression Stream).

End of Porcupine Stream Marker:  EPP\0


Bit Channel

The bits of a Bit Channel are expanded to one bit per byte, and the byte sequence is then compressed using ZST o (a lossless compressor, also called “Zstandard”).

Bit Channels are stored sequentially, one after the other, beginning with the lowest order Bit Channel. The Number of Bit Planes specifies how many Bit Channels are stored.

Each Bit Channel consists of a start-of-bit-channel marker, followed with a 64-bit integer that specifies the size of the ZST code stream that stores the bits, followed with that ZST code stream (which was generated by ZST), followed with an end-of-bit-channel marker.

Figure 3:  Bit Channel.

The first four bytes of a Bit Channel store the value 0x53424300 (ASCII string SBC\0) which marks the start-of-bit-channel.

Start of Bit Channel Marker:  SBC\0

The last 4 bytes of a Bit Channel store the value 0x45424300 (ASCII string EBC\0) which marks the end-of-bit-channel.

End of Bit Channel Marker:  EBC\0

Default Value

If all of the bits of a Bit Channel are the same, then a Default Value (one byte) may be stored that specifies (in its lowest bit) the value of all the bits of the Bit Channel. In that case, zero is stored in Size of ZST Code Stream (see Figure 3 above) and the single-byte Default Value is stored in place of the ZST Code Stream (immediately after the Size of ZST Code Stream, without storing a ZST Code Stream), after which the end-of-bit-channel marker immediately follows the single-byte Default Value.


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

Return to Computer Science

Return to Alternative University

Copyright © 2021 Arc Math Software, All rights reserved
Arc Math Software, P.O. Box 221190, Sacramento CA 95822 USA   Contact
2021–Jan–27  14:08  UTC