~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to modules/cdisplay_colorblind.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * cdisplay_colorblind.c
28
28
 
29
29
#include "config.h"
30
30
 
31
 
#include <stdio.h>
32
31
#include <string.h>
33
32
 
34
33
#include <gtk/gtk.h>
35
34
 
36
 
#include "libgimpbase/gimpbase.h"
 
35
#include "libgimpconfig/gimpconfig.h"
 
36
#include "libgimpmath/gimpmath.h"
37
37
#include "libgimpmodule/gimpmodule.h"
38
38
#include "libgimpwidgets/gimpwidgets.h"
39
 
#include "libgimpmath/gimpmath.h"
40
39
 
41
40
#include "libgimp/libgimp-intl.h"
42
41
 
51
50
#define CDISPLAY_TYPE_COLORBLIND_DEFICIENCY (cdisplay_colorblind_deficiency_type)
52
51
static GType  cdisplay_colorblind_deficiency_get_type (GTypeModule *module);
53
52
 
54
 
static const GEnumValue cdisplay_colorblind_deficiency_enum_values[] =
 
53
static const GEnumValue enum_values[] =
55
54
{
56
55
  { COLORBLIND_DEFICIENCY_PROTANOPIA,
57
 
    N_("Protanopia (insensitivity to red)"),     "protanopia"   },
 
56
    "COLORBLIND_DEFICIENCY_PROTANOPIA", "protanopia"   },
58
57
  { COLORBLIND_DEFICIENCY_DEUTERANOPIA,
59
 
    N_("Deuteranopia (insensitivity to green)"), "deuteranopia" },
 
58
    "COLORBLIND_DEFICIENCY_DEUTERANOPIA", "deuteranopia" },
60
59
  { COLORBLIND_DEFICIENCY_TRITANOPIA,
61
 
    N_("Tritanopia (insensitivity to blue)"),    "tritanopia"   },
 
60
    "COLORBLIND_DEFICIENCY_TRITANOPIA", "tritanopia"   },
62
61
  { 0, NULL, NULL }
63
62
};
64
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
  };
65
74
 
66
75
#define DEFAULT_DEFICIENCY  COLORBLIND_DEFICIENCY_DEUTERANOPIA
67
76
#define COLOR_CACHE_SIZE    1021
83
92
 
84
93
  ColorblindDeficiency  deficiency;
85
94
 
86
 
  gfloat                rgb2lms[9];
87
 
  gfloat                lms2rgb[9];
88
 
  gfloat                gammaRGB[3];
89
 
 
90
95
  gfloat                a1, b1, c1;
91
96
  gfloat                a2, b2, c2;
92
97
  gfloat                inflection;
93
98
 
94
99
  guint32               cache[2 * COLOR_CACHE_SIZE];
95
 
 
96
 
  GtkWidget            *hbox;
97
 
  GtkWidget            *combo;
 
100
  gfloat                gamma_lut[256];
98
101
};
99
102
 
100
103
struct _CdisplayColorblindClass
110
113
};
111
114
 
112
115
 
113
 
static GType   cdisplay_colorblind_get_type   (GTypeModule             *module);
114
 
static void    cdisplay_colorblind_class_init (CdisplayColorblindClass *klass);
115
 
static void    cdisplay_colorblind_init       (CdisplayColorblind      *colorblind);
116
 
 
117
 
static void    cdisplay_colorblind_dispose      (GObject               *object);
118
 
static void    cdisplay_colorblind_set_property (GObject               *object,
119
 
                                                                                                                                 guint                  property_id,
120
 
                                                 const GValue          *value,
121
 
                                                 GParamSpec            *pspec);
122
 
static void    cdisplay_colorblind_get_property (GObject               *object,
123
 
                                                 guint                  property_id,
124
 
                                                 GValue                *value,
125
 
                                                 GParamSpec            *pspec);
126
 
 
127
 
 
128
 
static GimpColorDisplay * cdisplay_colorblind_clone  (GimpColorDisplay   *display);
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 void    cdisplay_colorblind_load_state        (GimpColorDisplay   *display,
136
 
                                                      GimpParasite       *state);
