summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/accessibility/constants.js
blob: 0258cf29de1aab0eb643346a6119a952dd79792f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const {
  accessibility: {
    SIMULATION_TYPE: {
      ACHROMATOPSIA,
      DEUTERANOPIA,
      PROTANOPIA,
      TRITANOPIA,
      CONTRAST_LOSS,
    },
  },
} = require("resource://devtools/shared/constants.js");

/**
 * Constants used in accessibility actors.
 */

// Color blindness matrix values taken from Machado et al. (2009), https://doi.org/10.1109/TVCG.2009.113:
// https://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html
// Contrast loss matrix values are for 50% contrast (see https://docs.rainmeter.net/tips/colormatrix-guide/,
// and https://stackoverflow.com/questions/23865511/contrast-with-color-matrix). The matrices are flattened
// 4x5 matrices, needed for docShell setColorMatrix method. i.e. A 4x5 matrix of the form:
//   1  2  3  4  5
//   6  7  8  9  10
//   11 12 13 14 15
//   16 17 18 19 20
// will be need to be set in docShell as:
//   [1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19, 5, 10, 15, 20]
const COLOR_TRANSFORMATION_MATRICES = {
  NONE: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
  [ACHROMATOPSIA]: [
    0.299,
    0.299,
    0.299,
    0,
    0.587,
    0.587,
    0.587,
    0,
    0.114,
    0.114,
    0.114,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
  ],
  [PROTANOPIA]: [
    0.152286,
    0.114503,
    -0.003882,
    0,
    1.052583,
    0.786281,
    -0.048116,
    0,
    -0.204868,
    0.099216,
    1.051998,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
  ],
  [DEUTERANOPIA]: [
    0.367322,
    0.280085,
    -0.01182,
    0,
    0.860646,
    0.672501,
    0.04294,
    0,
    -0.227968,
    0.047413,
    0.968881,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
  ],
  [TRITANOPIA]: [
    1.255528,
    -0.078411,
    0.004733,
    0,
    -0.076749,
    0.930809,
    0.691367,
    0,
    -0.178779,
    0.147602,
    0.3039,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
  ],
  [CONTRAST_LOSS]: [
    0.5,
    0,
    0,
    0,
    0,
    0.5,
    0,
    0,
    0,
    0,
    0.5,
    0,
    0,
    0,
    0,
    0.5,
    0.25,
    0.25,
    0.25,
    0,
  ],
};

exports.simulation = {
  COLOR_TRANSFORMATION_MATRICES,
};