kwin Library API Documentation

misc.cpp

00001 /* Plastik KWin window decoration
00002   Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
00003 
00004   based on the window decoration "Web":
00005   Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; see the file COPYING.  If not, write to
00019   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020   Boston, MA 02111-1307, USA.
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     // normal button...
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() ); // set to the new color
00078             } else {
00079                 destImg.setPixel(x,y,qRgba(0,0,0,0) ); // set transparent...
00080             }
00081         }
00082     }
00083 
00084     return destImg;
00085 }
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Nov 4 00:48:56 2005 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003