137
 
static GimpParasite * cdisplay_colorblind_save_state (GimpColorDisplay   *display);
138
 
static GtkWidget    * cdisplay_colorblind_configure  (GimpColorDisplay   *display);
139
 
static void    cdisplay_colorblind_configure_reset   (GimpColorDisplay   *display);
140
 
 
141
 
static void    cdisplay_colorblind_changed           (GimpColorDisplay   *display);
142
 
 
143
 
static void    cdisplay_colorblind_set_deficiency    (CdisplayColorblind   *colorblind,
144
 
                                                      ColorblindDeficiency  value);
145
 
 
146
 
static void    colorblind_deficiency_callback        (GtkWidget          *widget,
147
 
                                                      CdisplayColorblind *colorblind);
 
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
};
148
195
 
149
196
 
150
197
static const GimpModuleInfo cdisplay_colorblind_info =
183
230
{
184
231
  if (! cdisplay_colorblind_type)
185
232
    {
186
 
      static const GTypeInfo display_info =
 
233
      const GTypeInfo display_info =
187
234
      {
188
235
        sizeof (CdisplayColorblindClass),
189
236
        (GBaseInitFunc) NULL,
211
258
cdisplay_colorblind_deficiency_get_type (GTypeModule *module)
212
259
{
213
260
  if (! cdisplay_colorblind_deficiency_type)
214
 
    cdisplay_colorblind_deficiency_type =
215
 
      gimp_module_register_enum (module,
216
 
                                 "CDisplayColorblindDeficiency",
217
 
                                 cdisplay_colorblind_deficiency_enum_values);
 
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
    }
218
271
 
219
272
  return cdisplay_colorblind_deficiency_type;
220
273
}
227
280
 
228
281
  parent_class = g_type_class_peek_parent (klass);
229
282
 
230
 
  object_class->dispose          = cdisplay_colorblind_dispose;
231
 
  object_class->get_property     = cdisplay_colorblind_get_property;
232
 
  object_class->set_property     = cdisplay_colorblind_set_property;
233
 
 
234
 
  g_object_class_install_property (object_class, PROP_DEFICIENCY,
235
 
                                   g_param_spec_enum ("deficiency", NULL, NULL,
236
 
                                                      CDISPLAY_TYPE_COLORBLIND_DEFICIENCY,
237
 
                                                      DEFAULT_DEFICIENCY,
238
 
                                                      G_PARAM_READWRITE |
239
 
                                                      G_PARAM_CONSTRUCT |
240
 
                                                      GIMP_MODULE_PARAM_SERIALIZE));
241
 
 
242
 
  display_class->name            = _("Color Deficient Vision");
243
 
  display_class->help_id         = "gimp-colordisplay-colorblind";
244
 
  display_class->clone           = cdisplay_colorblind_clone;
245
 
  display_class->convert         = cdisplay_colorblind_convert;
246
 
  display_class->load_state      = cdisplay_colorblind_load_state;
247
 
  display_class->save_state      = cdisplay_colorblind_save_state;
248
 
  display_class->configure       = cdisplay_colorblind_configure;
249
 
  display_class->configure_reset = cdisplay_colorblind_configure_reset;
250
 
  display_class->changed         = cdisplay_colorblind_changed;
 
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;
251
299
}
252
300
 
253
301
static void
254
302
cdisplay_colorblind_init (CdisplayColorblind *colorblind)
255
303
{
256
 
  /* For most modern Cathode-Ray Tube monitors (CRTs), the following
257
 
   * are good estimates of the RGB->LMS and LMS->RGB transform
258
 
   * matrices.  They are based on spectra measured on a typical CRT
259
 
   * with a PhotoResearch PR650 spectral photometer and the Stockman
260
 
   * human cone fundamentals. NOTE: these estimates will NOT work well
261
 
   * for LCDs!
262
 
   */
263
 
  colorblind->rgb2lms[0] = 0.05059983;
264
 
  colorblind->rgb2lms[1] = 0.08585369;
265
 
  colorblind->rgb2lms[2] = 0.00952420;
266
 
 
267
 
  colorblind->rgb2lms[3] = 0.01893033;
268
 
  colorblind->rgb2lms[4] = 0.08925308;
269
 
  colorblind->rgb2lms[5] = 0.01370054;
270
 
 
271
 
  colorblind->rgb2lms[6] = 0.00292202;
272
 
  colorblind->rgb2lms[7] = 0.00975732;
273
 
  colorblind->rgb2lms[8] = 0.07145979;
274
 
 
275
 
  colorblind->lms2rgb[0] =  30.830854;
276
 
  colorblind->lms2rgb[1] = -29.832659;
277
 
  colorblind->lms2rgb[2] =   1.610474;
278
 
 
279
 
  colorblind->lms2rgb[3] =  -6.481468;
280
 
  colorblind->lms2rgb[4] =  17.715578;
281
 
  colorblind->lms2rgb[5] =  -2.532642;
282
 
 
283
 
  colorblind->lms2rgb[6] =  -0.375690;
284
 
  colorblind->lms2rgb[7] =  -1.199062;
285
 
  colorblind->lms2rgb[8] =  14.273846;
286
 
 
287
 
  /* The RGB<->LMS transforms above are computed from the human cone
288
 
   * photo-pigment absorption spectra and the monitor phosphor
289
 
   * emission spectra. These parameters are fairly constant for most
290
 
   * humans and most montiors (at least for modern CRTs). However,
291
 
   * gamma will vary quite a bit, as it is a property of the monitor
292
 
   * (eg. amplifier gain), the video card, and even the
293
 
   * software. Further, users can adjust their gammas (either via
294
 
   * adjusting the monitor amp gains or in software). That said, the
295
 
   * following are the gamma estimates that we have used in the
296
 
   * Vischeck code. Many colorblind users have viewed our simulations
297
 
   * and told us that they "work" (simulated and original images are
298
 
   * indistinguishabled).
299
 
   */
300
 
  colorblind->gammaRGB[0] = 2.1;
301
 
  colorblind->gammaRGB[1] = 2.0;
302
 
  colorblind->gammaRGB[2] = 2.1;
303
 
}
304
 
 
305
 
static void
306
 
cdisplay_colorblind_dispose (GObject *object)
307
 
{
308
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (object);
309
 
 
310
 
  if (colorblind->hbox)
311
 
    gtk_widget_destroy (colorblind->hbox);
312
 
 
313
 
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
304
  gint i;
 
305
 
 
306
  for (i = 0; i < 256; i++)
 
307
    colorblind->gamma_lut[i] = pow (i, 1.0 / gammaRGB);
314
308
}
315
309
 
316
310
static void
352
346
    }
