00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __HYBRIDCHANNEL_GNX__
00033 #define __HYBRIDCHANNEL_GNX__
00034
00035 #include "channel.cpp"
00036
00037 template<class T>
00038 struct RgbaPixel
00039 {
00040 T r;
00041 T g;
00042 T b;
00043 T a;
00044 };
00045
00046
00047 template<class T>
00048 class HybridRgbaChannel : public Channel<T>
00049 {
00050 private:
00051 RgbaPixel<T> *data;
00052 public:
00053 HybridRgbaChannel(const int height, const int width);
00054 HybridRgbaChannel();
00055 virtual ~HybridRgbaChannel();
00056 virtual inline T Get(const int x, const int y);
00057 virtual inline void Set(const int x, const int y, const T val);
00058 virtual RgbaPixel<T>** GetRawRgbData();
00059 Channel<T>* EmptyClone();
00060 virtual void Normalize(int* x, int* y);
00061 virtual void Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty);
00062 };
00063
00064 template<class T>
00065 HybridRgbaChannel<T>::HybridRgbaChannel(const int height, const int width) : Channel<T>()
00066 {
00067 data = new RgbaPixel<T>[width*height];
00068 for(int i = 0;i<width*height;i++)
00069 {
00070 data[i].r = 20;
00071 data[i].g = 40;
00072 data[i].b = 60;
00073 data[i].a = 100;
00074 }
00075
00076 this->width = width;
00077 this->height = height;
00078 }
00079
00080 template<class T>
00081 HybridRgbaChannel<T>::HybridRgbaChannel() : Channel<T>()
00082 {
00083 data = 0;
00084 }
00085
00086 template<class T>
00087 HybridRgbaChannel<T>::~HybridRgbaChannel()
00088 {
00089 if(data != 0 && GetId() == 1)
00090 delete [] data;
00091 }
00092
00093 template<class T>
00094 inline T HybridRgbaChannel<T>::Get(const int x, const int y)
00095 {
00096 switch(GetId())
00097 {
00098 case 1:
00099 return(data[x+y*GetWidth()].r);
00100 case 2:
00101 return(data[x+y*GetWidth()].g);
00102 case 3:
00103 return(data[x+y*GetWidth()].b);
00104 default:
00105 return(data[x+y*GetWidth()].a);
00106 }
00107 }
00108
00109 template<class T>
00110 inline void HybridRgbaChannel<T>::Set(const int x, const int y, const T val)
00111 {
00112 switch(GetId())
00113 {
00114 case 1:
00115 data[x+y*GetWidth()].r = val;
00116 break;
00117 case 2:
00118 data[x+y*GetWidth()].g = val;
00119 break;
00120 case 3:
00121 data[x+y*GetWidth()].b = val;
00122 break;
00123 }
00124 }
00125
00126
00127 template<class T>
00128 RgbaPixel<T>** HybridRgbaChannel<T>::GetRawRgbData()
00129 {
00130 return(&data);
00131 }
00132
00133 template<class T>
00134 Channel<T>* HybridRgbaChannel<T>::EmptyClone()
00135 {
00136 HybridRgbaChannel<T> *copy = new HybridRgbaChannel<T>(height, width);
00137 *(copy->GetRawRgbData()) = data;
00138 return(copy);
00139 }
00140
00141 template<class T>
00142 void HybridRgbaChannel<T>::Normalize(int* x, int* y)
00143 {
00144 if(*x<0)
00145 *x = 0;
00146 if(*y<0)
00147 *y = 0;
00148 if(*x >= GetWidth())
00149 *x = GetWidth();
00150 if(*y >= GetHeight())
00151 *y = GetHeight();
00152 }
00153
00154 template<class T>
00155 void HybridRgbaChannel<T>::Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty)
00156 {
00157 int temp;
00158 Normalize(topleftx,toplefty);
00159 Normalize(bottomrightx,bottomrighty);
00160 if(*topleftx > *bottomrightx)
00161 {
00162 temp = *topleftx;
00163 *topleftx = *bottomrightx;
00164 *bottomrightx = temp;
00165 }
00166 if(*toplefty > *bottomrighty)
00167 {
00168 temp = *toplefty;
00169 *toplefty = *bottomrighty;
00170 *bottomrighty = temp;
00171 }
00172 }
00173
00174 #endif