Files
RecipesCam/src/utils/deviceFloor.check.ts
T
admin 588fbf77d9 perf(capture): trade CameraX MFNR for latency, average our own low-light burst off the shutter path
Measured on the 12S Ultra (2203121C), same scene, 1x, EV 0, 3 shots per arm:

- qualityPrioritization 'quality' -> 'balanced': tap->file 1013 ms vs 736 ms
  (-277 ms, -27%), settled 1552 ms vs 1280 ms, in-camera 521 ms vs 286 ms.
  Repeat on a second session: -228 ms. Image quality at ISO ~450 is inside the
  scatter of one arm (flat sigma +2.4%, edge +0.1%, texture -1.1%), so the MFNR
  pass quality would have bought is not measurable here. Also removes the
  EXPO_PUBLIC_CAPTURE_MODE seam: Metro inlines EXPO_PUBLIC_* in dev only, the
  release HBC build does not, so it could never gate shipped behaviour.
- Dark scenes now go through the app's own burst (ISO >= 100 gate for the probe)
  and mergeBurst runs in the export queue instead of on the shutter path, so a
  second shot is accepted while the frames are still being averaged: double-tap
  at 1.2 s used to drop the second photo, now it lands. Output stays the merged
  frame (flat sigma 0.825 vs 0.939 for a single frame).

Burst is skipped when the LED is the light source, when the shot came from the
native 0.5x session, for a held burst, for RAW, and below the devicePerf RAM
floor (deviceFloor.ts) where three raws plus the alignment rasters would be
seconds of shutter lag.

Bundles in the work this sits on: frame averaging (burstAlign/burstMerge),
the per-device floor, and the EXIF/ISO readback the burst gate needs (exifWrite,
photoMeta, exportEngine, RecipescamExportModule).

Self-checks: src/utils/{burstAlign,deviceFloor,exifWrite}.check.ts.
2026-09-26 11:37:48 +07:00

43 lines
2.0 KiB
TypeScript

// Runnable self-check: `node --no-warnings src/utils/deviceFloor.check.ts`.
// Covers the budget maths only — the RAM reading itself needs the device.
import assert from 'node:assert';
import {
canBurst,
floorRaster,
FLOOR_EXPORT_PIXELS,
isFloorDevice,
maxExportPixels,
} from './deviceFloor.ts';
// Tier boundaries: unknown (0, the platform refused) is never a floor device,
// and the 4 GB mid-range keeps the full path.
assert.strictEqual(isFloorDevice(0), false, 'unknown RAM must keep full quality');
assert.strictEqual(isFloorDevice(1024), true, 'Redmi Go / Nokia 1 / J2 Core');
assert.strictEqual(isFloorDevice(2048), true, 'Go programme ceiling');
assert.strictEqual(isFloorDevice(3072), false);
assert.strictEqual(isFloorDevice(12288), false, '12S Ultra');
// Caps follow the tier.
assert.strictEqual(maxExportPixels(0), Infinity);
assert.strictEqual(maxExportPixels(12288), Infinity);
assert.strictEqual(maxExportPixels(1024), FLOOR_EXPORT_PIXELS);
assert.strictEqual(canBurst(1024), false);
assert.strictEqual(canBurst(0), true);
// The floor device's own 3264x2448 (8 MP) capture, and the 12S Ultra's 3000x4000.
const go = floorRaster(3264, 2448, FLOOR_EXPORT_PIXELS);
assert.ok(go.width < 3264, 'floor capture is resampled');
assert.ok(go.width * go.height <= FLOOR_EXPORT_PIXELS, 'stays inside the cap');
assert.ok(go.width * go.height > FLOOR_EXPORT_PIXELS * 0.9, 'and does not overshoot it');
// Aspect is preserved to within a pixel on both orientations.
assert.ok(Math.abs(go.width / go.height - 3264 / 2448) < 0.002, '4:3 kept');
const tall = floorRaster(3000, 4000, 4_000_000);
assert.ok(Math.abs(tall.width / tall.height - 3000 / 4000) < 0.002, '3:4 kept');
// Untouched when it already fits, and never zero-sized on a degenerate raster.
assert.deepStrictEqual(floorRaster(2000, 1500, FLOOR_EXPORT_PIXELS), { width: 2000, height: 1500 });
assert.deepStrictEqual(floorRaster(1, 1, FLOOR_EXPORT_PIXELS), { width: 1, height: 1 });
assert.deepStrictEqual(floorRaster(0, 0, 100), { width: 0, height: 0 });
console.log('deviceFloor.check: 17 assertions passed');