• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • cups
image.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include <tqimage.h>
21 #include <math.h>
22 
23 void
24 mult(float a[3][3], /* I - First matrix */
25  float b[3][3], /* I - Second matrix */
26  float c[3][3]) /* I - Destination matrix */
27 {
28  int x, y; /* Looping vars */
29  float temp[3][3]; /* Temporary matrix */
30 
31 
32  /*
33  * Multiply a and b, putting the result in temp...
34  */
35 
36  for (y = 0; y < 3; y ++)
37  for (x = 0; x < 3; x ++)
38  temp[y][x] = b[y][0] * a[0][x] +
39  b[y][1] * a[1][x] +
40  b[y][2] * a[2][x];
41 
42  /*
43  * Copy temp to c (that way c can be a pointer to a or b).
44  */
45 
46  memcpy(c, temp, sizeof(temp));
47 }
48 
49 void
50 saturate(float mat[3][3], /* I - Matrix to append to */
51  float sat) /* I - Desired color saturation */
52 {
53  float smat[3][3]; /* Saturation matrix */
54 
55 
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;
65 
66  mult(smat, mat, mat);
67 }
68 
69 void
70 xform(float mat[3][3], /* I - Matrix */
71  float x, /* I - Input X coordinate */
72  float y, /* I - Input Y coordinate */
73  float z, /* I - Input Z coordinate */
74  float *tx, /* O - Output X coordinate */
75  float *ty, /* O - Output Y coordinate */
76  float *tz) /* O - Output Z coordinate */
77 {
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];
81 }
82 
83 void
84 xrotate(float mat[3][3], /* I - Matrix */
85  float rs, /* I - Rotation angle sine */
86  float rc) /* I - Rotation angle cosine */
87 {
88  float rmat[3][3]; /* I - Rotation matrix */
89 
90 
91  rmat[0][0] = 1.0;
92  rmat[0][1] = 0.0;
93  rmat[0][2] = 0.0;
94 
95  rmat[1][0] = 0.0;
96  rmat[1][1] = rc;
97  rmat[1][2] = rs;
98 
99  rmat[2][0] = 0.0;
100  rmat[2][1] = -rs;
101  rmat[2][2] = rc;
102 
103  mult(rmat, mat, mat);
104 }
105 
106 void
107 yrotate(float mat[3][3], /* I - Matrix */
108  float rs, /* I - Rotation angle sine */
109  float rc) /* I - Rotation angle cosine */
110 {
111  float rmat[3][3]; /* I - Rotation matrix */
112 
113 
114  rmat[0][0] = rc;
115  rmat[0][1] = 0.0;
116  rmat[0][2] = -rs;
117 
118  rmat[1][0] = 0.0;
119  rmat[1][1] = 1.0;
120  rmat[1][2] = 0.0;
121 
122  rmat[2][0] = rs;
123  rmat[2][1] = 0.0;
124  rmat[2][2] = rc;
125 
126  mult(rmat,mat,mat);
127 }
128 
129 void
130 zrotate(float mat[3][3], /* I - Matrix */
131  float rs, /* I - Rotation angle sine */
132  float rc) /* I - Rotation angle cosine */
133 {
134  float rmat[3][3]; /* I - Rotation matrix */
135 
136 
137  rmat[0][0] = rc;
138  rmat[0][1] = rs;
139  rmat[0][2] = 0.0;
140 
141  rmat[1][0] = -rs;
142  rmat[1][1] = rc;
143  rmat[1][2] = 0.0;
144 
145  rmat[2][0] = 0.0;
146  rmat[2][1] = 0.0;
147  rmat[2][2] = 1.0;
148 
149  mult(rmat,mat,mat);
150 }
151 
152 void
153 zshear(float mat[3][3], /* I - Matrix */
154  float dx, /* I - X shear */
155  float dy) /* I - Y shear */
156 {
157  float smat[3][3]; /* Shear matrix */
158 
159 
160  smat[0][0] = 1.0;
161  smat[0][1] = 0.0;
162  smat[0][2] = dx;
163 
164  smat[1][0] = 0.0;
165  smat[1][1] = 1.0;
166  smat[1][2] = dy;
167 
168  smat[2][0] = 0.0;
169  smat[2][1] = 0.0;
170  smat[2][2] = 1.0;
171 
172  mult(smat, mat, mat);
173 }
174 
175 void
176 huerotate(float mat[3][3], /* I - Matrix to append to */
177  float rot) /* I - Hue rotation in degrees */
178 {
179  float hmat[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}; /* Hue matrix */
180  float lx, ly, lz; /* Luminance vector */
181  float xrs, xrc; /* X rotation sine/cosine */
182  float yrs, yrc; /* Y rotation sine/cosine */
183  float zrs, zrc; /* Z rotation sine/cosine */
184  float zsx, zsy; /* Z shear x/y */
185 
186 
187  /*
188  * Rotate the gray vector into positive Z...
189  */
190 
191  xrs = M_SQRT1_2;
192  xrc = M_SQRT1_2;
193  xrotate(hmat,xrs,xrc);
194 
195  yrs = -1.0 / sqrt(3.0);
196  yrc = -M_SQRT2 * yrs;
197  yrotate(hmat,yrs,yrc);
198 
199  /*
200  * Shear the space to make the luminance plane horizontal...
201  */
202 
203  xform(hmat, 0.3086, 0.6094, 0.0820, &lx, &ly, &lz);
204  zsx = lx / lz;
205  zsy = ly / lz;
206  zshear(hmat, zsx, zsy);
207 
208  /*
209  * Rotate the hue...
210  */
211 
212  zrs = sin(rot * M_PI / 180.0);
213  zrc = cos(rot * M_PI / 180.0);
214 
215  zrotate(hmat, zrs, zrc);
216 
217  /*
218  * Unshear the space to put the luminance plane back...
219  */
220 
221  zshear(hmat, -zsx, -zsy);
222 
223  /*
224  * Rotate the gray vector back into place...
225  */
226 
227  yrotate(hmat, -yrs, yrc);
228  xrotate(hmat, -xrs, xrc);
229 
230  /*
231  * Append it to the current matrix...
232  */
233 
234  mult(hmat, mat, mat);
235 }
236 
237 void
238 bright(float mat[3][3],
239  float scale)
240 {
241  for (int i=0;i<3;i++)
242  for (int j=0;j<3;j++)
243  mat[i][j] *= scale;
244 }
245 
246 //----------------------------------------------------------------------------------------------------
247 
248 TQImage convertImage(const TQImage& image, int hue, int saturation, int brightness, int gamma)
249 {
250  float mat[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
251  int lut[3][3][256];
252  TQRgb c;
253  int r,g,b,v,r2,g2,b2;
254  float gam = 1.0/(float(gamma)/1000.0);
255  TQImage img(image);
256 
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);
264 
265  img.detach();
266  for (int i=0;i<image.width();i++)
267  for (int j=0;j<image.height();j++)
268  {
269  c = image.pixel(i,j);
270  r = tqRed(c);
271  g = tqGreen(c);
272  b = tqBlue(c);
273 
274  v = lut[0][0][r] + lut[1][0][g] + lut[2][0][b];
275  if (gamma != 1000) v = (int)rint(pow(v,gam));
276  if (v < 0) r2 = 0;
277  else if (v > 255) r2 = 255;
278  else r2 = v;
279 
280  v = lut[0][1][r] + lut[1][1][g] + lut[2][1][b];
281  if (gamma != 1000) v = (int)rint(pow(v,gam));
282  if (v < 0) g2 = 0;
283  else if (v > 255) g2 = 255;
284  else g2 = v;
285 
286  v = lut[0][2][r] + lut[1][2][g] + lut[2][2][b];
287  if (gamma != 1000) v = (int)rint(pow(v,gam));
288  if (v < 0) b2 = 0;
289  else if (v > 255) b2 = 255;
290  else b2 = v;
291 
292  img.setPixel(i,j,tqRgb(r2,g2,b2));
293  }
294  return img;
295 }

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.