#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
#include <iostream>
#include <sstream>
#include <utilgil.hpp>
#include <utilstl.hpp>
using namespace boost::gil;
//GCC Build String
//g++ sample4.cpp -lpng -lz -I . -I ~/lib/boost -I ~/lib
//REMEMBER TO PASS IN THE PATH OF AN RGB8 PNG IMAGE
int main(int args, char** argv)
{
assert(args == 2);
char* path = argv[1];
boost::gil::rgb8_image_t img;
png_read_image(path,img);
std::stringstream red,green,blue;
for (int x = 0; x < view(img).width(); x++)
for (int y = 0; y < view(img).height(); y++)
{
red << (int)boost::gil::get_color(view(img)(x,y),boost::gil::red_t()) << ",";
blue << (int)boost::gil::get_color(view(img)(x,y),boost::gil::blue_t()) << ",";
green << (int)boost::gil::get_color(view(img)(x,y),boost::gil::green_t()) << ",";
}
std::cout << "int width = " << view(img).width() << ";\n";
std::cout << "int height = " << view(img).height() << ";\n";
std::cout << "unsigned char buffer[][" << "width*height" << "]={\n";
std::cout << "{" << red.str() << "}\n" << "{" << green.str() << "}\n" << "{" << blue.str() << "}\n};\n\n";
std::cout << "const boost::gil::rgb8c_planar_view_t view = \n";
std::cout << "\tboost::gil::planar_rgb_view(width,\n";
std::cout << "\theight,buffer[0],buffer[1],buffer[2],width);\n";
}
/*SAMPLE OUTPUT
int width = 9;
int height = 10;
unsigned char buffer[][width*height]={
{255,255,255,255,255,255,255,207,162,160,255,255,255,255,255,255,252,188,160,160,255,255,255,
255,255,255,239,176,160,160,255,255,255,255,255,255,224,170,160,160,255,255,255,255,255,
255,214,163,160,160,255,255,255,255,255,255,206,160,160,160,255,255,255,255,255,255,198,
160,160,160,255,255,255,255,255,255,192,160,160,160,255,255,255,255,255,254,183,160,160,160,}
{52,52,52,52,52,52,52,172,96,93,52,52,52,52,52,52,249,141,93,93,52,52,52,52,52,52,228,121,93,93,
52,52,52,52,52,52,203,110,93,93,52,52,52,52,52,52,185,99,93,93,52,52,52,52,52,52,171,94,93,93,
52,52,52,52,52,52,158,94,93,93,52,52,52,52,52,52,148,94,93,93,52,52,52,52,52,252,132,93,93,93,}
{52,52,52,52,52,52,52,172,96,93,52,52,52,52,52,52,249,141,93,93,52,52,52,52,52,52,228,121,93,93,52,
52,52,52,52,52,203,110,93,93,52,52,52,52,52,52,185,99,93,93,52,52,52,52,52,52,171,94,93,93,52,
52,52,52,52,52,158,94,93,93,52,52,52,52,52,52,148,94,93,93,52,52,52,52,52,252,132,93,93,93,}
};
const boost::gil::rgb8c_planar_view_t view =
boost::gil::planar_rgb_view(width,
height,buffer[0],buffer[1],buffer[2],width);
*/