sdfer 1.0
Copyright 2021 Nils Jonas Norberg [email protected]
License: MIT ( https://opensource.org/licenses/mit )
- Generate SDF images (used for anti-aliased icons, text and more)
- Written in c/c++ with care for memory-access patterns
- Linear time over number of pixels
Spread=2, extends the edge 2 pixels inside/outside
./sdfer -d=1 -s=2 test_images/square.png
Input image | Output image |
---|---|
![]() |
![]() |
Spread=8
./sdfer -d=1 -s=8 test_images/square.png
Input image | Output image |
---|---|
![]() |
![]() |
(For Windows, install Msys2, also the executable becomes "sdfer.exe")
- clone ok_sdf and this repo locally
git clone https://github.com/j-norberg/ok_sdf.git
git clone https://github.com/j-norberg/sdfer.git
cd sdfer
- make
make
- run internal tests
./sdfer --test
-t=127 Threshhold When the input-image is read, the threshold-value determines what pixel is considered a part of the masked image. Defaults to 127, can be between 0 and 254 inclusive.
-i Invert When the input-image is read, anything above the threshold-value is considered part of the masked image. When -i is active the result is inverted, so anything above the threshold is considered outside.
-p Pad When the pad-option is active, the input-image is enlarged with the spread-amount in every direction, this ensures that the full fade-out will be present in the out-image, and not cut off.
-s=100 Spread The signed distance field will extend this far (in pixels). For use with font-shapes or similar usage, lower number will give you better resolution, but for a larger value can enable more advanced features (blur, shadow, outlines)
-d=2 Downsample This option allow you to down-sample the output-image. This is common to increase the fidelity of angles in shapes.
-c Crop This options will look at the output image and crop it so that the fade touches the edges in each direction.
Known limits: a. image-dimensions b. output format 8-bits (limits useful range of spread)
- please report bugs (include test image)
sdfer relies on my "ok_sdf" library and requires that it's a sibling of this project in the filesystem.
sdfer relies on stb_image and stb_image_write (included in src/dep)