2024-12-15 21:19:09 -05:00
|
|
|
export function paintLinear(
|
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
hist: number[]
|
|
|
|
) {
|
|
|
|
const img =
|
|
|
|
new ImageData(width, height);
|
2024-12-01 21:57:10 -05:00
|
|
|
|
2024-12-15 21:19:09 -05:00
|
|
|
let hMax = 0;
|
|
|
|
for (let value of hist) {
|
|
|
|
hMax = Math.max(hMax, value);
|
|
|
|
}
|
2024-12-01 21:57:10 -05:00
|
|
|
|
2024-12-15 21:19:09 -05:00
|
|
|
for (let i = 0; i < hist.length; i++) {
|
|
|
|
const pixelIndex = i * 4;
|
2024-12-01 21:57:10 -05:00
|
|
|
|
2024-12-15 21:19:09 -05:00
|
|
|
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;
|
2024-12-01 21:57:10 -05:00
|
|
|
}
|