I tried to use the following code from Using Boost.GIL to convert an image into “raw” bytes to convert a png file into raw bits(which is later used by OpenGL),
Includes:
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_io.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
Inside function:
boost::gil::rgba8_image_t image;
png_read_and_convert_image(path, image);
unsigned char* data = new unsigned char[image.width() * image.height() *
boost::gil::num_channels<boost::gil::rgba8_pixel_t>()];
std::size_t i = 0;
auto lambda = [data, &i](boost::gil::rgba8_pixel_t p)
{
data[i] = boost::gil::at_c<0>(p); ++i;
data[i] = boost::gil::at_c<1>(p); ++i;
data[i] = boost::gil::at_c<2>(p); ++i;
data[i] = boost::gil::at_c<3>(p); ++i;
};
boost::gil::for_each_pixel(image._view, std::function<void(boost::gil::rgba8_pixel_t)>(lambda));
where std::string path
is given. But this doesn't compile.(int_p_NULL
: undeclared identifier in png_io_private.hpp
). I have also tried replacing for_each_pixel
by the following
for (int x = 0; x < image.width(); ++x)
{
boost::gil::rgba8_view_t::y_iterator it = image._view.col_begin(x);
for (int y = 0; y < image.height(); ++y)
{
data[i] = boost::gil::at_c<0>(it[y]); ++i;
data[i] = boost::gil::at_c<1>(it[y]); ++i;
data[i] = boost::gil::at_c<2>(it[y]); ++i;
data[i] = boost::gil::at_c<3>(it[y]); ++i;
}
}
This code doesn't compile either and gives the same error. What should I do to read the .png image correctly?
Edit: @cv_and_he pointed out that lambdas don't work naturally with boost.gil. I have modified the first piece of code, and it now gives the same error as the second.