UNPKG

imagerot

Version:

A lightweight, cross-environment image library for applying unique effects via raw image buffers.

35 lines (34 loc) 1.64 kB
"use strict"; 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.scanlines = void 0; const defaultOpacity = 0.5; const defaultThickness = 1; const defaultLines = 10; const global = (_a, ...args_1) => __awaiter(void 0, [_a, ...args_1], void 0, function* ({ data, width, height }, options = null) { const { opacity = defaultOpacity, thickness = defaultThickness, lines = defaultLines, } = (options || {}); const scanlinePixelAmount = Math.floor(height / lines); for (let i = 0; i < data.length; i += 4) { let currentLine = Math.floor((i / 4) / width); if (currentLine % scanlinePixelAmount < thickness) { data[i] = data[i] * (1 - opacity); data[i + 1] = data[i + 1] * (1 - opacity); data[i + 2] = data[i + 2] * (1 - opacity); } } return data; }); const scanlines = { name: 'scanlines', browser: global, node: global }; exports.scanlines = scanlines;