Files
shaka-player/build/pixelsChanged.js
T
Joey Parrish 852a11d055 test: Fix Windows screenshots
Since upgrading to Chromium-based Edge, some slight rendering changes
have thrown off our screenshots.  In some, the shade of green in the
background has changed slightly.

This slightly increases the threshold for detecting individual pixel
changes, so that most of these tiny shade changes now pass.

In one other case, a change in the outline of the green-on-blue test
required an actual screenshot update for both Chrome and Edge on
Windows.

Change-Id: I413f927e3d3a00b8369600808392c6b05a185d54
2021-01-25 13:59:23 -08:00

36 lines
991 B
JavaScript
Executable File

#!/usr/bin/env node
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview
*
* A node script that uses the Jimp module to compute the number of changed
* pixels between two images.
*/
const Jimp = require('jimp');
/**
* Compare two images and output the number of changed pixels. Uses the same
* node module as the comparisons done in the tests through Karma.
*
* @param {string} oldPath
* @param {string} newPath
*/
async function main(oldPath, newPath) {
const oldImage = await Jimp.read(oldPath);
const newImage = await Jimp.read(newPath);
const diff = Jimp.diff(oldImage, newImage, /* threshold= */ 0.07);
// "percent" is, surprisingly, a number between 0 and 1, not between 0 and
// 100. Convert this to a number of pixels.
const pixelsChanged =
diff.percent * diff.image.bitmap.width * diff.image.bitmap.height;
console.log(pixelsChanged);
}
main(process.argv[2], process.argv[3]);