imagerot
Version:
A lightweight, cross-environment image library for applying unique effects via raw image buffers.
32 lines (31 loc) • 1.9 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.acid = void 0;
const helpers_1 = require("../../helpers");
const acid = (_a) => __awaiter(void 0, [_a], void 0, function* ({ data, width, height, effects }) {
const pixelOps = (0, helpers_1.getPixelOps)(effects);
const noiseIntensityRatio = 0.1;
const scanlinesConfig = { opacity: 0.1, thickness: 2, lines: 100 };
const rectangleConfig = { offset: 20, intensity: 15, sizeModifier: 3, invertChance: 0.1 };
const crAbConfig = { intensity: 5 };
data = (yield effects.scanlines.method({ data, width, height }, scanlinesConfig)) || data;
data = (yield effects.rainbow.method({ data, width, height })) || data;
data = (yield effects.rectangles.method({ data, width, height }, rectangleConfig)) || data;
for (let i = 0; i < data.length; i += 4) {
pixelOps.solarize({ index: i, data }, { intensity: 0.4 });
pixelOps.brightness({ index: i, data }, { brightness: -4 });
pixelOps.noise({ index: i, data }, { ratio: noiseIntensityRatio });
}
data = (yield effects.chromaticAberration.method({ data, width, height }, crAbConfig)) || data;
return data;
});
exports.acid = acid;