From 252ab27ef467232ddbd3bcdefd41f95ed8502f5b Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 10 Mar 2015 09:10:57 +0100 Subject: Filters. Fix for Bug #790534 (Simulate color blindness/defects?). Fixed bugs: - https://launchpad.net/bugs/790534 (bzr r13984) --- src/extension/internal/filter/color.h | 77 +++++++++++++++++++++++++++- src/extension/internal/filter/filter-all.cpp | 1 + 2 files changed, 77 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index 19af6e969..c3c26bf8b 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -3,13 +3,14 @@ /* Change the 'COLOR' above to be your file name */ /* - * Copyright (C) 2013 Authors: + * Copyright (C) 2013-2015 Authors: * Ivan Louette (filters) * Nicolas Dufour (UI) * * Color filters * Brilliance * Channel painting + * Color blindness * Color shift * Colorize * Component transfer @@ -230,6 +231,80 @@ ChannelPaint::get_filter_text (Inkscape::Extension::Extension * ext) return _filter; }; /* Channel Painting filter */ +/** + \brief Custom predefined Color Blindness filter. + + Color Blindness filter. + Based on https://openclipart.org/detail/22299/Color%20Blindness%20filters + + Filter's parameters: + * Blindness type (enum, default Achromatomaly) -> colormatrix +*/ +class ColorBlindness : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + ColorBlindness ( ) : Filter() { }; + virtual ~ColorBlindness ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Color Blindness") "\n" + "org.inkscape.effect.filter.ColorBlindness\n" + "\n" + "\n" + "\n" + "<_item value=\"0.618 0.32 0.062 0 0 0.163 0.775 0.062 0 0 0.163 0.32 0.516 0 0 0 0 0 1 0 \">" N_("Rod monochromacy (atypical achromatopsia)") "\n" + "<_item value=\"0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0 0 0 1 0 \">" N_("Cone monochromacy (typical achromatopsia)") "\n" + "<_item value=\"0.8 0.2 0 0 0 0.2583 0.74167 0 0 0 0 0.14167 0.85833 0 0 0 0 0 1 0 \">" N_("Geen weak (deuteranomaly)") "\n" + "<_item value=\"0.625 0.375 0 0 0 0.7 0.3 0 0 0 0 0.3 0.7 0 0 0 0 0 1 0 \">" N_("Green blind (deuteranopia)") "\n" + "<_item value=\"0.8166 0.1833 0 0 0 0.333 0.666 0 0 0 0 0.125 0.875 0 0 0 0 0 1 0 \">" N_("Red weak (protanomaly)") "\n" + "<_item value=\"0.566 0.43333 0 0 0 0.55833 0.4416 0 0 0 0 0.24167 0.75833 0 0 0 0 0 1 0 \">" N_("Red blind (protanopia)") "\n" + "<_item value=\"0.966 0.033 0 0 0 0 0.733 0.266 0 0 0 0.1833 0.816 0 0 0 0 0 1 0 \">" N_("Blue weak (tritanomaly)") "\n" + "<_item value=\"0.95 0.05 0 0 0 0.2583 0.4333 0.5667 0 0 0 0.475 0.525 0 0 0 0 0 1 0 \">" N_("Blue blind (tritanopia)") "\n" + "\n" + "\n" + "\n" + "\n" +"Filters based on https://openclipart.org/detail/22299/Color%20Blindness%20filters\n" +"\n" +"These filters don't correctly reflect actual color blindness for two main reasons:\n" +" * Everyone is different, and is not affected exactly the same way.\n" +" * The filters are in the RGB color space, and ignore confusion lines.\n" + "\n" + "\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Simulate color blindness") "\n" + "\n" + "\n", new ColorBlindness()); + }; +}; + +gchar const * +ColorBlindness::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream type; + type << ext->get_param_enum("type"); + + _filter = g_strdup_printf( + "\n" + "\n" + "\n", type.str().c_str()); + + return _filter; +}; /* Color Blindness filter */ + /** \brief Custom predefined Color shift filter. diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index 0273d1669..35504d37f 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -54,6 +54,7 @@ Filter::filters_all (void ) // Color Brilliance::init(); ChannelPaint::init(); + ColorBlindness::init(); ColorShift::init(); Colorize::init(); ComponentTransfer::init(); -- cgit v1.2.3