Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 3107 → Rev 3104

/branches/Version13x/Scribus/scribus/plugins/colorwheel/colorblind.cpp
File deleted
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/plugins/colorwheel/colorblind.h
===================================================================
--- Scribus/scribus/plugins/colorwheel/colorblind.h (revision 3107)
+++ Scribus/scribus/plugins/colorwheel/colorblind.h (nonexistent)
@@ -1,143 +0,0 @@
-#ifndef COLORBLIND_H
-#define COLORBLIND_H
-
-#include <qvariant.h>
-#include <qcolor.h>
-#include <qobject.h>
-
-/*! This code is an implementation of an algorithm described by Hans Brettel,
-Francoise Vienot and John Mollon in the Journal of the Optical Society of
-America V14(10), pg 2647. (See http://vischeck.com/ for more info.)
-
-Based on the GIMP's cdisplay_colorblind.c
-by Michael Natterer <mitch@gimp.org>, Sven Neumann <sven@gimp.org>,
-Robert Dougherty <bob@vischeck.com> and Alex Wade <alex@vischeck.com>.
-
-This code is written using "Scribus coding standard" as a part of the
-Scribus project (www.scribus.net).
-
-\author Petr Vanek <petr@yarpen.cz>
-
-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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-class VisionDefectColor : public QObject, public QColor
-{
- Q_OBJECT
-public:
- /*! Enumerate Vision Defects for readable ComboBox access */
- enum defectMode {
- normalVision = 0,
- protanopeVision = 1,
- deuteranopeVision = 2,
- tritanopeVision = 3,
- colorBlindnessVision = 4
- };
-
- /*! QColor like constructors. Setup the RGB parts, then init().
- \param r red part of the color
- \param g green part of the color
- \param b blue part of the color
- */
- VisionDefectColor(int r, int g, int b);
- /*! QColor like constructors. Setup the RGB parts, then init().
- \param c QColor object
- */
- VisionDefectColor(QColor c);
-
- /*! Actual defect type. One of the 'defectMode' */
- int deficiency;
-
- /*! Perform conversion itself.
- Gama removing, RGB2LSM, matrix operation for selected deficiency,
- LSM2RGB, gama applying. */
- void convertDefect();
-
- /*! Return the color parts
- \retval uint red part
- */
- uint getRed();
- /*! Return the color parts
- \retval uint green part
- */
- uint getGreen();
- /*! Return the color parts
- \retval uint blue part
- */
- uint getBlue();
- /*! Return QColor
- \retval QColor new QColor
- */
- QColor getColor();
-
-private:
- /*! Convert matrix */
- double rgb2lms[9];
- /*! Convert matrix */
- double lms2rgb[9];
- /*! Gamma matrix */
- double gammaRGB[3];
-
- /*! cross products with transform matrixes for actual defect */
- double a1, b1, c1;
- /*! cross products with transform matrixes for actual defect */
- double a2, b2, c2;
- /*! Inflection border line */
- double inflection;
-
- /*! Internal RGB color parts */
- double red, green, blue;
-
- /*! original color */
- QColor originalColor;
-
- /*! Initialization of the internal values. rgb2lms, lms2rgb etc.
- For most modern Cathode-Ray Tube monitors (CRTs), the following
- are good estimates of the RGB->LMS and LMS->RGB transform
- matrices. They are based on spectra measured on a typical CRT
- with a PhotoResearch PR650 spectral photometer and the Stockman
- human cone fundamentals. NOTE: these estimates will NOT work well
- for LCDs!
- The RGB<->LMS transforms are computed from the human cone
- photo-pigment absorption spectra and the monitor phosphor
- emission spectra. These parameters are fairly constant for most
- humans and most montiors (at least for modern CRTs). However,
- gamma will vary quite a bit, as it is a property of the monitor
- (eg. amplifier gain), the video card, and even the
- software. Further, users can adjust their gammas (either via
- adjusting the monitor amp gains or in software). That said, the
- following are the gamma estimates that we have used in the
- Vischeck code. Many colorblind users have viewed our simulations
- and told us that they "work" (simulated and original images are
- indistinguishabled).
- */
- void init();
-
- /*! This function performs initialisations that are dependant
- on the type of color deficiency (see defectMode). */
- void setupDefect();
-
- /*! Ensures that x is between the limits set by low and high.
- Glib CLAMP() macro replacement for C++ speedup optimalization.
- \param x value itself
- \param low low border
- \param high high border
- \retval double value from interval
- */
- double clamp(double x, double low, double high);
-
-};
-
-#endif
/Scribus/scribus/plugins/colorwheel/colorblind.h
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/plugins/colorwheel/cwdialog.cpp
===================================================================
--- Scribus/scribus/plugins/colorwheel/cwdialog.cpp (revision 3107)
+++ Scribus/scribus/plugins/colorwheel/cwdialog.cpp (revision 3104)
@@ -16,9 +16,7 @@
#include "prefsmanager.h"
#include "prefsfile.h"
#include "mpalette.h"
-#include "colorblind.h"
-
extern ScribusApp SCRIBUS_API *ScApp;
ColorWheelDialog::ColorWheelDialog(QWidget* parent, const char* name, bool modal, WFlags fl)
@@ -100,9 +98,8 @@
typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Tetradic), colorWheel->Tetradic);
// defects
defectCombo->insertItem(tr("Normal Vision"));
- defectCombo->insertItem(tr("Protanopia (red)"));
- defectCombo->insertItem(tr("Deuteranopia (green)"));
- defectCombo->insertItem(tr("Tritanopia (blue)"));
+ defectCombo->insertItem(tr("Protanopy"));
+ defectCombo->insertItem(tr("Deuteranopy"));
defectCombo->insertItem(tr("Full Color Blindness"));
// preferences
@@ -334,13 +331,59 @@
QColor ColorWheelDialog::computeDefect(QColor c)
{
- if (defectCombo->currentItem() == VisionDefectColor::normalVision)
+ int g;
+ if (defectCombo->currentItem() == normalVision)
return c;
- VisionDefectColor *defect = new VisionDefectColor(c);
- defect->deficiency = defectCombo->currentItem();
- defect->convertDefect();
- QColor nc = defect->getColor();
- delete defect;
- return nc;
+ double l, m, s;
+ getLMSfromRGB(c, &l, &m, &s);
+ switch (defectCombo->currentItem())
+ {
+ case (protanopeVision):
+ l = getProtanopesLMS(m, s);
+ break;
+ case (deuteranopeVision):
+ m = getDeuteranopesLMS(l, s);
+ break;
+ case (colorBlindnessVision):
+ // into gray
+ g = QMIN(qRound(0.3*c.red() + 0.59*c.green() + 0.11*c.blue()), 255);
+ return QColor(g, g, g);
+ default:
+ return c;
+ break;
+ }
+ return getRGBfromLMS(l, m, s);
}
+void ColorWheelDialog::getLMSfromRGB(QColor rgb, double *l, double *m, double *s)
+{
+ /* It's common matrix multiplication. I'm doing it this
+ way not to use more library dependencies (petr) */
+ double r = (double)rgb.red();
+ double g = (double)rgb.green();
+ double b = (double)rgb.blue();
+ *l = 17.88240*r + 43.5161*g + 4.11935*b;
+ *m = 3.45525*r + 27.1554*g + 3.86714*b;
+ *s = 0.0299566*r + 0.184309*g + 1.46709*b;
+}
+
+QColor ColorWheelDialog::getRGBfromLMS(double l, double m, double s)
+{
+ /* inverse matrix to the getLMSfromRGB */
+ double r = 0.080944*l -0.130504*m + 0.116721*s;
+ double g = -0.010249*l + 0.054019*m -0.113615*s;
+ double b = -0.000365*l -0.004122*m + 0.693511*s;
+ return QColor((int)r, (int)g, (int)b);
+}
+
+/* M and S components without change */
+double ColorWheelDialog::getProtanopesLMS(double m, double s)
+{
+ return 2.02344*m - 2.52581*s;
+}
+
+/* L and S components without change */
+double ColorWheelDialog::getDeuteranopesLMS(double l, double s)
+{
+ return 0.494207*l + 1.24827*s;
+}
/branches/Version13x/Scribus/scribus/plugins/colorwheel/cwdialog.h
19,6 → 19,15
 
