#sdf #rasterization

sdfer

SDF (Signed Distance Field) generation algorithms

3 unstable releases

0.2.1 Jan 23, 2024
0.2.0 Jan 4, 2024
0.1.0 Dec 21, 2023

#48 in Rendering

Download history 478/week @ 2024-07-19 582/week @ 2024-07-26 339/week @ 2024-08-02 189/week @ 2024-08-09 207/week @ 2024-08-16 141/week @ 2024-08-23 219/week @ 2024-08-30 123/week @ 2024-09-06 127/week @ 2024-09-13 105/week @ 2024-09-20 210/week @ 2024-09-27 153/week @ 2024-10-04 157/week @ 2024-10-11 36/week @ 2024-10-18 20/week @ 2024-10-25 141/week @ 2024-11-01

390 downloads per month
Used in tgf

MIT license

42KB
925 lines

SDF ("Signed Distance Field") generation algorithms

Crates.io Docs

Algorithms

Currently, this library contains these SDF generation algorithms:

  • sdfer::bruteforce_bitmap: bitmap-based "closest opposite-color pixel" bruteforce search
  • sdfer::esdt: "Euclidean Subpixel Distance Transform"
    • this is a Rust port of the original JS implementation, from the @use-gpu/glyph npm package
    • the https://acko.net/blog/subpixel-distance-transform/ blog post explains how the older EDT ("Euclidean Distance Transform") algorithm was modified to better use the information present in e.g. grayscale AA rasterization of glyphs (where "grayscale AA" is really an alpha channel encoding of per-pixel coverage)
    • scales (roughly) linearly with the number of output pixels (which are 1:1 with input pixels, so no oversized rasterization required either), making it far more viable than most other algorithms, for on-demand runtime glyph->SDF conversion
      (e.g. to avoid pixel-snapping text during scrolling/panning, to allow some amount of smooth pinch-zooming before needing larger rasterizations, etc.)

License

Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).

Note: this is MIT-only, instead of the common dual-licensing, mainly due to the ESDT algorithm implementation being a port of the JS code from the @use-gpu/glyph npm package, which itself is MIT-licensed.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~0–0.8MB
~11K SLoC