@thi.ng/pixel
Version:
Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution
23 lines (22 loc) • 662 B
JavaScript
import { fit, fitClamped } from "@thi.ng/math/fit";
import { mix } from "@thi.ng/math/mix";
import { Lane } from "../api.js";
import { __luminanceABGR } from "../internal/utils.js";
const FLOAT_GRAY_RANGE = (min, max) => {
return {
__float: true,
alpha: false,
gray: true,
channels: [Lane.RED],
shift: { 3: 0 },
size: 1,
range: [min, max],
normalized: (val) => fitClamped(val, min, max, 0, 1),
fromNormalized: (val) => mix(min, max, val),
fromABGR: (src) => [mix(min, max, __luminanceABGR(src) / 255)],
toABGR: (src) => (fit(src[0], min, max, 0, 255) | 0) * 65793 | 4278190080
};
};
export {
FLOAT_GRAY_RANGE
};