~ubuntu-branches/ubuntu/karmic/gimp/karmic-security

« back to all changes in this revision

Viewing changes to modules/cdisplay_colorblind.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GIMP - The GNU Image Manipulation Program
2
 
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * cdisplay_colorblind.c
5
 
 * Copyright (C) 2002-2003 Michael Natterer <mitch@gimp.org>,
6
 
 *                         Sven Neumann <sven@gimp.org>,
7
 
 *                         Robert Dougherty <bob@vischeck.com> and
8
 
 *                         Alex Wade <alex@vischeck.com>
9
 
 *
10
 
 * This code is an implementation of an algorithm described by Hans Brettel,
11
 
 * Francoise Vienot and John Mollon in the Journal of the Optical Society of
12
 
 * America V14(10), pg 2647. (See http://vischeck.com/ for more info.)
13
 
 *
14
 
 * This program is free software; you can redistribute it and/or modify
15
 
 * it under the terms of the GNU General Public License as published by
16
 
 * the Free Software Foundation; either version 2 of the License, or
17
 
 * (at your option) any later version.
18
 
 *
19
 
 * This program is distributed in the hope that it will be useful,
20
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
 * GNU General Public License for more details.
23
 
 *
24
 
 * You should have received a copy of the GNU General Public License
25
 
 * along with this program; if not, write to the Free Software
26
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
 
 */
28
 
 
29
 
#include "config.h"
30
 
 
31
 
#include <string.h>
32
 
 
33
 
#include <gtk/gtk.h>
34
 
 
35
 
#include "libgimpconfig/gimpconfig.h"
36
 
#include "libgimpmath/gimpmath.h"
37
 
#include "libgimpmodule/gimpmodule.h"
38
 
#include "libgimpwidgets/gimpwidgets.h"
39
 
 
40
 
#include "libgimp/libgimp-intl.h"
41
 
 
42
 
 
43
 
typedef enum
44
 
{
45
 
  COLORBLIND_DEFICIENCY_PROTANOPIA,
46
 
  COLORBLIND_DEFICIENCY_DEUTERANOPIA,
47
 
  COLORBLIND_DEFICIENCY_TRITANOPIA
48
 
} ColorblindDeficiency;
49
 
 
50
 
#define CDISPLAY_TYPE_COLORBLIND_DEFICIENCY (cdisplay_colorblind_deficiency_type)
51
 
static GType  cdisplay_colorblind_deficiency_get_type (GTypeModule *module);
52
 
 
53
 
static const GEnumValue enum_values[] =
54
 
{
55
 
  { COLORBLIND_DEFICIENCY_PROTANOPIA,
56
 
    "COLORBLIND_DEFICIENCY_PROTANOPIA", "protanopia"   },
57
 
  { COLORBLIND_DEFICIENCY_DEUTERANOPIA,
58
 
    "COLORBLIND_DEFICIENCY_DEUTERANOPIA", "deuteranopia" },
59
 
  { COLORBLIND_DEFICIENCY_TRITANOPIA,
60
 
    "COLORBLIND_DEFICIENCY_TRITANOPIA", "tritanopia"   },
61
 
  { 0, NULL, NULL }
62
 
};
63
 
 
64
 
static const GimpEnumDesc enum_descs[] =
65
 
  {
66
 
    { COLORBLIND_DEFICIENCY_PROTANOPIA,
67
 
      N_("Protanopia (insensitivity to red)"), NULL },
68
 
    { COLORBLIND_DEFICIENCY_DEUTERANOPIA,
69
 
      N_("Deuteranopia (insensitivity to green)"), NULL },
70
 
    { COLORBLIND_DEFICIENCY_TRITANOPIA,
71
 
      N_("Tritanopia (insensitivity to blue)"), NULL },
72
 
    { 0, NULL, NULL }
73
 
  };
74
 
 
75
 
#define DEFAULT_DEFICIENCY  COLORBLIND_DEFICIENCY_DEUTERANOPIA
76
 
#define COLOR_CACHE_SIZE    1021
77
 
 
78
 
 
79
 
#define CDISPLAY_TYPE_COLORBLIND            (cdisplay_colorblind_type)
80
 
#define CDISPLAY_COLORBLIND(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_COLORBLIND, CdisplayColorblind))
81
 
#define CDISPLAY_COLORBLIND_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_COLORBLIND, CdisplayColorblindClass))
82
 
#define CDISPLAY_IS_COLORBLIND(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_COLORBLIND))
83
 
#define CDISPLAY_IS_COLORBLIND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_COLORBLIND))
84
 
 
85
 
 
86
 
typedef struct _CdisplayColorblind      CdisplayColorblind;
87
 
typedef struct _CdisplayColorblindClass CdisplayColorblindClass;
88
 
 
89
 
struct _CdisplayColorblind
90
 
{
91
 
  GimpColorDisplay      parent_instance;
92
 
 
93
 
  ColorblindDeficiency  deficiency;
94
 
 
95
 
  gfloat                a1, b1, c1;
96
 
  gfloat                a2, b2, c2;
97
 
  gfloat                inflection;
98
 
 
99
 
  guint32               cache[2 * COLOR_CACHE_SIZE];
100
 
  gfloat                gamma_lut[256];
101
 
};
102
 
 
103
 
struct _CdisplayColorblindClass
104
 
{
105
 
  GimpColorDisplayClass  parent_instance;
106
 
};
107
 
 
108
 
 
109
 
enum
110
 
{
111
 
  PROP_0,
112
 
  PROP_DEFICIENCY
113
 
};
114
 
 
115
 
 
116
 
static GType       cdisplay_colorblind_get_type   (GTypeModule              *module);
117
 
static void        cdisplay_colorblind_class_init (CdisplayColorblindClass  *klass);
118
 
static void        cdisplay_colorblind_init       (CdisplayColorblind       *colorblind);
119
 
 
120
 
static void        cdisplay_colorblind_set_property  (GObject               *object,
121
 
                                                      guint                  property_id,
122
 
                                                      const GValue          *value,
123
 
                                                      GParamSpec            *pspec);
124
 
static void        cdisplay_colorblind_get_property  (GObject               *object,
125
 
                                                      guint                  property_id,
126
 
                                                      GValue                *value,
127
 
                                                      GParamSpec            *pspec);
128
 
 
129
 
static void        cdisplay_colorblind_convert       (GimpColorDisplay      *display,
130
 
                                                      guchar                *buf,
131
 
                                                      gint                   w,
132
 
                                                      gint                   h,
133
 
                                                      gint                   bpp,
134
 
                                                      gint                   bpl);
135
 
static GtkWidget * cdisplay_colorblind_configure      (GimpColorDisplay     *display);
136
 
static void        cdisplay_colorblind_changed        (GimpColorDisplay     *display);
137
 
 
138
 
static void        cdisplay_colorblind_set_deficiency (CdisplayColorblind   *colorblind,
139
 
                                                       ColorblindDeficiency  value);
140
 
 
141
 
 
142
 
  /* The RGB<->LMS transforms above are computed from the human cone
143
 
   * photo-pigment absorption spectra and the monitor phosphor
144
 
   * emission spectra. These parameters are fairly constant for most
145
 
   * humans and most montiors (at least for modern CRTs). However,
146
 
   * gamma will vary quite a bit, as it is a property of the monitor
147
 
   * (eg. amplifier gain), the video card, and even the
148
 
   * software. Further, users can adjust their gammas (either via
149
 
   * adjusting the monitor amp gains or in software). That said, the
150
 
   * following are the gamma estimates that we have used in the
151
 
   * Vischeck code. Many colorblind users have viewed our simulations
152
 
   * and told us that they "work" (simulated and original images are
153
 
   * indistinguishabled).
154
 
   */
155
 
 
156
 
static const gfloat gammaRGB = 2.1;
157
 
 
158
 
 
159
 
  /* For most modern Cathode-Ray Tube monitors (CRTs), the following
160
 
   * are good estimates of the RGB->LMS and LMS->RGB transform
161
 
   * matrices.  They are based on spectra measured on a typical CRT
162
 
   * with a PhotoResearch PR650 spectral photometer and the Stockman
163
 
   * human cone fundamentals. NOTE: these estimates will NOT work well
164
 
   * for LCDs!
165
 
   */
166
 
static const gfloat rgb2lms[9] =
167
 
{
168
 
  0.05059983,
169
 
  0.08585369,
170
 
  0.00952420,
171
 
 
172
 
  0.01893033,
173
 
  0.08925308,
174
 
  0.01370054,
175
 
 
176
 
  0.00292202,
177
 
  0.00975732,
178
 
  0.07145979
179
 
};
180
 
 
181
 
static const gfloat lms2rgb[9] =
182
 
{
183
 
   30.830854,
184
 
  -29.832659,
185
 
    1.610474,
186
 
 
187
 
   -6.481468,
188
 
   17.715578,
189
 
   -2.532642,
190
 
 
191
 
   -0.375690,
192
 
   -1.199062,
193
 
   14.273846
194
 
};
195
 
 
196
 
 
197
 
static const GimpModuleInfo cdisplay_colorblind_info =
198
 
{
199
 
  GIMP_MODULE_ABI_VERSION,
200
 
  N_("Color deficit simulation filter (Brettel-Vienot-Mollon algorithm)"),
201
 
  "Michael Natterer <mitch@gimp.org>, Bob Dougherty <bob@vischeck.com>, "
202
 
  "Alex Wade <alex@vischeck.com>",
203
 
  "v0.2",
204
 
  "(c) 2002-2004, released under the GPL",
205
 
  "January 22, 2003"
206
 
};
207
 
 
208
 
static GType                  cdisplay_colorblind_type            = 0;
209
 
static GType                  cdisplay_colorblind_deficiency_type = 0;
210
 
static GimpColorDisplayClass *parent_class                        = NULL;
211
 
 
212
 
 
213
 
G_MODULE_EXPORT const GimpModuleInfo *
214
 
gimp_module_query (GTypeModule *module)
215
 
{
216
 
  return &cdisplay_colorblind_info;
217
 
}
218
 
 
219
 
G_MODULE_EXPORT gboolean
220
 
gimp_module_register (GTypeModule *module)
221
 
{
222
 
  cdisplay_colorblind_get_type (module);
223
 
  cdisplay_colorblind_deficiency_get_type (module);
224
 
 
225
 
  return TRUE;
226
 
}
227
 
 
228
 
static GType
229
 
cdisplay_colorblind_get_type (GTypeModule *module)
230
 
{
231
 
  if (! cdisplay_colorblind_type)
232
 
    {
233
 
      const GTypeInfo display_info =
234
 
      {
235
 
        sizeof (CdisplayColorblindClass),
236
 
        (GBaseInitFunc) NULL,
237
 
        (GBaseFinalizeFunc) NULL,
238
 
        (GClassInitFunc) cdisplay_colorblind_class_init,
239
 
        NULL,           /* class_finalize */
240
 
        NULL,           /* class_data     */
241
 
        sizeof (CdisplayColorblind),
242
 
        0,              /* n_preallocs    */
243
 
        (GInstanceInitFunc) cdisplay_colorblind_init,
244
 
      };
245
 
 
246
 
      cdisplay_colorblind_type =
247
 
        g_type_module_register_type (module,
248
 
                                     GIMP_TYPE_COLOR_DISPLAY,
249
 
                                     "CdisplayColorblind",
250
 
                                     &display_info, 0);
251
 
    }
252
 
 
253
 
  return cdisplay_colorblind_type;
254
 
}
255
 
 
256
 
 
257
 
static GType
258
 
cdisplay_colorblind_deficiency_get_type (GTypeModule *module)
259
 
{
260
 
  if (! cdisplay_colorblind_deficiency_type)
261
 
    {
262
 
      cdisplay_colorblind_deficiency_type =
263
 
        g_type_module_register_enum (module, "CDisplayColorblindDeficiency",
264
 
                                     enum_values);
265
 
 
266
 
      gimp_type_set_translation_domain (cdisplay_colorblind_deficiency_type,
267
 
                                        GETTEXT_PACKAGE "-libgimp");
268
 
      gimp_enum_set_value_descriptions (cdisplay_colorblind_deficiency_type,
269
 
                                        enum_descs);
270
 
    }
271
 
 
272
 
  return cdisplay_colorblind_deficiency_type;
273
 
}
274
 
 
275
 
static void
276
 
cdisplay_colorblind_class_init (CdisplayColorblindClass *klass)
277
 
{
278
 
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
279
 
  GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
280
 
 
281
 
  parent_class = g_type_class_peek_parent (klass);
282
 
 
283
 
  object_class->get_property = cdisplay_colorblind_get_property;
284
 
  object_class->set_property = cdisplay_colorblind_set_property;
285
 
 
286
 
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_DEFICIENCY,
287
 
                                 "deficiency", NULL,
288
 
                                 CDISPLAY_TYPE_COLORBLIND_DEFICIENCY,
289
 
                                 DEFAULT_DEFICIENCY,
290
 
                                 0);
291
 
 
292
 
  display_class->name        = _("Color Deficient Vision");
293
 
  display_class->help_id     = "gimp-colordisplay-colorblind";
294
 
  display_class->stock_id    = GIMP_STOCK_DISPLAY_FILTER_COLORBLIND;
295
 
 
296
 
  display_class->convert     = cdisplay_colorblind_convert;
297
 
  display_class->configure   = cdisplay_colorblind_configure;
298
 
  display_class->changed     = cdisplay_colorblind_changed;
299
 
}
300
 
 
301
 
