Skip to content

PackBits Compression

Michael R Sweet edited this page Mar 21, 2025 · 4 revisions

LPrint provides a pair of functions that implement the classic PackBits compression algorithm as defined in many places, including at https://en.wikipedia.org/wiki/PackBits:

Sources:

  • "lprint-common.c": PackBits code
  • "lprint.h": API definitions

API

lprintPackBitsAlloc

unsigned char *       // O - Pointer to compression buffer
lprintPackBitsAlloc(
    size_t len)       // I - Size of input buffer

Allocate a PackBits compression buffer. Free the returned pointer with free()...

lprintPackBitsCompress

size_t                         // O - Number of compressed bytes
lprintPackBitsCompress(
    unsigned char       *dst,  // I - Destination buffer
    const unsigned char *src,  // I - Source buffer
    size_t              len)   // I - Number of source bytes (at least 3)

PackBits compress some bytes to the destination buffer.

The destination should be allocated wth lprintPackBitsAlloc().

Clone this wiki locally