index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _utils = require("@jimp/utils");
  7. /**
  8. * Apply a ordered dithering effect
  9. * @param {function(Error, Jimp)} cb (optional) a callback for when complete
  10. * @returns {Jimp} this for chaining of methods
  11. */
  12. function dither(cb) {
  13. var rgb565Matrix = [1, 9, 3, 11, 13, 5, 15, 7, 4, 12, 2, 10, 16, 8, 14, 6];
  14. this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
  15. var thresholdId = ((y & 3) << 2) + x % 4;
  16. var dither = rgb565Matrix[thresholdId];
  17. this.bitmap.data[idx] = Math.min(this.bitmap.data[idx] + dither, 0xff);
  18. this.bitmap.data[idx + 1] = Math.min(this.bitmap.data[idx + 1] + dither, 0xff);
  19. this.bitmap.data[idx + 2] = Math.min(this.bitmap.data[idx + 2] + dither, 0xff);
  20. });
  21. if ((0, _utils.isNodePattern)(cb)) {
  22. cb.call(this, null, this);
  23. }
  24. return this;
  25. }
  26. var _default = function _default() {
  27. return {
  28. dither565: dither,
  29. dither16: dither
  30. };
  31. };
  32. exports["default"] = _default;
  33. //# sourceMappingURL=index.js.map