UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

29 lines (28 loc) 789 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = flipY; /** * Flip an image vertically. The image * @memberof Image * @instance * @return {this} */ function flipY() { this.checkProcessable('flipY', { bitDepth: [8, 16] }); for (let i = 0; i < Math.floor(this.height / 2); i++) { for (let j = 0; j < this.width; j++) { let posCurrent = j * this.channels + i * this.width * this.channels; let posOpposite = j * this.channels + (this.height - 1 - i) * this.channels * this.width; 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; }