diff options
-rw-r--r-- | kdecore/kiconloader.cpp | 5 | ||||
-rw-r--r-- | kdefx/kimageeffect.cpp | 37 | ||||
-rw-r--r-- | kdefx/kimageeffect.h | 10 |
3 files changed, 51 insertions, 1 deletions
diff --git a/kdecore/kiconloader.cpp b/kdecore/kiconloader.cpp index bd1ad3a91..62950e5d8 100644 --- a/kdecore/kiconloader.cpp +++ b/kdecore/kiconloader.cpp @@ -51,6 +51,8 @@ #include "svgicons/ksvgiconpainter.h" #endif +#include <kimageeffect.h> + #include "kiconloader_p.h" /*** KIconThemeNode: A node in the icon theme dependancy tree. ***/ @@ -855,7 +857,8 @@ TQPixmap KIconLoader::loadIcon(const TQString& _name, KIcon::Group group, int si } } - pix.convertFromImage(*img); + if (TQPaintDevice::x11AppDepth() == 32) pix.convertFromImage(KImageEffect::convertToPremultipliedAlpha( *img )); + else pix.convertFromImage(*img); delete img; diff --git a/kdefx/kimageeffect.cpp b/kdefx/kimageeffect.cpp index 4864bdfa6..8fac1f5cb 100644 --- a/kdefx/kimageeffect.cpp +++ b/kdefx/kimageeffect.cpp @@ -4937,3 +4937,40 @@ TQImage KImageEffect::bumpmap(TQImage &img, TQImage &map, double azimuth, double } return dst; } + +/** + * Convert an image with standard alpha to premultiplied alpha + * + * @param img the image you want convert + * + * @return The destination image (dst) containing the result. + * @author Timothy Pearson <kb9vqf@pearsoncomputing.net> + */ +TQImage KImageEffect::convertToPremultipliedAlpha(TQImage input) { + TQImage alphaImage = input; + if (!alphaImage.isNull()) alphaImage = alphaImage.convertDepth( 32 ); + + int w = alphaImage.width(); + int h = alphaImage.height(); + + register int r; + register int g; + register int b; + register int a; + register float alpha_adjust; + register TQRgb l; + TQRgb *ls; + for (int y = 0; y < h; ++y) { + ls = (TQRgb *)alphaImage.scanLine( y ); + for (int x = 0; x < w; ++x) { + l = ls[x]; + alpha_adjust = (tqAlpha( l )/255.0); + r = int( tqRed( l ) * alpha_adjust ); + g = int( tqGreen( l ) * alpha_adjust ); + b = int( tqBlue( l ) * alpha_adjust ); + a = int( tqAlpha( l ) * 1.0 ); + ls[x] = tqRgba( r, g, b, a ); + } + } + return alphaImage; +}
\ No newline at end of file diff --git a/kdefx/kimageeffect.h b/kdefx/kimageeffect.h index 155df71b1..8d73e5bfb 100644 --- a/kdefx/kimageeffect.h +++ b/kdefx/kimageeffect.h @@ -773,6 +773,16 @@ public: int ambient, bool compensate, bool invert, BumpmapType type, bool tiled); + /** + * Convert an image with standard alpha to premultiplied alpha + * + * @param img the image you want convert + * + * @return The destination image (dst) containing the result. + * @author Timothy Pearson <kb9vqf@pearsoncomputing.net> + */ + static TQImage convertToPremultipliedAlpha(TQImage input); + private: /** |