Skip to content

Commit

Permalink
Add basic cog support
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Nov 30, 2024
1 parent 8cf1720 commit 8c32d83
Show file tree
Hide file tree
Showing 69 changed files with 1,371 additions and 101 deletions.
606 changes: 508 additions & 98 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ anyhow = "1.0"
approx = "0.5.1"
async-trait = "0.1"
bit-set = "0.8"
bytemuck = "1.19.0"
brotli = ">=5, <8"
cargo-husky = { version = "1", features = ["user-hooks"], default-features = false }
clap = { version = "4", features = ["derive"] }
Expand All @@ -45,6 +46,7 @@ env_logger = "0.11"
flate2 = "1"
flume = "0.11"
futures = "0.3"
image = "0.25.5"
indoc = "2"
insta = "1"
itertools = "0.13"
Expand All @@ -59,6 +61,7 @@ moka = { version = "0.12", features = ["future"] }
num_cpus = "1"
pbf_font_tools = { version = "2.5.1", features = ["freetype"] }
pmtiles = { version = "0.11", features = ["http-async", "mmap-async-tokio", "tilejson", "reqwest-rustls-tls-native-roots"] }
png = "0.17.14"
postgis = "0.9"
postgres = { version = "0.19", features = ["with-time-0_3", "with-uuid-1", "with-serde_json-1"] }
postgres-protocol = "0.6"
Expand All @@ -85,6 +88,7 @@ static-files = "0.2"
subst = { version = "0.3", features = ["yaml"] }
testcontainers-modules = { version = "0.11.4", features = ["postgres"] }
thiserror = "1"
tiff = "0.9.1"
tile-grid = "0.6"
tilejson = "0.4"
tokio = { version = "1", features = ["macros"] }
Expand Down
9 changes: 7 additions & 2 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ name = "bench"
harness = false

[features]
default = ["webui", "fonts", "lambda", "mbtiles", "pmtiles", "postgres", "sprites"]
default = ["webui", "fonts", "lambda", "mbtiles", "pmtiles", "cog", "postgres", "sprites"]
webui = ["dep:actix-web-static-files", "dep:static-files"]
fonts = ["dep:bit-set", "dep:pbf_font_tools"]
lambda = ["dep:lambda-web"]
mbtiles = ["dep:mbtiles"]
pmtiles = ["dep:pmtiles"]
cog = ["dep:tiff", "dep:png", "dep:bytemuck"]
postgres = ["dep:deadpool-postgres", "dep:json-patch", "dep:postgis", "dep:postgres", "dep:postgres-protocol", "dep:semver", "dep:tokio-postgres-rustls"]
sprites = ["dep:spreet", "tokio/fs"]
bless-tests = []
Expand All @@ -77,12 +78,14 @@ actix-web-static-files = { workspace = true, optional = true }
actix-web.workspace = true
async-trait.workspace = true
bit-set = { workspace = true, optional = true }
bytemuck = { workspace = true, optional = true }
brotli.workspace = true
clap.workspace = true
deadpool-postgres = { workspace = true, optional = true }
enum-display.workspace = true
env_logger.workspace = true
futures.workspace = true
image = {workspace = true, optional=true }
itertools.workspace = true
json-patch = { workspace = true, optional = true }
lambda-web = { workspace = true, optional = true }
Expand All @@ -93,6 +96,7 @@ moka.workspace = true
num_cpus.workspace = true
pbf_font_tools = { workspace = true, optional = true }
pmtiles = { workspace = true, optional = true }
png= { workspace = true, optional=true }
postgis = { workspace = true, optional = true }
postgres = { workspace = true, optional = true }
postgres-protocol = { workspace = true, optional = true }
Expand All @@ -101,14 +105,15 @@ rustls-native-certs.workspace = true
rustls-pemfile.workspace = true
rustls.workspace = true
semver = { workspace = true, optional = true }
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
serde_yaml.workspace = true
serde.workspace = true
spreet = { workspace = true, optional = true }
static-files = { workspace = true, optional = true }
subst.workspace = true
thiserror.workspace = true
tiff= { workspace = true, optional=true }
tilejson.workspace = true
tokio = { workspace = true, features = ["io-std"] }
tokio-postgres-rustls = { workspace = true, optional = true }
Expand Down
5 changes: 5 additions & 0 deletions martin/src/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ impl Args {
config.mbtiles = parse_file_args(&mut cli_strings, "mbtiles", false);
}

#[cfg(feature = "cog")]
if !cli_strings.is_empty() {
config.cog = parse_file_args(&mut cli_strings, "tif", false);
}

#[cfg(feature = "sprites")]
if !self.extras.sprite.is_empty() {
config.sprites = FileConfigEnum::new(self.extras.sprite);
Expand Down
56 changes: 56 additions & 0 deletions martin/src/cog/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::path::PathBuf;

use png::{ColorType, EncodingError};
use tiff::TiffError;

#[derive(thiserror::Error, Debug)]
pub enum CogError {
#[error("Couldn't decoded {1} as tiff file: {0}")]
InvalidTifFile(TiffError, PathBuf),

#[error("Requested zoom level:{0} from file {1} is out of range, the zoom level is from {2} to {3}")]
ZoomOutOfRange(u8, PathBuf, u8, u8),

#[error("Couldn't find any image(the tiff tag newsubfile is not mask) in the tiff file: {0}")]
NoImagesFound(PathBuf),

#[error("Couldn't seek to ifd number {1} (0 based indexing) in tiff file {2} : {0}")]
IfdSeekFailed(TiffError, usize, PathBuf),

#[error("Too many images in the tiff file: {0}")]
TooManyImages(PathBuf),

#[error("Couldn't find tags {1:?} at ifd {2} of tiff file {3} : {0}")]
TagsNotFound(TiffError, Vec<u16>, usize, PathBuf),

#[error("Planar configuration not equals to 1 is not supported, the tiff file is {2}")]
PlanaConfigurationNotSupported(PathBuf, usize, u16),

#[error("Failed to transform {1}th tile data at ifd {2} from {3} to png: {0}")]
ToPngBytesFailed(TiffError, u32, usize, PathBuf),

#[error("Failed to read {1}th chunk(0 based index) at ifd {2} from tiff file {3}: {0}")]
ReadChunkFailed(TiffError, u32, usize, PathBuf),

#[error("Failed to write header of png file at {0}: {1}")]
WritePngHeaderFailed(PathBuf, EncodingError),

#[error("Failed to write pixel bytes to png file at {0}: {1}")]
WriteToPngFailed(PathBuf, EncodingError),

#[error(
"The combination of bit depth {0} and colory typr {2:?} of the tiff file {1} is not accepted by png crate when encoding tif chunk data to png"
)]
PngBitDepthNotAccepted(u8, PathBuf, ColorType),

#[error(
"The color type {0:?} and its bit depth of the tiff file {1} is not supported by png crate"
)]
NotSupportedColorTypeAndBitDepth(tiff::ColorType, PathBuf),

#[error("Couldn't parse the {0} value in gdal metadata(tiff tag 42112) from {1}")]
ParseSTATISTICSValueFailed(String, PathBuf),

#[error("todo")]
InvalidGdalMetaData(String, PathBuf),
}
Loading

0 comments on commit 8c32d83

Please sign in to comment.