index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if (horizontal && vertical) {
  17. // shortcut
  18. return this.rotate(180, true, cb);
  19. }
  20. var bitmap = Buffer.alloc(this.bitmap.data.length);
  21. this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
  22. var _x = horizontal ? this.bitmap.width - 1 - x : x;
  23. var _y = vertical ? this.bitmap.height - 1 - y : y;
  24. var _idx = this.bitmap.width * _y + _x << 2;
  25. var data = this.bitmap.data.readUInt32BE(idx);
  26. bitmap.writeUInt32BE(data, _idx);
  27. });
  28. this.bitmap.data = Buffer.from(bitmap);
  29. if ((0, _utils.isNodePattern)(cb)) {
  30. cb.call(this, null, this);
  31. }
  32. return this;
  33. }
  34. var _default = function _default() {
  35. return {
  36. flip: flipFn,
  37. mirror: flipFn
  38. };
  39. };
  40. exports["default"] = _default;
  41. module.exports = exports.default;
  42. //# sourceMappingURL=index.js.map