Explorar el Código

v.0.2.0.3 [photo]

ypv hace 2 días
padre
commit
04d8fabce7

+ 83 - 0
ПМ.03.01/4.7.200/002/app.js

@@ -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);

+ 24 - 0
ПМ.03.01/4.7.200/002/index.html

@@ -105,6 +105,30 @@
       </fieldset>
     </section>
 
+
+    <section class="photo-mode" aria-label="Симуляция приборов на реальной фотографии">
+      <h2>Работа с реальной фотографией</h2>
+      <p class="hint photo-intro">Загрузите фотографию и сравните учебную симуляцию ЭОП и тепловизора. Это не настоящие ночные или температурные данные: исходное фото не содержит спектральной информации или измерений температуры.</p>
+      <div class="photo-upload">
+        <label for="photoFile" class="upload-label">Выберите изображение (JPG, PNG, WebP)</label>
+        <input id="photoFile" type="file" accept="image/*">
+        <button type="button" id="photoReset">Очистить фотографию</button>
+        <span id="photoStatus" class="hint">Пока изображение не загружено.</span>
+      </div>
+      <div class="stage photo-stage">
+        <article class="panel nv">
+          <div class="panel-head"><div class="panel-title"><span class="dot"></span>Симуляция ЭОП</div><div class="readout" id="photoNvReadout">—</div></div>
+          <canvas id="photoNvCanvas" width="720" height="405"></canvas>
+          <div class="panel-foot">Серый уровень исходной фотографии преобразуется в зелёное изображение с моделируемым усилением. ИК-подсветка условно повышает видимость.</div>
+        </article>
+        <article class="panel thermal">
+          <div class="panel-head"><div class="panel-title"><span class="dot"></span>Симуляция тепловизора</div><div class="readout" id="photoThermalReadout">—</div></div>
+          <canvas id="photoThermalCanvas" width="720" height="405"></canvas>
+          <div class="panel-foot">Псевдотепловая палитра отображает яркость исходного фото, а не реальную температуру или ИК-излучение.</div>
+        </article>
+      </div>
+    </section>
+
     <section class="quiz" id="quiz">
       <h2>Проверка знаний</h2>
 

+ 3 - 0
ПМ.03.01/4.7.200/002/specification.md

@@ -2,6 +2,9 @@
 
 - **Что изменено:**
 
+загружаемая фотография должна быть на месте текущей схемы (заменять ее), должны быть и отображаться на схеме выбранные ползунками параметры, в тепловизоре должны быть выделены теплые объекты (предложи, как это сделать)
+v.0.2.0.3 [photo]
+
 Рефакториринг: убран дублирующий js из index.html  
 v.0.1.1.2 [refactor] ✅ DONE
 

+ 11 - 1
ПМ.03.01/4.7.200/002/style.css

@@ -417,4 +417,14 @@ input:focus {
   * {
     transition: none !important;
   }
-}
+}
+
+/* ---------- Режим загружаемой фотографии ---------- */
+.photo-mode { margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,0.02); }
+.photo-mode h2 { margin: 0 0 8px; font-size: 18px; }
+.photo-intro { max-width: 1000px; margin-bottom: 14px; }
+.photo-upload { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px; border: 1px dashed var(--line2); border-radius: 14px; margin-bottom: 16px; }
+.upload-label { display: block; margin: 0; color: var(--text); font-weight: 600; }
+.photo-upload input[type="file"] { max-width: 100%; color: var(--muted); }
+.photo-stage { margin-top: 0; }
+@media (max-width: 620px) { .photo-upload { align-items: flex-start; flex-direction: column; } }