Subversion Repositories Scribus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3107 subik 1
#ifndef COLORBLIND_H
2
#define COLORBLIND_H
3
 
4
#include <qvariant.h>
5
#include <qcolor.h>
6
#include <qobject.h>
7
 
8
/*! This code is an implementation of an algorithm described by Hans Brettel,
9
Francoise Vienot and John Mollon in the Journal of the Optical Society of
10
America V14(10), pg 2647. (See http://vischeck.com/ for more info.)
11
 
12
Based on the GIMP's cdisplay_colorblind.c
13
by Michael Natterer <mitch@gimp.org>, Sven Neumann <sven@gimp.org>,
14
Robert Dougherty <bob@vischeck.com> and Alex Wade <alex@vischeck.com>.
15
 
16
This code is written using "Scribus coding standard" as a part of the
17
Scribus project (www.scribus.net).
18
 
19
\author Petr Vanek <petr@yarpen.cz>
20
 
21
This program is free software; you can redistribute it and/or modify
22
it under the terms of the GNU General Public License as published by
23
the Free Software Foundation; either version 2 of the License, or
24
(at your option) any later version.
25
 
26
This program is distributed in the hope that it will be useful,
27
but WITHOUT ANY WARRANTY; without even the implied warranty of
28
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
GNU General Public License for more details.
30
 
31
You should have received a copy of the GNU General Public License
32
along with this program; if not, write to the Free Software
33
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34
*/
35
 
36
class VisionDefectColor : public QObject, public QColor
37
{
38
        Q_OBJECT
39
public:
40
        /*! Enumerate Vision Defects for readable ComboBox access */
41
        enum defectMode {
42
                normalVision = 0,
43
                protanopeVision = 1,
44
                deuteranopeVision = 2,
45
                tritanopeVision = 3,
46
                colorBlindnessVision = 4
47
        };
48
 
49
        /*! QColor like constructors. Setup the RGB parts, then init().
50
        \param r red part of the color
51
        \param g green part of the color
52
        \param b blue part of the color
53
        */
54
        VisionDefectColor(int r, int g, int b);
55
        /*! QColor like constructors. Setup the RGB parts, then init().
56
        \param c QColor object
57
         */
58
        VisionDefectColor(QColor c);
59
 
60
        /*! Actual defect type. One of the 'defectMode' */
61
        int deficiency;
62
 
63
        /*! Perform conversion itself.
64
        Gama removing, RGB2LSM, matrix operation for selected deficiency,
65
        LSM2RGB, gama applying. */
66
        void convertDefect();
67
 
68
        /*! Return the color parts
69
        \retval uint red part
70
        */
71
        uint getRed();
72
        /*! Return the color parts
73
        \retval uint green part
74
        */
75
        uint getGreen();
76
        /*! Return the color parts
77
        \retval uint blue part
78
        */
79
        uint getBlue();
80
        /*! Return QColor
81
        \retval QColor new QColor
82
        */
83
        QColor getColor();
84
 
85
private:
86
        /*! Convert matrix */
87
        double rgb2lms[9];
88
        /*! Convert matrix */
89
        double lms2rgb[9];
90
        /*! Gamma matrix */
91
        double gammaRGB[3];
92
 
93
        /*! cross products with transform matrixes for actual defect */
94
        double a1, b1, c1;
95
        /*! cross products with transform matrixes for actual defect */
96
        double a2, b2, c2;
97
        /*! Inflection border line */
98
        double inflection;
99
 
100
        /*! Internal RGB color parts */
101
        double red, green, blue;
102
 
103
        /*! original color */
104
        QColor originalColor;
105
 
106
        /*! Initialization of the internal values. rgb2lms, lms2rgb etc.
107
        For most modern Cathode-Ray Tube monitors (CRTs), the following
108
        are good estimates of the RGB->LMS and LMS->RGB transform
109
        matrices.  They are based on spectra measured on a typical CRT
110
        with a PhotoResearch PR650 spectral photometer and the Stockman
111
        human cone fundamentals. NOTE: these estimates will NOT work well
112
        for LCDs!
113
        The RGB<->LMS transforms are computed from the human cone
114
        photo-pigment absorption spectra and the monitor phosphor
115
        emission spectra. These parameters are fairly constant for most
116
        humans and most montiors (at least for modern CRTs). However,
117
        gamma will vary quite a bit, as it is a property of the monitor
118
        (eg. amplifier gain), the video card, and even the
119
        software. Further, users can adjust their gammas (either via
120
        adjusting the monitor amp gains or in software). That said, the
121
        following are the gamma estimates that we have used in the
122
        Vischeck code. Many colorblind users have viewed our simulations
123
        and told us that they "work" (simulated and original images are
124
        indistinguishabled).
125
        */
126
        void init();
127
 
128
        /*! This function performs initialisations that are dependant
129
        on the type of color deficiency (see defectMode). */
130
        void setupDefect();
131
 
132
        /*! Ensures that x is between the limits set by low and high.
133
        Glib CLAMP() macro replacement for C++ speedup optimalization.
134
        \param x value itself
135
        \param low low border
136
        \param high high border
137
        \retval double value from interval
138
        */
139
        double clamp(double x, double low, double high);
140
 
141
};
142
 
143
#endif