videoColorSpace.any.js (1517B)
1 // META: global=window,dedicatedworker 2 3 const VIDEO_COLOR_SPACE_SETS = { 4 primaries: ['bt709', 'bt470bg', 'smpte170m', 'bt2020', 'smpte432'], 5 transfer: ['bt709', 'smpte170m', 'iec61966-2-1', 'linear', 'pq', 'hlg'], 6 matrix: ['rgb', 'bt709', 'bt470bg', 'smpte170m', 'bt2020-ncl'], 7 fullRange: [true, false], 8 }; 9 10 function generateAllCombinations() { 11 const keys = Object.keys(VIDEO_COLOR_SPACE_SETS); 12 let colorSpaces = []; 13 generateAllCombinationsHelper(keys, 0, {}, colorSpaces); 14 return colorSpaces; 15 } 16 17 function generateAllCombinationsHelper(keys, keyIndex, colorSpace, results) { 18 if (keyIndex >= keys.length) { 19 // Push the copied object since the colorSpace will be reused. 20 results.push(Object.assign({}, colorSpace)); 21 return; 22 } 23 24 const prop = keys[keyIndex]; 25 // case 1: Skip this property. 26 generateAllCombinationsHelper(keys, keyIndex + 1, colorSpace, results); 27 // case 2: Set this property with a valid value. 28 for (const val of VIDEO_COLOR_SPACE_SETS[prop]) { 29 colorSpace[prop] = val; 30 generateAllCombinationsHelper(keys, keyIndex + 1, colorSpace, results); 31 delete colorSpace[prop]; 32 } 33 } 34 35 test(t => { 36 let colorSpaces = generateAllCombinations(); 37 for (const colorSpace of colorSpaces) { 38 let vcs = new VideoColorSpace(colorSpace); 39 let json = vcs.toJSON(); 40 for (const k of Object.keys(json)) { 41 assert_equals( 42 json[k], 43 colorSpace.hasOwnProperty(k) ? colorSpace[k] : null 44 ); 45 } 46 } 47 }, 'Test VideoColorSpace toJSON() works.');