mirror of
https://github.com/bspeice/speice.io
synced 2024-12-22 16:48:10 -05:00
29 lines
588 B
TypeScript
29 lines
588 B
TypeScript
export function paintLogarithmic(
|
|
width: number,
|
|
height: number,
|
|
hist: number[]
|
|
) {
|
|
const img =
|
|
new ImageData(width, height);
|
|
|
|
const histLog = hist.map(Math.log);
|
|
|
|
let hLogMax = -Infinity;
|
|
for (let value of histLog) {
|
|
hLogMax = Math.max(hLogMax, value);
|
|
}
|
|
|
|
for (let i = 0; i < hist.length; i++) {
|
|
const pixelIndex = i * 4;
|
|
|
|
img.data[pixelIndex] = 0; // red
|
|
img.data[pixelIndex + 1] = 0; // green
|
|
img.data[pixelIndex + 2] = 0; // blue
|
|
|
|
const alpha =
|
|
histLog[i] / hLogMax * 0xff;
|
|
img.data[pixelIndex + 3] = alpha;
|
|
}
|
|
|
|
return img;
|
|
} |