Skip to content

Commit

Permalink
refactor: move debug tile code
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKreil committed Jul 2, 2024
1 parent df85f88 commit add67bd
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 47 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ clap = { version = "4.5.7" }
clap-verbosity-flag = { version = "2.2.0", default-features = false }
enumset = { version = "1.1.3", default-features = false }
futures = { version = "0.3.30", default-features = false }
image = { version = "0.25.0", default-features = false, features = ["jpeg", "png"] }
itertools = { version = "0.13.0", default-features = false }
lazy_static = { version = "1.4.0", default-features = false }
log = { version = "0.4.21", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion versatiles_geometry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ repository.workspace = true
version.workspace = true

[dependencies]
ab_glyph.workspace = true
anyhow.workspace = true
byteorder.workspace = true
lazy_static.workspace = true
Expand Down
2 changes: 0 additions & 2 deletions versatiles_geometry/src/vector_tile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod debug;
mod feature;
mod geometry_type;
mod layer;
mod property_manager;
mod tile;
mod value;

pub use debug::create_debug_vector_tile;
pub use layer::VectorTileLayer;
pub use tile::VectorTile;
4 changes: 1 addition & 3 deletions versatiles_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ repository.workspace = true
version.workspace = true

[dependencies]
ab_glyph.workspace = true
anyhow.workspace = true
image = { version = "0.25.0", default-features = false, features = ["jpeg", "png"] }
imageproc = { version = "0.25.0", default-features = false }
image.workspace = true
webp = { version = "0.3.0", default-features = false, features = ["img"] }

versatiles_core.workspace = true
Expand Down
Binary file removed versatiles_image/assets/trim.ttf
Binary file not shown.
29 changes: 1 addition & 28 deletions versatiles_image/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
use crate::format::*;
use ab_glyph::{FontArc, PxScale};
use anyhow::Result;
use image::{DynamicImage, GrayAlphaImage, GrayImage, Luma, LumaA, Rgb, RgbImage, Rgba, RgbaImage};
use imageproc::drawing::draw_text_mut;
use versatiles_core::types::{Blob, TileCoord3, TileFormat};

static mut FONT: Option<FontArc> = None;

pub fn create_debug_image(coord: &TileCoord3) -> DynamicImage {
let font = unsafe {
if FONT.is_none() {
FONT.insert(FontArc::try_from_slice(include_bytes!("../assets/trim.ttf")).unwrap())
} else {
FONT.as_ref().unwrap()
}
};

let br = ((coord.x + coord.y) % 2) as u8 * 16 + 224;
let mut image1 = RgbImage::from_pixel(512, 512, Rgb::from([br, br, br]));

let mut draw = |y: i32, c: Rgb<u8>, text: String| {
draw_text_mut(&mut image1, c, 220, y, PxScale::from(40f32), font, &text)
};

draw(195, Rgb([127, 30, 16]), format!("z: {}", coord.z));
draw(225, Rgb([0, 92, 45]), format!("x: {}", coord.x));
draw(255, Rgb([30, 23, 98]), format!("y: {}", coord.y));

DynamicImage::ImageRgb8(image1)
}
use versatiles_core::types::{Blob, TileFormat};

/// Generate a DynamicImage with RGBA colors
pub fn create_image_rgba() -> DynamicImage {
Expand Down
2 changes: 2 additions & 0 deletions versatiles_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ repository.workspace = true
version.workspace = true

[dependencies]
ab_glyph.workspace = true
anyhow.workspace = true
async-trait.workspace = true
futures.workspace = true
imageproc = { version = "0.25.0", default-features = false }
itertools.workspace = true
log.workspace = true
nom = { version = "7.1.3" }
Expand Down
31 changes: 31 additions & 0 deletions versatiles_pipeline/src/operations/read/from_debug/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use ab_glyph::{FontArc, PxScale};
use imageproc::{
drawing::draw_text_mut,
image::{DynamicImage, Rgb, RgbImage},
};
use versatiles_core::types::TileCoord3;

static mut FONT: Option<FontArc> = None;

pub fn create_debug_image(coord: &TileCoord3) -> DynamicImage {
let font = unsafe {
if FONT.is_none() {
FONT.insert(FontArc::try_from_slice(include_bytes!("./trim.ttf")).unwrap())
} else {
FONT.as_ref().unwrap()
}
};

let br = ((coord.x + coord.y) % 2) as u8 * 16 + 224;
let mut image1 = RgbImage::from_pixel(512, 512, Rgb::from([br, br, br]));

let mut draw = |y: i32, c: Rgb<u8>, text: String| {
draw_text_mut(&mut image1, c, 220, y, PxScale::from(40f32), font, &text)
};

draw(195, Rgb([127, 30, 16]), format!("z: {}", coord.z));
draw(225, Rgb([0, 92, 45]), format!("x: {}", coord.x));
draw(255, Rgb([30, 23, 98]), format!("y: {}", coord.y));

DynamicImage::ImageRgb8(image1)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#![allow(dead_code, unused_variables, unreachable_code)]
mod image;
mod vector;

use crate::{traits::*, vpl::VPLNode, PipelineFactory};
use anyhow::{bail, Result};
use async_trait::async_trait;
use futures::future::BoxFuture;
use image::create_debug_image;
use std::fmt::Debug;
use vector::create_debug_vector_tile;
use versatiles_core::{
types::{
Blob, TileBBox, TileBBoxPyramid, TileCompression, TileCoord3, TileFormat, TileStream,
TilesReaderParameters,
},
utils::compress,
};
use versatiles_geometry::vector_tile::create_debug_vector_tile;
use versatiles_image::helper::{create_debug_image, image2blob};
use versatiles_image::helper::image2blob;

#[derive(versatiles_derive::VPLDecode, Clone, Debug)]
/// Generates mocked tiles.
Expand Down Expand Up @@ -57,7 +59,7 @@ impl Operation {
impl ReadOperationTrait for Operation {
fn build(
vpl_node: VPLNode,
factory: &PipelineFactory,
_factory: &PipelineFactory,
) -> BoxFuture<'_, Result<Box<dyn OperationTrait>>>
where
Self: Sized + OperationTrait,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{VectorTile, VectorTileLayer};
use crate::{
AreaTrait, Feature, Geometry, LineStringGeometry, MultiLineStringGeometry, MultiPolygonGeometry,
PointGeometry, RingGeometry,
};
use ab_glyph::{Font, FontArc, Outline, OutlineCurve::*, Point};
use anyhow::Result;
use std::{f64::consts::PI, ops::Div, vec};
use versatiles_core::types::{Blob, TileCoord3};
use versatiles_geometry::{
vector_tile::{VectorTile, VectorTileLayer},
AreaTrait, Feature, Geometry, LineStringGeometry, MultiLineStringGeometry, MultiPolygonGeometry,
PointGeometry, RingGeometry,
};

static mut FONT: Option<FontArc> = None;

Expand All @@ -24,7 +24,7 @@ pub fn create_debug_vector_tile(coord: &TileCoord3) -> Result<Blob> {
fn draw_text(name: &str, y: f32, text: String) -> VectorTileLayer {
let font = unsafe {
if FONT.is_none() {
FONT.insert(FontArc::try_from_slice(include_bytes!("../../assets/trim.ttf")).unwrap())
FONT.insert(FontArc::try_from_slice(include_bytes!("./trim.ttf")).unwrap())
} else {
FONT.as_ref().unwrap()
}
Expand Down

0 comments on commit add67bd

Please sign in to comment.