353
347
}
354
348
 
355
 
static GimpColorDisplay *
356
 
cdisplay_colorblind_clone (GimpColorDisplay *display)
 
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)
357
358
{
358
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
359
 
  CdisplayColorblind *copy;
360
 
 
361
 
  copy = CDISPLAY_COLORBLIND (gimp_color_display_new (G_TYPE_FROM_INSTANCE (colorblind)));
362
 
 
363
 
  copy->deficiency = colorblind->deficiency;
364
 
 
365
 
  return GIMP_COLOR_DISPLAY (copy);
 
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;
366
384
}
367
385
 
368
386
static void
374
392
                             gint              bpl)
375
393
{
376
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;
377
404
  guchar             *b;
378
 
  gfloat              rgb2lms[9],lms2rgb[9];
379
 
  gfloat              a1, b1, c1, a2, b2, c2;
380
 
  gfloat              tmp;
381
 
  gfloat              red, green, blue, redOld, greenOld;
382
405
  gint                x, y;
383
406
 
384
407
  /* Require 3 bytes per pixel (assume RGB) */
385
408
  if (bpp != 3)
386
409
    return;
387
410
 
388
 
  /* to improve readability, copy the parameters into local variables */
389
 
  memcpy (rgb2lms, colorblind->rgb2lms, sizeof (rgb2lms));
390
 
  memcpy (lms2rgb, colorblind->lms2rgb, sizeof (lms2rgb));
391
 
  a1 = colorblind->a1; b1 = colorblind->b1; c1 = colorblind->c1;
392
 
  a2 = colorblind->a2; b2 = colorblind->b2; c2 = colorblind->c2;
393
 
 
394
411
  for (y = 0; y < height; y++, buf += bpl)
395
412
    for (x = 0, b = buf; x < width; x++, b += bpp)
396
413
      {
412
429
            continue;
413
430
          }
414
431
 
415
 
        red   = b[0];
416
 
        green = b[1];
417
 
        blue  = b[2];
418
 
 
419
432
        /* Remove gamma to linearize RGB intensities */
420
 
        red   = pow (red,   1.0 / colorblind->gammaRGB[0]);
421
 
        green = pow (green, 1.0 / colorblind->gammaRGB[1]);
422
 
        blue  = pow (blue,  1.0 / colorblind->gammaRGB[2]);
 
433
        red   = colorblind->gamma_lut[b[0]];
 
434
        green = colorblind->gamma_lut[b[1]];
 
435
        blue  = colorblind->gamma_lut[b[2]];
423
436
 
424
437
        /* Convert to LMS (dot product with transform matrix) */
425
438
        redOld   = red;
435
448
            tmp = blue / red;
436
449
            /* See which side of the inflection line we fall... */
437
450
            if (tmp < colorblind->inflection)
438
 
            green = -(a1 * red + c1 * blue) / b1;
 
451
              green = -(a1 * red + c1 * blue) / b1;
439
452
            else
440
453
              green = -(a2 * red + c2 * blue) / b2;
441
454
            break;
471
484
        blue  = redOld * lms2rgb[6] + greenOld * lms2rgb[7] + blue * lms2rgb[8];
472
485
 
473
486
        /* Apply gamma to go back to non-linear intensities */
474
 
        red   = pow (red,   colorblind->gammaRGB[0]);
475
 
        green = pow (green, colorblind->gammaRGB[1]);
476
 
        blue  = pow (blue,  colorblind->gammaRGB[2]);
477
 
 
478
 
        /* Ensure that we stay within the RGB gamut */
479
 
        /* *** FIX THIS: it would be better to desaturate than blindly clip. */
480
 
        red   = CLAMP (red,   0, 255);
481
 
        green = CLAMP (green, 0, 255);
482
 
        blue  = CLAMP (blue,  0, 255);
483
 
 
484
 
        /* Stuff result back into buffer */
485
 
        b[0] = (guchar) red;
486
 
        b[1] = (guchar) green;
487
 
        b[2] = (guchar) blue;
 
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);
488
490
 