static void
302
 
cdisplay_colorblind_init (CdisplayColorblind *colorblind)
303
 
{
304
 
  gint i;
305
 
 
306
 
  for (i = 0; i < 256; i++)
307
 
    colorblind->gamma_lut[i] = pow (i, 1.0 / gammaRGB);
308
 
}
309
 
 
310
 
static void
311
 
cdisplay_colorblind_get_property (GObject    *object,
312
 
                                  guint       property_id,
313
 
                                  GValue     *value,
314
 
                                  GParamSpec *pspec)
315
 
{
316
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (object);
317
 
 
318
 
  switch (property_id)
319
 
    {
320
 
    case PROP_DEFICIENCY:
321
 
      g_value_set_enum (value, colorblind->deficiency);
322
 
      break;
323
 
    default:
324
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
325
 
      break;
326
 
    }
327
 
}
328
 
 
329
 
static void
330
 
cdisplay_colorblind_set_property (GObject      *object,
331
 
                                  guint         property_id,
332
 
                                  const GValue *value,
333
 
                                  GParamSpec   *pspec)
334
 
{
335
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (object);
336
 
 
337
 
  switch (property_id)
338
 
    {
339
 
    case PROP_DEFICIENCY:
340
 
      cdisplay_colorblind_set_deficiency (colorblind,
341
 
                                          g_value_get_enum (value));
342
 
      break;
343
 
    default:
344
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
345
 
      break;
346
 
    }
347
 
}
348
 
 
349
 
 
350
 
