Subversion Repositories Scribus

Rev

Rev 6438 | Details | Compare with Previous | Last modification | View Log | RSS feed

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