RepositoryC++DEGermany
stbrumme

stbrumme/toojpeg

A JPEG encoder in a single C++ file

154stars
32forks
4issues
5views

A JPEG encoder in a single C++ file

This is a mirror of my library hosted at https://create.stephan-brumme.com/toojpeg/

TooJpeg is a compact baseline JPEG/JFIF writer, written in C++11 (but looks like C for the most part).
Its interface has only one function: writeJpeg() - and that's it !

My library supports the most common JPEG output color spaces:

  • YCbCr444,
  • YCbCr420 (=2x2 downsampled) and
  • Y (grayscale)

Saving NASA's huge 21600x10800px blue marble image with quality=90 takes just 2.4 (YCbCr420) or 3.6 seconds (YCbCr444) on a standard x64 machine - faster than other small JPEG encoders.
The compiled library enlarges your binary by about 7kb (CLang x64) or 12kb (GCC x64) in -O3 mode.
Far more details can be found on the project homepage: https://create.stephan-brumme.com/toojpeg/

How to use

  1. create an image with any content you like, e.g. 1024x768, RGB (3 bytes per pixel)
   auto pixels = new unsigned char[1024*768*3];
  1. define a callback that receives the compressed data byte-by-byte
// for example, write to disk (could be anything else, too, such as network transfer, in-memory storage, etc.)
void myOutput(unsigned char oneByte) { fputc(oneByte, myFileHandle); }
  1. start JPEG compression
TooJpeg::writeJpeg(myOutput, mypixels, 1024, 768);
// actually there are some optional parameters, too
//bool ok = TooJpeg::writeJpeg(myOutput, pixels, width, height, isRGB, quality, downSample, comment);

Similar Projects

Discover other similar projects and AI models.

RepositoryC++
google/guetzli

Perceptual JPEG encoder

12.9k
Apr 22, 2023
RepositoryC++
kornelski/jpeg-compressor

Research JPEG encoder

196
Jun 9, 2018
RepositoryC
mozilla/mozjpeg

Improved JPEG encoder.

5.7k
Jun 23, 2025
RepositoryC
tjko/jpegoptim

jpegoptim - utility to optimize/compress JPEG files

1.8k
Nov 25, 2026
RepositoryTypeScript
a-r-d/PureJsImage

Low-memory, zero-dependency image codecs and processing in pure TypeScript for Node.js, browsers, and serverless runtimes. Bounded decode/resize pipelines plus deep TIFF, scientific raster, GeoTIFF, OME-TIFF, and whole-slide support.

43
Nov 23, 2026
RepositoryC++
tensorflow/tensorflow

An Open Source Machine Learning Framework for Everyone

201.9k
Dec 1, 2026
RepositoryMarkdown
codecrafters-io/build-your-own-x

Master programming by recreating your favorite technologies from scratch.

567.0k
Nov 19, 2026
Repository
sindresorhus/awesome

😎 Awesome lists about all kinds of interesting topics [NOTE: Pull requests are temporarily disabled until I have a chance to catch up with the existing ones]

546.4k
Sep 2, 2026
RepositoryPython
public-apis/public-apis

A collective list of free APIs

502.6k
Nov 30, 2026