imagerot
Version:
A lightweight, cross-environment image library for applying unique effects via raw image buffers.
31 lines (30 loc) • 1.87 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.lacunae = void 0;
const helpers_1 = require("../../helpers");
const math_1 = require("../../constants/math");
const lacunae = (_a) => __awaiter(void 0, [_a], void 0, function* ({ data }) {
for (let index = 0; index < data.length; index += 4) {
const useNoise = (0, math_1.random)() < 0.2;
const useGrain = (0, math_1.random)() < 0.4 ? (0, math_1.floor)((0, math_1.random)() * 50) : 0;
for (let i = 0; i < 3; i++) {
data[index + i] = data[index + i] - (0, helpers_1.randomize)(1, 15);
data[index + i] = data[index + i] < 0 ? data[index + i] + 255 : data[index + i];
data[index + i] = useNoise ? (0, math_1.min)(data[index + i] + (0, helpers_1.randomize)(1, i === 0 ? 15 : 10), 255) : data[index + i];
data[index + i] = (0, math_1.min)(255, (0, math_1.max)(0, data[index + i] + (0, math_1.floor)((0, math_1.random)() * 20 - 40)));
data[index + i] = useGrain ? (0, math_1.min)(255, (0, math_1.max)(0, data[index + i] + useGrain)) : data[index + i];
}
;
}
return data;
});
exports.lacunae = lacunae;