Question

I am trying to read an image from memory by using boost::gil present in boost 1.53. I have taken the following lines from an example taken from internet:

#include <boost/gil/gil_all.hpp>
boost::gil::rgb8_image_t img;
boost::gil::image_read_settings<jpeg_tag> readSettings;
boost::gil::read_image(mystream, img, readSettings);

Except the first line, the type and function in the remaining lines cannot be found in the boost::gil namespace, so I cannot test if the above lines do what I want. Do you have any idea where to get the required types and functions?

Was it helpful?

Solution

See the new version of gil here: gil stable version

It works well and it is stable.

using namespace boost::gil;
image_read_settings<jpeg_tag> readSettings;
rgb8_image_t newImage;
read_image(stream, newImage, readSettings);

You code seems correct.

OTHER TIPS

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top