489
491
        /* Put the result into our cache */
490
492
        colorblind->cache[2 * index]     = pixel;
492
494
      }
493
495
}
494
496
 
495
 
static void
496
 
cdisplay_colorblind_load_state (GimpColorDisplay *display,
497
 
                                GimpParasite     *state)
498
 
{
499
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
500
 
  const gchar        *str;
501
 
 
502
 
  str = gimp_parasite_data (state);
503
 
 
504
 
  if (str[gimp_parasite_data_size (state) - 1] == '\0')
505
 
    {
506
 
      gint value;
507
 
 
508
 
      if (sscanf (str, "%d", &value) == 1)
509
 
        cdisplay_colorblind_set_deficiency (colorblind, value);
510
 
    }
511
 
}
512
 
 
513
 
static GimpParasite *
514
 
cdisplay_colorblind_save_state (GimpColorDisplay *display)
515
 
{
516
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
517
 
  gchar               buf[32];
518
 
 
519
 
  g_snprintf (buf, sizeof (buf), "%d", colorblind->deficiency);
520
 
 
521
 
  return gimp_parasite_new ("Display/Colorblind", GIMP_PARASITE_PERSISTENT,
522
 
                            strlen (buf) + 1, buf);
523
 
}
524
 
 
525
497
static GtkWidget *
526
498
cdisplay_colorblind_configure (GimpColorDisplay *display)
527
499
{
528
500
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
 
501
  GtkWidget          *hbox;
529
502
  GtkWidget          *label;
530
 
 
531
 
  if (colorblind->hbox)
532
 
    gtk_widget_destroy (colorblind->hbox);
533
 
 
534
 
  colorblind->hbox = gtk_hbox_new (FALSE, 6);
535
 
 
536
 
  g_signal_connect (colorblind->hbox, "destroy",
537
 
                    G_CALLBACK (gtk_widget_destroyed),
538
 
                    &colorblind->hbox);
539
 
 
540
 
  label = gtk_label_new_with_mnemonic (_("Color _Deficiency Type:"));
541
 
  gtk_box_pack_start (GTK_BOX (colorblind->hbox), label, FALSE, FALSE, 0);
 
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);
542
509
  gtk_widget_show (label);
