author | sandman <sandman> | 2002-06-24 17:07:45 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-24 17:07:45 (UTC) |
commit | f284f40fe5912736666a56143705f260d14feb34 (patch) (side-by-side diff) | |
tree | 2aa6dee5e26aaeffc3505ca0c536651bce09cfe6 /noncore/styles/liquid/effects.cpp | |
parent | db5385bc16f56b4c5b84ad4a92ac6bdd46eea321 (diff) | |
download | opie-f284f40fe5912736666a56143705f260d14feb34.zip opie-f284f40fe5912736666a56143705f260d14feb34.tar.gz opie-f284f40fe5912736666a56143705f260d14feb34.tar.bz2 |
Inital checkin of liquid style for OPIE
Diffstat (limited to 'noncore/styles/liquid/effects.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/styles/liquid/effects.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/noncore/styles/liquid/effects.cpp b/noncore/styles/liquid/effects.cpp new file mode 100644 index 0000000..0c76fbc --- a/dev/null +++ b/noncore/styles/liquid/effects.cpp @@ -0,0 +1,118 @@ + +#include <qimage.h> +#include <qpixmap.h> +#include <qcolor.h> + +#include "effects.h" + + + +QImage & QImageEffect::fade (QImage & img, float val, const QColor & color) +{ + if ( img. width ( ) == 0 || img. height ( ) == 0 ) + return img; + +// We don't handle bitmaps + if (img.depth () == 1) + return img; + + unsigned char + tbl[256]; + for (int i = 0; i < 256; i++) + tbl[i] = (int) (val * i + 0.5); + + int + red = + color. + red (); + int + green = + color. + green (); + int + blue = + color. + blue (); + + QRgb col; + int + r, + g, + b, + cr, + cg, + cb; + + if (img.depth () <= 8) + { + // pseudo color + for (int i = 0; i < img.numColors (); i++) + { + col = img.color (i); + cr = qRed (col); + cg = qGreen (col); + cb=qBlue(col); + if (cr > red) + r = cr - tbl[cr - red]; + + else + r = cr + tbl[red - cr]; + if (cg > green) + g = cg - tbl[cg - green]; + + else + g = cg + tbl[green - cg]; + if (cb > blue) + b = cb - tbl[cb - blue]; + + else + b = cb + tbl[blue - cb]; + img.setColor (i, qRgb (r, g, b)); + } + + } + else + { + // truecolor + for (int y = 0; y < img.height (); y++) + { + QRgb * data = (QRgb *) img.scanLine (y); + for (int x = 0; x < img.width (); x++) + { + col = *data; + cr = qRed (col); +cg=qGreen(col); +cb=qBlue(col); + if (cr > red) + r = cr - tbl[cr - red]; + + else + r = cr + tbl[red - cr]; + if (cg > green) + g = cg - tbl[cg - green]; + + else + g = cg + tbl[green - cg]; + if (cb > blue) + b = cb - tbl[cb - blue]; + + else + b = cb + tbl[blue - cb]; + *data++ = qRgb (r, g, b); + } + } + } + + return img; +} + + + +QPixmap& QPixmapEffect::fade(QPixmap &pixmap, float val, const QColor &color) +{ + QImage img = pixmap.convertToImage(); + QImageEffect::fade(img, val, color); + pixmap.convertFromImage(img); + + return pixmap; +} |