SEGGER emCompress-PRO

The allround compression solution

emCompress-PRO provides compression and decompression in any host application or embedded firmware, perfectly fitting most common use cases.

emCompress-PRO is a versatile compression library for most common use cases. It provides standard compression codecs and a zlib-like API for compression and decompression of input streams.

emCompress-PRO includes all compression and decompression codecs in source code, which enables usage in any host application and in any embe­dded firmware. In addition to the codecs, emCompress-PRO includes example application code for archive handling.

Codecs & performance values

emCompress-PRO includes well-defined, commonly used compression codecs. All codecs are implemented according to their specification or RFC, which enables interoperability with other tools and libraries.

DEFLATE

DEFLATE is the lossless compression stream format originally developed for and with the ZIP file format. It uses a combination of LZ77 and Huffman coding. DEFLATE is specified in RFC 1951.

CodecCompressed size [1]Compression speed [2]Decompression speed [2]Compression RAMDecompression RAM
DEFLATE(128,3,258)133.531 KB23611140.934 KB12.672 KB
DEFLATE(256,3,258)128.562 KB26110741.559 KB12.855 KB
DEFLATE(512,3,258)121.521 KB29610042.809 KB13.184 KB
DEFLATE(1k,3,258)116.601 KB3759645.309 KB13.738 KB
DEFLATE(2k,3,258)114.010 KB5049450.309 KB14.785 KB
DEFLATE(4k,3,258)112.430 KB7429260.309 KB16.832 KB
DEFLATE(8k,3,258)111.637 KB1,0789180.309 KB20.879 KB
DEFLATE(12k,3,258)111.396 KB1,76892100.309 KB24.902 KB
DEFLATE(16k,3,258)111.310 KB1,45991120.309 KB28.926 KB
DEFLATE(32k,3,258)111.313 KB1,01190200.309 KB44.969 KB


LZMA

LZMA (Lempel–Ziv–Markov chain algorithm) is the lossless compression algorithm which was first used in the 7z file format. This algorithm uses a dictionary compression scheme similar to the LZ77 algorithm and features a high compression ratio and a variable compression-dictionary size, while still maintaining decompression speed similar to other commonly used compression algorithms.

 

CodecCompressed size [1]Compression speed [2]Decompression speed [2]Compression RAMDecompression RAM
LZMA(1k,0,0,0)108.676 KB282876.010 MB5,060 B
LZMA(1k,3,1,1)103.675 KB289916.010 MB27.613 KB
LZMA(2k,0,0,0)106.270 KB363916.015 MB6,084 B
LZMA(2k,3,1,1)101.701 KB378936.015 MB28.613 KB
LZMA(4k,0,0,0)104.640 KB582856.025 MB8,132 B
LZMA(4k,3,1,1)100.450 KB593906.025 MB30.613 KB
LZMA(8k,0,0,0)103.592 KB980876.044 MB11.941 KB
LZMA(8k,3,1,1)99.742 KB992876.044 MB34.613 KB
LZMA(16k,0,0,0)102.706 KB1,821826.083 MB19.941 KB
LZMA(16k,3,1,1)99.198 KB1,785856.083 MB42.613 KB
LZMA(32k,0,0,0)102.059 KB2,389976.162 MB35.941 KB
LZMA(32k,3,1,1)98.808 KB2,550866.162 MB58.613 KB
LZMA(64k,0,0,0)100.030 KB4,182896.318 MB67.941 KB
LZMA(64k,3,1,1)97.180 KB4,274836.318 MB90.613 KB
LZMA(128k,0,0,0)99.840 KB5,081856.630 MB131.941 KB
LZMA(128k,3,1,1)97.067 KB5,026866.630 MB154.613 KB
LZMA(256k,0,0,0)99.851 KB3,001837.255 MB259.941 KB
LZMA(256k,3,1,1)97.080 KB3,212877.255 MB282.613 KB


LZJU90

LZJU90 defines the transfer encoding for MIME compliant mail systems. It uses prefix coding of a length and distance that leaves literals uncompressed.

 

CodecCompressed size [1]Compression speed [2]Decompression speed [2]Compression RAMDecompression RAM
LZJU(1535,2,255,9,1,10)121.459 KB363569.898 KB1,616 B
LZJU(1535,3,256,9,1,10)127.421 KB291489.906 KB1,616 B
LZJU(3583,2,255,9,1,11)117.644 KB6845419.898 KB3,664 B
LZJU(3583,3,256,9,1,11)122.245 KB5394819.906 KB3,664 B
LZJU(7679,2,255,9,1,12)116.253 KB1,1395439.898 KB7,760 B
LZJU(7679,3,256,9,1,12)119.478 KB8784939.906 KB7,760 B
LZJU(10751,2,255,9,2,13)117.183 KB1,5685354.898 KB10.578 KB
LZJU(10751,3,256,9,2,13)119.294 KB1,2565054.906 KB10.578 KB
LZJU(15871,2,255,9,1,13)115.639 KB2,5215579.898 KB15.578 KB
LZJU(15871,3,256,9,1,13)117.665 KB1,6355079.906 KB15.578 KB
LZJU(32255,2,255,9,1,14)115.902 KB4,30855159.898 KB31.578 KB
LZJU(32255,3,256,9,1,14)116.756 KB2,48552159.906 KB31.578 KB
LZJU(43519,3,256,9,2,15)117.021 KB3,94449214.906 KB42.578 KB
LZJU(43519,2,255,9,2,15)116.456 KB5,33755214.898 KB42.578 KB
LZJU(65023,2,255,9,1,15)115.133 KB6,73658319.898 KB63.578 KB
LZJU(65023,3,256,9,1,15)114.745 KB5,34552319.906 KB63.578 KB


