00001 
00002 # ifndef Conjecture_Image_h
00003 # define Conjecture_Image_h Conjecture_Image_h
00004 
00005 
00006 
00007 
00008 
00009 # include <string>         
00010 # include "Coord.h"        
00011 # include "ImageArgs.h"    
00012 # include "Page.h"         
00013 
00014 
00015 # include "pnm.h"    
00016 
00017 namespace Conjecture {
00050     class Image : public Root {
00051         
00052       public:
00053         Image(const std::string& file, bool verbose = false);
00054         
00055         
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065         Image(const Image* src, const Coord& topleft, const Coord& bottomright, const ImageArgs& config);
00066         
00067         
00068 
00069 
00070 
00071 
00072 
00073 
00074         ~Image();
00075         
00076         
00077 
00078 
00079 
00080         inline u1 get(u2 x, u2 y) const        { return this->_data->p[this->index(x,y)]; }
00081         inline u1 get(const Coord& pos) const  { return this->_data->p[this->index(pos.x,pos.y)]; }
00082         
00083         inline void set(u2 x, u2 y, int val)        { this->_data->p[this->index(x,y)] = val; }
00084         inline void set(const Coord& pos, int val)  { this->_data->p[this->index(pos.x,pos.y)] = val; }
00085         
00086         
00087         bool writeMono(const std::string& filebase, bool verbose = false) const;
00088         bool writeGrey(const std::string& filebase, bool verbose = false) const;
00089         bool writeColor(const std::string& filebase, bool verbose = false) const;
00090         
00091         
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103         int  bytesPerPixel() const { return this->_data->bpp; }
00104         
00105         
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114         static void test(int argc = 0, const char* argv[] = NULL);
00115         
00120         Coord size() const { return Coord(this->data()->x, this->data()->y); }
00121         
00126         uint16_t width() const { return this->size().x; }
00127         
00132         uint16_t height() const { return this->size().y; }
00133         
00134         
00135 
00136         
00137         inline const pix* data() const { return this->_data; }
00138         
00139       protected:
00140         
00141         inline void dataIs(pix* data) { this->_data = data; }
00142         
00143         
00144         
00149         inline int index(u2 x, u2 y) const { return x + y*this->_data->x; }
00150         
00151       private: 
00152         
00153         
00154         
00155         inline pix*          dataRef() { return this->_data; }
00156         
00157         
00158         
00159         
00160         
00161         pix*           _data;
00162     };
00163 };
00164 
00165 # endif // Conjecture_Image_h
00166