2

I have configured my environment so that I can load a suitably crafted .png file into an image defined like this:

        boost::gil::rgb8_image_t input;

but how do I load a png file of any typical type (such as is generated by the GIMP, or MS Paint). I think it needs boost::gil::any_image but I don't know the types that I need to configure it with.

I've tried:

        typedef boost::mpl::vector<
            boost::mpl::rgba8_planar_image_t,
            boost::mpl::rgba8_image_t,
            boost::mpl::rgb8_planar_image_t,
            boost::mpl::rgb8_image_t,
            boost::mpl::gray8_image_t
        > my_img_types;
        boost::mpl::any_image<my_img_types> input;
        boost::gil::png_read_image(ipath, input);

but that doesn't load a file created by MS Paint or the GIMP.

codeshot
  • 1,183
  • 1
  • 9
  • 20
  • Apparently, MS Paint on Windows 7 when used to save a grayscale png after editing saves a file with PNG pixel type 4 which http://www.w3.org/TR/PNG-Chunks.html says means "Each pixel is a grayscale sample, followed by an alpha sample." But I can't see what image type to use from boost::gil - there is no graya8_image_t or graya8_planar_image_t. – codeshot Jul 01 '12 at 16:56

2 Answers2

5

Have you tried using the family of functions png_read_and_convert_*

For example:

boost::gil::rgb8_image_t input;
boost::gil::png_read_and_convert_image(ipath, input);

You will lose the original type of the image this way, but if you want a fixed type for your code to manipulate this might be a good way to go.

combinatorial
  • 9,132
  • 4
  • 40
  • 58
0

I think you should try GIL IO extension. Here link: https://www.boost.org/doc/libs/1_79_0/libs/gil/doc/html/io.html

minimal example:

    std::string filename( "image.tif" );
    rgb8_image_t img;
    read_image( filename, img, tiff_tag() );
leanid.chaika
  • 2,143
  • 2
  • 27
  • 30