Subversion Repositories Scribus

Rev

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