index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * Flip the image horizontally
  9. * @param {boolean} horizontal a Boolean, if true the image will be flipped horizontally
  10. * @param {boolean} vertical a Boolean, if true the image will be flipped vertically
  11. * @param {function(Error, Jimp)} cb (optional) a callback for when complete
  12. * @returns {Jimp} this for chaining of methods
  13. */
  14. function flipFn(horizontal, vertical, cb) {
  15. if (typeof horizontal !== 'boolean' || typeof vertical !== 'boolean') return _utils.throwError.call(this, 'horizontal and vertical must be Booleans', cb);
  16. var bitmap = Buffer.alloc(this.bitmap.data.length);
  17. this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
  18. var _x = horizontal ? this.bitmap.width - 1 - x : x;
  19. var _y = vertical ? this.bitmap.height - 1 - y : y;
  20. var _idx = this.bitmap.width * _y + _x << 2;
  21. var data = this.bitmap.data.readUInt32BE(idx);
  22. bitmap.writeUInt32BE(data, _idx);
  23. });
  24. this.bitmap.data = Buffer.from(bitmap);
  25. if ((0, _utils.isNodePattern)(cb)) {
  26. cb.call(this, null, this);
  27. }
  28. return this;
  29. }
  30. var _default = function _default() {
  31. return {
  32. flip: flipFn,
  33. mirror: flipFn
  34. };
  35. };
  36. exports["default"] = _default;
  37. //# sourceMappingURL=index.js.map