SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
DistanceMapping.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include <sourcepp/Macros.h>
7
9
10enum class Dither {
11 NONE = 0,
13 // anything generic that doesn't depend on the geometry of the distance field (floyd-steinberg etc) would belong somewhere more general.
14};
15
16enum class Flags : uint32_t {
17 NONE = 0,
18 DISTANCEAA = 1 << 0,
19 EUCLIDEAN = 1 << 1,
20 SAMPLECENTERED = 1 << 2,
21};
23
24
37[[nodiscard]] std::vector<std::byte> alphaToDistance(
38 std::span<const std::byte> imageData,
39 ImageFormat inFormat,
40 ImageFormat outFormat,
41 uint16_t width,
42 uint16_t height,
43 uint16_t reduceX,
44 uint16_t reduceY,
45 bool srgb,
46 float distanceSpread = 1.f,
47 float alphaThreshold = 0.04f,
48 Flags flags = Flags::NONE,
49 Dither dither = Dither::NONE,
52 bool* valveQuirks = nullptr
53);
54
55} // namespace vtfpp::DistanceMapping
#define SOURCEPP_BITFLAGS_ENUM(Enum)
Defines bitwise operators for an enum or enum class.
Definition Macros.h:29
@ GRADIENT_TANGENT
Experimental dithering approach that diffuses quantization error perpendicular to the distance gradie...
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,...
@ SAMPLECENTERED
Search from the center of pixels (in destination coordinate space) rather than in their north-west co...
@ EUCLIDEAN
The distance-mapping algorithm is a brute-force scan of a square area. If this is enabled,...
@ DISTANCEAA
Experimental; interpret the alpha channel as antialiased. Can result in a more precise distance map,...
@ NICE
Valve NICE filtering, equivalent to Lanczos-3.