summaryrefslogtreecommitdiffstats
path: root/amarok/src/colorgenerator.h
blob: 1ca9e0a7217196dc8f4a21adc7cd1f2c8d47fcca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***************************************************************************
    copyright            : (C) 2004 by amarok squad
    email                : amarok@kde.org
 ***************************************************************************/

/***************************************************************************
 *   This library is free software; you can redistribute it and/or modify  *
 *   it  under the terms of the GNU Lesser General Public License version  *
 *   2.1 as published by the Free Software Foundation.                     *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA  02110-1301  *
 *   USA                                                                   *
 ***************************************************************************/

#ifndef COLORGENERATOR_H
#define COLORGENERATOR_H

#include "debug.h"

namespace Amarok {


class Color : public TQColor
{
    static const int CONTRAST = 130;
    static const int SATURATION_TARGET = 30;

public:
    Color( const TQColor &c ) : TQColor( c )
    {
        DEBUG_BLOCK

        int h,s1,s,v1,v;
        getHsv( &h, &s1, &v1 );

        debug() << "Initial Color Properties: s:" << s1 << " v:" << v1 << endl;

        //we want the new colour to be low saturation
        //TODO what if s is less than SATURATION_TARGET to start with
        s = s1 - CONTRAST;
        v = v1;

        if ( s < SATURATION_TARGET ) {
            int remainingContrast = SATURATION_TARGET - s;
            s = SATURATION_TARGET;

            debug() << "Unapplied Contrast: " << remainingContrast << endl;

            //we only add to the value to avoid the dreaded "grey-gradient"
            v += remainingContrast;

            if ( v > 255 ) {
                int error = v - 255;
                debug() << "Over-compensation: " << error << endl;

                //if the error is significant then this must be a pretty bright colour
                //it would look better if the gradient was dark
                if( error > CONTRAST/2 )
                    v = v1 - error;
                else
                    v = 255;
            }
        }

        setHsv( h, s, v );

        debug() << "Final Colour Properties: s:" << s << " v:" << v << endl;
    }
};

}

#endif