/** \brief GUI dialog for Color Wheel Plugin.
Quite everything in this class is self explanatory (except few things ;)).
Ehm... And now to the "few things". There is some magic (read strange)
stuff since it's using the Vison Defects simulations. It is based on
the matrix operations. I'm computing it this way (plain multiplication)
to prevent new library dependecy - IMHO is no need to have some matrix
library for onlu 3 or 4 transformations of the 3x3 matrix.
I've took the "Digital Video Colourmaps for Checking the Legibility
of Displays of Dichromats" article by Francoise Vienot, Hans Brettel
and John D. Mollon as the base reference. Don't forget that google is
your friend ;)
\author Petr Vanek; petr@yarpen.cz
\date April 2005
*/
44,6 → 53,13
QComboBox* defectCombo;
 
protected:
/*! Enumerate Vision Defects for readable ComboBox access */
enum defectMode {
normalVision = 0,
protanopeVision = 1,
deuteranopeVision = 2,
colorBlindnessVision = 3
};
/** It fills a colors into list view. It takes colors
from ColorWheel widget. */
void fillColorList();
63,7 → 79,36
\param c input color. QColor from sample list.
\retval QColor It returns c for normalVision. It calls transformations for other filters*/
QColor computeDefect(QColor c);
/*! Converts RGB to the LMS color space
\param rgb original color
\param l returning reference to the "L" from LMS
\param m returning reference to the "M" from LMS
\param s returning reference to the "S" from LMS
*/
void getLMSfromRGB(QColor rgb, double *l, double *m, double *s);
/*! Converts LMS color to the RGB
\param l the "L" from LMS
\param m the "M" from LMS
\param s the "S" from LMS
\retval rgb color
*/
QColor getRGBfromLMS(double l, double m, double s);
/*! Compute Protanopy filter.
It doesn't need L.
\param m M from LMS
\param s S from LMS
\retval L from LMS
*/
double getProtanopesLMS(double m, double s);
/*! Compute Deuteranopy filter.
It doesn't need M.
\param l L from LMS
\param s S from LMS
\retval M from LMS
*/
double getDeuteranopesLMS(double l, double s);
 
 
public slots:
virtual void typeCombo_activated(int);
virtual void defectCombo_activated(int);
/branches/Version13x/Scribus/scribus/plugins/colorwheel/Makefile.am
6,9 → 6,9
 
libcolorwheel_la_LDFLAGS = -version-info 0:0:0
libcolorwheel_la_METASOURCES = AUTO
libcolorwheel_la_SOURCES = colorwheel.cpp colorwheelwidget.cpp cwdialog.cpp colorblind.cpp
libcolorwheel_la_SOURCES = colorwheel.cpp colorwheelwidget.cpp cwdialog.cpp
 
EXTRA_DIST = colorwheel.cpp colorwheel.h colorwheelwidget.cpp colorwheelwidget.h cwdialog.cpp cwdialog.h colorblind.cpp colorblind.h
EXTRA_DIST = colorwheel.cpp colorwheel.h colorwheelwidget.cpp colorwheelwidget.h cwdialog.cpp cwdialog.h
 
KDE_OPTIONS = qtonly
AM_LDFLAGS = $(LIBFREETYPE_LIBS) $(MODULE_LINK_FLAGS)