Expand description
Heightmap codecs for elevation tile formats.
Two flavours of heightmap encoding are supported:
- RGB tiles (this module, top level):
terrarium,mapbox,gsi. Elevations packed into 3-byte(R, G, B)pixels, usually served wrapped in a PNG or WebP container. - Cesium heightmap-1.0 (
cesium): 16-bit little-endian heights plus child-tile mask. Cesium’s legacy terrain format.
The container submodule (behind the image cargo feature) wraps
the encoded RGB bytes in PNG or WebP for serving as image tiles.
Three formats are supported, each as a (encode_pixel, decode_pixel, encode, decode) quadruplet:
terrarium— Mapzen / Tilezen / Stadia “Terrarium” encoding.elevation = (R * 256 + G + B / 256) - 32768mapbox— Mapbox “Terrain-RGB” encoding.elevation = -10000 + (R * 65536 + G * 256 + B) * 0.1gsi— Geospatial Information Authority of Japan (地理院) signed-integer DEM PNG.(128, 0, 0)is the no-data sentinel (decodes toNaN).
Per-pixel functions (encode_pixel / decode_pixel) convert single
samples and are useful for streaming, hot loops, custom layouts, and
tests. Bulk encode / decode are thin wrappers that walk row-major
width × height buffers.
§Unified runtime-dispatch API
When the format is only known at runtime (CLI flag, request param,
config file), use the HeightmapFormat enum and the top-level
encode_pixel, decode_pixel, encode, decode functions:
use terrain_codec::heightmap::{HeightmapFormat, encode_pixel};
let fmt: HeightmapFormat = "terrarium".parse().unwrap();
let rgb = encode_pixel(fmt, 123.45);The codecs operate on raw (R, G, B) byte triplets and produce flat
row-major buffers, so they’re agnostic to the container format. Wrap
the encoded bytes in PNG/WebP yourself (e.g. via the image crate)
depending on your service.
Modules§
- cesium
- Cesium heightmap-1.0 terrain tile format.
- container
- PNG / WebP / AVIF container helpers for heightmap RGB bytes.
- gsi
- Geospatial Information Authority of Japan (GSI / 国土地理院) DEM tile encoding.
- mapbox
- Mapbox “Terrain-RGB” elevation tile encoding.
- terrarium
- Mapzen / Tilezen / Stadia “Terrarium” elevation tile encoding.
Structs§
- Parse
Heightmap Format Error - Error returned by
HeightmapFormat::from_strfor an unrecognised name.
Enums§
- Heightmap
Format - Identifies one of the supported RGB heightmap encodings, for
runtime-dispatched encode/decode via the top-level functions
(
encode_pixel,decode_pixel,encode,decode).
Functions§
- decode
- Decode a flat
width × height × 3RGB buffer back to elevations using the chosen format. - decode_
pixel - Decode a single
(R, G, B)pixel into elevation (metres) using the chosen format. - encode
- Encode
elevations(metres) into a flatwidth × height × 3RGB buffer using the chosen format. - encode_
pixel - Encode a single elevation sample (metres) into
(R, G, B)using the chosen format.