mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 10:42:22 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
146b7e6027 | ||
|
|
7b6ec7f963 |
No files matched your search
@@ -0,0 +1,4 @@
|
||||
- Fix the page freezing for three to five seconds when Shipwrecks is switched
|
||||
on over a loaded globe. Each of the 7,958 markers read the terrain height as
|
||||
it was created; they are now placed on the ellipsoid, where they already
|
||||
drew (mazy1998, #1703).
|
||||
@@ -1,3 +0,0 @@
|
||||
- Halve the time the satellite cloud image takes to prepare on the 3D Tiles
|
||||
map by applying its transparency curve from a lookup table, in place
|
||||
(mazy1998, #1713).
|
||||
@@ -194,8 +194,8 @@ refers to a person by a title or role (Mr, captain, master, owner, crew,
|
||||
such word can still pass. Deaths appear only as a Wikidata count.
|
||||
|
||||
The globe draws a round marker with a hull and mast per wreck, all in one
|
||||
billboard collection, ground-clamped with the depth test off and the horizon
|
||||
cull GhostMaps uses, sized by deaths (a bigger toll draws on top) and coloured
|
||||
billboard collection, placed on the ellipsoid (no terrain height read per
|
||||
marker) with the depth test off and the horizon cull GhostMaps uses, sized by deaths (a bigger toll draws on top) and coloured
|
||||
by era (a legend under the row): before 1900 (ancient wrecks dated only by
|
||||
period count here), 1900–1945, after 1945, and date unknown. A period filter
|
||||
under the row picks a start year and an end year side by side (two pickers
|
||||
|
||||
@@ -159,6 +159,11 @@ export function createShipwrecksLayer({
|
||||
(a, b) => (a.casualties || 0) - (b.casualties || 0),
|
||||
);
|
||||
for (const record of ordered) {
|
||||
// On the ellipsoid, with no height reference. A ground-clamped billboard
|
||||
// reads the terrain height as it is created, and that read for every
|
||||
// wreck in one pass froze the page for seconds. Wrecks lie at sea, the
|
||||
// depth test is off and the card already sits here, so the marker
|
||||
// shows in the same place.
|
||||
const position = Cesium.Cartesian3.fromDegrees(record.lon, record.lat);
|
||||
const size = markerPixelSize(record.casualties);
|
||||
const billboard = _markers.add({
|
||||
@@ -167,7 +172,6 @@ export function createShipwrecksLayer({
|
||||
image: _images[eraOf(record)],
|
||||
width: size,
|
||||
height: size,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
});
|
||||
const pin = {
|
||||
|
||||
@@ -163,6 +163,20 @@ test('markers sit on the wreck: no eye offset, bigger toll drawn last', async ()
|
||||
assert.equal(h.markers.billboards[2].width, markerPixelSize(1500));
|
||||
});
|
||||
|
||||
test('markers are placed without a terrain height read each', async () => {
|
||||
// A ground-clamped billboard reads the terrain height when it is created;
|
||||
// for every wreck in one pass that froze the page for seconds.
|
||||
const h = harness({ snapshots: [snapshot([wreck('a'), wreck('b')])] });
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
assert.equal(h.markers.billboards.length, 2);
|
||||
for (const billboard of h.markers.billboards) {
|
||||
assert.equal(billboard.heightReference, undefined);
|
||||
const { height } = Cesium.Cartographic.fromCartesian(billboard.position);
|
||||
assert.equal(Math.abs(height) < 1e-6, true);
|
||||
}
|
||||
});
|
||||
|
||||
test('an unchanged snapshot does not rebuild the markers', async () => {
|
||||
const records = [wreck('a')];
|
||||
const h = harness({
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
export const INFRARED_ALPHA_T0 = 0.4;
|
||||
export const INFRARED_ALPHA_T1 = 0.7;
|
||||
|
||||
function infraredAmount(strength) {
|
||||
return strength === 'full'
|
||||
? 0
|
||||
: strength === 'filtered' || !Number.isFinite(strength)
|
||||
? 1
|
||||
: Math.max(0, Math.min(100, strength)) / 100;
|
||||
}
|
||||
|
||||
/** Scale each pixel's alpha in place; RGB is left as it is. The scale depends
|
||||
* only on the brightest channel, so it is worked out once for each of the 256
|
||||
* byte values instead of once per pixel: a 4096×2048 image has 8.4 million
|
||||
* pixels and the power curve per pixel held the page for over 100 ms. The
|
||||
* table holds the same numbers the per-pixel formula produced, so the output
|
||||
* bytes are unchanged.
|
||||
/** Return display pixels without changing RGB or the source RGBA bytes.
|
||||
* `strength` is 0–100: zero is the full image and 100 is the cloud key.
|
||||
*/
|
||||
export function applyInfraredAlpha(pixels, strength = 'filtered') {
|
||||
const amount = infraredAmount(strength);
|
||||
export function infraredAlpha(rgba, strength = 'filtered') {
|
||||
const pixels = new Uint8ClampedArray(rgba);
|
||||
const amount =
|
||||
strength === 'full'
|
||||
? 0
|
||||
: strength === 'filtered' || !Number.isFinite(strength)
|
||||
? 1
|
||||
: Math.max(0, Math.min(100, strength)) / 100;
|
||||
if (amount === 0) return pixels;
|
||||
const scale = new Float64Array(256);
|
||||
for (let value = 0; value < 256; value++) {
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
// Match Cesium's czm_srgbToLinear conversion in draped imagery.
|
||||
const linearMax = (value / 255) ** 2.2;
|
||||
const linearMax =
|
||||
(Math.max(rgba[i], rgba[i + 1], rgba[i + 2]) / 255) ** 2.2;
|
||||
const t = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
@@ -33,21 +26,7 @@ export function applyInfraredAlpha(pixels, strength = 'filtered') {
|
||||
),
|
||||
);
|
||||
const filtered = t * t * (3 - 2 * t);
|
||||
scale[value] = 1 - amount + filtered * amount;
|
||||
}
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
const r = pixels[i];
|
||||
const g = pixels[i + 1];
|
||||
const b = pixels[i + 2];
|
||||
const max = r > g ? (r > b ? r : b) : g > b ? g : b;
|
||||
pixels[i + 3] = pixels[i + 3] * scale[max];
|
||||
pixels[i + 3] = rgba[i + 3] * (1 - amount + filtered * amount);
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
|
||||
/** Return display pixels without changing RGB or the source RGBA bytes.
|
||||
* `strength` is 0–100: zero is the full image and 100 is the cloud key.
|
||||
*/
|
||||
export function infraredAlpha(rgba, strength = 'filtered') {
|
||||
return applyInfraredAlpha(new Uint8ClampedArray(rgba), strength);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
applyInfraredAlpha,
|
||||
infraredAlpha,
|
||||
INFRARED_ALPHA_T0,
|
||||
INFRARED_ALPHA_T1,
|
||||
@@ -62,43 +61,3 @@ test('full infrared preserves every channel including partial and zero alpha', (
|
||||
]);
|
||||
assert.deepEqual(infraredAlpha(pixels, 'full'), pixels);
|
||||
});
|
||||
|
||||
test('the lookup table gives the per-pixel curve byte for byte, in place', () => {
|
||||
// The transfer as it was written per pixel, before the table.
|
||||
const perPixel = (rgba, amount) => {
|
||||
const out = new Uint8ClampedArray(rgba);
|
||||
for (let i = 0; i < out.length; i += 4) {
|
||||
const linearMax =
|
||||
(Math.max(rgba[i], rgba[i + 1], rgba[i + 2]) / 255) ** 2.2;
|
||||
const t = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
1,
|
||||
(linearMax - INFRARED_ALPHA_T0) /
|
||||
(INFRARED_ALPHA_T1 - INFRARED_ALPHA_T0),
|
||||
),
|
||||
);
|
||||
out[i + 3] = rgba[i + 3] * (1 - amount + t * t * (3 - 2 * t) * amount);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
// Every brightest-channel value in each channel, against a spread of alphas.
|
||||
const bytes = [];
|
||||
for (let value = 0; value < 256; value++)
|
||||
for (const alpha of [0, 1, 37, 128, 200, 254, 255]) {
|
||||
bytes.push(value, 0, 0, alpha);
|
||||
bytes.push(value >> 1, value, 0, alpha);
|
||||
bytes.push(0, value >> 2, value, alpha);
|
||||
}
|
||||
const source = new Uint8ClampedArray(bytes);
|
||||
for (const strength of [1, 33, 50, 99, 100, 'filtered', Number.NaN]) {
|
||||
const amount = Number.isFinite(strength) ? strength / 100 : 1;
|
||||
const pixels = source.slice();
|
||||
assert.equal(applyInfraredAlpha(pixels, strength), pixels);
|
||||
assert.deepEqual(pixels, perPixel(source, amount), `strength ${strength}`);
|
||||
}
|
||||
for (const strength of [0, 'full']) {
|
||||
const pixels = source.slice();
|
||||
assert.deepEqual(applyInfraredAlpha(pixels, strength), source);
|
||||
}
|
||||
});
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
drawWeatherPixels,
|
||||
closeWeatherPixels,
|
||||
} from './source.js';
|
||||
import { applyInfraredAlpha } from './infraredAlpha.js';
|
||||
import { infraredAlpha } from './infraredAlpha.js';
|
||||
|
||||
export const MAX_MOSAIC_BYTES = 4 * 1024 * 1024;
|
||||
|
||||
@@ -31,8 +31,7 @@ export function processInfraredImage(
|
||||
|
||||
function applyInfraredTransfer(context, canvas, mode) {
|
||||
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
// In place: a copy of a 4096×2048 image is 33 MB, made and written back.
|
||||
applyInfraredAlpha(pixels.data, mode);
|
||||
pixels.data.set(infraredAlpha(pixels.data, mode));
|
||||
context.putImageData(pixels, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,28 +26,6 @@ function canvas() {
|
||||
return output;
|
||||
}
|
||||
|
||||
test('the transfer is applied to the canvas pixels in place, with no copy written back', () => {
|
||||
let read = null;
|
||||
const output = {};
|
||||
output.getContext = () => ({
|
||||
drawImage() {},
|
||||
getImageData: () => {
|
||||
read = { data: new Uint8ClampedArray([194, 0, 0, 200]) };
|
||||
// A second full-size buffer copied over the first is what this guards.
|
||||
read.data.set = () => {
|
||||
throw new Error('the canvas pixels were overwritten from a copy');
|
||||
};
|
||||
return read;
|
||||
},
|
||||
putImageData: (pixels) => {
|
||||
output.pixels = pixels;
|
||||
},
|
||||
});
|
||||
processInfraredImage({ width: 1, height: 1 }, 'filtered', () => output);
|
||||
assert.equal(output.pixels, read);
|
||||
assert.deepEqual([...read.data], [194, 0, 0, 98]);
|
||||
});
|
||||
|
||||
test('decoded pixels are processed once on a same-sized canvas', () => {
|
||||
const image = { width: 1, height: 1 };
|
||||
const output = processInfraredImage(image, 'filtered', canvas);
|
||||
|
||||
Reference in new issue
Block a user