JCALG1 r5.xx
(c)1999-2011 Jeremy Collake

This software is provided as-is, without warranty of ANY KIND, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The author shall NOT be held liable for ANY damage to you, your computer, or to anyone or anything else, that may result from its use, or misuse. Basically, you use it at YOUR OWN RISK.

This library may be used freely in non-commercial applications. Commercial applications require a VERY MODEST licensing fee. Please contact support@bitsum.com for licensing.

First of all, I would like to credit Joergen Ibsen, author of apLib, for many suggestions and help with my development of JCALG1. You may notice some similarities between the JCALG1 decompressor and that of apLib. The reason for this is because I could not come up with a better encoding scheme than Joergen Ibsen's. Therefore, I give him credit to developing much of the encoding scheme that JCALG1 uses.

JCALG1 is a small, open-source, LZSS derived compression library.

Canterbury Corpus compression results for JCALG1 with window size of 128Kb (c7):

File Original Size Compressed Size Bits Per Byte Weighted
bib 111,261 36594 2.63  
book1 768,771 335310 3.49  
book2 610,856 213402 2.79  
geo 102,400 71022 5.55  
news 377,109 142978 3.03  
obj1 21,504 9982 3.71  
obj2 246,814 77722 2.52  
paper1 53,161 20014 3.01  
paper2 82,199 32534 3.17  
pic 513,216 58338 0.91  
progc 39,611 14194 2.87  
progl 71,646 17174 1.92  
progp 49,379 11674 1.89  
trans 93,695 19486 1.66  
TOTAL: 3,141,622 1060424 2.80 2.70


This is where I tell you what you need to know, ever-so-briefly ;). I decided to document all functions in C, since most people are familar with it. All functions use the STDCALL calling convention (parameters pushed onto stack, called function adjusts stack before return).
DWORD JCALG1_Compress(
void *Source,
DWORD Length,
void *Destination,
DWORD WindowSize,
AllocFunc *pAlloc,
DeAllocFunc *pDealloc,
CallbackFunc *pCallback,
BOOLEAN bDisableChecksum);
Returns: Size of the compressed data, or NULL if the data could not be compressed. 

DWORD JCALG1_Decompress_Fast(
void *Source,
void *Destination);
DWORD JCALG1_Decompress_Small(
void *Source,
void *Destination);
Returns: Size of the uncompressed data or 0 if the block of data is not a valid JCALG1 compressed stream (failed header or checksum tests). As the function names attempt to infer, the 'small' version of this procedure is the one optimized for size while the 'fast' version is the one optimized for speed.

DWORD JCALG1_GetUncompressedSizeOfCompressedBlock(
void *pBlock)
Returns: Size of the uncompressed block, in bytes.


DWORD JCALG1_GetNeededBufferSize(
DWORD n Size);
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;

BOOL CallbackFunc(
DWORD pCurrentSrc,
DWORD pCurrentDest);
Return: FALSE to stop compression, TRUE to continue compression.


void *AllocFunc(
DWORD Size);
Returns: Pointer to allocated memory block.


BOOL DeallocFunc(
void *pMemory)
Returns: FALSE if failure.