|
|
@@ -319,6 +319,7 @@
|
|
|
function onControlsChange() {
|
|
|
updateOutputs();
|
|
|
scheduleRender();
|
|
|
+ renderPhotoSimulations();
|
|
|
}
|
|
|
|
|
|
/* ---------- Подписки ---------- */
|
|
|
@@ -345,6 +346,87 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /* ---------- Симуляция на загружаемой фотографии ---------- */
|
|
|
+ const photoFile = document.getElementById("photoFile");
|
|
|
+ const photoReset = document.getElementById("photoReset");
|
|
|
+ const photoStatus = document.getElementById("photoStatus");
|
|
|
+ const photoNvCanvas = document.getElementById("photoNvCanvas");
|
|
|
+ const photoThermalCanvas = document.getElementById("photoThermalCanvas");
|
|
|
+ const photoNvReadout = document.getElementById("photoNvReadout");
|
|
|
+ const photoThermalReadout = document.getElementById("photoThermalReadout");
|
|
|
+ const photoNvCtx = photoNvCanvas?.getContext("2d");
|
|
|
+ const photoThermalCtx = photoThermalCanvas?.getContext("2d");
|
|
|
+ let uploadedPhoto = null;
|
|
|
+
|
|
|
+ function fitPhotoCanvas(ctx, canvas, image) {
|
|
|
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
+ const scale = Math.min(canvas.width / image.width, canvas.height / image.height);
|
|
|
+ const w = image.width * scale, h = image.height * scale;
|
|
|
+ ctx.drawImage(image, (canvas.width-w)/2, (canvas.height-h)/2, w, h);
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderPhotoSimulations() {
|
|
|
+ if (!uploadedPhoto || !photoNvCtx || !photoThermalCtx) return;
|
|
|
+ fitPhotoCanvas(photoNvCtx, photoNvCanvas, uploadedPhoto);
|
|
|
+ fitPhotoCanvas(photoThermalCtx, photoThermalCanvas, uploadedPhoto);
|
|
|
+ const source = photoNvCtx.getImageData(0, 0, NV_W, NV_H);
|
|
|
+ const thermalSource = photoThermalCtx.getImageData(0, 0, NV_W, NV_H);
|
|
|
+ const nvGain = parseFloat(gainInput.value);
|
|
|
+ const luxFactor = clamp(parseFloat(luxInput.value) / 0.05, 0.02, 1);
|
|
|
+ const irFactor = irInput.checked ? 0.32 : 0;
|
|
|
+ const photoNV = source.data;
|
|
|
+ const photoThermal = thermalSource.data;
|
|
|
+ for (let i=0; i<photoNV.length; i+=4) {
|
|
|
+ const luminance = (0.2126*photoNV[i] + 0.7152*photoNV[i+1] + 0.0722*photoNV[i+2]) / 255;
|
|
|
+ const amplified = clamp((luminance * (0.25 + nvGain*1.65) * (0.18 + luxFactor*0.9)) + irFactor*(0.25+luminance), 0, 1);
|
|
|
+ const green = Math.round(255 * Math.pow(amplified, 0.72));
|
|
|
+ photoNV[i] = Math.round(green*0.20); photoNV[i+1] = green; photoNV[i+2] = Math.round(green*0.42);
|
|
|
+ const tl = (0.2126*thermalSource.data[i] + 0.7152*thermalSource.data[i+1] + 0.0722*thermalSource.data[i+2]) / 255;
|
|
|
+ const t = clamp((tl - 0.03) / 0.94, 0, 1);
|
|
|
+ const color = paletteRGB(paletteInput.value, t);
|
|
|
+ photoThermal[i] = color[0]; photoThermal[i+1] = color[1]; photoThermal[i+2] = color[2];
|
|
|
+ }
|
|
|
+ photoNvCtx.putImageData(source, 0, 0);
|
|
|
+ photoThermalCtx.putImageData(thermalSource, 0, 0);
|
|
|
+ photoNvReadout.textContent = `Усиление ${nvGain.toFixed(2)}× · ${irInput.checked ? "условная ИК-подсветка" : "без подсветки"}`;
|
|
|
+ photoThermalReadout.textContent = `Псевдопалитра · ${paletteInput.value}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ function paletteRGB(name, t) {
|
|
|
+ t = clamp(t, 0, 1);
|
|
|
+ if (name === "whiteHot") return [Math.round(255*t),Math.round(255*t),Math.round(255*t)];
|
|
|
+ if (name === "blackHot") return [Math.round(255*(1-t)),Math.round(255*(1-t)),Math.round(255*(1-t))];
|
|
|
+ let stops;
|
|
|
+ if (name === "ironbow") stops=[[0,0,0],[40,0,70],[140,30,20],[230,120,0],[255,210,40],[255,255,255]];
|
|
|
+ else if (name === "rainbow") stops=[[0,0,70],[0,160,255],[0,220,120],[255,230,0],[255,80,0],[255,255,255]];
|
|
|
+ else stops=[[20,0,30],[120,0,90],[220,40,20],[255,160,0],[255,255,180]];
|
|
|
+ const n=stops.length-1, p=t*n, idx=Math.floor(p), f=p-idx, a=stops[idx], b=stops[Math.min(n,idx+1)];
|
|
|
+ return [0,1,2].map(k=>Math.round(a[k]+(b[k]-a[k])*f));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (photoFile) photoFile.addEventListener("change", () => {
|
|
|
+ const file = photoFile.files?.[0];
|
|
|
+ if (!file) return;
|
|
|
+ if (!file.type.startsWith("image/")) { photoStatus.textContent = "Выберите файл изображения."; return; }
|
|
|
+ const url = URL.createObjectURL(file);
|
|
|
+ const image = new Image();
|
|
|
+ image.onload = () => {
|
|
|
+ uploadedPhoto = image;
|
|
|
+ renderPhotoSimulations();
|
|
|
+ photoStatus.textContent = `Загружено: ${file.name} (${image.width}×${image.height}). Обработка выполняется локально в браузере.`;
|
|
|
+ URL.revokeObjectURL(url);
|
|
|
+ };
|
|
|
+ image.onerror = () => { photoStatus.textContent = "Не удалось открыть изображение."; URL.revokeObjectURL(url); };
|
|
|
+ image.src = url;
|
|
|
+ });
|
|
|
+ if (photoReset) photoReset.addEventListener("click", () => {
|
|
|
+ uploadedPhoto = null; if (photoFile) photoFile.value = "";
|
|
|
+ [photoNvCanvas, photoThermalCanvas].forEach(c => c && c.getContext("2d").clearRect(0,0,c.width,c.height));
|
|
|
+ if (photoStatus) photoStatus.textContent = "Пока изображение не загружено.";
|
|
|
+ if (photoNvReadout) photoNvReadout.textContent = "—"; if (photoThermalReadout) photoThermalReadout.textContent = "—";
|
|
|
+ });
|
|
|
+
|
|
|
/* ---------- Квиз ---------- */
|
|
|
const answers = {
|
|
|
q1: "b",
|
|
|
@@ -400,6 +482,7 @@
|
|
|
/* ---------- Запуск ---------- */
|
|
|
updateOutputs();
|
|
|
render();
|
|
|
+ renderPhotoSimulations();
|
|
|
|
|
|
// Плавный "живой" шум сенсоров
|
|
|
setInterval(render, 140);
|