[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Are there accessible color manipulation functions in kdelibs?
From:       Matthew Woehlke <mw_triad () users ! sourceforge ! net>
Date:       2006-12-01 17:06:49
Message-ID: ekpnfa$4ff$1 () sea ! gmane ! org
[Download RAW message or body]

I'm wondering if the following functions or equivalents exist somewhere 
in either kdebase or kdelibs (my guess would be kdefx). If not, can they 
be added? I am sure some of these must already exist in at least private 
implementations...

====
QColor blendRGB(const QColor& c1, const QColor& c2, double k,
                 bool trunc=true)
QColor blendHSV(const QColor& c1, const QColor& c2, double k,
                 bool trunc=true)
QColor blendHLS(const QColor& c1, const QColor& c2, double k,
                 bool trunc=true)
-
Blends between two colors in the specified color space. 'k' is the blend 
factor, e.g. k=0 gives c1, k=1 gives c2. If 'trunc' is false, allow 
values < 0 or > 1 (otherwise clamp to [0, 1]), e.g. blendRGB(Qt::gray, 
Qt::white, -1, false) gives Qt::black, blendHSV(Qt::red, Qt::green, 2.0, 
false) gives Qt::blue, etc.). If either color is Qt::white or Qt::black, 
then HLS/HSV treat it as having H and S equal to the other color.

====
double blend(double a, double b, double k)
-
Blends between two values, i.e. 'return a*(1.0-k) + b*k;'. Used 
internally by the above, or useful to

====
void toHLS(const QColor& c, int& h, int&l, int&s, bool true_luma=false)
QColor fromHLS(int h, int l, int s, bool true_luma=false)
-
Convert to/from HLS space (different from HSV space; L=1 means white). 
If 'true_luma' is true, use 'real' values for L to give pure colors, 
instead of 0.5 so that the 'true gray value' of any given HLS is equal to L.

====
QColor darken(const QColor& c, double k)
QColor lighten(const QColor& c, double k)
-
Similar to blendHLS(c, base, k, false) where base is Qt::black (darken) 
or Qt::white (lighten). So k=0 gives c, k=1 gives base, k=0.5 gives a 
color halfway between c and base in HLS space (H,S unaltered), k=-1 
gives a color twice as far from base as c in HLS space, etc.


...and the above should probably all have Qrgba versions as well.

I've used these in a style I wrote, have seen similar implementations 
elsewhere (in fact, I adapted my toHLS/fromHLS from qt-style-bluecurve), 
and just copied them into part of KDevelop. For KDE4 it seems like it 
would be nice for these to be available in a central spot.

-- 
Matthew
This message includes NO WARRANTY, not even the implied warranties of 
READABILITY or RELEVANCE TO A PARTICULAR TOPIC. Read at your own risk. ;-)

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic