/JPEG-LS

A light-weight JPEG-LS (ITU-T T.87) image encoder. 仅400行C语言的JPEG-LS图像编码器。

Primary LanguageCGNU General Public License v3.0GPL-3.0

language build build

JPEG-LS encoder

A simple JPEG-LS baseline (ITU-T T.87) image compressor (encoder) in C language.

Background of JPEG-LS

JPEG-LS (JLS) is a lossless/lossy image compression standard which has the best lossless compression ratio compared to PNG, Lossless-JPEG2000, Lossless-WEBP, etc.

The standard specification of JPEG-LS is ITU-T T.87 [1], see https://www.itu.int/rec/T-REC-T.87/en

JPEG-LS uses the maximum difference between the pixels before and after compression (NEAR value) to control distortion, NEAR=0 is the lossless mode; NEAR>0 is the lossy mode, the larger the NEAR, the greater the distortion and the greater the compression ratio.

The file suffix name for JPEG-LS compressed image is .jls .

Development progress

  • gray 8 bit image lossless/lossy encode
  • gray 9-16 bit image lossless/lossy encode
  • RGB 24 bit image lossless/lossy encode

Code list

The code is in pure-C. See src folder:

  • JLS.c : Implement a JLS encoder
  • JLS.h : Expose the JLS encoder function to users
  • JLSMain.c : A main program with main() function, which call the JLS encoder to achieve image file compression.

Compile

Compile in Windows (CMD)

If you installed MinGW Compiler for Windows, you can compile using the command line (CMD).

gcc src/*.c -o JLSencode.exe -O3

We'll get the executable file JLSencoder.exe . Here I've compiled it for you.

Compile in Linux

Run the command in the current directory:

gcc src/*.c -o JLSencode -O3

We'll get the binary file JLSencoder .

Run

Prepare uncompressed image files

This program can compress the following three types of image file to .jls compressed file.

For grayscale image file, BPP can be 8-bit, 9-bit, 10-bit, ..., 16-bit.

There are some example PGM and PPM files in testimage directory.

Run image compress in Windows (CMD)

Use the following command to compress a image file to a .jls file.

.\JLSencode.exe  <input-image-file>  <output-file(.jls)>  [near]

Where [near] is a optional parameter of range 0~9 :

  • 0 : lossless (default)
  • 1~9 : lossy. The larger the near value, the higher distortion and the lower compressed size.

For example, the following command to compress rgb1.ppm in testimage folder to rgb1.jls with near=1

.\JLSencode.exe  testimage\rgb888.ppm  rgb888.jls  1

Run image compress in Linux

Use the following command to compress a image file to a .jls file.

./JLSencode  <input-image-file>  <output-file(.jls)>  [near]

Appendix: How to decompress .jls file?

This repo do not offer a JPEG-LS decompressor. There are several ways to decompress a .jls file:

  • The most convenient method: Try this website to view .jls image online (but it may not work).
  • Use other JPEG-LS code or libraries such as UBC's JPEG-LS demo [3] or CharLS [4].
  • Use python pillow library and pillow_jpls library [5].

Reference

[1] ITU-T T.87 : JPEG-LS baseline specification : https://www.itu.int/rec/T-REC-T.87/en

[2] PNM Image File Specification : https://netpbm.sourceforge.net/doc/pnm.html

[3] UBC's JPEG-LS baseline Public Domain Code : http://www.stat.columbia.edu/~jakulin/jpeg-ls/mirror.htm

[4] CharLS, a C++ JPEG-LS library implementation : https://github.com/team-charls/charls

[5] pillow-jpls library for Python - PyPI : https://pypi.org/project/pillow-jpls

[6] FPGA-based Verilog JPEG-LS encoder (basic version which support 8-bit gray lossless and lossy) : https://github.com/WangXuan95/FPGA-JPEG-LS-encoder

[7] FPGA-based Verilog JPEG-LS encoder (ultra high performance version which support 8-bit gray lossless) : https://github.com/WangXuan95/UH-JLS