PackBits
| (5 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
{{FormatInfo  | {{FormatInfo  | ||
|formattype=electronic  | |formattype=electronic  | ||
| − | |subcat=  | + | |subcat=Compression  | 
}}  | }}  | ||
'''PackBits''' (or '''Apple Macintosh PackBits''', or '''Macintosh RLE''') is a form of [[run-length encoding]] often used to compress image data.  | '''PackBits''' (or '''Apple Macintosh PackBits''', or '''Macintosh RLE''') is a form of [[run-length encoding]] often used to compress image data.  | ||
| − | + | == Format details ==  | |
| + | The compressed data stream consists of a code byte, followed by zero or more data bytes, followed by another code byte, and so on.  | ||
| + | |||
| + | {| class="wikitable"  | ||
| + | ! Code byte (N)  | ||
| + | ! Instructions  | ||
| + | |-  | ||
| + | |0 ≤ N ≤ 127   || Interpret the next N+1 bytes literally.  | ||
| + | |-  | ||
| + | |N = 128       || Reserved  | ||
| + | |-  | ||
| + | |129 ≤ N ≤ 255 || Repeat the next byte 257−N times.  | ||
| + | |}  | ||
| + | |||
| + | For whatever reason, PackBits is usually described in terms of ''[[signed char|signed bytes]]'', which leads to the equivalent definition:  | ||
| + | |||
| + | {| class="wikitable"  | ||
| + | |N = −128      || Reserved  | ||
| + | |-  | ||
| + | |−127 ≤ N ≤ −1 || Repeat the next byte 1−N times.  | ||
| + | |-  | ||
| + | |0 ≤ N ≤ 127   || Interpret the next N+1 bytes literally.  | ||
| + | |}  | ||
| + | |||
| + | The reserved code byte (128 or −128) should be ignored, unless a format specification says otherwise. A few formats use it to mark the end of the compressed data.  | ||
| + | |||
| + | == Variants ==  | ||
| + | PackBits compresses a sequence of bytes, but variants exist in which a unit of decompressed data is more than one byte (e.g. some [[PICT]], [[Palm bitmap]], and [[IFF-DEEP]] compression schemes), or even less than one byte (e.g. [[GlowIcons]]).  | ||
== Related formats ==  | == Related formats ==  | ||
| − | Formats that may use PackBits compression include [[MacPaint]], [[TIFF]], [[ILBM]], and [[  | + | Formats that may use PackBits compression include [[MacPaint]], [[PICT]], [[TIFF]], [[ILBM]], and [[DEGAS image|DEGAS]].  | 
== Specifications ==  | == Specifications ==  | ||
* [http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf TIFF 6.0 Specification], Section 9: PackBits Compression  | * [http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf TIFF 6.0 Specification], Section 9: PackBits Compression  | ||
* [http://web.archive.org/web/20080705155158/http://developer.apple.com/technotes/tn/tn1023.html Technical Note TN1023]: Understanding PackBits  | * [http://web.archive.org/web/20080705155158/http://developer.apple.com/technotes/tn/tn1023.html Technical Note TN1023]: Understanding PackBits  | ||
| + | * {{AtariForumWiki|PackBits_Compression_Algorithm|AtariForumWiki: PackBits Compression Algorithm}}  | ||
== Resources ==  | == Resources ==  | ||
* [[Wikipedia:PackBits|Wikipedia article]]  | * [[Wikipedia:PackBits|Wikipedia article]]  | ||
| − | [[Category:  | + | [[Category:Graphics]]  | 
[[Category:Macintosh]]  | [[Category:Macintosh]]  | ||
Latest revision as of 17:40, 23 June 2024
PackBits (or Apple Macintosh PackBits, or Macintosh RLE) is a form of run-length encoding often used to compress image data.
Contents | 
[edit] Format details
The compressed data stream consists of a code byte, followed by zero or more data bytes, followed by another code byte, and so on.
| Code byte (N) | Instructions | 
|---|---|
| 0 ≤ N ≤ 127 | Interpret the next N+1 bytes literally. | 
| N = 128 | Reserved | 
| 129 ≤ N ≤ 255 | Repeat the next byte 257−N times. | 
For whatever reason, PackBits is usually described in terms of signed bytes, which leads to the equivalent definition:
| N = −128 | Reserved | 
| −127 ≤ N ≤ −1 | Repeat the next byte 1−N times. | 
| 0 ≤ N ≤ 127 | Interpret the next N+1 bytes literally. | 
The reserved code byte (128 or −128) should be ignored, unless a format specification says otherwise. A few formats use it to mark the end of the compressed data.
[edit] Variants
PackBits compresses a sequence of bytes, but variants exist in which a unit of decompressed data is more than one byte (e.g. some PICT, Palm bitmap, and IFF-DEEP compression schemes), or even less than one byte (e.g. GlowIcons).
[edit] Related formats
Formats that may use PackBits compression include MacPaint, PICT, TIFF, ILBM, and DEGAS.
[edit] Specifications
- TIFF 6.0 Specification, Section 9: PackBits Compression
 - Technical Note TN1023: Understanding PackBits
 - AtariForumWiki: PackBits Compression Algorithm