misc.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <kpixmap.h>
00024 #include <kpixmapeffect.h>
00025
00026 #include <qcolor.h>
00027 #include <qimage.h>
00028 #include <qpainter.h>
00029
00030 #include "misc.h"
00031
00032 QColor hsvRelative(QColor& baseColor, int relativeH, int relativeS, int relativeV)
00033 {
00034 int h, s, v;
00035 baseColor.hsv(&h, &s, &v);
00036
00037 h += relativeH;
00038 s += relativeS;
00039 v += relativeV;
00040
00041 if(h < 0) { h = 0; }
00042 else if(h > 359) { h = 359; }
00043 if(s < 0) { s = 0; }
00044 else if(s > 255) { s = 255; }
00045 if(v < 0) { v = 0; }
00046 else if(v > 255) { v = 255; }
00047
00048 QColor c;
00049 c.setHsv( h, s, v );
00050 return c;
00051 }
00052
00053 QColor alphaBlendColors(const QColor &bgColor, const QColor &fgColor, const int a)
00054 {
00055
00056
00057 QRgb rgb = bgColor.rgb();
00058 QRgb rgb_b = fgColor.rgb();
00059 int alpha = a;
00060 if(alpha>255) alpha = 255;
00061 if(alpha<0) alpha = 0;
00062 int inv_alpha = 255 - alpha;
00063
00064 QColor result = QColor( qRgb(qRed(rgb_b)*inv_alpha/255 + qRed(rgb)*alpha/255,
00065 qGreen(rgb_b)*inv_alpha/255 + qGreen(rgb)*alpha/255,
00066 qBlue(rgb_b)*inv_alpha/255 + qBlue(rgb)*alpha/255) );
00067
00068 return result;
00069 }
00070
00071 QImage recolorImage(QImage *img, QColor color) {
00072 QImage destImg(img->width(),img->height(),32);
00073 destImg.setAlphaBuffer(true);
00074 for (int x = 0; x < img->width(); x++) {
00075 for (int y = 0; y < img->height(); y++) {
00076 if(img->pixel(x,y) == qRgb(0,0,255) ) {
00077 destImg.setPixel(x,y,color.rgb() );
00078 } else {
00079 destImg.setPixel(x,y,qRgba(0,0,0,0) );
00080 }
00081 }
00082 }
00083
00084 return destImg;
00085 }
This file is part of the documentation for kwin Library Version 3.4.3.