/*
351
 
 * This function performs a binary search in the gamma LUT.  It
352
 
 * assumes a monotone gamma function and it simply clips out of gamut
353
 
 * values. It would be better to desaturate instead of clipping.
354
 
 */
355
 
static inline guchar
356
 
lut_lookup (gfloat        value,
357
 
            const gfloat *lut)
358
 
{
359
 
  guchar offset = 127;
360
 
  guchar step   = 64;
361
 
 
362
 
  while (step)
363
 
    {
364
 
      if (lut[offset] > value)
365
 
        {
366
 
          offset -= step;
367
 
        }
368
 
      else
369
 
        {
370
 
          if (lut[offset + 1] > value)
371
 
            return offset;
372
 
 
373
 
          offset += step;
374
 
        }
375
 
 
376
 
      step /= 2;
377
 
    }
378
 
 
379
 
  /*  the algorithm above can't reach 255  */
380
 
  if (offset == 254 && lut[255] < value)
381
 
    return 255;
382
 
 
383
 
  return offset;
384
 
}
385
 
 
386
 
static void
387
 
cdisplay_colorblind_convert (GimpColorDisplay *display,
388
 
                             guchar           *buf,
389
 
                             gint              width,
390
 
                             gint              height,
391
 
                             gint              bpp,
392
 
                             gint              bpl)
