summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/wide-gamut-canvas/canvas-display-p3.js
blob: c6ee97b7880a4ac2333b82b60407102045d1f509 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// Each PNG:
//  * is 2x2 and has a single color
//  * has a filename that indicates its contents:
//      <embedded-profile>-<8-or-16-bit-color-value>.png
//  * was generated using ImageMagick commands like:
//      convert -size 2x2 xc:'#BB0000FF' -profile Display-P3.icc Display-P3-BB0000FF.png
//      convert -size 2x2 xc:'#BBBC00000000FFFF' -profile Adobe-RGB.icc Adobe-RGB-BBBC00000000FFFF.png

// Top level key is the image filename. Second level key is the pair of
// CanvasRenderingContext2DSettings.colorSpace and ImageDataSettings.colorSpace.
const imageTests = {
    // 8 bit source images

    "sRGB-FF0000FF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [234, 51, 35, 255],
    },
    "sRGB-FF0000CC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 0, 0, 204],
        "display-p3 display-p3": [234, 51, 35, 204],
    },
    "sRGB-BB0000FF.png": {
        "srgb srgb": [187, 0, 0, 255],
        "srgb display-p3": [171, 35, 23, 255],
        "display-p3 srgb": [187, 1, 0, 255],
        "display-p3 display-p3": [171, 35, 23, 255],
    },
    "sRGB-BB0000CC.png": {
        "srgb srgb": [187, 0, 0, 204],
        "srgb display-p3": [171, 35, 23, 204],
        "display-p3 srgb": [187, 1, 0, 204],
        "display-p3 display-p3": [171, 35, 23, 204],
    },

    "Display-P3-FF0000FF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [255, 0, 0, 255],
    },
    "Display-P3-FF0000CC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 0, 0, 204],
        "display-p3 display-p3": [255, 0, 0, 204],
    },
    "Display-P3-BB0000FF.png": {
        "srgb srgb": [205, 0, 0, 255],
        "srgb display-p3": [188, 39, 26, 255],
        "display-p3 srgb": [205, 0, 0, 255],
        "display-p3 display-p3": [187, 0, 0, 255],
    },
    "Display-P3-BB0000CC.png": {
        "srgb srgb": [205, 0, 0, 204],
        "srgb display-p3": [188, 39, 26, 204],
        "display-p3 srgb": [205, 0, 0, 204],
        "display-p3 display-p3": [187, 0, 0, 204],
    },

    "Adobe-RGB-FF0000FF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 19, 11, 255],
        "display-p3 display-p3": [255, 61, 43, 255],
    },
    "Adobe-RGB-FF0000CC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 19, 11, 204],
        "display-p3 display-p3": [255, 61, 43, 204],
    },
    "Adobe-RGB-BB0000FF.png": {
        "srgb srgb": [219, 0, 0, 255],
        "srgb display-p3": [201, 42, 29, 255],
        "display-p3 srgb": [219, 0, 1, 255],
        "display-p3 display-p3": [201, 42, 29, 255],
    },
    "Adobe-RGB-BB0000CC.png": {
        "srgb srgb": [219, 0, 0, 204],
        "srgb display-p3": [201, 42, 29, 204],
        "display-p3 srgb": [219, 0, 1, 204],
        "display-p3 display-p3": [201, 42, 29, 204],
    },

    "Generic-CMYK-FF000000.jpg": {
        "srgb srgb": [0, 163, 218, 255],
        "srgb display-p3": [72, 161, 213, 255],
        "display-p3 srgb": [0, 163, 218, 255],
        "display-p3 display-p3": [0, 160, 213, 255],
    },
    "Generic-CMYK-BE000000.jpg": {
        "srgb srgb": [0, 180, 223, 255],
        "srgb display-p3": [80, 177, 219, 255],
        "display-p3 srgb": [0, 180, 223, 255],
        "display-p3 display-p3": [65, 177, 219, 255],
    },

    // 16 bit source images

    "sRGB-FFFF00000000FFFF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [234, 51, 35, 255],
    },
    "sRGB-FFFF00000000CCCC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 0, 0, 204],
        "display-p3 display-p3": [234, 51, 35, 204],
    },
    "sRGB-BBBC00000000FFFF.png": {
        "srgb srgb": [187, 0, 0, 255],
        "srgb display-p3": [171, 35, 23, 255],
        "display-p3 srgb": [187, 1, 0, 255],
        "display-p3 display-p3": [171, 35, 23, 255],
    },
    "sRGB-BBBC00000000CCCC.png": {
        "srgb srgb": [187, 0, 0, 204],
        "srgb display-p3": [171, 35, 23, 204],
        "display-p3 srgb": [187, 1, 0, 204],
        "display-p3 display-p3": [171, 35, 23, 204],
    },

    "Display-P3-FFFF00000000FFFF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [255, 0, 0, 255],
    },
    "Display-P3-FFFF00000000CCCC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 0, 0, 204],
        "display-p3 display-p3": [255, 0, 0, 204],
    },
    "Display-P3-BBBC00000000FFFF.png": {
        "srgb srgb": [205, 0, 0, 255],
        "srgb display-p3": [188, 39, 26, 255],
        "display-p3 srgb": [205, 0, 0, 255],
        "display-p3 display-p3": [187, 0, 0, 255],
    },
    "Display-P3-BBBC00000000CCCC.png": {
        "srgb srgb": [205, 0, 0, 204],
        "srgb display-p3": [188, 39, 26, 204],
        "display-p3 srgb": [205, 0, 0, 204],
        "display-p3 display-p3": [187, 0, 0, 204],
    },

    "Adobe-RGB-FFFF00000000FFFF.png": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 19, 11, 255],
        "display-p3 display-p3": [255, 61, 43, 255],
    },
    "Adobe-RGB-FFFF00000000CCCC.png": {
        "srgb srgb": [255, 0, 0, 204],
        "srgb display-p3": [234, 51, 35, 204],
        "display-p3 srgb": [255, 19, 11, 204],
        "display-p3 display-p3": [255, 61, 43, 204],
    },
    "Adobe-RGB-BBBC00000000FFFF.png": {
        "srgb srgb": [219, 0, 0, 255],
        "srgb display-p3": [201, 42, 29, 255],
        "display-p3 srgb": [219, 0, 1, 255],
        "display-p3 display-p3": [201, 42, 29, 255],
    },
    "Adobe-RGB-BBBC00000000CCCC.png": {
        "srgb srgb": [219, 0, 0, 204],
        "srgb display-p3": [201, 42, 29, 204],
        "display-p3 srgb": [219, 0, 1, 204],
        "display-p3 display-p3": [201, 42, 29, 204],
    },
};

