{"id":19133162,"url":"https://github.com/tversteeg/distance-field","last_synced_at":"2025-04-09T12:07:00.377Z","repository":{"id":8951154,"uuid":"60347764","full_name":"tversteeg/distance-field","owner":"tversteeg","description":":capital_abcd: Generate distance field bitmaps--vector compression for games","archived":false,"fork":false,"pushed_at":"2025-03-19T11:08:41.000Z","size":589,"stargazers_count":27,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T10:14:30.018Z","etag":null,"topics":["graphics","rust","signed-distance-field"],"latest_commit_sha":null,"homepage":"https://docs.rs/distance-field","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tversteeg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-03T12:58:44.000Z","updated_at":"2025-02-18T08:12:15.000Z","dependencies_parsed_at":"2024-01-15T05:05:51.256Z","dependency_job_id":"4952bf37-d594-400a-90a8-1fca628a10d9","html_url":"https://github.com/tversteeg/distance-field","commit_stats":{"total_commits":60,"total_committers":8,"mean_commits":7.5,"dds":0.3833333333333333,"last_synced_commit":"70d95384743e70b411b101f1b27b2eb85ffb1cb3"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tversteeg%2Fdistance-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tversteeg%2Fdistance-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tversteeg%2Fdistance-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tversteeg%2Fdistance-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tversteeg","download_url":"https://codeload.github.com/tversteeg/distance-field/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphics","rust","signed-distance-field"],"created_at":"2024-11-09T06:21:16.223Z","updated_at":"2025-04-09T12:07:00.354Z","avatar_url":"https://github.com/tversteeg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# distance-field\n\n[![Build Status](https://github.com/tversteeg/distance-field/workflows/CI/badge.svg)](https://github.com/tversteeg/distance-field/actions?workflow=CI)\n[![Crates.io](https://img.shields.io/crates/v/distance-field.svg)](https://crates.io/crates/distance-field)\n[![Documentation](https://docs.rs/distance-field/badge.svg)](https://docs.rs/distance-field)\n[![License: GPL-3.0](https://img.shields.io/crates/l/distance-field.svg)](#license)\n[![Downloads](https://img.shields.io/crates/d/distance-field.svg)](#downloads)\n\n### [Documentation](https://docs.rs/distance-field/)\n\n\u003c!-- cargo-rdme start --\u003e\n\nGenerate distance field bitmaps for rendering as pseudo-vector images in shaders.\n\nAn example usecase for the library would be to automatically convert asset images. You can achieve this by having a `build.rs` similar to this:\n\n```rust\nuse std::fs::File;\nuse distance_field::DistanceFieldExt;\n\nfn convert_image_to_dfield(input: \u0026str, output: \u0026str) {\n    // Load the 'input' image\n    let img = image::open(input).unwrap();\n\n    // Generate a distance field from the image\n    let outbuf = img.grayscale().distance_field(distance_field::Options {\n        size: (128, 128),\n        max_distance: 256,\n        ..Default::default()\n    });\n\n    // Save it to 'output' as a PNG\n    image::DynamicImage::ImageLuma8(outbuf).save(output).unwrap();\n}\n\nfn main() {\n    convert_image_to_dfield(\"img/input.png\", \"output.png\");\n}\n```\n\n\u003c!-- cargo-rdme end --\u003e\n\n# Generator binary\n\nCheckout the repository and `cd` into it; then run:\n\n    cargo run --example generator -- img/input.png output.png 64 64\n\nThis will take the following image as input:\n\n![Rust logo](img/input.png?raw=true)\n\nAnd generate a 64x64 distance field:\n\n![Distance field](img/output.png?raw=true)\n\nNow we can use the generated distance field to create a vector image.\n\n### Using the distance field\n\nFirst we need to scale it up with a linear interpolation:\n\n![Upscaled linear](img/linear.png?raw=true)\n\nThen we apply a treshold function:\n\n![Treshold](img/treshold.png?raw=true)\n\nYou can see that we have something which looks very similar to the original input image and that just from a 64x64 image! But it's still very pixelated and doesn't look like a vector image. This can be fixed by not doing a hard treshold but allowing some shades of gray.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftversteeg%2Fdistance-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftversteeg%2Fdistance-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftversteeg%2Fdistance-field/lists"}