@thi.ng/pixel
Version:
Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution
25 lines (24 loc) • 685 B
JavaScript
import { clamp, clamp01 } from "@thi.ng/math/interval";
import { Lane } from "../api.js";
const __from = (x) => x / 127.5 - 1;
const __to = (x, shift) => clamp(x * 127.5 + 128, 0, 255) << shift;
const FLOAT_NORMAL = {
__float: true,
alpha: false,
gray: false,
channels: [Lane.RED, Lane.GREEN, Lane.BLUE],
shift: { 3: 0, 2: 8, 1: 16 },
size: 3,
range: [-1, 1],
normalized: (val) => clamp01(val * 0.5 + 0.5),
fromNormalized: (val) => val * 2 - 1,
fromABGR: (src) => [
__from(src & 255),
__from(src >> 8 & 255),
__from(src >> 16 & 255)
],
toABGR: (src) => __to(src[0], 0) | __to(src[1], 8) | __to(src[2], 16) | 4278190080
};
export {
FLOAT_NORMAL
};