paeth-predictor.js 372 B

12345678910111213141516
  1. "use strict";
  2. module.exports = function paethPredictor(left, above, upLeft) {
  3. let paeth = left + above - upLeft;
  4. let pLeft = Math.abs(paeth - left);
  5. let pAbove = Math.abs(paeth - above);
  6. let pUpLeft = Math.abs(paeth - upLeft);
  7. if (pLeft <= pAbove && pLeft <= pUpLeft) {
  8. return left;
  9. }
  10. if (pAbove <= pUpLeft) {
  11. return above;
  12. }
  13. return upLeft;
  14. };