Files
gods-eye-view/src/layers/weather/infraredImage.js
T
German KhokhlovandClaude Opus 5.5 00704ddc89 i18n: fix review findings and polish ru/es strings
Fixes the 51 P0–P2 findings from the full review of the i18n branch and
the issues found while checking every new string on screen in ru and es.

- Translate errors and statuses that still reached ru/es in English:
  feed and tile errors, provider statuses, the ALPR chip, the traffic
  mode chip, voice plan step labels, fire feed values, receiver bands,
  scene save reasons and the Cesium attribution link.
- Show preset city names in the UI language (src/ui/placeNames.js);
  data and everything sent to the model stay English.
- Share layer names between the layer panel, HUD and voice card
  (src/ui/layerNames.js).
- Keep long ru/es strings whole: voice card error lines, analyst
  titles, the voice tier status, the Nepal evidence button, the ALPR
  retry chip. English layout is unchanged.
- Ask before a language switch drops unsaved work.
- Catalog fixes: glossary terms (пуск, пресет), gender agreement and
  consistent "peticiones" in es, fewer calques in both languages.
- Fix English text that was itself wrong (e.g. "Exit cockpit to fly to
  a weather", raw tool ids in voice plan steps).

Catalogs: es/ru 2535 messages each, complete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 23:49:52 +04:00

119 lines
3.6 KiB
JavaScript

import { readResponseBytesCapped } from '../../sources/httpBody.js';
import { msg } from '../../i18n/index.js';
import { weatherImageUrl } from './source.js';
import { infraredAlpha } from './infraredAlpha.js';
export const MAX_MOSAIC_BYTES = 4 * 1024 * 1024;
/** Apply the display transfer once to a decoded image; `flipY` draws a
* bottom-up image back upright. */
export function processInfraredImage(
image,
mode,
createCanvas,
{ flipY = false } = {},
) {
const canvas = createCanvas();
canvas.width = image.width;
canvas.height = image.height;
const context = canvas.getContext('2d');
if (flipY) context.setTransform(1, 0, 0, -1, 0, image.height);
context.drawImage(image, 0, 0);
if (flipY) context.setTransform(1, 0, 0, 1, 0, 0);
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
pixels.data.set(infraredAlpha(pixels.data, mode));
context.putImageData(pixels, 0, 0);
return canvas;
}
/** Decode locally, releasing the object URL on success, failure or cancellation. */
export function decodeInfraredImage(blob, signal) {
signal.throwIfAborted();
if (typeof globalThis.createImageBitmap === 'function')
return globalThis.createImageBitmap(blob);
return new Promise((resolve, reject) => {
const image = new Image();
const url = URL.createObjectURL(blob);
const cleanup = () => {
signal.removeEventListener('abort', abort);
image.onload = image.onerror = null;
URL.revokeObjectURL(url);
};
const abort = () => {
cleanup();
image.src = '';
reject(signal.reason);
};
image.onload = () => {
cleanup();
resolve(image);
};
image.onerror = () => {
cleanup();
reject(new Error(msg('Infrared decode failed')));
};
signal.addEventListener('abort', abort, { once: true });
image.src = url;
});
}
/** Fetch one capped whole-extent frame, or a `bbox` detail window of it, and draw
* it into a canvas. Infrared frames get the display transfer; a canvas also keeps
* Cesium's texture row order, which an ImageBitmap upload would not. The decoded
* image is always released. */
export async function acquireWeatherImage(
product,
time,
{
signal,
mode,
size,
bbox = null,
maxBytes,
createCanvas,
fetchImpl,
decodeImage = decodeInfraredImage,
now = () => performance.now(),
onFetched = () => {},
},
) {
const response = await fetchImpl(weatherImageUrl(product, time, size, bbox), {
signal,
});
if (!response.ok) throw new Error(`Weather HTTP ${response.status}`);
const bytes = await readResponseBytesCapped(response, maxBytes);
signal.throwIfAborted();
onFetched();
const started = now();
const image = await decodeImage(
new Blob([bytes], { type: 'image/png' }),
signal,
);
try {
signal.throwIfAborted();
if (image.width !== size.width || image.height !== size.height)
throw new Error('Invalid weather image dimensions');
let texture;
if (product === 'clouds' || product === 'clouds-regional')
texture = processInfraredImage(image, mode, createCanvas);
else {
texture = createCanvas();
texture.width = image.width;
texture.height = image.height;
texture.getContext('2d').drawImage(image, 0, 0);
}
return { texture, decodeMs: now() - started };
} finally {
image.close?.();
}
}
/** Acquire one capped global mosaic before adding any imagery layer. */
export function acquireInfraredMosaic(time, options) {
return acquireWeatherImage('clouds', time, {
...options,
size: { width: 2048, height: 1024 },
maxBytes: MAX_MOSAIC_BYTES,
});
}