// // libpng.hpp // AwesomeAttract0r // // Created by Joshua Moerman on 10/24/11. // Copyright 2011 Vadovas. All rights reserved. // #ifndef AwesomeAttract0r_libpng_hpp #define AwesomeAttract0r_libpng_hpp #ifndef __APPLE__ #include #else #warning PNG++ is not yet supported (will save as bmp) #include "bmp.hpp" namespace png { struct rgb_pixel{ char* data; char red, green, blue; rgb_pixel(char* d) : data(d) , red(0) , green(0) , blue(0) {} rgb_pixel(unsigned int r, unsigned int g, unsigned int b) : data(0) , red(r) , green(g) , blue(b) {} void operator=(rgb_pixel const & rh){ data[0] = rh.blue; data[1] = rh.green; data[2] = rh.red; } }; struct row{ char * data; row(char* d) : data(d) {} rgb_pixel operator[](unsigned int c){return rgb_pixel(data + c*3);} }; template struct image{ bmp::bitmap bitmap; char * data; unsigned int width; unsigned int height; image(unsigned int w, unsigned int h) : bitmap(w, h) , data(0) , width(w) , height(h) { data = new char[width*height*3]; bitmap.data = data; } ~image(){ delete[] data; } row operator[](unsigned int r){return row(data + r*height*3);} void write(std::string const & filename){ bitmap.write(filename); } private: image(image const &); image & operator=(image const &); }; } #endif #endif