www.pudn.com > firev0.01.rar > hdimage.hpp


/*
This file is part of the FIRE -- Flexible Image Retrieval System

FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef __hdimage_h
#define __hdimage_h

#include "image.hpp"
#include 
using namespace std;
namespace img {


   /// Class for RGB images.
  /** 
   * This class is inherited from BaseImage, but there are some
   * operators and the loader functions changed. As Pixeltype here is
   * used vector where the type of the vector has to be determined by
   * template programming. It is not assured, that every pixel has the
   * same dimensionality. For the methods in this object taking need
   * of it, this is assumed and it is taken the size of the (0,0)
   * pixel.
   */
  template
  class HDImage : public BaseImage < vector > {
  public:
    ///default constructor.
    HDImage() : BaseImage >() {}
    
    /// standard constructor, which also allocates memory.
    HDImage(const int yDim, const int xDim) : BaseImage >(yDim, xDim) {}

    HDImage(const int yDim, const int xDim, const int zDim) : BaseImage > (yDim, xDim) {
      for(unsigned int i=0;i(zDim);
      }
    }
    
    /// copy constructor.
    HDImage(const BaseImage &img) : BaseImage(img) {}
    
    ///get the values one by one from the image, const version
    ///assuming all pixels have same dim as first one.
    inline const T operator[](const int i) const {
      return data_[i/pixelDim()][i%pixelDim()];
    }
    
    ///get the values one by one from the image
    ///assuming all pixels have same dim as first one.
    inline T& operator[](const int i) {
      return data_[i/pixelDim()][i%pixelDim()];
    }
    
    /// get the dimensionality of the first pixel. (to be assumed, that all pixels have the same
    const unsigned int pixelDim() const {return data_[0].size();};


    inline const vector& operator()(const int i) const {
      return data_[i];
    }
    
    inline vector &operator()(const int i) {
      return data_[i];
    }

    ///get the values from the image by coordinate (y,x), const version.
    inline const vector & operator()(const int y, const int x) const {
      return data_[(y*xDim_)+x];
    };
    
    ///get the values from the image by coordinate (y,x).
    inline vector & operator()(const int y, const int x) {
      return(data_[y*xDim_+x]);
    };
    
    
    ///get the values by coordinate and color (y,x,c), const version.
    inline const T operator()(const int y, const int x, const int c) const {
      return data_[y*xDim_+x][c];
    }
    
    ///get the values by coordinate and color (y,x,c), const version.
    inline T& operator()(const int y, const int x, const int c) {
      return data_[y*xDim_+x][c];
    }
    
    ///read this file as jpeg image
    void readJPG(const char *filename) {
      DBG(DBG_ERROR) << "[hdimage::readJPG] Not yet implemented." << endl;
    }
    
    ///read this file as png image
    void readPNG(const char *filename) {
      DBG(DBG_ERROR) << "[hdimage::readPNG] Not yet implemented." << endl;
    }

    void writePNG(const char* prefix) {
      ostringstream a;
      for(unsigned int i=0;ixDim();
      int height=this->yDim();
      
      png_byte toWrite[height*width];
      for(int y=0;yoperator()(y,x)[c]<255?this->operator()(y,x)[c]:255);
        }
      }
      
      write_png(filename, toWrite, this->xDim(), this->yDim(), 8, 1);
      
      DBG(DBG_VERBOSE) << "ready writing png '" << filename << "'." << endl;
    }
    
  };
}

#endif