51
50
#define CDISPLAY_TYPE_COLORBLIND_DEFICIENCY (cdisplay_colorblind_deficiency_type)
52
51
static GType cdisplay_colorblind_deficiency_get_type (GTypeModule *module);
54
static const GEnumValue cdisplay_colorblind_deficiency_enum_values[] =
53
static const GEnumValue enum_values[] =
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" },
64
static const GimpEnumDesc enum_descs[] =
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 },
66
75
#define DEFAULT_DEFICIENCY COLORBLIND_DEFICIENCY_DEUTERANOPIA
67
76
#define COLOR_CACHE_SIZE 1021
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);
117
static void cdisplay_colorblind_dispose (GObject *object);
118
static void cdisplay_colorblind_set_property (GObject *object,
122
static void cdisplay_colorblind_get_property (GObject *object,
128
static GimpColorDisplay * cdisplay_colorblind_clone (GimpColorDisplay *display);
129
static void cdisplay_colorblind_convert (GimpColorDisplay *display,
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);
141
static void cdisplay_colorblind_changed (GimpColorDisplay *display);
143
static void cdisplay_colorblind_set_deficiency (CdisplayColorblind *colorblind,
144
ColorblindDeficiency value);
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);
120
static void cdisplay_colorblind_set_property (GObject *object,
124
static void cdisplay_colorblind_get_property (GObject *object,
129
static void cdisplay_colorblind_convert (GimpColorDisplay *display,
135
static GtkWidget * cdisplay_colorblind_configure (GimpColorDisplay *display);
136
static void cdisplay_colorblind_changed (GimpColorDisplay *display);
138
static void cdisplay_colorblind_set_deficiency (CdisplayColorblind *colorblind,
139
ColorblindDeficiency value);
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).
156
static const gfloat gammaRGB = 2.1;
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
166
static const gfloat rgb2lms[9] =
181
static const gfloat lms2rgb[9] =
150
197
static const GimpModuleInfo cdisplay_colorblind_info =
211
258
cdisplay_colorblind_deficiency_get_type (GTypeModule *module)
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);
262
cdisplay_colorblind_deficiency_type =
263
g_type_module_register_enum (module, "CDisplayColorblindDeficiency",
266
gimp_type_set_translation_domain (cdisplay_colorblind_deficiency_type,
267
GETTEXT_PACKAGE "-libgimp");
268
gimp_enum_set_value_descriptions (cdisplay_colorblind_deficiency_type,
219
272
return cdisplay_colorblind_deficiency_type;
228
281
parent_class = g_type_class_peek_parent (klass);
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;
234
g_object_class_install_property (object_class, PROP_DEFICIENCY,
235
g_param_spec_enum ("deficiency", NULL, NULL,
236
CDISPLAY_TYPE_COLORBLIND_DEFICIENCY,
240
GIMP_MODULE_PARAM_SERIALIZE));
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;
286
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_DEFICIENCY,
288
CDISPLAY_TYPE_COLORBLIND_DEFICIENCY,
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;
296
display_class->convert = cdisplay_colorblind_convert;
297
display_class->configure = cdisplay_colorblind_configure;
298
display_class->changed = cdisplay_colorblind_changed;
254
302
cdisplay_colorblind_init (CdisplayColorblind *colorblind)
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
263
colorblind->rgb2lms[0] = 0.05059983;
264
colorblind->rgb2lms[1] = 0.08585369;
265
colorblind->rgb2lms[2] = 0.00952420;
267
colorblind->rgb2lms[3] = 0.01893033;
268
colorblind->rgb2lms[4] = 0.08925308;
269
colorblind->rgb2lms[5] = 0.01370054;
271
colorblind->rgb2lms[6] = 0.00292202;
272
colorblind->rgb2lms[7] = 0.00975732;
273
colorblind->rgb2lms[8] = 0.07145979;
275
colorblind->lms2rgb[0] = 30.830854;
276
colorblind->lms2rgb[1] = -29.832659;
277
colorblind->lms2rgb[2] = 1.610474;
279
colorblind->lms2rgb[3] = -6.481468;
280
colorblind->lms2rgb[4] = 17.715578;
281
colorblind->lms2rgb[5] = -2.532642;
283
colorblind->lms2rgb[6] = -0.375690;
284
colorblind->lms2rgb[7] = -1.199062;
285
colorblind->lms2rgb[8] = 14.273846;
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).
300
colorblind->gammaRGB[0] = 2.1;
301
colorblind->gammaRGB[1] = 2.0;
302
colorblind->gammaRGB[2] = 2.1;
306
cdisplay_colorblind_dispose (GObject *object)
308
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (object);
310
if (colorblind->hbox)
311
gtk_widget_destroy (colorblind->hbox);
313
G_OBJECT_CLASS (parent_class)->dispose (object);
306
for (i = 0; i < 256; i++)
307
colorblind->gamma_lut[i] = pow (i, 1.0 / gammaRGB);
355
static GimpColorDisplay *
356
cdisplay_colorblind_clone (GimpColorDisplay *display)
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.
356
lut_lookup (gfloat value,
358
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
359
CdisplayColorblind *copy;
361
copy = CDISPLAY_COLORBLIND (gimp_color_display_new (G_TYPE_FROM_INSTANCE (colorblind)));
363
copy->deficiency = colorblind->deficiency;
365
return GIMP_COLOR_DISPLAY (copy);
364
if (lut[offset] > value)
370
if (lut[offset + 1] > value)
379
/* the algorithm above can't reach 255 */
380
if (offset == 254 && lut[255] < value)
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;
402
gfloat red, green, blue;
403
gfloat redOld, greenOld;
378
gfloat rgb2lms[9],lms2rgb[9];
379
gfloat a1, b1, c1, a2, b2, c2;
381
gfloat red, green, blue, redOld, greenOld;
384
407
/* Require 3 bytes per pixel (assume RGB) */
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;
394
411
for (y = 0; y < height; y++, buf += bpl)
395
412
for (x = 0, b = buf; x < width; x++, b += bpp)
471
484
blue = redOld * lms2rgb[6] + greenOld * lms2rgb[7] + blue * lms2rgb[8];
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]);
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);
484
/* Stuff result back into buffer */
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);
489
491
/* Put the result into our cache */
490
492
colorblind->cache[2 * index] = pixel;
496
cdisplay_colorblind_load_state (GimpColorDisplay *display,
499
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
502
str = gimp_parasite_data (state);
504
if (str[gimp_parasite_data_size (state) - 1] == '\0')
508
if (sscanf (str, "%d", &value) == 1)
509
cdisplay_colorblind_set_deficiency (colorblind, value);
513
static GimpParasite *
514
cdisplay_colorblind_save_state (GimpColorDisplay *display)
516
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
519
g_snprintf (buf, sizeof (buf), "%d", colorblind->deficiency);
521
return gimp_parasite_new ("Display/Colorblind", GIMP_PARASITE_PERSISTENT,
522
strlen (buf) + 1, buf);
525
497
static GtkWidget *
526
498
cdisplay_colorblind_configure (GimpColorDisplay *display)
528
500
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
529
502
GtkWidget *label;
531
if (colorblind->hbox)
532
gtk_widget_destroy (colorblind->hbox);
534
colorblind->hbox = gtk_hbox_new (FALSE, 6);
536
g_signal_connect (colorblind->hbox, "destroy",
537
G_CALLBACK (gtk_widget_destroyed),
540
label = gtk_label_new_with_mnemonic (_("Color _Deficiency Type:"));
541
gtk_box_pack_start (GTK_BOX (colorblind->hbox), label, FALSE, FALSE, 0);
505
hbox = gtk_hbox_new (FALSE, 6);
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);
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,
553
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (colorblind->combo),
554
colorblind->deficiency);
556
g_signal_connect (colorblind->combo, "changed",
557
G_CALLBACK (colorblind_deficiency_callback),
560
gtk_box_pack_start (GTK_BOX (colorblind->hbox), colorblind->combo,
562
gtk_widget_show (colorblind->combo);
564
gtk_label_set_mnemonic_widget (GTK_LABEL (label), colorblind->combo);
566
return colorblind->hbox;
570
cdisplay_colorblind_configure_reset (GimpColorDisplay *display)
572
CdisplayColorblind *colorblind = CDISPLAY_COLORBLIND (display);
574
if (colorblind->combo)
576
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (colorblind->combo),
578
colorblind->deficiency = DEFAULT_DEFICIENCY;
580
gimp_color_display_changed (GIMP_COLOR_DISPLAY (colorblind));
512
gimp_prop_enum_combo_box_new (G_OBJECT (colorblind), "deficiency", 0, 0);
514
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
515
gtk_widget_show (combo);
517
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);