Subversion Repositories Scribus

Rev

Rev 4430 | 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
 
6438 subik 66
        /*! \brief Actual defect type. One of the 'defectMode' */
3107 subik 67
        int deficiency;
68
 
6438 subik 69
        /*! \brief Perform conversion itself.
3107 subik 70
        Gama removing, RGB2LSM, matrix operation for selected deficiency,
71
        LSM2RGB, gama applying. */
72
        void convertDefect();
73
 
6438 subik 74
        /*! \brief Return the color parts
3107 subik 75
        \retval uint red part
76
        */
77
        uint getRed();
6438 subik 78
        /*! \brief Return the color parts
3107 subik 79
        \retval uint green part
80
        */
81
        uint getGreen();
6438 subik 82
        /*! \brief Return the color parts
3107 subik 83
        \retval uint blue part
84
        */
85
        uint getBlue();
6438 subik 86
        /*! \brief Return QColor
3107 subik 87
        \retval QColor new QColor
88
        */
89
        QColor getColor();
90
 
91
private:
6438 subik 92
        /*! \brief Convert matrix */
3107 subik 93
        double rgb2lms[9];
6438 subik 94
        /*! \brief Convert matrix */
3107 subik 95
        double lms2rgb[9];
6438 subik 96
        /*! \brief Gamma matrix */
3107 subik 97
        double gammaRGB[3];
98
 
6438 subik 99
        /*! \brief cross products with transform matrixes for actual defect */
3107 subik 100
        double a1, b1, c1;
6438 subik 101
        /*! \brief cross products with transform matrixes for actual defect */
3107 subik 102
        double a2, b2, c2;
6438 subik 103
        /*! \brief Inflection border line */
3107 subik 104
        double inflection;
105
 
6438 subik 106
        /*! \brief Internal RGB color parts */
3107 subik 107
        double red, green, blue;
108
 
6438 subik 109
        /*! \brief original color */
3107 subik 110
        QColor originalColor;
111
 
6438 subik 112
        /*! \brief Initialization of the internal values. rgb2lms, lms2rgb etc.
3107 subik 113
        For most modern Cathode-Ray Tube monitors (CRTs), the following
114
        are good estimates of the RGB->LMS and LMS->RGB transform
115
        matrices.  They are based on spectra measured on a typical CRT
116
        with a PhotoResearch PR650 spectral photometer and the Stockman
117
        human cone fundamentals. NOTE: these estimates will NOT work well
118
        for LCDs!
119
        The RGB<->LMS transforms are computed from the human cone
120
        photo-pigment absorption spectra and the monitor phosphor
121
        emission spectra. These parameters are fairly constant for most
122
        humans and most montiors (at least for modern CRTs). However,
123
        gamma will vary quite a bit, as it is a property of the monitor
124
        (eg. amplifier gain), the video card, and even the
125
        software. Further, users can adjust their gammas (either via
126
        adjusting the monitor amp gains or in software). That said, the
127
        following are the gamma estimates that we have used in the
128
        Vischeck code. Many colorblind users have viewed our simulations
129
        and told us that they "work" (simulated and original images are
130
        indistinguishabled).
131
        */
132
        void init();
133
 
6438 subik 134
        /*! \brief This function performs initialisations that are dependant
3107 subik 135
        on the type of color deficiency (see defectMode). */
136
        void setupDefect();
137
 
6438 subik 138
        /*! \brief Ensures that x is between the limits set by low and high.
3107 subik 139
        Glib CLAMP() macro replacement for C++ speedup optimalization.
140
        \param x value itself
141
        \param low low border
142
        \param high high border
143
        \retval double value from interval
144
        */
145
        double clamp(double x, double low, double high);
146
 
147
};
148
 
149
#endif