paeth-predictor.js 372 B

1234567891011121314151617
  1. 'use strict';
  2. module.exports = function paethPredictor(left, above, upLeft) {
  3. var paeth = left + above - upLeft;
  4. var pLeft = Math.abs(paeth - left);
  5. var pAbove = Math.abs(paeth - above);
  6. var 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. };