summaryrefslogtreecommitdiffstats
path: root/chalk/chalkcolor/kis_color.h
blob: b7646586e357870543339ba4fafb02f6e9d9b04e (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
82
83
84
85
86
87
88
89
90
/*
 *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#ifndef _KIS_COLOR_H_
#define _KIS_COLOR_H_

#include <tqcolor.h>
#include "ksharedptr.h"

#include "kis_global.h"
#include "kis_profile.h"
#include "kis_colorspace.h"


/**
 * A KisColor describes a color in a certain colorspace.
 *
 */
class KisColor {

public:
    /// Create an empty KisColor. It will be valid, but also black and transparent
    KisColor();

    virtual ~KisColor();

    /// Create a KisColor from a TQColor. The TQColor is immediately converted to native. The TQColor
    /// is assumed to have the current monitor profile.
    KisColor(const TQColor & color, KisColorSpace * colorSpace);

    /// Create a KisColor from a TQColor. The TQColor is immediately converted to native. The TQColor
    /// is assumed to have the current monitor profile.
    KisColor(const TQColor & color, TQ_UINT8 alpha, KisColorSpace * colorSpace);

    /// Create a KisColor using a native color strategy. The data is copied.
    KisColor(const TQ_UINT8 * data, KisColorSpace * colorSpace);

    /// Create a KisColor by converting src into another colorspace
    KisColor(const KisColor &src, KisColorSpace * colorSpace);

    /// Copy constructor -- deep copies the colors.
    KisColor(const KisColor & rhs);

    /// Effective C++, item 11
    KisColor &operator=(const KisColor &);

    /// For easy memcpy'ing etc.
    TQ_UINT8 * data() const { return m_data; }

    KisColorSpace * colorSpace() const { return m_colorSpace; }

    KisProfile *  profile() const { return m_colorSpace->getProfile(); }

    /// Convert this KisColor to the specified colorspace. If the specified colorspace is the
    /// same as the original colorspace, do nothing. Returns the converted KisColor.
    void convertTo(KisColorSpace * cs);

    /// Replace the existing color data, and colorspace with the specified data.
    void setColor(TQ_UINT8 * data, KisColorSpace * colorSpace = 0);

    /// To save the user the trouble of doing color->colorSpace()->toTQColor(color->data(), &c, &a
    void toTQColor(TQColor *c) const;
    void toTQColor(TQColor *c, TQ_UINT8 *opacity) const;

    TQColor toTQColor() const;

    void dump() const;

private:

    TQ_UINT8 * m_data;

    KisColorSpace * m_colorSpace;
};

#endif