UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

30 lines (29 loc) 790 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = copyImage; /** * Make a copy of the current image * @memberof Image * @instance * @param {Image} fromImage * @param {Image} toImage * @param {number} x * @param {number} y */ function copyImage(fromImage, toImage, x, y) { let fromWidth = fromImage.width; let fromHeight = fromImage.height; let toWidth = toImage.width; let channels = fromImage.channels; for (let i = 0; i < fromWidth; i++) { for (let j = 0; j < fromHeight; j++) { for (let k = 0; k < channels; k++) { let source = (j * fromWidth + i) * channels + k; let target = ((y + j) * toWidth + x + i) * channels + k; toImage.data[target] = fromImage.data[source]; } } } }