ElevationStorageCodec

Cross-platform encode/decode for one elevation tile in the cache.

Storage format (JS / iOS — the platforms that use this codec):

  • isFloat = true → TIFF-Float32. Lossless for Float32 sources; widens Int16 sources to Float32. Coverage-level (scale, offset) = (1, 0) (unused).

  • isFloat = false → TIFF-Uint16 with per-tile (scale, offset) that pack a FloatBuffer's actual range into the 16-bit codes. Int16 sources go through unchanged at (1, 0). Float→Int never rounds through a WorldWind ShortArray intermediate — the lossy step is the 16-bit quantization ((max-min)/65535 per code), not "round to nearest meter".

The JVM/GeoPackage path uses PNG-Int16 + the gpkg gpkg_2d_gridded_tile_ancillary table; it has its own implementation in GpkgCachedElevationDataFactory. Same encoding contract (storage isFloat + per-tile scale/offset), different wire format.

Types

Link copied to clipboard
data class Encoded(val bytes: ByteArray, val tileScale: Float, val tileOffset: Float)

Bytes ready for blob storage plus the per-tile scale/offset the read path needs to recover the original sample values. Persist tileScale + tileOffset alongside bytes in whatever ancillary store the platform uses (IDB object store / iOS sidecar).

Functions

Link copied to clipboard
fun decode(bytes: ByteArray, isFloat: Boolean, tileScale: Float, tileOffset: Float): ElevationTileBuffer

Decode a stored tile. Returns either a ShortBuffer-equivalent (for unscaled Int16 storage) or a FloatBuffer-equivalent (for Float32 storage or Int16 storage with non-trivial scale/offset where applying them would lose precision).

Link copied to clipboard
fun encode(buffer: ElevationTileBuffer, isFloat: Boolean, tileWidth: Int, tileHeight: Int): ElevationStorageCodec.Encoded

Encode a tile buffer for storage. Dispatches on buffer type and isFloat: