2023-07-21 23:26:54 -04:00
|
|
|
import { RenderParams, histIndex, imageIndex } from "./0-utility.js";
|
2023-07-20 19:55:26 -04:00
|
|
|
import {
|
|
|
|
camera,
|
|
|
|
transform1Weight,
|
|
|
|
transform2Weight,
|
|
|
|
transform3Weight,
|
2023-07-21 23:26:54 -04:00
|
|
|
} from "./2a-baseline.js";
|
2023-07-20 19:55:26 -04:00
|
|
|
import {
|
|
|
|
TransformPost,
|
|
|
|
transform1Post,
|
|
|
|
transform2Post,
|
|
|
|
transform3Post,
|
2023-07-21 23:26:54 -04:00
|
|
|
transformAllPost,
|
|
|
|
} from "./2b-post.js";
|
|
|
|
import { RendererFinal, transformFinal } from "./2c-final.js";
|
2023-07-02 19:34:34 -04:00
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
export class RendererHistogram extends RendererFinal {
|
|
|
|
protected histogram: number[] = [];
|
2023-07-02 19:34:34 -04:00
|
|
|
|
|
|
|
constructor(
|
2023-07-20 19:55:26 -04:00
|
|
|
size: number,
|
|
|
|
transforms: [number, TransformPost][],
|
|
|
|
final: TransformPost
|
2023-07-02 19:34:34 -04:00
|
|
|
) {
|
2023-07-20 19:55:26 -04:00
|
|
|
super(size, transforms, final);
|
|
|
|
|
|
|
|
for (var i = 0; i < this.size * this.size; i++) {
|
2023-07-02 19:34:34 -04:00
|
|
|
this.histogram.push(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
plot(x: number, y: number): void {
|
|
|
|
[x, y] = this.final.apply(x, y);
|
|
|
|
const [pixelX, pixelY] = camera(x, y, this.size);
|
2023-07-02 19:34:34 -04:00
|
|
|
|
|
|
|
if (
|
|
|
|
pixelX < 0 ||
|
2023-07-20 19:55:26 -04:00
|
|
|
pixelY >= this.size ||
|
2023-07-02 19:34:34 -04:00
|
|
|
pixelY < 0 ||
|
2023-07-20 19:55:26 -04:00
|
|
|
pixelY >= this.size
|
2023-07-02 19:34:34 -04:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
const hIndex = histIndex(pixelX, pixelY, this.size);
|
|
|
|
this.histogram[hIndex] += 1;
|
2023-07-02 19:34:34 -04:00
|
|
|
}
|
|
|
|
|
2023-07-20 19:55:26 -04:00
|
|
|
render(image: ImageData): void {
|
|
|
|
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] = (this.histogram[hIndex] > 0 ? 1 : 0) * 0xff;
|
2023-07-02 19:34:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 23:26:54 -04:00
|
|
|
export const paramsBinary: RenderParams = {
|
|
|
|
quality: 1,
|
|
|
|
renderer: (size) =>
|
|
|
|
new RendererHistogram(size, transformAllPost, transformFinal),
|
|
|
|
};
|