AImage.h

Go to the documentation of this file.
00001 // Copyright (C) 2006 Alexei Miasnikov
00002 //
00003 // Contents: Definition of an Image class
00004 //
00005 // Principal Author: Alexei Miasnikov
00006 //
00007 // Status: in progress
00008 //
00009 // Revision History:
00010 //
00011 
00012 
00013 #ifndef _IMAGE_H_
00014 #define _IMAGE_H_
00015 
00016 #include <iostream>
00017 #include <string>
00018 
00019 using namespace std;
00020 const int MAXGRAY=256;
00021 
00022 
00023 enum IMAGE_TYPE { GRAY, COLOR };
00024 enum FILE_TYPE { BW, PGM, PPM, JPG, BMP, FT_NA };
00025 
00026 
00027 FILE_TYPE getFileType(const string& in_file_name);
00028 
00029 // --------------- LookUpTable class --------------------- //
00030 
00031 class LookUpTable
00032 {
00033  public:
00034   LookUpTable();
00035   // default constructor
00036 
00037   LookUpTable( const LookUpTable&);
00038   // Copy constructor
00039 
00040   LookUpTable& operator = (const LookUpTable&);
00041 
00042   void set(int,int);
00043   
00044   int get(int) const;
00045  private:
00046   unsigned char table[256];
00047 };
00048 
00049 // --------------- Abstract Image class ----------------------------- //
00050 
00051 class AImage
00052 {
00053  public:
00054 
00055   AImage():  width(0),  height(0), size(0){ }
00056   // Default constructor creates empty image
00057   
00058   AImage(int w,int h)
00059           :   width(w),  height(h), size( w*h) { }
00060   // Create an empty image of w x h size
00061 
00062   AImage( const  string& in_file_name) : width(0),  height(0), size(0){ }
00063   // Create image from the input file
00064   
00065   AImage( const AImage& i) : width(i.width),  height(i.height), size(i.width * i.height) { }
00066   // Copy constructor
00067   
00068   AImage( const AImage& image, int tlx, int tly, int brx, int bry, bool zero_pading) 
00069           : width(image.width + tlx + brx),
00070                 height(image.height + bry + bry),
00071                 size((image.width + tlx + brx) * (image.height + tly + bry))
00072 { }
00073   // Copy image with padding
00074 
00075   int getSize() const { return size; }
00076 
00077   int getWidth() const { return width; }
00078 
00079   int getHeight() const { return height; }
00080 
00081  // virtual void printOn( CArchive& out) const;
00082 
00083   virtual void saveTo( const string& file_name ) = 0;
00084   
00085   virtual IMAGE_TYPE getType() const = 0;
00086 
00087 protected:
00088 
00089   int width;
00090   // The width of the image
00091   int height;
00092   // The height of the image
00093   int size;
00094   // image size
00095   
00096 };
00097 
00098 
00099 // ----------------------- LUTImage class ------------------- //
00100 
00101 class LUTImage 
00102 {
00103 public:
00104 
00105   LUTImage() { }
00106   // Default constructor creates empty image
00107   
00108   LUTImage(const AImage& i) { }
00109   // Default constructor creates empty image
00110   
00111   LUTImage(int w, int h) { }
00112   
00113   LUTImage(const LUTImage& li) : theLookUpTable( li.theLookUpTable ) { }
00114 
00115   void setLookUpTable( const LookUpTable& t){
00116     theLookUpTable = t;
00117   }
00118 
00119   void setInLT( int i, int v){
00120     theLookUpTable.set(i,v);
00121   }
00122 
00123   int getInLT( int i) const {
00124     return theLookUpTable.get(i);
00125   }
00126 
00127 protected:
00128 
00129   LookUpTable theLookUpTable;
00130 };
00131 
00132 
00133 // --------------- Image class ----------------------------- //
00134 
00135 class GRImage : public AImage
00136 {
00137  public:
00138 
00139   GRImage(): AImage(), image_string( NULL ) { }
00140   // Default constructor creates empty image
00141   
00142   GRImage(int w,int h): AImage(w,h), image_string( new unsigned char[h*w] ) 
00143     {
00144       for (int i=0;i<size;i++)
00145         image_string[i] = 0;
00146     }
00147   // Create an empty image of w x h size
00148 
00149   GRImage( const string& in_file_name);
00150   // Create image from the input file
00151   
00152   GRImage( const GRImage& image);
00153   // Copy constructor
00154   
00155   GRImage( const GRImage&, int, int , int , int , bool );
00156   // Copy image with padding
00157 
00158   ~GRImage( );
00159 
00160   void setPixel(int i, int j,int v);
00161 
00162   virtual int getPixel(int i, int j) const;
00163 
00164   void setPixel(int n,int v);
00165 
00166   void setPixelCliped(int n,int v);
00167 
00168   void setPixelCliped(int i,int j,int v);
00169 
00170   virtual int getPixel(int n) const;
00171 
00172  // virtual void printOn( CArchive& out) const;
00173 
00174   void saveTo( const string& file_name );
00175 
00176   IMAGE_TYPE getType() const {return GRAY; }
00177   
00178   GRImage& operator = (const GRImage&);
00179 
00180 protected:
00181 
00182   friend class GRLUTImage;       
00183   
00184   virtual void printOnPGM( ostream& out)const;
00185   virtual void printOnBW( ostream& )const;
00186   // Output the image into a stream
00187   
00188   unsigned char* image_string;
00189   // Image data 
00190 
00191   void readFromBW( istream& in);
00192   void readFromPGM( istream& in);
00193 };
00194 
00195 
00196 // ----------------------- LUTImage class ------------------- //
00197 
00198 class GRLUTImage : public GRImage, public LUTImage
00199 {
00200 public:
00201   
00202   
00203   GRLUTImage(const GRLUTImage& li) : GRImage( li ), LUTImage((const LUTImage&) li ) {   }
00204   
00205   
00206   GRLUTImage() : GRImage() { }
00207   // Default constructor creates empty image
00208   
00209   GRLUTImage(const GRImage& i) : GRImage( i ) { }
00210   // Default constructor creates empty image
00211   
00212   GRLUTImage(int w, int h) : GRImage(w,h) { }
00213   // Create an empty image of w x h size
00214   
00215   int getPixel(int i, int j) const;
00216   
00217   int getPixel(int n) const;
00218   
00219   
00220   inline friend ostream& operator << ( ostream& o, const GRLUTImage& i ) {
00221     i.printOn( o );
00222     return o;
00223   }
00224   // Output operator - prints data in ostream
00225 
00226 
00227 private:
00228 
00229   void printOn( ostream& )const;
00230 };
00231 
00232 
00233 
00234 
00235 // --------------- Color Image class ----------------------------- //
00236 
00237 class CImage : public AImage
00238 {
00239  public:
00240   CImage(): AImage() { }
00241   // Default constructor creates empty image
00242   
00243   CImage(int w,int h): AImage(w,h), redImage(w,h), blueImage(w,h), greenImage(w,h) { }
00244   // Create an empty image of w x h size
00245 
00246   CImage( const string& in_file_name, FILE_TYPE ft = PPM);
00247   // Create image from the input file
00248   
00249   CImage( const CImage& image) : 
00250     AImage(image.width, image.height),
00251     redImage( image.redImage ),
00252     blueImage( image.blueImage ),
00253     greenImage( image.greenImage ) { }
00254   // Copy constructor
00255   
00256   CImage( const CImage& i, int p1, int p2, int p3, int p4, bool p5) : 
00257     AImage(i, p1, p2, p3, p4, p5),
00258     redImage(i.redImage, p1, p2, p3, p4, p5),
00259     blueImage(i.blueImage, p1, p2, p3, p4, p5),
00260     greenImage(i.greenImage, p1, p2, p3, p4, p5) { }
00261   // Copy image with padding
00262   
00263   // modifiers
00265   
00266   void setRedPixel(int i, int j,int v) { redImage.setPixel(i,j,v); }
00267   void setRedPixel(int n,int v) { redImage.setPixel(n,v); }
00268 
00269   void setBluePixel(int i, int j,int v) { blueImage.setPixel(i,j,v); }
00270   void setBluePixel(int n,int v) { blueImage.setPixel(n,v); }
00271   
00272   void setGreenPixel(int i, int j,int v) { greenImage.setPixel(i,j,v); }
00273   void setGreenPixel(int n,int v) { greenImage.setPixel(n,v); }
00274 
00275   void setRedPixelCliped(int n,int v) { redImage.setPixelCliped(n,v); }
00276   void setRedPixelCliped(int i,int j,int v) { redImage.setPixelCliped(i,j,v); }
00277 
00278   void setBluePixelCliped(int n,int v) { blueImage.setPixelCliped(n,v); }
00279   void setBluePixelCliped(int i,int j,int v){ blueImage.setPixelCliped(i,j,v); }
00280 
00281   void setGreenPixelCliped(int n,int v) { greenImage.setPixelCliped(n,v); }
00282   void setGreenPixelCliped(int i,int j,int v) { greenImage.setPixelCliped(i,j,v); }
00283 
00284 
00285   // accessors
00286   virtual unsigned char getRedPixel(int i, int j) const { return redImage.getPixel(i,j); }
00287   virtual unsigned char getRedPixel(int n) const { return redImage.getPixel(n); }
00288 
00289   virtual unsigned char getBluePixel(int i, int j) const { return blueImage.getPixel(i,j); }
00290   virtual unsigned char getBluePixel(int n) const { return blueImage.getPixel(n); }
00291 
00292   virtual unsigned char getGreenPixel(int i, int j) const { return  greenImage.getPixel(i,j); }
00293   virtual unsigned char getGreenPixel(int n) const {  return greenImage.getPixel(n); }
00294 
00295   const GRImage& getRedImage() const { return redImage; }
00296 
00297   const GRImage& getGreenImage() const { return greenImage; }
00298 
00299   const GRImage& getBlueImage() const { return blueImage; }
00300 
00301   // virtual void printOn( CArchive& out) const;
00302 
00303   void saveTo( const string& file_name );
00304 
00305   IMAGE_TYPE getType() const { return COLOR; }
00306   
00307 
00308 protected:
00309 
00310   friend class CLUTImage;        
00311   CImage& operator = (const CImage&);
00312   // Assign operator is prohibited
00313   
00314   // Output the image into a stream
00315   void printOnPPM( ostream& out)const;
00316 
00317   void readFromPPM( istream& in);
00318 
00319   // Image data 
00320   GRImage redImage;
00321   GRImage blueImage;
00322   GRImage greenImage;
00323 };
00324 
00325 
00326 // ----------------------- Color LUTImage class ------------------- //
00327 
00328 class CLUTImage : public CImage, public LUTImage
00329 {
00330 public:
00331 
00332         CLUTImage(const CLUTImage& li) : CImage( li ), LUTImage((const LUTImage&)li){ } 
00333         
00334         CLUTImage() : CImage() { }
00335   // Default constructor creates empty image
00336   
00337         CLUTImage(const CImage& i) : CImage( i ){ }
00338         
00339 
00340         CLUTImage(int w, int h) : CImage(w,h) { }
00341   // Create an empty image of w x h size
00342 
00343 
00344         //modifiers
00345  
00346   // modifiers
00348 
00349  
00350   // accessors
00351   virtual unsigned char getRedPixel(int i, int j) const { 
00352           return   theLookUpTable.get(CImage::getRedPixel(i,j));
00353   }
00354   virtual unsigned char getRedPixel(int n) const { 
00355           return   theLookUpTable.get(CImage::getRedPixel(n));
00356   }
00357 
00358   virtual unsigned char getBluePixel(int i, int j) const { 
00359           return   theLookUpTable.get(CImage::getBluePixel(i,j));
00360   }
00361   virtual unsigned char getBluePixel(int n) const { 
00362           return   theLookUpTable.get(CImage::getBluePixel(n));
00363   }
00364   virtual unsigned char getGreenPixel(int i, int j) const { 
00365           return   theLookUpTable.get(CImage::getGreenPixel(i,j));
00366   }
00367   virtual unsigned char getGreenPixel(int n) const{ 
00368           return   theLookUpTable.get(CImage::getGreenPixel(n));
00369   } 
00370 
00371 
00372 private:
00373   
00374 //  void printOnPPM(ostream& out)const;
00375 };
00376 
00377 
00378 
00379 
00380 
00381 void convert(const CImage* ci, GRImage* gi);
00382 
00383 
00384 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1