image-js
Version:
Image processing and manipulation in JavaScript
30 lines (29 loc) • 784 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = flipX;
/**
* Flip an image horizontally.
* @memberof Image
* @instance
* @return {this}
*/
function flipX() {
this.checkProcessable('flipX', {
bitDepth: [8, 16]
});
for (let i = 0; i < this.height; i++) {
let offsetY = i * this.width * this.channels;
for (let j = 0; j < Math.floor(this.width / 2); j++) {
let posCurrent = j * this.channels + offsetY;
let posOpposite = (this.width - j - 1) * this.channels + offsetY;
for (let k = 0; k < this.channels; k++) {
let tmp = this.data[posCurrent + k];
this.data[posCurrent + k] = this.data[posOpposite + k];
this.data[posOpposite + k] = tmp;
}
}
}
return this;
}