JPEG libraries for C/C++
For C and C++ there are 3 good choices:
- libjpeg-turbo is the JPEG codec used by browsers, Linux distributions, Android, Pillow, OpenCV and most image programs. It’s the IJG libjpeg API with SIMD acceleration (2-6 times faster), plus the simpler TurboJPEG API that decodes or encodes a whole image in one call and does lossless transforms. Pick it by default.
- mozjpeg is a fork of libjpeg-turbo with the same API that produces 5-15% smaller files (trellis quantization, optimized progressive scans) at the cost of much slower encoding. Use it to compress images once for the web; decode with libjpeg-turbo.
- stb_image is a single public-domain header that decodes baseline and progressive JPEG (plus PNG, GIF, BMP and more);
stb_image_write.hwrites baseline JPEG. Good for games and tools that load trusted images; slower and with no metadata or Exif orientation support.
None of them parses Exif tags: libjpeg-turbo gives you the raw APP1 bytes. For tag-level access use libexif (LGPL), Exiv2 (GPL) or the single-file TinyEXIF (BSD-2).
- libjpeg-turbo libjpeg-turbo is the standard SIMD-accelerated JPEG codec for C and C++. How to decode and encode JPEG with the TurboJPEG 3 API, rotate losslessly.
- mozjpeg mozjpeg is Mozilla's JPEG encoder for C and C++ that makes 5-15% smaller files than libjpeg-turbo. How to install it, encode with trellis quantization.
- stb_image stb_image and stb_image_write are single-header, public-domain C libraries to decode and encode JPEG. How to add them to a project, load a JPEG, get its size.