mirror of
https://github.com/bspeice/speice.io
synced 2024-12-23 00:58:09 -05:00
26 lines
488 B
TypeScript
26 lines
488 B
TypeScript
export function paintLinear(
|
|
width: number,
|
|
height: number,
|
|
hist: number[]
|
|
) {
|
|
const img =
|
|
new ImageData(width, height);
|
|
|
|
let hMax = 0;
|
|
for (let value of hist) {
|
|
hMax = Math.max(hMax, value);
|
|
}
|
|
|
|
for (let i = 0; i < hist.length; i++) {
|
|
const pixelIndex = i * 4;
|
|
|
|
img.data[pixelIndex] = 0;
|
|
img.data[pixelIndex + 1] = 0;
|
|
img.data[pixelIndex + 2] = 0;
|
|
|
|
const alpha = hist[i] / hMax * 0xff;
|
|
img.data[pixelIndex + 3] = alpha;
|
|
}
|
|
|
|
return img;
|
|
} |