543
510
 
544
 
  colorblind->combo =
545
 
    gimp_int_combo_box_new (_("Protanopia (insensitivity to red)"),
546
 
                            COLORBLIND_DEFICIENCY_PROTANOPIA,
547
 
                            _("Deuteranopia (insensitivity to green)"),
548
 
                            COLORBLIND_DEFICIENCY_DEUTERANOPIA,
549
 
                            _("Tritanopia (insensitivity to blue)"),
550
 
                            COLORBLIND_DEFICIENCY_TRITANOPIA,
551
 
                            NULL);
552
 
 
553
 
  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (colorblind->combo),
554
 
                                 colorblind->deficiency);
555
 
 
556
 
  g_signal_connect (colorblind->combo, "changed",
557
 
                    G_CALLBACK (colorblind_deficiency_callback),
558
 
                    colorblind);
559
 
 
560
 
  gtk_box_pack_start (GTK_BOX (colorblind->hbox), colorblind->combo,
561
 
                      TRUE, TRUE, 0);
562
 
  gtk_widget_show (colorblind->combo);
563
 
 
564
 
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), colorblind->combo);
565
 
 
566
 
  return colorblind->hbox;
567
 
}
568
 
 
569
 
static void
570
 
cdisplay_colorblind_configure_reset (GimpColorDisplay *display)
571
 
{
572
 
  CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
573
 
 
574
 
  if (colorblind->combo)
575
 
    {
576
 
      gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (colorblind->combo),
577
 
                                     DEFAULT_DEFICIENCY);
578
 
      colorblind->deficiency = DEFAULT_DEFICIENCY;
579
 
 
580
 
      gimp_color_display_changed (GIMP_COLOR_DISPLAY (colorblind));
581
 
    }
 
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;
582
520
}
583
521
 
584
522
static void
609
547
   * our anchors) (we can just peel this out of the rgb2lms transform
610
548
   * matrix)
611
549
   */
612
 
  anchor_e[0] =
613
 
    colorblind->rgb2lms[0] + colorblind->rgb2lms[1] + colorblind->rgb2lms[2];
614
 
  anchor_e[1] =
615
 
    colorblind->rgb2lms[3] + colorblind->rgb2lms[4] + colorblind->rgb2lms[5];
616
 
  anchor_e[2] =
617
 
    colorblind->rgb2lms[6] + colorblind->rgb2lms[7] + colorblind->rgb2lms[8];
 
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];
618
553
 
619
554
  switch (colorblind->deficiency)
620
555
    {
675
610
      gimp_color_display_changed (GIMP_COLOR_DISPLAY (colorblind));
676
611
    }
677
612
}
678
 
 
679
 
static void
680
 
colorblind_deficiency_callback (GtkWidget          *widget,
681
 
                                CdisplayColorblind *colorblind)
682
 
{
683
 
  gint  value;
684
 
 
685
 
  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
686
 
 
687
 
  cdisplay_colorblind_set_deficiency (colorblind, value);
688
 
}