393
 
{
394
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
395
 
  const gfloat        a1 = colorblind->a1;
396
 
  const gfloat        b1 = colorblind->b1;
397
 
  const gfloat        c1 = colorblind->c1;
398
 
  const gfloat        a2 = colorblind->a2;
399
 
  const gfloat        b2 = colorblind->b2;
400
 
  const gfloat        c2 = colorblind->c2;
401
 
  gfloat              tmp;
402
 
  gfloat              red, green, blue;
403
 
  gfloat              redOld, greenOld;
404
 
  guchar             *b;
405
 
  gint                x, y;
406
 
 
407
 
  /* Require 3 bytes per pixel (assume RGB) */
408
 
  if (bpp != 3)
409
 
    return;
410
 
 
411
 
  for (y = 0; y < height; y++, buf += bpl)
412
 
    for (x = 0, b = buf; x < width; x++, b += bpp)
413
 
      {
414
 
        guint32 pixel;
415
 
        guint   index;
416
 
 
417
 
        /* First check our cache */
418
 
        pixel = b[0] << 16 | b[1] << 8 | b[2];
419
 
        index = pixel % COLOR_CACHE_SIZE;
420
 
 
421
 
        if (colorblind->cache[2 * index] == pixel)
422
 
          {
423
 
            pixel = colorblind->cache[2 * index + 1];
424
 
 
425
 
            b[2] = pixel & 0xFF; pixel >>= 8;
426
 
            b[1] = pixel & 0xFF; pixel >>= 8;
427
 
            b[0] = pixel & 0xFF;
428
 
 
429
 
            continue;
430
 
          }
431
 
 
432
 
        /* Remove gamma to linearize RGB intensities */
433
 
        red   = colorblind->gamma_lut[b[0]];
434
 
        green = colorblind->gamma_lut[b[1]];
435
 
        blue  = colorblind->gamma_lut[b[2]];
436
 
 
437
 
        /* Convert to LMS (dot product with transform matrix) */
438
 
        redOld   = red;
439
 
        greenOld = green;
440
 
 
441
 
        red   = redOld * rgb2lms[0] + greenOld * rgb2lms[1] + blue * rgb2lms[2];
442
 
        green = redOld * rgb2lms[3] + greenOld * rgb2lms[4] + blue * rgb2lms[5];
443
 
        blue  = redOld * rgb2lms[6] + greenOld * rgb2lms[7] + blue * rgb2lms[8];
444
 
 
445
 
        switch (colorblind->deficiency)
446
 
          {
447
 
          case COLORBLIND_DEFICIENCY_DEUTERANOPIA:
448
 
            tmp = blue / red;
449
 
            /* See which side of the inflection line we fall... */
450
 
            if (tmp < colorblind->inflection)
451
 
              green = -(a1 * red + c1 * blue) / b1;
452
 
            else
453
 
              green = -(a2 * red + c2 * blue) / b2;
454
 
            break;
455
 
 
456
 
          case COLORBLIND_DEFICIENCY_PROTANOPIA:
457
 
            tmp = blue / green;
458
 
            /* See which side of the inflection line we fall... */
459
 
            if (tmp < colorblind->inflection)
460
 
              red = -(b1 * green + c1 * blue) / a1;
461
 
            else
462
 
              red = -(b2 * green + c2 * blue) / a2;
463
 
            break;
464
 
 
465
 
          case COLORBLIND_DEFICIENCY_TRITANOPIA:
466
 
            tmp = green / red;
467
 
            /* See which side of the inflection line we fall... */
468
 
            if (tmp < colorblind->inflection)
469
 
              blue = -(a1 * red + b1 * green) / c1;
470
 
            else
471
 
              blue = -(a2 * red + b2 * green) / c2;
472
 
            break;
473
 
 
474
 
          default:
475
 
            break;
476
 
          }
477
 
 
478
 
        /* Convert back to RGB (cross product with transform matrix) */
479
 
        redOld   = red;
480
 
        greenOld = green;
481
 
 
482
 
        red   = redOld * lms2rgb[0] + greenOld * lms2rgb[1] + blue * lms2rgb[2];
483
 
        green = redOld * lms2rgb[3] + greenOld * lms2rgb[4] + blue * lms2rgb[5];
484
 
        blue  = redOld * lms2rgb[6] + greenOld * lms2rgb[7] + blue * lms2rgb[8];
485
 
 
486
 
        /* Apply gamma to go back to non-linear intensities */
487
 
        b[0] = lut_lookup (red,   colorblind->gamma_lut);
488
 
        b[1] = lut_lookup (green, colorblind->gamma_lut);
489
 
        b[2] = lut_lookup (blue,  colorblind->gamma_lut);
490
 
 
491
 
        /* Put the result into our cache */
492
 
        colorblind->cache[2 * index]     = pixel;
493
 
        colorblind->cache[2 * index + 1] = b[0] << 16 | b[1] << 8 | b[2];
494
 
      }
495
 
}
496
 
 
497
 
