SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
vtfpp::DistanceMapping Namespace Reference

Namespaces

namespace  detail

Enumerations

enum class  Dither { NONE = 0 , GRADIENT_TANGENT }
enum class  Flags : uint32_t { NONE = 0 , DISTANCEAA = 1 << 0 , EUCLIDEAN = 1 << 1 , SAMPLECENTERED = 1 << 2 }

Functions

std::vector< std::byte > alphaToDistance (std::span< const std::byte > imageData, ImageFormat inFormat, ImageFormat outFormat, uint16_t width, uint16_t height, uint16_t reduceX, uint16_t reduceY, bool srgb, float distanceSpread=1.f, float alphaThreshold=0.04f, Flags flags=Flags::NONE, Dither dither=Dither::NONE, ImageConversion::ResizeFilter filter=ImageConversion::ResizeFilter::NICE, ImageConversion::ResizeEdge edge=ImageConversion::ResizeEdge::CLAMP, bool *valveQuirks=nullptr)
 In one operation, convert an image's alpha channel, or, for single-channel formats, its only channel, to a VTEX-style distance map, and downscale other channels, if present in the output, according to the given resize parameters.

Enumeration Type Documentation

◆ Dither

enum class vtfpp::DistanceMapping::Dither
strong
Enumerator
NONE 

No dithering.

GRADIENT_TANGENT 

Experimental dithering approach that diffuses quantization error perpendicular to the distance gradient at any destination pixel. Slow and requires up to double the memory.

Definition at line 10 of file DistanceMapping.h.

◆ Flags

enum class vtfpp::DistanceMapping::Flags : uint32_t
strong
Enumerator
NONE 
DISTANCEAA 

Experimental; interpret the alpha channel as antialiased. Can result in a more precise distance map, but produces nonsense if large gradients are present.

EUCLIDEAN 

The distance-mapping algorithm is a brute-force scan of a square area. If this is enabled, only accept distance hits in a circular area.

SAMPLECENTERED 

Search from the center of pixels (in destination coordinate space) rather than in their north-west corners. Can mitigate a perceived southeast shift at extreme reductions.

Definition at line 16 of file DistanceMapping.h.

Function Documentation

◆ alphaToDistance()

std::vector< std::byte > vtfpp::DistanceMapping::alphaToDistance ( std::span< const std::byte > imageData,
ImageFormat inFormat,
ImageFormat outFormat,
uint16_t width,
uint16_t height,
uint16_t reduceX,
uint16_t reduceY,
bool srgb,
float distanceSpread = 1.f,
float alphaThreshold = 0.04f,
DistanceMapping::Flags flags = Flags::NONE,
DistanceMapping::Dither dither = Dither::NONE,
ImageConversion::ResizeFilter filter = ImageConversion::ResizeFilter::NICE,
ImageConversion::ResizeEdge edge = ImageConversion::ResizeEdge::CLAMP,
bool * valveQuirks = nullptr )
nodiscard

In one operation, convert an image's alpha channel, or, for single-channel formats, its only channel, to a VTEX-style distance map, and downscale other channels, if present in the output, according to the given resize parameters.

Returns
Empty if:
  • inFormat or outFormat do not satisfy their documented predicates,
  • reduceX or reduceY are not powers of two,
  • distanceSpread would result in a search radius of zero with either reduceX or reduceY,
  • alphaThreshold is out of range, or
  • edge is ResizeEdge::ZERO.

Otherwise, an image at width / reduceX by height / reduceY in outFormat:

  • if outFormat is single-channel, R contains the distance map.
  • if outFormat has alpha, A contains the distance map, while R/G/B contain:
    • if inFormat had R/G/B, the scaled R/G/B of the input image, otherwise
    • 0 in all other channels.
Parameters
inFormatAny format that is either single-channel, or has an alpha channel.
outFormatThe same requirements as inFormat; channel count does not need to correspond to inFormat.
reduceXPower-of-two horizontal reduction factor.
reduceYPower-of-two vertical reduction factor.
srgbUsed in the case of RGBA->RGBA. premultipliedAlpha is omitted.
distanceSpreadScale factor beyond reduceX and reduceY, of search radius for distance hits.
alphaThresholdThreshold below which alpha values are considered zero.
flagsAdditional behaviors that deviate from VTEX but may be useful; see DistanceFlags.
ditherInternally, distance maps are always computed in floating point. When set to a value other than NONE, and the output format is of integral type, dithering is applied prior to quantization. Depending on the application and contents, this can improve or worsen the quality of the distance map.
filterDefault value mimics VTEX. Does not affect the alpha channel; distance mapping is a distinct sampling operation from source to destination space. Entirely unused if input is single-channel.
edgeDictates the sampling policy of the distance function regardless of whether there are non-alpha channels to be resized.
valveQuirksWhen non-null, mimic VTEX's policy of blanking out any edge pixels in the distance map to 0 (i.e. infinite distance), and report back whether this resulted in any change (such that a command-line tool emulating VTEX would want to report a warning).

Definition at line 474 of file DistanceMapping.cpp.