const svgImageTests = {
    // SVG source images

    "sRGB-FF0000.svg": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [234, 51, 35, 255],
    },
    "sRGB-BB0000.svg": {
        "srgb srgb": [187, 0, 0, 255],
        "srgb display-p3": [171, 35, 23, 255],
        "display-p3 srgb": [187, 1, 0, 255],
        "display-p3 display-p3": [171, 35, 23, 255],
    },

    "Display-P3-1-0-0.svg": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [255, 0, 0, 255],
    },
    "Display-P3-0.7333-0-0.svg": {
        "srgb srgb": [205, 0, 0, 255],
        "srgb display-p3": [188, 39, 26, 255],
        "display-p3 srgb": [205, 0, 0, 255],
        "display-p3 display-p3": [187, 0, 0, 255],
    },
};

// Each video:
//  * is 300x200 and has a single color
//  * has a filename base that indicates its contents:
//
//      <color-space>-<8-or-10-bit-color-value>
//
//  * was generated using commands like:
//
//      W=300 H=200 Y=3F Cb=66 Cr=F0 ; \
//        perl -e "print pack('c', 0x$Y) x ($W * $H), pack('c', 0x$Cb) x ($W * $H / 4), pack('c', 0x$Cr) x ($W * $H / 4)" | \
//        ffmpeg -f rawvideo -pix_fmt yuv420p -s:v ${W}x$H -r 25 -i - -pix_fmt yuv420p -colorspace bt709 -color_primaries bt709 -color_trc iec61966_2_1 sRGB-FF0100.webm
//
//      W=300 H=200 Y=0BB Cb=1BD Cr=2EF ; \
//        perl -e "print pack('s', 0x$Y) x ($W * $H), pack('s', 0x$Cb) x ($W * $H / 4), pack('s', 0x$Cr) x ($W * $H / 4)" | \
//        ffmpeg -f rawvideo -pix_fmt yuv420p10le -s:v ${W}x$H -r 25 -i - -c:v libx265 -vtag hvc1 -pix_fmt yuv420p10le -colorspace bt2020nc -color_primaries bt2020 -color_trc bt2020-10 Rec2020-222000000.mp4
//
//      W=300 H=200 Y=0BB Cb=1BD Cr=2EF ; \
//        perl -e "print pack('s', 0x$Y) x ($W * $H), pack('s', 0x$Cb) x ($W * $H / 4), pack('s', 0x$Cr) x ($W * $H / 4)" | \
//        ffmpeg -f rawvideo -pix_fmt yuv420p10le -s:v ${W}x$H -r 25 -i - -vcodec libvpx-vp9 -profile:v 2 -pix_fmt yuv420p10le -colorspace bt2020nc -color_primaries bt2020 -color_trc bt2020-10 Rec2020-222000000.webm
//
//    where the Y'CbCr values were computed using https://jdashg.github.io/misc/colors/from-coeffs.html.
const videoTests = {
    // Rec.709 Y'CbCr (0x3F, 0x66, 0xF0) = sRGB (0xFF, 0x01, 0x00)
    "sRGB-FF0100": {
        "srgb srgb": [255, 1, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [234, 51, 35, 255],
    },
    // Rec.709 Y'CbCr (0x32, 0x6D, 0xD2) = sRGB (0xBB, 0x00, 0x00)
    "sRGB-BB0000": {
        "srgb srgb": [187, 0, 0, 255],
        "srgb display-p3": [171, 35, 23, 255],
        "display-p3 srgb": [187, 1, 0, 255],
        "display-p3 display-p3": [171, 35, 23, 255],
    },

    // 10 bit Rec.2020 Y'CbCr (0x126, 0x183, 0x3C0) = Rec.2020 (0x3FF, 0x000, 0x000)
    "Rec2020-3FF000000": {
        "srgb srgb": [255, 0, 0, 255],
        "srgb display-p3": [234, 51, 35, 255],
        "display-p3 srgb": [255, 0, 0, 255],
        "display-p3 display-p3": [255, 0, 9, 255],
    },
    // 10 bit Rec.2020 Y'CbCr (0x0BB, 0x1BD, 0x2EF) = Rec.2020 (0x222, 0x000, 0x000)
    "Rec2020-222000000": {
        "srgb srgb": [186, 0, 0, 255],
        "srgb display-p3": [170, 34, 23, 255],
        "display-p3 srgb": [186, 0, 0, 255],
        "display-p3 display-p3": [169, 0, 3, 255],
    },
};

const fromSRGBToDisplayP3 = {
    "255,0,0,255": [234, 51, 35, 255],
    "255,0,0,204": [234, 51, 35, 204],
    "187,0,0,255": [171, 35, 23, 255],
    "187,0,0,204": [171, 35, 23, 204],
};

const fromDisplayP3ToSRGB = {
    "255,0,0,255": [255, 0, 0, 255],
    "255,0,0,204": [255, 0, 0, 204],
    "187,0,0,255": [205, 0, 0, 255],
    "187,0,0,204": [205, 0, 0, 204],
};

function pixelsApproximatelyEqual(p1, p2) {
    for (let i = 0; i < 4; ++i) {
        if (Math.abs(p1[i] - p2[i]) > 3)
            return false;
    }
    return true;
}