static GtkWidget *
498
 
cdisplay_colorblind_configure (GimpColorDisplay *display)
499
 
{
500
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
501
 
  GtkWidget          *hbox;
502
 
  GtkWidget          *label;
503
 
  GtkWidget          *combo;
504
 
 
505
 
  hbox = gtk_hbox_new (FALSE, 6);
506
 
 
507
 
  label = gtk_label_new_with_mnemonic (_("Color _deficiency type:"));
508
 
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
509
 
  gtk_widget_show (label);
510
 
 
511
 
  combo =
512
 
    gimp_prop_enum_combo_box_new (G_OBJECT (colorblind), "deficiency", 0, 0);
513
 
 
514
 
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
515
 
  gtk_widget_show (combo);
516
 
 
517
 
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
518
 
 
519
 
  return hbox;
520
 
}
521
 
 
522
 
static void
523
 
cdisplay_colorblind_changed (GimpColorDisplay *display)
524
 
{
525
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
526
 
  gfloat              anchor_e[3];
527
 
  gfloat              anchor[12];
528
 
 
529
 
  /*  This function performs initialisations that are dependant
530
 
   *  on the type of color deficiency.
531
 
   */
532
 
 
533
 
  /* Performs protan, deutan or tritan color image simulation based on
534
 
   * Brettel, Vienot and Mollon JOSA 14/10 1997
535
 
   *  L,M,S for lambda=475,485,575,660
536
 
   *
537
 
   * Load the LMS anchor-point values for lambda = 475 & 485 nm (for
538
 
   * protans & deutans) and the LMS values for lambda = 575 & 660 nm
539
 
   * (for tritans)
540
 
   */
541
 
  anchor[0] = 0.08008;  anchor[1]  = 0.1579;    anchor[2]  = 0.5897;
542
 
  anchor[3] = 0.1284;   anchor[4]  = 0.2237;    anchor[5]  = 0.3636;
543
 
  anchor[6] = 0.9856;   anchor[7]  = 0.7325;    anchor[8]  = 0.001079;
544
 
  anchor[9] = 0.0914;   anchor[10] = 0.007009;  anchor[11] = 0.0;
545
 
 
546
 
  /* We also need LMS for RGB=(1,1,1)- the equal-energy point (one of
547
 
   * our anchors) (we can just peel this out of the rgb2lms transform
548
 
   * matrix)
549
 
   */
550
 
  anchor_e[0] = rgb2lms[0] + rgb2lms[1] + rgb2lms[2];
551
 
  anchor_e[1] = rgb2lms[3] + rgb2lms[4] + rgb2lms[5];
552
 
  anchor_e[2] = rgb2lms[6] + rgb2lms[7] + rgb2lms[8];
553
 
 
554
 
  switch (colorblind->deficiency)
555
 
    {
556
 
    case COLORBLIND_DEFICIENCY_DEUTERANOPIA:
557
 
      /* find a,b,c for lam=575nm and lam=475 */
558
 
      colorblind->a1 = anchor_e[1] * anchor[8] - anchor_e[2] * anchor[7];
559
 
      colorblind->b1 = anchor_e[2] * anchor[6] - anchor_e[0] * anchor[8];
560
 
      colorblind->c1 = anchor_e[0] * anchor[7] - anchor_e[1] * anchor[6];
561
 
      colorblind->a2 = anchor_e[1] * anchor[2] - anchor_e[2] * anchor[1];
562
 
      colorblind->b2 = anchor_e[2] * anchor[0] - anchor_e[0] * anchor[2];
563
 
      colorblind->c2 = anchor_e[0] * anchor[1] - anchor_e[1] * anchor[0];
564
 
      colorblind->inflection = (anchor_e[2] / anchor_e[0]);
565
 
      break;
566
 
 
567
 
    case COLORBLIND_DEFICIENCY_PROTANOPIA:
568
 
      /* find a,b,c for lam=575nm and lam=475 */
569
 
      colorblind->a1 = anchor_e[1] * anchor[8] - anchor_e[2] * anchor[7];
570
 
      colorblind->b1 = anchor_e[2] * anchor[6] - anchor_e[0] * anchor[8];
571
 
      colorblind->c1 = anchor_e[0] * anchor[7] - anchor_e[1] * anchor[6];
572
 
      colorblind->a2 = anchor_e[1] * anchor[2] - anchor_e[2] * anchor[1];
573
 
      colorblind->b2 = anchor_e[2] * anchor[0] - anchor_e[0] * anchor[2];
574
 
      colorblind->c2 = anchor_e[0] * anchor[1] - anchor_e[1] * anchor[0];
575
 
      colorblind->inflection = (anchor_e[2] / anchor_e[1]);
576
 
      break;
577
 
 
578
 
    case COLORBLIND_DEFICIENCY_TRITANOPIA:
579
 
      /* Set 1: regions where lambda_a=575, set 2: lambda_a=475 */
580
 
      colorblind->a1 = anchor_e[1] * anchor[11] - anchor_e[2] * anchor[10];
581
 
      colorblind->b1 = anchor_e[2] * anchor[9]  - anchor_e[0] * anchor[11];
582
 
      colorblind->c1 = anchor_e[0] * anchor[10] - anchor_e[1] * anchor[9];
583
 
      colorblind->a2 = anchor_e[1] * anchor[5]  - anchor_e[2] * anchor[4];
584
 
      colorblind->b2 = anchor_e[2] * anchor[3]  - anchor_e[0] * anchor[5];
585
 
      colorblind->c2 = anchor_e[0] * anchor[4]  - anchor_e[1] * anchor[3];
586
 
      colorblind->inflection = (anchor_e[1] / anchor_e[0]);
587
 
      break;
588
 
    }
589
 
 
590
 
  /* Invalidate the cache */
591
 
  memset (colorblind->cache, 0, sizeof (colorblind->cache));
592
 
}
593
 
 
594
 
static void
595
 
cdisplay_colorblind_set_deficiency (CdisplayColorblind   *colorblind,
596
 
                                    ColorblindDeficiency  value)
597
 
{
598
 
  if (value != colorblind->deficiency)
599
 
    {
600
 
      GEnumClass *enum_class;
601
 
 
602
 
      enum_class = g_type_class_peek (CDISPLAY_TYPE_COLORBLIND_DEFICIENCY);
603
 
 
604
 
      if (! g_enum_get_value (enum_class, value))
605
 
        return;
606
 
 
607
 
      colorblind->deficiency = value;
608
 
 
609
 
      g_object_notify (G_OBJECT (colorblind), "deficiency");
610
 
      gimp_color_display_changed (GIMP_COLOR_DISPLAY (colorblind));
611
 
    }
612
 
}