JCALG1 – Compression Library

Open-Source Compression Library

JCALG1

A small, lossless compression library loosely based on LZSS and written entirely in 32-bit x86 assembly. It compresses very well, though slowly, and decompresses as fast as any other LZ77 derivative.

A legacy project, first released in 1999. The download includes the library and its x86 assembly source.

Version
r5.34
License
MIT
Written in
32-bit x86 assembly
Author
Jeremy Collake
Credits
Joergen Ibsen, the author of apLib, was instrumental in the algorithm’s development; much of the encoding is similar to apLib’s.

Features

Small, Strong and Simple

Strong Compression

A good compression ratio, typically much better than ZIP’s deflate.

Tiny, Fast Decompressor

An extremely small and fast decompressor that needs no memory beyond the output buffer.

High-Entropy Data

A unique ability to handle data that is already compressed or otherwise high in entropy.

Adjustable Window

Choose a smaller window for faster compression, at the cost of compression ratio.

Easy to Integrate

A handful of STDCALL functions that fit into any application.

Free

Open source under the MIT license.

Results

Canterbury Corpus

Compression results with a 128 KB window (c7).

FileOriginal SizeCompressed SizeBits Per Byte
bib111,26136,5942.63
book1768,771335,3103.49
book2610,856213,4022.79
geo102,40071,0225.55
news377,109142,9783.03
obj121,5049,9823.71
obj2246,81477,7222.52
paper153,16120,0143.01
paper282,19932,5343.17
pic513,21658,3380.91
progc39,61114,1942.87
progl71,64617,1741.92
progp49,37911,6741.89
trans93,69519,4861.66
Total3,141,6221,060,4242.80 (2.70 weighted)

Documentation

API Reference

All functions use the STDCALL calling convention: Parameters are pushed onto the stack, and the called function adjusts the stack pointer before returning.

DWORD JCALG1_Compress(
    void         *Source,
    DWORD         Length,
    void         *Destination,
    DWORD         WindowSize,
    AllocFunc    *pAlloc,
    DeAllocFunc  *pDealloc,
    CallbackFunc *pCallback,
    BOOLEAN       bDisableChecksum);
  • Source: The uncompressed data.
  • Length: The size of the uncompressed data.
  • Destination: The buffer for the compressed data. It should be at least 4 bytes larger than the uncompressed data; JCALG1_GetNeededBufferSize returns the minimum size.
  • WindowSize: A nonzero value up to the size of the file. The larger it is, the better the compression ratio, but the slower the compression.
  • pAlloc, pDealloc: Memory allocation and deallocation functions (prototypes below).
  • pCallback: Called on every iteration of the main compression loop (prototype below).
  • bDisableChecksum: If TRUE, no checksum is computed or stored.

Returns: The size of the compressed data, or 0 if the data could not be compressed.

DWORD JCALG1_Decompress_Fast(void *Source, void *Destination);
DWORD JCALG1_Decompress_Small(void *Source, void *Destination);
  • Source: The compressed data.
  • Destination: The buffer for the uncompressed data.

Returns: The size of the uncompressed data, or 0 if the block is not a valid JCALG1 stream (it failed the header or checksum tests). The Small version is optimized for size, the Fast version for speed.

DWORD JCALG1_GetUncompressedSizeOfCompressedBlock(void *pBlock);
  • pBlock: A JCALG1 compressed block.

Returns: The size of the uncompressed block, in bytes.

DWORD JCALG1_GetNeededBufferSize(DWORD nSize);
  • nSize: The size, in bytes, of a block of uncompressed data.

Returns: The minimum destination buffer size (currently nSize + 4).

void JCALG1_GetInfo(_JCALG1_Info *JCALG1_Info);

typedef struct __JCALG1_Info {
    DWORD MajorRev;
    DWORD MinorRev;
    DWORD FastDecompressorSize;
    DWORD SmallDecompressorSize;
} _JCALG1_Info;
  • JCALG1_Info: A _JCALG1_Info structure to fill in.
BOOL CallbackFunc(DWORD pCurrentSrc, DWORD pCurrentDest);
  • pCurrentSrc: The offset of the current position in the uncompressed data.
  • pCurrentDest: The offset of the current position in the compressed data.

Returns: FALSE to stop compression, TRUE to continue.

void *AllocFunc(DWORD Size);
  • Size: The number of bytes requested.

Returns: A pointer to the allocated memory block.

BOOL DeallocFunc(void *pMemory);
  • pMemory: The memory block to free.

Returns: FALSE on failure.


Discover more from Bitsum

Subscribe to get the latest posts sent to your email.

Bitsum Technologies

Independent Windows software since 2002. We build novel solutions to software performance and automation challenges.