Libjpeg-turbo

About

Libjpeg-turbo is a library that provides support for the JPEG image format. It is widely used in various applications, including image processing, image compression, and image decompression. For more information, visit the official Libjpeg-turbo website.

Note

On Discoverer we use libjpeg-turbo as main productive JPEG image format provider for CPU-based applications.

Supported versions

In case your applications requite the use of another JPEG image format provider, you can install it by yourself, but those builds will not be supported by the Discoverer HPC team.

To check which Libjpeg-turbo versions and build types are currently supported on Discoverer, execute on the login node:

module avail libjpeg-turbo

Loading

If you need to access the latest version of the Libjpeg-turbo library, load the module without specifying the version:

module load libjpeg-turbo

In case you need to access a specific version of the Libjpeg-turbo library, you can specify the version:

module load libjpeg-turbo/<version>

General notes on using floating point data

The floating point (fp) model, which is supported by the major compiler collections, regulates both the optimizations on floating-point data and the level of accuracy. Our libjpeg-turbo installations support the strict floating-point model, which means that our libjpeg-turbo builds passed the floating-point tests for comparison that are included in the programming code distribution.

Utilities

We provide highly productive cjpeg, djpeg, jpegtran, rdjpgcom, tjbench, and wrjpgcom utilities that are linked to the optimized libjpeg-turbo versions installed in our software repository. If it is necessary to rely on those optimized tools, first load the appropriate libjpeg-turbo environment modules, as previously mentioned, and then execute the executables under their respective names.

Warning

When large image sets should be processed, use the Slurm batch job to execute the utilities.

Build recipes and tests

We use the recent LLVM Compiler Infrastructure to build the Libjpeg-turbo library code. We do not support any other compilers for that purpose. The LLVM.org compilers are the default compilers on Discoverer Petascale Supercomputer. Since the code of the library does not include Fortran, the compiled binaries are not Fortran-compatible and can be used with any other compiler collection. That means our build of libjpeg-turbo is optimised for producing the fastest possible binaries for CPU-based applications.

For those who are interested in the process of compiling and optimizing the code of Libjpeg-turbo we follow, there is public access to our build recipes at:

https://gitlab.discoverer.bg/vkolev/recipes/-/tree/main/libjpeg-turbo/

There are also logs that were collected during the compilation and testing processes.

Available libraries

libjpeg-turbo provides two distinct shared libraries that are installed by default:

libjpeg.so - Traditional libjpeg API

This library implements the industry-standard libjpeg API, compatible with libjpeg v6b/v7/v8. Most applications that require JPEG support will link against this library, as it is the de facto standard.

  • Header file: jpeglib.h
  • Link flag: -ljpeg
  • pkg-config: libjpeg
libturbojpeg.so - TurboJPEG API

This library provides a simplified API built on top of the same core. Applications specifically designed to use TurboJPEG will link against this library.

  • Header file: turbojpeg.h
  • Link flag: -lturbojpeg
  • pkg-config: libturbojpeg

Note

Both libraries use the identical SIMD-accelerated core implementation, so performance is equivalent. They can be used in the same application without conflicts due to different symbol namespaces.

Which library does your application need

In most cases, your application’s build system or documentation will specify which library it requires. Typically:

  • Most applications use libjpeg.so (the traditional libjpeg API)
  • Some newer applications or video processing tools may use libturbojpeg.so
  • Some applications may use both libraries

If you are unsure, check your application’s build configuration (Makefile, CMakeLists.txt, configure script) or documentation. The linking flags (-ljpeg or -lturbojpeg) will indicate which library is needed.

Library variants

Both libjpeg and libturbojpeg are available as static (.a) and shared (.so) libraries. The Environment Modules automatically configure the appropriate paths for dynamic linking, which is the recommended approach for HPC environments.

Shared Libraries (Recommended):
  • libjpeg.so and libturbojpeg.so are used by default
  • Automatically configured when loading the module
  • Recommended for HPC environments
Static Libraries:
  • libjpeg.a and libturbojpeg.a are also available
  • Use only if your application specifically requires static linking
  • Requires explicit -static flag during linking

Linking your application

After loading the libjpeg-turbo module, the environment variables are automatically configured. You can link your application using one of the following methods:

Method 1: Using environment variables (recommended)

# Load the module first
module load libjpeg-turbo

# Link against libjpeg (most common) - C code
gcc -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg
clang -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg

# Link against libjpeg - C++ code
g++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg
clang++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg

# Link against libturbojpeg - C code
gcc -o myapp myapp.c $CFLAGS $LDFLAGS -lturbojpeg
clang -o myapp myapp.c $CFLAGS $LDFLAGS -lturbojpeg

# Link against libturbojpeg - C++ code
g++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -lturbojpeg
clang++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -lturbojpeg

Method 2: Using pkg-config

# Load the module first
module load libjpeg-turbo

# Link against libjpeg - C code
gcc -o myapp myapp.c $(pkg-config --cflags --libs libjpeg)
clang -o myapp myapp.c $(pkg-config --cflags --libs libjpeg)

# Link against libjpeg - C++ code
g++ -o myapp myapp.cpp $(pkg-config --cflags --libs libjpeg)
clang++ -o myapp myapp.cpp $(pkg-config --cflags --libs libjpeg)

# Link against libturbojpeg - C code
gcc -o myapp myapp.c $(pkg-config --cflags --libs libturbojpeg)
clang -o myapp myapp.c $(pkg-config --cflags --libs libturbojpeg)

# Link against libturbojpeg - C++ code
g++ -o myapp myapp.cpp $(pkg-config --cflags --libs libturbojpeg)
clang++ -o myapp myapp.cpp $(pkg-config --cflags --libs libturbojpeg)

Method 3: Manual linking

# Load the module first
module load libjpeg-turbo

# Link against libjpeg - C code
gcc -o myapp myapp.c -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -ljpeg
clang -o myapp myapp.c -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -ljpeg

# Link against libjpeg - C++ code
g++ -o myapp myapp.cpp -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -ljpeg
clang++ -o myapp myapp.cpp -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -ljpeg

# Link against libturbojpeg - C code
gcc -o myapp myapp.c -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -lturbojpeg
clang -o myapp myapp.c -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -lturbojpeg

# Link against libturbojpeg - C++ code
g++ -o myapp myapp.cpp -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -lturbojpeg
clang++ -o myapp myapp.cpp -I$JPEG_ROOT/include -L$JPEG_ROOT/lib64 -lturbojpeg

Linking against both libraries:

If your application requires both libraries:

# C code
gcc -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg -lturbojpeg
clang -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg -lturbojpeg

# C++ code
g++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg -lturbojpeg
clang++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg -lturbojpeg

Static linking (if required):

If your application specifically requires static linking:

# C code
gcc -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg -static
clang -o myapp myapp.c $CFLAGS $LDFLAGS -ljpeg -static

# C++ code
g++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg -static
clang++ -o myapp myapp.cpp $CXXFLAGS $LDFLAGS -ljpeg -static

Note

The Environment Modules automatically set CFLAGS, CXXFLAGS, and LDFLAGS when you load the module. Using these variables is the recommended approach as they remain correct even if the module path changes.

Getting help

See Getting help