Image.h

00001 
00002 # ifndef Conjecture_Image_h
00003 # define Conjecture_Image_h Conjecture_Image_h
00004 
00005 // Insert SVN header substitution variable here
00006 // Class Champion: Unassigned
00007 
00008 // C++ Dependencies
00009 # include <string>         // uses
00010 # include "Coord.h"        // Coord, uint8_t
00011 # include "ImageArgs.h"    // ImageArgs
00012 # include "Page.h"         // needs friendship for special Image constructor
00013 
00014 // C Dependencies
00015 # include "pnm.h"    // struct pixmap
00016 
00017 namespace Conjecture {
00050     class Image : public Root {
00051         
00052       public:
00053         Image(const std::string& file, bool verbose = false);
00054         
00055         /*
00056          * Create a copy of a sub-region of another Image.
00057          *
00058          * 'topleft' and 'bottomright' identify the pixel boundaries of
00059          * the desired region, and are relative to <0,0> in the top left
00060          * corner of 'src'.
00061          *
00062          * See the documentation of ImageConfig for the 'config' parameter.
00063          *
00064          */
00065         Image(const Image* src, const Coord& topleft, const Coord& bottomright, const ImageArgs& config);
00066         
00067         /*
00068          * Destructor for Image instances.
00069          *
00070          * This destructor is critical, because images may be created and
00071          * destroyed often (and allocate nested space).
00072          *
00073          */
00074         ~Image();
00075         
00076         /*
00077          * Obtain the pixel value for position <x,y>
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         // Miscellaneous
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          * Images can be stored either monochrome, greyscale or color.
00093          * The latter uses 3 bytes per pixel, the former two use 1 byte
00094          * per pixel.  FUTURE FIX: I assume pbm packs 8 into one byte??
00095          *
00096          * FUTURE FIX: Should we not bother with color at all, and always
00097          * read images in greyscale? Problem with this is that color may
00098          * provide useful hints for partitioning and maybe even
00099          * identification. For now, we maintain support for color,
00100          * although the primary focus currently is on greyscale analysis.
00101          *
00102          */
00103         int  bytesPerPixel() const { return this->_data->bpp; }
00104         
00105         /*
00106          * Unit testing method.
00107          *
00108          * This static method should create instances of the class (and
00109          * instances of any other class necessary) and perform tests to
00110          * ensure that all methods within the class are working as
00111          * expected.
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         // Accessors
00135 
00136         // This field must go away!
00137         inline const pix* data() const { return this->_data; }
00138         
00139       protected:
00140         // Accessors
00141         inline void dataIs(pix* data) { this->_data = data; }
00142         
00143         // Methods 
00144         
00149         inline int index(u2 x, u2 y) const { return x + y*this->_data->x; }
00150         
00151       private: 
00152         // Methods 
00153         
00154         // Accessors
00155         inline pix*          dataRef() { return this->_data; }
00156         
00157         // State
00158         
00159         // This field has no public access - dirty - must replace with
00160         // something cleaner!
00161         pix*           _data;
00162     };
00163 };
00164 
00165 # endif // Conjecture_Image_h
00166 

Generated on Thu Jun 15 19:56:09 2006 for Conjecture by  doxygen 1.4.6