Clone wiki

pngxx / Home

pngxx and jpegxx

Welcome to the wiki for the pngxx and jpegxx libraries. They are presented in a single wiki because they share a common interface, except for some minor differences that are noted where necessary. However, please file any bugs you find in jpegxx in the jpegxx bug tracker.

What are these libraries?

jpegxx and pngxx are wrappers around the popular IJG JPEG and libpng libraries. They are written with portable ANSI/ISO C++, in a modern style.

The libraries allow you to read and write JPEG and PNG images from any source and to any sink. Sources and sinks are described through standard C++ iterators or streams.

How are they licensed?

The majority of the code in jpegxx and pngxx is licensed under the Boost Software License v1.0. The libraries incorporate modified versions of the IJG jpeg library and libpng/zlib respectively, which are licensed under their own custom licenses.

To cut a long story short (and in to a non-legally-binding form!), you can use the libraries in both commerical and open-source software provided you put the occasional copyright notice here or there.

A taster

Here's a quick example. To find out more, please follow the links below. The libraries are much more flexible than a couple of small snippets can show. Notably, the libraries allow you to easily read in to and write out from your own image classes directly, without any intermediate storage.

Loading an image

std::vector<unsigned char> raster;
imagexx::raster_details d = 
    pngxx::read_image("image.png", back_inserter(raster));

std::size_t width = d.width();
std::size_t height = d.height();
imagexx::pixel_format f = d.type();
double width_mm = d.width_mm(); // in millimeters
double height_mm = d.height_mm(); // in millimeters

// N.B. imagexx is a library containing 
// code common to pngxx and jpegxx.

Saving an image

imagexx::raster_details d(imagexx::rgba, width, height);
pngx::write_image(d, "image.png", raster.begin(), raster.end());

More information