Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

image.h

Go to the documentation of this file.
00001 
00006 #ifndef IMAGE_H
00007 #define IMAGE_H
00008 
00009 
00010 #include <string>
00011 
00012 
00013 #include "file.h"
00014 
00015 /* main image class */
00016 class Image
00017 {
00018 public:
00020   enum PixelFormat
00021   {
00022     RGB8,
00023     RGBA8,
00024     ALPHA8
00025   };
00026 
00028   Image (void) { rc = NULL; }
00029 
00031   Image (const std::string &file);
00032 
00034   Image (File f);
00035 
00037   Image (PixelFormat f, int w, int h, uchar *data)
00038   {
00039     rc = new int;
00040     /* TODO: fix this hack */
00041     *rc = 2;
00042     format = f;
00043     width = w;
00044     height = h;
00045     image = data;
00046   }
00047 
00049   Image (const Image &im)
00050   {
00051     rc = im.rc;
00052     (*rc)++;
00053 
00054     image = im.image;
00055     width = im.width;
00056     height = im.height;
00057     format = im.format;
00058   }
00059 
00061   Image& operator = (const Image &im)
00062   {
00063     if (rc != NULL)
00064       {
00065         (*rc)--;
00066         if (*rc == 0)
00067           {
00068             delete [] image;
00069             delete rc;
00070           }
00071       }
00072 
00073     rc = im.rc;
00074     (*rc)++;
00075 
00076     image = im.image;
00077     width = im.width;
00078     height = im.height;
00079     format = im.format;
00080 
00081     return (*this);
00082   }
00083 
00085   void Scale (const int nw, const int nh);
00086 
00088   void Convert (const PixelFormat f);
00089 
00091   uchar *Data (void) const { return image; }
00092   int Width (void) const { return width; }
00093   int Height (void) const { return height; }
00094   PixelFormat Format (void) const { return format; }
00095 
00097   ~Image (void)
00098   {
00099     if (rc != NULL)
00100       {
00101         (*rc)--;
00102         if (*rc == 0)
00103           {
00104             delete [] image;
00105             delete rc;
00106           }
00107       }
00108   }
00109 
00110 private:
00111   /* Reference count.  */
00112   int *rc;
00113 
00114   /* Image data.  */
00115   uchar *image;
00116 
00117   /* Format.  */
00118   PixelFormat format;
00119 
00120   /* Dimensions.  */
00121   int width, height;
00122 
00123   /* Loads a Targa file.  */
00124   void ReadTarga (uchar *data, int len);
00125 };
00126 
00127 #endif

Generated on Fri Jan 12 14:15:02 2007 for Construct by  doxygen 1.4.3-20050530