Utilities » Distance Field conversion utility

Converts red channel of an image to distance field representation.

This utility is built if MAGNUM_WITH_DISTANCEFIELDCONVERTER is enabled when building Magnum. To use this utility with CMake, you need to request the distancefieldconverter component of the Magnum package and use the Magnum::distancefieldconverter target for example in a custom command:

find_package(Magnum REQUIRED distancefieldconverter)

add_custom_command(OUTPUT ... COMMAND Magnum::distancefieldconverter ...)

See Downloading and building, Usage with CMake and the TextureTools namespace for more information.

Example usage

magnum-distancefieldconverter logo-src.png logo.png \
    --output-size "256 256" --radius 24

This will open monochrome logo-src.png image using any plugin that can open PNG files and converts it to 256x256 distance field logo.png using any plugin that can write PNG files.

Full usage documentation

magnum-distancefieldconverter [--magnum-...] [-h|--help] [--importer IMPORTER]
    [--converter CONVERTER] [--plugin-dir DIR] --output-size "X Y" --radius N
    [--] input output

Arguments:

  • input — input image
  • output — output image
  • -h, --help — display help message and exit
  • --importer IMPORTER — image importer plugin (default: AnyImageImporter)
  • --converter CONVERTER — image converter plugin (default: AnyImageConverter)
  • --plugin-dir DIR — override base plugin dir
  • --output-size "X Y" — size of output image
  • --radius N — distance field computation radius
  • --magnum-... — engine-specific options (see Command-line options for details)

Images with PixelFormat::R8Unorm, PixelFormat::RGB8Unorm or PixelFormat::RGBA8Unorm are accepted on input.

The resulting image can then be used with Shaders::DistanceFieldVectorGL. See TextureTools::DistanceField for more information about the algorithm and parameters. Size restrictions from it apply here as well, in particular the ratio of the source image size and and --output-size is expected to be a multiple of 2.