2

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.

Community
  • 1
  • 1
Henricus V.
  • 898
  • 1
  • 8
  • 29
  • I have no idea if this will help, since I have no experience with the library, but I've noticed that all the answers linked use a view with `for_each_pixels` and you are using an image directly. Could you try `boost::gil::for_each_pixel(const_view(image),...` and see if it works? – llonesmiz Feb 09 '16 at 03:58
  • @cv_and_he Thanks, that solved some of the problem, but the compiler still says I am attempting to reference a deleted function. – Henricus V. Feb 09 '16 at 04:17
  • http://comments.gmane.org/gmane.comp.lang.c%2B%2B.isocpp.general/513 – llonesmiz Feb 09 '16 at 04:21

1 Answers1

2

int_p_NULL is defined in libpng-1.2.x/png.h; make sure you have included png.h directly or indirectly, and that you aren't using a newer version of libpng.

Glenn Randers-Pehrson
  • 11,940
  • 3
  • 37
  • 61
  • I basically followed the [Design guide](http://www.boost.org/doc/libs/develop/libs/gil/doc/html/gildesignguide.html) of boost::gil. Is there something wrong to use versions above 1.2? – Henricus V. Feb 09 '16 at 03:30
  • The boost:gil documentation that you mentioned says that you need to have png.h in your inlude path, but doesn't say anything about the required version. But the reference to int_p_NULL indicates that it needs 1.2.x. BTW that's not a function; it's just a synonym for NULL that exists in libpng-1.0.x and 1.2.x but removed from 1.4.0. – Glenn Randers-Pehrson Feb 09 '16 at 12:51