00001
00005
00006 #ifndef _H_IMG_Pixmap
00007 #define _H_IMG_Pixmap
00008
00009 #include "IMG_Types.h"
00010
00011 #include "IMG_Rect.h"
00012
00013
00019
00020 class IMG_Pixmap {
00021 public:
00023 typedef enum {
00024 kPixelTypeRGB32 = 0,
00025 kPixelTypeRGBA32 = 1,
00026
00027
00028
00029 kPixelTypeRGB24 = 5
00030 } PixelType;
00031
00035 IMG_Pixmap();
00036
00040 virtual ~IMG_Pixmap();
00041
00046 inline void* getDataPtr() const;
00047
00052 inline TUns32 getWidth() const;
00053
00058 inline TUns32 getHeight() const;
00059
00064 inline void getBounds(IMG_Rect& r) const;
00065
00070 inline PixelType getPixelType() const;
00071
00077 inline void clamp(TInt32& x, TInt32& y) const;
00078
00084 inline void clamp(float& u, float& v) const;
00085
00094 inline void getPixelAddress(float u, float v, TInt32& x, TInt32& y) const;
00095
00102
00103
00104 protected:
00106 void* m_image;
00108 TUns32 m_width;
00110 TUns32 m_height;
00112 TUns32 m_rowBytes;
00114 TUns32 m_pixelSize;
00116 PixelType m_pixelType;
00117
00118
00119 };
00120
00121 inline void* IMG_Pixmap::getDataPtr() const
00122 {
00123 return m_image;
00124 }
00125
00126 inline TUns32 IMG_Pixmap::getWidth() const
00127 {
00128 return m_width;
00129 }
00130
00131 inline TUns32 IMG_Pixmap::getHeight() const
00132 {
00133 return m_height;
00134 }
00135
00136 inline void IMG_Pixmap::getBounds(IMG_Rect& r) const
00137 {
00138 r.set(0, 0, m_width, m_height);
00139 }
00140
00141 inline IMG_Pixmap::PixelType IMG_Pixmap::getPixelType() const
00142 {
00143 return m_pixelType;
00144 }
00145
00146 inline void IMG_Pixmap::clamp(TInt32& x, TInt32& y) const
00147 {
00148 if (x < 0) x = 0;
00149 if (x > (TInt32)m_width) x = (TInt32)m_width;
00150 if (y < 0) y = 0;
00151 if (y > (TInt32)m_height) y = (TInt32)m_height;
00152 }
00153
00154 inline void IMG_Pixmap::clamp(float& u, float& v) const
00155 {
00156 if (u < 0.f) u = 0.f;
00157 if (u > 1.f) u = 1.f;
00158 if (v < 0.f) v = 0.f;
00159 if (v > 1.f) v = 1.f;
00160 }
00161
00162 inline void IMG_Pixmap::getPixelAddress(float u, float v, TInt32& x, TInt32& y) const
00163 {
00164 x = (TInt32)(((float)m_width) * u);
00165 y = (TInt32)(((float)m_height) * v);
00166 }
00167
00168 #endif // _H_IMG_Pixmap