CImage.h

Go to the documentation of this file.
00001 
00013 #ifndef CIMAGE_H
00014 #define CIMAGE_H
00015 
00021 class CImage
00022 {
00023  public:
00027   CImage(int w = -1, int h = -1)
00028     {
00029       if (w > 0 && h > 0)
00030         {
00031           m_pPixels = new float[4*w*h];
00032           m_Width   = w;
00033           m_Height  = h;
00034         }
00035       else
00036         {
00037           m_pPixels = 0;
00038           m_Width   = -1;
00039           m_Height  = -1;
00040         }
00041     }
00042 
00046   ~CImage()
00047     {
00048       if (m_pPixels)
00049         delete [] m_pPixels;
00050     }
00051 
00056   inline float& operator()(unsigned int i, unsigned int j, unsigned int k)
00057     {
00058       POP_ASSERT((signed) ((j * m_Width + i) * 4 + k) < m_Width * m_Height * 4,
00059               "Trying to access a color out of range.");
00060       return m_pPixels[(j * m_Width + i) * 4 + k];
00061     }
00062 
00067   inline const float& operator()(unsigned int i, unsigned int j, unsigned int k) const
00068     {
00069       POP_ASSERT((signed) ((j * m_Width + i) * 4 + k) < m_Width * m_Height * 4,
00070               "Trying to access a color out of range.");
00071       return m_pPixels[(j * m_Width + i) * 4 + k];
00072     }
00073 
00078   void Allocate(int w, int h)
00079     {
00080       if (m_pPixels)
00081         delete [] m_pPixels;
00082 
00083       m_pPixels = new float [4*w*h];
00084       m_Width   = w;
00085       m_Height  = h;
00086     }
00087 
00091   int WriteBmpFile(const std::string& FileName) const;
00092 
00093  private:
00094   float *m_pPixels; 
00095   int m_Width;      
00096   int m_Height;     
00097 };
00098 
00099 
00100 #endif // CIMAGE_H
00101 

Generated on Fri Dec 5 03:20:33 2008 for Mathematical Ray-tracer by  doxygen 1.5.4