LZPJ

LZPJ is the "plain jane" implementation of LZ77.

 

CodecCompressed size [1]Compression speed [2]Decompression speed [2]Compression RAMDecompression RAM
LZPJ(127,3,18)159.831 KB230391,904 B184 B
LZPJ(255,3,18)151.369 KB302442,544 B312 B

[1]  Uncompressed input size: 182.695 KB

[2]  ns/Byte on Intel i7 @ 4.6GHz, only for comparison between codecs

API use

emCompress-PRO provides a simple zlib-like API, for incremental process of input. This interface enables the use of compression and decompression of data on the fly. It can be used to process data in chunks as they are received from a remote system instead of requiring that all data be available at once. It can also be used to process data and output chunks into a small buffer for further processing instead of requiring a large output buffer that can hold all of the  compressed or decompressed data at once. Chunk-wise input and output can be combined to ensure minimum memory buffer requirements.


Code example

 

/*********************************************************************
*
*       Decompress()
*
*  Function description
*    Decompress DEFLATE or LZMA blocks.
*
*  Parameters
*    pFile  - Pointer to input file.
*    pAPI   - Pointer to decompression API.
*    pParas - Pointer to decompression parameters.
*    Size   - Size of data to decompress.
*/
void Decompress(FILE* pFile, const CX_DECODE_API* pAPI, const CX_PARAS* pParas, int Size) {
  CX_DECODE_CONTEXT C;
  CX_STREAM         Stream;
  int               Status;
  U8                ByteIn;
  U8                ByteOut;
  //
  // Prepare decoder and stream.
  //
  Stream.AvailIn  = 0;
  Stream.AvailOut = 0;
  Status = CX_DECODE_Init(&C, pAPI, &_StaticAllocator, pParas);
  //
  for (;;) {
    //
    // Read next byte from input.
    //
    if (Stream.AvailIn == 0 && Size > 0) {
      fread(&ByteIn, 1, 1, pFile);
      Stream.pIn     = &ByteIn;
      Stream.AvailIn = 1;
      Size--;
    }
    //
    // Reset output buffer.
    //
    Stream.pOut     = &ByteOut;
    Stream.AvailOut = 1;
    //
    // Process stream.
    //
    Status = CX_DECODE_Process(&C, &Stream, Size == 0 ? CX_FLUSH_END : CX_FLUSH_NONE);
    if (Status < 0) {
      printf("Failed to decode: %s\n", CX_GetErrorText(Status));
      exit(100);
    }
    if (Status == 1) {
      break;
    }
  }
  //
  CX_DECODE_Exit(&C);
}


Use cases

emCompress-PRO is the allround solution for compression and decompression.

Speed up firmware updates

Modern products, in particular IoT devices, require the ability to update their firmware in the field. Most of these devices implement over-the-air (OTA) updates through their main communication channel. When a device is connected via WiFi, available bandwidth is not an issue, but other channels such as Bluetooth or Zigbee might have limited bandwidth. Also, updates via wired connections often have bandwidth restrictions, e.g. the popular CAN bus.

To speed up the update process, lossless compression of firmware images reduces the amount of data to be transferred to the device. emCompress-PRO enables firmware updates with compressed images. Its interface is suited to receive a compressed data stream and to decompress it on the fly for the update module, which processes the decompressed data afterward.

Learn more at:
https://casestudies.segger.com/size-matters-using-emcompress-to-accelerate-firmware-updates-via-can-bus/

Minimize the required memory footprint for asset storage

Most systems include digital assets for their user interface. Assets can be images, videos and fonts for a graphical user interface (GUI) on a display, sound files to be output on a speaker, web pages for a web or app interface, or any other static data. Storage space for static data, such as an external flash, can be limited. To fit more data into available memory, or even to design hardware with smaller memory, digital assets can be stored in compressed form.

emCompress-PRO enables on-demand decompression of data when it is needed. Data can be decompressed into small chunks so the entire asset doesn’t have to be held in memory before being deployed.

Process data provided by third-party compression tools

Connected devices might receive compressed data from external sources. When a device does not include its own software to manage such data, the system might need to be designed to process data created by third-party tools.

emCompress-PRO implements popular codecs, such as DEFLATE and LZMA, which provides compatibility with commonly used compression tools. A system receiving external data can select the decompressor on demand making it ready for most customer use cases.

Data is not always compressed  in a single block but may be packaged in an archive. While emCompress-PRO implements compression codecs, it also comes with sample code to handle and process common archive formats. An input archive stream can be decompressed into structured files when a file system like emFile is used.

Compress data on different kinds of targets

Most use cases require decompression on the target system. Compression of data can be done with off-the-shelf tools, such as the popular zip file archiver, or integrated in a tool or framework which also creates the data, such as a firmware update utility.

Besides data decompression emCompress-PRO provides compression functionality as well and is not limited to embedded targets. Both parts of the codecs are written in plain C and can be integrated in firmware images as well as host applications.

  • Compression and decompression of streams and files

  • Common codecs included: DEFLATE, LZMA, LZPJ, LZJU90

  • Easy-to-use zlib-like API

  • Source code for host and embedded applications

Tecnologix offers support which is directly handled by development team. Do not hesitate to get in touch with our experts.
Just ask here

Technical Support

Tecnologix offers support which is directly handled by development team. Do not hesitate to get in touch with our experts.

Just ask here