image-js
Version:
Image processing and manipulation in JavaScript
32 lines • 1.31 kB
JavaScript
import { Image } from '../Image.js';
import { getDefaultColor } from '../utils/getDefaultColor.js';
import { getOutputImage, maskToOutputMask } from '../utils/getOutputImage.js';
import { setBlendedVisiblePixel } from '../utils/setBlendedVisiblePixel.js';
import checkProcessable from '../utils/validators/checkProcessable.js';
import { validateColor } from '../utils/validators/validators.js';
/**
* Draw a set of points on an image or a mask.
* @param image - The image on which to draw the points.
* @param points - Array of points.
* @param options - Draw points on Image options.
* @returns New mask.
*/
export function drawPoints(image, points, options = {}) {
const { color = getDefaultColor(image), origin = { row: 0, column: 0 } } = options;
let newImage;
if (image instanceof Image) {
newImage = getOutputImage(image, options, { clone: true });
validateColor(color, newImage);
}
else {
newImage = maskToOutputMask(image, options, { clone: true });
}
checkProcessable(newImage, {
bitDepth: [1, 8, 16],
});
for (const point of points) {
setBlendedVisiblePixel(newImage, Math.round(origin.column + point.column), Math.round(origin.row + point.row), color);
}
return newImage;
}
//# sourceMappingURL=drawPoints.js.map