Boost 1.68, which is planned for release on 8th of August, 2018, will finally deliver the new Boost.GIL IO (aka IOv2) reviewed and accepted long time ago.
It is already available from the current master
branch of the Boost super-project (check Boost.GIL CONTRIBUTING.md for guidelines how to work with the super-project).
Now, you can use GIL from Boost 1.68 or later, here is example that shows how to read image from input stream. It does not have to be file-based stream, but any std::istream
-compatible stream should work.
#include <boost/gil.hpp>
#include <boost/gil/io/io.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <fstream>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "input jpeg file missing\n";
return EXIT_FAILURE;
}
try
{
std::ifstream stream(argv[1], std::ios::binary);
namespace bg = boost::gil;
bg::image_read_settings<bg::jpeg_tag> read_settings;
bg::rgb8_image_t image;
bg::read_image(stream, image, read_settings);
return EXIT_SUCCESS;
}
catch (std::exception const& e)
{
std::cerr << e.what() << std::endl;
}
return EXIT_FAILURE;
}