imagerot
Version:
A lightweight, cross-environment image library for applying unique effects via raw image buffers.
40 lines (39 loc) • 1.78 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.solarize = void 0;
const defaultIntensity = 0.5;
const solarization = (value, intensity) => {
const threshold = Math.floor(intensity * 255);
return value < threshold ? value : 255 - value;
};
const pixelOp = ({ index, data }, options = null) => {
const { intensity = defaultIntensity } = (options || {});
const r = data[index], g = data[index + 1], b = data[index + 2];
data[index] = solarization(r, intensity);
data[index + 1] = solarization(g, intensity);
data[index + 2] = solarization(b, intensity);
data[index + 3] = data[index + 3];
};
const global = (_a, ...args_1) => __awaiter(void 0, [_a, ...args_1], void 0, function* ({ data }, options = null) {
const { intensity = defaultIntensity } = (options || {});
for (let i = 0; i < data.length; i += 4) {
pixelOp({ index: i, data }, { intensity });
}
return data;
});
const solarize = {
name: 'solarize',
browser: global,
node: global,
pixelOp: pixelOp
};
exports.solarize = solarize;