mirror of
https://github.com/bspeice/speice.io
synced 2024-12-23 00:58:09 -05:00
18 lines
546 B
TypeScript
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;
|
|
} |