00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __COLOR_VECTOR___
00024 #define __COLOR_VECTOR___
00025
00026 #include<cstdlib>
00027 #include<iostream>
00028
00029 namespace color {
00030
00031
00032 union _colorVertex {
00033 float r,g,b,a;
00034 float rgb[4];
00035 };
00036
00037 class Color3D {
00038
00039
00040 public:
00041 Color3D();
00042 Color3D(const Color3D &c);
00043 void setcolor(float r, float g, float b, float a);
00044 const union _colorVertex &getColor() const;
00045 void add(const Color3D &c);
00046 void sub(const Color3D &c);
00047 void mul(const Color3D &c);
00048 void div(const Color3D &c);
00049 unsigned int toInteger() const;
00050 Color3D &operator=(const Color3D &c);
00051 Color3D& operator/=(const Color3D &c) { div(c); return *this; }
00052 Color3D& operator*=(const Color3D &c) { mul(c); return *this; }
00053 Color3D& operator-=(const Color3D &c) { sub(c); return *this; }
00054 Color3D& operator+=(const Color3D &c) { add(c); return *this; }
00055 Color3D& operator+(const Color3D &c) { add(c); return *this; }
00056 Color3D& operator-(const Color3D &c) { sub(c); return *this; }
00057 Color3D& operator*(const Color3D &c) { mul(c); return *this; }
00058 Color3D& operator/(const Color3D &c) { div(c); return *this; }
00059 friend std::ostream& operator<<(std::ostream& out, const Color3D &c);
00060 union _colorVertex color;
00061 };
00062
00063
00064 template<std::size_t x, std::size_t y>
00065 class M4Color3D {
00066
00067 public:
00068 Color3D row[x][y];
00069 M4Color3D()
00070 {
00071 w=x,h=y;
00072
00073 }
00074
00075 void randbuffer()
00076 {
00077 unsigned int i,z;
00078 for(i =0; i< w; i++)
00079 for(z = 0; z < h; z++)
00080 {
00081 row[i][z].color.rgb[0] = rand()%255;
00082 row[i][z].color.rgb[1] = rand()%255;
00083 row[i][z].color.rgb[2] = rand()%255;
00084 row[i][z].color.rgb[3] = rand()%255;
00085 }
00086 }
00087
00088 void setp(int xvar, int yvar, Color3D &col)
00089 {
00090 row[xvar][yvar] = col;
00091 }
00092
00093 void add(const M4Color3D &c)
00094 {
00095 unsigned int i,z;
00096
00097 for(i = 0; i < w; i++)
00098 for(z = 0; z < y; z++)
00099 row[i][z] += c.row[i][z];
00100 }
00101
00102 void sub(const M4Color3D &c)
00103 {
00104 unsigned int i,z;
00105
00106 for(i = 0; i < w; i++)
00107 for(z = 0; z < y; z++)
00108 row[i][z] -= c.row[i][z];
00109
00110 }
00111
00112 void mul(const M4Color3D &c)
00113 {
00114 unsigned int i,z;
00115
00116 for(i = 0; i < w; i++)
00117 for(z = 0; z < y; z++)
00118 row[i][z] *= c.row[i][z];
00119
00120 }
00121 void div(const M4Color3D &c)
00122 {
00123 unsigned int i,z;
00124
00125 for(i = 0; i < w; i++)
00126 for(z = 0; z < y; z++)
00127 if(c.row[i][z] != 0)
00128 row[i][z] /= c.row[i][z];
00129
00130 }
00131
00132 void addColor3D(const Color3D &c)
00133 {
00134
00135 for(unsigned int i = 0; i < w; i++)
00136 for(unsigned int z = 0; z < h; z++)
00137 row[i][z] += c;
00138
00139 }
00140
00141 void mulColor3D(const Color3D &c)
00142 {
00143 for(unsigned int i = 0; i < w; i++)
00144 for(unsigned int z = 0; z < h; z++)
00145 row[i][z] *= c;
00146 }
00147
00148 void subColor3D(const Color3D &c)
00149 {
00150
00151 for(unsigned int i = 0; i < w; i++)
00152 for(unsigned int z = 0; z < h; z++)
00153 row[i][z] -= c;
00154
00155 }
00156
00157
00158 void divColor3D(const Color3D &c)
00159 {
00160 for(unsigned int i = 0; i < w; i++)
00161 for(unsigned int z = 0; z < h; z++)
00162 row[i][z] /= c;
00163
00164 }
00165
00166
00167 void printData() const
00168 {
00169 for(unsigned int i = 0; i < w; i++)
00170 for(unsigned int z = 0; z < h; z++)
00171 std::cout << row[i][z] << "\n";
00172 }
00173
00174 void triblend()
00175 {
00176
00177 unsigned int i,z;
00178
00179 for(i = 1; i < w-1; i++)
00180 for(z = 1; z < h-1; z++)
00181 {
00182 Color3D c[3];
00183
00184 c[0] = row[i][z];
00185 c[1] = row[i][z+1];
00186 c[2] = row[i+1][z];
00187
00188 row[i-1][z+1] = c[0] - c[1] * c[2];
00189 }
00190 }
00191
00192 void upper_left()
00193 {
00194 unsigned int i,z;
00195
00196 for(i = 1; i < w-1; i++)
00197 for(z = 1; z < h-1; z++)
00198 {
00199
00200 Color3D col = row[i][z];
00201 row[i-1][z-1] = col;
00202
00203 }
00204
00205 }
00206
00207
00208 void increase(float ramt, float gamt, float bamt)
00209 {
00210 unsigned int i,z;
00211
00212 for(i = 0; i < w; i++)
00213 for(z = 0; z < h; z++)
00214 {
00215
00216 row[i][z].color.rgb[0] += ramt;
00217 row[i][z].color.rgb[1] += gamt;
00218 row[i][z].color.rgb[2] += bamt;
00219
00220 }
00221
00222 }
00223
00224 unsigned int w, h;
00225 };
00226
00227 }
00228
00229 #endif
00230
00231