2023-07-21 23:26:54 -04:00
|
|
|
import { RenderParams, histIndex, imageIndex } from "./0-utility.js";
|
|
|
|
import { transformAllPost } from "./2b-post.js";
|
|
|
|
import { transformFinal } from "./2c-final.js";
|
|
|
|
import { RendererHistogram } from "./3a-binary.js";
|
2023-07-02 19:34:34 -04:00
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
export class RendererLogarithmic extends RendererHistogram {
|
2023-07-02 19:34:34 -04:00
|
|
|
render(image: ImageData): void {
|
2023-07-20 19:55:26 -04:00
|
|
|
// Because log(0) is -Infinity, all the math actually works out.
|
|
|
|
const histogramLog = this.histogram.map(Math.log);
|
2023-07-21 23:26:54 -04:00
|
|
|
const histogramLogMax = histogramLog.reduce(
|
|
|
|
(max, v) => Math.max(max, v),
|
|
|
|
-Infinity
|
|
|
|
);
|
2023-07-02 19:34:34 -04:00
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
for (var x = 0; x < this.size; x++) {
|
|
|
|
for (var y = 0; y < this.size; y++) {
|
|
|
|
const hIndex = histIndex(x, y, this.size);
|
|
|
|
const iIndex = imageIndex(x, y, this.size);
|
|
|
|
image.data[iIndex + 0] = 0;
|
|
|
|
image.data[iIndex + 1] = 0;
|
|
|
|
image.data[iIndex + 2] = 0;
|
|
|
|
image.data[iIndex + 3] =
|
|
|
|
(histogramLog[hIndex] / histogramLogMax) * 0xff;
|
2023-07-02 19:34:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 23:26:54 -04:00
|
|
|
export const paramsLogarithmic: RenderParams = {
|
|
|
|
quality: 10,
|
|
|
|
renderer: (size) =>
|
|
|
|
new RendererLogarithmic(size, transformAllPost, transformFinal),
|
|
|
|
};
|