Skip to main content

async_geotiff/render/
pipeline.rs

1//! Render an immutable Raster Style plan after reading/warping its source.
2use crate::{
3    error::AgResult, pixel::ImageData, render::encode::TileFormat, style::raster::RasterPlan,
4    warp::resampler::Resampling,
5};
6use bytes::Bytes;
7use std::sync::Arc;
8
9/// Immutable, cheaply cloneable render plan produced by [`crate::style::compile`].
10#[derive(Debug, Clone)]
11pub struct CompiledTileStyle {
12    pub(crate) raster: Arc<RasterPlan>,
13    pub(crate) nodata: Option<f64>,
14    pub(crate) format: TileFormat,
15    pub(crate) resampling: Resampling,
16}
17
18impl CompiledTileStyle {
19    /// Resampling kernel requested for reading/resizing source pixels.
20    pub fn resampling(&self) -> Resampling {
21        self.resampling
22    }
23}
24
25/// Apply a compiled style and encode pixels in its requested image format.
26///
27/// This function does not reproject the input. Image bands and mask dimensions
28/// must match the style and pixel grid; incompatible inputs return an error.
29/// Use [`crate::tiler::Tiler`] to read, reproject and render a tile together.
30pub fn render(image: &ImageData, style: &CompiledTileStyle) -> AgResult<Bytes> {
31    style
32        .raster
33        .render(image, style.nodata.or(image.nodata), style.format)
34}