You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
326 lines
8.9 KiB
326 lines
8.9 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
|
||
|
(C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
|
||
|
(C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
|
||
|
|
||
|
*/
|
||
|
|
||
|
// $Id$
|
||
|
|
||
14 years ago
|
#include <tqimage.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include "kpixmapeffect.h"
|
||
|
#include "kpixmap.h"
|
||
|
#include "kimageeffect.h"
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Gradient effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
|
||
14 years ago
|
KPixmap& KPixmapEffect::gradient(KPixmap &pixmap, const TQColor &ca,
|
||
|
const TQColor &cb, GradientType eff, int ncols)
|
||
15 years ago
|
{
|
||
|
if(pixmap.depth() > 8 &&
|
||
|
(eff == VerticalGradient || eff == HorizontalGradient)) {
|
||
|
|
||
|
int rDiff, gDiff, bDiff;
|
||
|
int rca, gca, bca /*, rcb, gcb, bcb*/;
|
||
|
|
||
|
register int x, y;
|
||
|
|
||
|
rDiff = (/*rcb = */ cb.red()) - (rca = ca.red());
|
||
|
gDiff = (/*gcb = */ cb.green()) - (gca = ca.green());
|
||
|
bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue());
|
||
|
|
||
|
register int rl = rca << 16;
|
||
|
register int gl = gca << 16;
|
||
|
register int bl = bca << 16;
|
||
|
|
||
|
int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff;
|
||
|
int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff;
|
||
|
int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff;
|
||
|
|
||
14 years ago
|
TQPainter p(&pixmap);
|
||
15 years ago
|
|
||
|
// these for-loops could be merged, but the if's in the inner loop
|
||
|
// would make it slow
|
||
|
switch(eff) {
|
||
|
case VerticalGradient:
|
||
|
for ( y = 0; y < pixmap.height(); y++ ) {
|
||
|
rl += rcdelta;
|
||
|
gl += gcdelta;
|
||
|
bl += bcdelta;
|
||
|
|
||
14 years ago
|
p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
|
||
15 years ago
|
p.drawLine(0, y, pixmap.width()-1, y);
|
||
|
}
|
||
|
break;
|
||
|
case HorizontalGradient:
|
||
|
for( x = 0; x < pixmap.width(); x++) {
|
||
|
rl += rcdelta;
|
||
|
gl += gcdelta;
|
||
|
bl += bcdelta;
|
||
|
|
||
14 years ago
|
p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
|
||
15 years ago
|
p.drawLine(x, 0, x, pixmap.height()-1);
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
TQImage image = KImageEffect::gradient(pixmap.size(), ca, cb,
|
||
15 years ago
|
(KImageEffect::GradientType) eff, ncols);
|
||
|
pixmap.convertFromImage(image);
|
||
|
}
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
|
||
14 years ago
|
KPixmap& KPixmapEffect::unbalancedGradient(KPixmap &pixmap, const TQColor &ca,
|
||
|
const TQColor &cb, GradientType eff, int xfactor, int yfactor,
|
||
15 years ago
|
int ncols)
|
||
|
{
|
||
14 years ago
|
TQImage image = KImageEffect::unbalancedGradient(pixmap.size(), ca, cb,
|
||
15 years ago
|
(KImageEffect::GradientType) eff,
|
||
|
xfactor, yfactor, ncols);
|
||
|
pixmap.convertFromImage(image);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Intensity effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
|
||
|
|
||
|
KPixmap& KPixmapEffect::intensity(KPixmap &pixmap, float percent)
|
||
|
{
|
||
14 years ago
|
TQImage image = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::intensity(image, percent);
|
||
|
pixmap.convertFromImage(image);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
|
||
|
KPixmap& KPixmapEffect::channelIntensity(KPixmap &pixmap, float percent,
|
||
|
RGBComponent channel)
|
||
|
{
|
||
14 years ago
|
TQImage image = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::channelIntensity(image, percent,
|
||
|
(KImageEffect::RGBComponent) channel);
|
||
|
pixmap.convertFromImage(image);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Blend effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
|
||
|
KPixmap& KPixmapEffect::blend(KPixmap &pixmap, float initial_intensity,
|
||
14 years ago
|
const TQColor &bgnd, GradientType eff,
|
||
15 years ago
|
bool anti_dir, int ncols)
|
||
|
{
|
||
|
|
||
14 years ago
|
TQImage image = pixmap.convertToImage();
|
||
15 years ago
|
if (image.depth() <=8)
|
||
|
image = image.convertDepth(32); //Sloww..
|
||
|
|
||
|
KImageEffect::blend(image, initial_intensity, bgnd,
|
||
|
(KImageEffect::GradientType) eff, anti_dir);
|
||
|
|
||
|
unsigned int tmp;
|
||
|
|
||
|
if(pixmap.depth() <= 8 ) {
|
||
|
if ( ncols < 2 || ncols > 256 )
|
||
|
ncols = 3;
|
||
14 years ago
|
TQColor *dPal = new TQColor[ncols];
|
||
15 years ago
|
for (int i=0; i<ncols; i++) {
|
||
|
tmp = 0 + 255 * i / ( ncols - 1 );
|
||
|
dPal[i].setRgb ( tmp, tmp, tmp );
|
||
|
}
|
||
|
KImageEffect::dither(image, dPal, ncols);
|
||
|
pixmap.convertFromImage(image);
|
||
|
delete [] dPal;
|
||
|
}
|
||
|
else
|
||
|
pixmap.convertFromImage(image);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Hash effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
KPixmap& KPixmapEffect::hash(KPixmap &pixmap, Lighting lite,
|
||
|
unsigned int spacing, int ncols)
|
||
|
{
|
||
14 years ago
|
TQImage image = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::hash(image, (KImageEffect::Lighting) lite, spacing);
|
||
|
|
||
|
unsigned int tmp;
|
||
|
|
||
|
if(pixmap.depth() <= 8 ) {
|
||
|
if ( ncols < 2 || ncols > 256 )
|
||
|
ncols = 3;
|
||
14 years ago
|
TQColor *dPal = new TQColor[ncols];
|
||
15 years ago
|
for (int i=0; i<ncols; i++) {
|
||
|
tmp = 0 + 255 * i / ( ncols - 1 );
|
||
|
dPal[i].setRgb ( tmp, tmp, tmp );
|
||
|
}
|
||
|
KImageEffect::dither(image, dPal, ncols);
|
||
|
pixmap.convertFromImage(image);
|
||
|
delete [] dPal;
|
||
|
}
|
||
|
else
|
||
|
pixmap.convertFromImage(image);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Pattern effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
#if 0
|
||
14 years ago
|
void KPixmapEffect::pattern(KPixmap &pixmap, const TQColor &ca,
|
||
|
const TQColor &cb, unsigned pat[8])
|
||
15 years ago
|
{
|
||
14 years ago
|
TQImage img = pattern(pixmap.size(), ca, cb, pat);
|
||
15 years ago
|
pixmap.convertFromImage(img);
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
|
||
14 years ago
|
KPixmap KPixmapEffect::pattern(const KPixmap& pmtile, TQSize size,
|
||
|
const TQColor &ca, const TQColor &cb, int ncols)
|
||
15 years ago
|
{
|
||
|
if (pmtile.depth() > 8)
|
||
|
ncols = 0;
|
||
|
|
||
14 years ago
|
TQImage img = pmtile.convertToImage();
|
||
15 years ago
|
KImageEffect::flatten(img, ca, cb, ncols);
|
||
|
KPixmap pixmap;
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return KPixmapEffect::createTiled(pixmap, size);
|
||
|
}
|
||
|
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
|
||
14 years ago
|
KPixmap KPixmapEffect::createTiled(const KPixmap& pixmap, TQSize size)
|
||
15 years ago
|
{
|
||
|
KPixmap pix(size);
|
||
|
|
||
14 years ago
|
TQPainter p(&pix);
|
||
15 years ago
|
p.drawTiledPixmap(0, 0, size.width(), size.height(), pixmap);
|
||
|
|
||
|
return pix;
|
||
|
}
|
||
|
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Fade effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
14 years ago
|
KPixmap& KPixmapEffect::fade(KPixmap &pixmap, double val, const TQColor &color)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQImage img = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::fade(img, val, color);
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
KPixmap& KPixmapEffect::toGray(KPixmap &pixmap, bool fast)
|
||
|
{
|
||
14 years ago
|
TQImage img = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::toGray(img, fast);
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
|
KPixmap& KPixmapEffect::desaturate(KPixmap &pixmap, float desat)
|
||
|
{
|
||
14 years ago
|
TQImage img = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::desaturate(img, desat);
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
// -----------------------------------------------------------------------------
|
||
|
KPixmap& KPixmapEffect::contrast(KPixmap &pixmap, int c)
|
||
|
{
|
||
14 years ago
|
TQImage img = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::contrast(img, c);
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Dither effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
|
// -----------------------------------------------------------------------------
|
||
14 years ago
|
KPixmap& KPixmapEffect::dither(KPixmap &pixmap, const TQColor *palette, int size)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQImage img = pixmap.convertToImage();
|
||
15 years ago
|
KImageEffect::dither(img, palette, size);
|
||
|
pixmap.convertFromImage(img);
|
||
|
|
||
|
return pixmap;
|
||
|
}
|
||
|
|
||
|
//======================================================================
|
||
|
//
|
||
|
// Other effects
|
||
|
//
|
||
|
//======================================================================
|
||
|
|
||
14 years ago
|
KPixmap KPixmapEffect::selectedPixmap( const KPixmap &pix, const TQColor &col )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQImage img = pix.convertToImage();
|
||
15 years ago
|
KImageEffect::selectedImage(img, col);
|
||
|
KPixmap outPix;
|
||
|
outPix.convertFromImage(img);
|
||
|
return outPix;
|
||
|
}
|