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

tdefx

  • tdefx
kpixmapeffect.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
3  (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
4  (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 
6 */
7 
8 // $Id$
9 
10 #include <tqimage.h>
11 #include <tqpainter.h>
12 
13 #include "kpixmapeffect.h"
14 #include "kpixmap.h"
15 #include "kimageeffect.h"
16 
17 //======================================================================
18 //
19 // Gradient effects
20 //
21 //======================================================================
22 
23 
24 KPixmap& KPixmapEffect::gradient(KPixmap &pixmap, const TQColor &ca,
25  const TQColor &cb, GradientType eff, int ncols)
26 {
27  if(pixmap.depth() > 8 &&
28  (eff == VerticalGradient || eff == HorizontalGradient)) {
29 
30  int rDiff, gDiff, bDiff;
31  int rca, gca, bca /*, rcb, gcb, bcb*/;
32 
33  int x, y;
34 
35  rDiff = (/*rcb = */ cb.red()) - (rca = ca.red());
36  gDiff = (/*gcb = */ cb.green()) - (gca = ca.green());
37  bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue());
38 
39  int rl = rca << 16;
40  int gl = gca << 16;
41  int bl = bca << 16;
42 
43  int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff;
44  int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff;
45  int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff;
46 
47  TQPainter p(&pixmap);
48 
49  // these for-loops could be merged, but the if's in the inner loop
50  // would make it slow
51  switch(eff) {
52  case VerticalGradient:
53  for ( y = 0; y < pixmap.height(); y++ ) {
54  rl += rcdelta;
55  gl += gcdelta;
56  bl += bcdelta;
57 
58  p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
59  p.drawLine(0, y, pixmap.width()-1, y);
60  }
61  break;
62  case HorizontalGradient:
63  for( x = 0; x < pixmap.width(); x++) {
64  rl += rcdelta;
65  gl += gcdelta;
66  bl += bcdelta;
67 
68  p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
69  p.drawLine(x, 0, x, pixmap.height()-1);
70  }
71  break;
72  default:
73  ;
74  }
75  }
76  else {
77  TQImage image = KImageEffect::gradient(pixmap.size(), ca, cb,
78  (KImageEffect::GradientType) eff, ncols);
79  pixmap.convertFromImage(image);
80  }
81 
82  return pixmap;
83 }
84 
85 
86 // -----------------------------------------------------------------------------
87 
88 KPixmap& KPixmapEffect::unbalancedGradient(KPixmap &pixmap, const TQColor &ca,
89  const TQColor &cb, GradientType eff, int xfactor, int yfactor,
90  int ncols)
91 {
92  TQImage image = KImageEffect::unbalancedGradient(pixmap.size(), ca, cb,
93  (KImageEffect::GradientType) eff,
94  xfactor, yfactor, ncols);
95  pixmap.convertFromImage(image);
96 
97  return pixmap;
98 }
99 
100 
101 //======================================================================
102 //
103 // Intensity effects
104 //
105 //======================================================================
106 
107 
108 
109 KPixmap& KPixmapEffect::intensity(KPixmap &pixmap, float percent)
110 {
111  TQImage image = pixmap.convertToImage();
112  KImageEffect::intensity(image, percent);
113  pixmap.convertFromImage(image);
114 
115  return pixmap;
116 }
117 
118 
119 // -----------------------------------------------------------------------------
120 
121 KPixmap& KPixmapEffect::channelIntensity(KPixmap &pixmap, float percent,
122  RGBComponent channel)
123 {
124  TQImage image = pixmap.convertToImage();
125  KImageEffect::channelIntensity(image, percent,
126  (KImageEffect::RGBComponent) channel);
127  pixmap.convertFromImage(image);
128 
129  return pixmap;
130 }
131 
132 
133 //======================================================================
134 //
135 // Blend effects
136 //
137 //======================================================================
138 
139 
140 KPixmap& KPixmapEffect::blend(KPixmap &pixmap, float initial_intensity,
141  const TQColor &bgnd, GradientType eff,
142  bool anti_dir, int ncols)
143 {
144 
145  TQImage image = pixmap.convertToImage();
146  if (image.depth() <=8)
147  image = image.convertDepth(32); //Sloww..
148 
149  KImageEffect::blend(image, initial_intensity, bgnd,
150  (KImageEffect::GradientType) eff, anti_dir);
151 
152  unsigned int tmp;
153 
154  if(pixmap.depth() <= 8 ) {
155  if ( ncols < 2 || ncols > 256 )
156  ncols = 3;
157  TQColor *dPal = new TQColor[ncols];
158  for (int i=0; i<ncols; i++) {
159  tmp = 0 + 255 * i / ( ncols - 1 );
160  dPal[i].setRgb ( tmp, tmp, tmp );
161  }
162  KImageEffect::dither(image, dPal, ncols);
163  pixmap.convertFromImage(image);
164  delete [] dPal;
165  }
166  else
167  pixmap.convertFromImage(image);
168 
169  return pixmap;
170 }
171 
172 
173 //======================================================================
174 //
175 // Hash effects
176 //
177 //======================================================================
178 
179 KPixmap& KPixmapEffect::hash(KPixmap &pixmap, Lighting lite,
180  unsigned int spacing, int ncols)
181 {
182  TQImage image = pixmap.convertToImage();
183  KImageEffect::hash(image, (KImageEffect::Lighting) lite, spacing);
184 
185  unsigned int tmp;
186 
187  if(pixmap.depth() <= 8 ) {
188  if ( ncols < 2 || ncols > 256 )
189  ncols = 3;
190  TQColor *dPal = new TQColor[ncols];
191  for (int i=0; i<ncols; i++) {
192  tmp = 0 + 255 * i / ( ncols - 1 );
193  dPal[i].setRgb ( tmp, tmp, tmp );
194  }
195  KImageEffect::dither(image, dPal, ncols);
196  pixmap.convertFromImage(image);
197  delete [] dPal;
198  }
199  else
200  pixmap.convertFromImage(image);
201 
202  return pixmap;
203 }
204 
205 
206 //======================================================================
207 //
208 // Pattern effects
209 //
210 //======================================================================
211 
212 #if 0
213 void KPixmapEffect::pattern(KPixmap &pixmap, const TQColor &ca,
214  const TQColor &cb, unsigned pat[8])
215 {
216  TQImage img = pattern(pixmap.size(), ca, cb, pat);
217  pixmap.convertFromImage(img);
218 }
219 #endif
220 
221 // -----------------------------------------------------------------------------
222 
223 KPixmap KPixmapEffect::pattern(const KPixmap& pmtile, TQSize size,
224  const TQColor &ca, const TQColor &cb, int ncols)
225 {
226  if (pmtile.depth() > 8)
227  ncols = 0;
228 
229  TQImage img = pmtile.convertToImage();
230  KImageEffect::flatten(img, ca, cb, ncols);
231  KPixmap pixmap;
232  pixmap.convertFromImage(img);
233 
234  return KPixmapEffect::createTiled(pixmap, size);
235 }
236 
237 
238 // -----------------------------------------------------------------------------
239 
240 KPixmap KPixmapEffect::createTiled(const KPixmap& pixmap, TQSize size)
241 {
242  KPixmap pix(size);
243 
244  TQPainter p(&pix);
245  p.drawTiledPixmap(0, 0, size.width(), size.height(), pixmap);
246 
247  return pix;
248 }
249 
250 
251 //======================================================================
252 //
253 // Fade effects
254 //
255 //======================================================================
256 
257 KPixmap& KPixmapEffect::fade(KPixmap &pixmap, double val, const TQColor &color)
258 {
259  TQImage img = pixmap.convertToImage();
260  KImageEffect::fade(img, val, color);
261  pixmap.convertFromImage(img);
262 
263  return pixmap;
264 }
265 
266 
267 // -----------------------------------------------------------------------------
268 KPixmap& KPixmapEffect::toGray(KPixmap &pixmap, bool fast)
269 {
270  TQImage img = pixmap.convertToImage();
271  KImageEffect::toGray(img, fast);
272  pixmap.convertFromImage(img);
273 
274  return pixmap;
275 }
276 
277 // -----------------------------------------------------------------------------
278 KPixmap& KPixmapEffect::desaturate(KPixmap &pixmap, float desat)
279 {
280  TQImage img = pixmap.convertToImage();
281  KImageEffect::desaturate(img, desat);
282  pixmap.convertFromImage(img);
283 
284  return pixmap;
285 }
286 // -----------------------------------------------------------------------------
287 KPixmap& KPixmapEffect::contrast(KPixmap &pixmap, int c)
288 {
289  TQImage img = pixmap.convertToImage();
290  KImageEffect::contrast(img, c);
291  pixmap.convertFromImage(img);
292 
293  return pixmap;
294 }
295 
296 //======================================================================
297 //
298 // Dither effects
299 //
300 //======================================================================
301 
302 // -----------------------------------------------------------------------------
303 KPixmap& KPixmapEffect::dither(KPixmap &pixmap, const TQColor *palette, int size)
304 {
305  TQImage img = pixmap.convertToImage();
306  KImageEffect::dither(img, palette, size);
307  pixmap.convertFromImage(img);
308 
309  return pixmap;
310 }
311 
312 //======================================================================
313 //
314 // Other effects
315 //
316 //======================================================================
317 
318 KPixmap KPixmapEffect::selectedPixmap( const KPixmap &pix, const TQColor &col )
319 {
320  TQImage img = pix.convertToImage();
321  KImageEffect::selectedImage(img, col);
322  KPixmap outPix;
323  outPix.convertFromImage(img);
324  return outPix;
325 }
KImageEffect::dither
static TQImage & dither(TQImage &image, const TQColor *palette, int size)
Dither an image using Floyd-Steinberg dithering for low-color situations.
Definition: kimageeffect.cpp:2261
KImageEffect::blend
static TQImage & blend(const TQColor &clr, TQImage &dst, float opacity)
Blends a color into the destination image, using an opacity value for blending one into another.
Definition: kimageeffect.cpp:1067
KImageEffect::channelIntensity
static TQImage & channelIntensity(TQImage &image, float percent, RGBComponent channel)
Modifies the intensity of a pixmap's RGB channel component.
Definition: kimageeffect.cpp:846
KImageEffect::fade
static TQImage & fade(TQImage &image, float val, const TQColor &color)
Fade an image to a certain background color.
Definition: kimageeffect.cpp:2044
KImageEffect::GradientType
GradientType
This enum provides a gradient type specification.
Definition: kimageeffect.h:58
KImageEffect::gradient
static TQImage gradient(const TQSize &size, const TQColor &ca, const TQColor &cb, GradientType type, int ncols=3)
Create a gradient from color a to color b of the specified type.
Definition: kimageeffect.cpp:124
KImageEffect::desaturate
static TQImage & desaturate(TQImage &image, float desat=0.3)
Desaturate an image evenly.
Definition: kimageeffect.cpp:2176
KImageEffect::flatten
static TQImage & flatten(TQImage &image, const TQColor &ca, const TQColor &cb, int ncols=0)
This recolors a pixmap.
Definition: kimageeffect.cpp:1947
KImageEffect::Lighting
Lighting
This enum provides a lighting direction specification.
Definition: kimageeffect.h:84
KImageEffect::toGray
static TQImage & toGray(TQImage &image, bool fast=false)
Convert an image to grayscale.
Definition: kimageeffect.cpp:2126
KImageEffect::contrast
static TQImage & contrast(TQImage &image, int c)
Fast, but low quality contrast of an image.
Definition: kimageeffect.cpp:2199
KImageEffect::RGBComponent
RGBComponent
This enum provides a RGB channel specification.
Definition: kimageeffect.h:73
KImageEffect::selectedImage
static TQImage & selectedImage(TQImage &img, const TQColor &col)
Calculate the image for a selected image, for instance a selected icon on the desktop.
Definition: kimageeffect.cpp:2705
KImageEffect::hash
static TQImage & hash(TQImage &image, Lighting lite=NorthLite, unsigned int spacing=0)
Build a hash on any given TQImage.
Definition: kimageeffect.cpp:1866
KImageEffect::intensity
static TQImage & intensity(TQImage &image, float percent)
Either brighten or dim the image by a specified percent.
Definition: kimageeffect.cpp:654
KImageEffect::unbalancedGradient
static TQImage unbalancedGradient(const TQSize &size, const TQColor &ca, const TQColor &cb, GradientType type, int xfactor=100, int yfactor=100, int ncols=3)
Create an unbalanced gradient.
Definition: kimageeffect.cpp:388
KPixmapEffect::fade
static KPixmap & fade(KPixmap &pixmap, double val, const TQColor &color)
Fades a pixmap to a certain color.
Definition: kpixmapeffect.cpp:257
KPixmapEffect::intensity
static KPixmap & intensity(KPixmap &pixmap, float ratio)
Either brightens or dims a pixmap by a specified ratio.
Definition: kpixmapeffect.cpp:109
KPixmapEffect::gradient
static KPixmap & gradient(KPixmap &pixmap, const TQColor &ca, const TQColor &cb, GradientType type, int ncols=3)
Creates a gradient from color a to color b of the specified type.
Definition: kpixmapeffect.cpp:24
KPixmapEffect::blend
static KPixmap & blend(KPixmap &pixmap, float initial_intensity, const TQColor &bgnd, GradientType eff, bool anti_dir=false, int ncols=3)
Blends the provided pixmap into a background of the indicated color.
Definition: kpixmapeffect.cpp:140
KPixmapEffect::pattern
static KPixmap pattern(const KPixmap &pixmap, TQSize size, const TQColor &ca, const TQColor &cb, int ncols=8)
Creates a pattern from a pixmap.
Definition: kpixmapeffect.cpp:223
KPixmapEffect::hash
static KPixmap & hash(KPixmap &pixmap, Lighting lite=NorthLite, unsigned int spacing=0, int ncols=3)
Builds a hash on any given pixmap.
Definition: kpixmapeffect.cpp:179
KPixmapEffect::selectedPixmap
static KPixmap selectedPixmap(const KPixmap &pixmap, const TQColor &col)
Calculate a 'selected' pixmap, for instance a selected icon on the desktop.
Definition: kpixmapeffect.cpp:318
KPixmapEffect::toGray
static KPixmap & toGray(KPixmap &pixmap, bool fast=false)
Converts a pixmap to grayscale.
Definition: kpixmapeffect.cpp:268
KPixmapEffect::dither
static KPixmap & dither(KPixmap &pixmap, const TQColor *palette, int size)
Dithers a pixmap using Floyd-Steinberg dithering for low-color situations.
Definition: kpixmapeffect.cpp:303
KPixmapEffect::desaturate
static KPixmap & desaturate(KPixmap &pixmap, float desat=0.3)
Desaturates a pixmap.
Definition: kpixmapeffect.cpp:278
KPixmapEffect::createTiled
static KPixmap createTiled(const KPixmap &pixmap, TQSize size)
Creates a pixmap of a given size with the given pixmap.
Definition: kpixmapeffect.cpp:240
KPixmapEffect::unbalancedGradient
static KPixmap & unbalancedGradient(KPixmap &pixmap, const TQColor &ca, const TQColor &cb, GradientType type, int xfactor=100, int yfactor=100, int ncols=3)
Creates an unbalanced gradient.
Definition: kpixmapeffect.cpp:88
KPixmapEffect::channelIntensity
static KPixmap & channelIntensity(KPixmap &pixmap, float ratio, RGBComponent channel)
Modifies the intensity of a pixmap's RGB channel component.
Definition: kpixmapeffect.cpp:121
KPixmapEffect::contrast
static KPixmap & contrast(KPixmap &pixmap, int c)
Modifies the contrast of a pixmap.
Definition: kpixmapeffect.cpp:287
KPixmap
Off-screen paint device with extended features.
Definition: kpixmap.h:58
KPixmap::convertFromImage
bool convertFromImage(const TQImage &img, int conversion_flags)
Converts an image and sets this pixmap.
Definition: kpixmap.cpp:223

tdefx

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

tdefx

Skip menu "tdefx"
  • 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 tdefx by doxygen 1.9.1
This website is maintained by Timothy Pearson.