speice.io/blog/2024-11-15-playing-with-fire/3-log-density/paintLinear.ts

18 lines
546 B
TypeScript

export function paintLinear(width: number, height: number, histogram: number[]): ImageData {
const image = new ImageData(width, height);
let valueMax = 0;
for (let value of histogram) {
valueMax = Math.max(valueMax, value);
}
for (let i = 0; i < histogram.length; i++) {
const pixelIndex = i * 4;
image.data[pixelIndex] = 0;
image.data[pixelIndex + 1] = 0;
image.data[pixelIndex + 2] = 0;
image.data[pixelIndex + 3] = histogram[i] / valueMax * 0xff;
}
return image;
}