36 for (y = 0; y < 3; y ++)
37 for (x = 0; x < 3; x ++)
38 temp[y][x] = b[y][0] * a[0][x] +
46 memcpy(c, temp,
sizeof(temp));
50 saturate(
float mat[3][3],
56 smat[0][0] = (1.0 - sat) * 0.3086 + sat;
57 smat[0][1] = (1.0 - sat) * 0.3086;
58 smat[0][2] = (1.0 - sat) * 0.3086;
59 smat[1][0] = (1.0 - sat) * 0.6094;
60 smat[1][1] = (1.0 - sat) * 0.6094 + sat;
61 smat[1][2] = (1.0 - sat) * 0.6094;
62 smat[2][0] = (1.0 - sat) * 0.0820;
63 smat[2][1] = (1.0 - sat) * 0.0820;
64 smat[2][2] = (1.0 - sat) * 0.0820 + sat;
70 xform(
float mat[3][3],
78 *tx = x * mat[0][0] + y * mat[1][0] + z * mat[2][0];
79 *ty = x * mat[0][1] + y * mat[1][1] + z * mat[2][1];
80 *tz = x * mat[0][2] + y * mat[1][2] + z * mat[2][2];
84 xrotate(
float mat[3][3],
103 mult(rmat, mat, mat);
107 yrotate(
float mat[3][3],
130 zrotate(
float mat[3][3],
153 zshear(
float mat[3][3],
172 mult(smat, mat, mat);
176 huerotate(
float mat[3][3],
179 float hmat[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
193 xrotate(hmat,xrs,xrc);
195 yrs = -1.0 / sqrt(3.0);
196 yrc = -M_SQRT2 * yrs;
197 yrotate(hmat,yrs,yrc);
203 xform(hmat, 0.3086, 0.6094, 0.0820, &lx, &ly, &lz);
206 zshear(hmat, zsx, zsy);
212 zrs = sin(rot * M_PI / 180.0);
213 zrc = cos(rot * M_PI / 180.0);
215 zrotate(hmat, zrs, zrc);
221 zshear(hmat, -zsx, -zsy);
227 yrotate(hmat, -yrs, yrc);
228 xrotate(hmat, -xrs, xrc);
234 mult(hmat, mat, mat);
238 bright(
float mat[3][3],
241 for (
int i=0;i<3;i++)
242 for (
int j=0;j<3;j++)
248 TQImage convertImage(
const TQImage& image,
int hue,
int saturation,
int brightness,
int gamma)
250 float mat[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
253 int r,g,b,v,r2,g2,b2;
254 float gam = 1.0/(float(gamma)/1000.0);
257 saturate(mat,saturation*0.01);
258 huerotate(mat,(
float)hue);
259 bright(mat,brightness*0.01);
260 for (
int i = 0; i < 3; i ++)
261 for (
int j = 0; j < 3; j ++)
262 for (
int k = 0; k < 256; k ++)
263 lut[i][j][k] = (
int)(mat[i][j] * k + 0.5);
266 for (
int i=0;i<image.width();i++)
267 for (
int j=0;j<image.height();j++)
269 c = image.pixel(i,j);
274 v = lut[0][0][r] + lut[1][0][g] + lut[2][0][b];
275 if (gamma != 1000) v = (int)rint(pow(v,gam));
277 else if (v > 255) r2 = 255;
280 v = lut[0][1][r] + lut[1][1][g] + lut[2][1][b];
281 if (gamma != 1000) v = (int)rint(pow(v,gam));
283 else if (v > 255) g2 = 255;
286 v = lut[0][2][r] + lut[1][2][g] + lut[2][2][b];
287 if (gamma != 1000) v = (int)rint(pow(v,gam));
289 else if (v > 255) b2 = 255;
292 img.setPixel(i,j,tqRgb(r2,g2,b2));