Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/msdfgen/msdfgen.h
21409 views
1
2
#pragma once
3
4
/*
5
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
6
* ---------------------------------------------
7
* A utility by Viktor Chlumsky, (c) 2014 - 2025
8
*
9
* The technique used to generate multi-channel distance fields in this code
10
* has been developed by Viktor Chlumsky in 2014 for his master's thesis,
11
* "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
12
* quality of sharp corners in glyphs and other 2D shapes compared to monochrome
13
* distance fields. To reconstruct an image of the shape, apply the median of three
14
* operation on the triplet of sampled signed distance values.
15
*
16
*/
17
18
#include "core/base.h"
19
#include "core/arithmetics.hpp"
20
#include "core/Vector2.hpp"
21
#include "core/Range.hpp"
22
#include "core/Projection.h"
23
#include "core/DistanceMapping.h"
24
#include "core/SDFTransformation.h"
25
#include "core/Scanline.h"
26
#include "core/Shape.h"
27
#include "core/BitmapRef.hpp"
28
#include "core/Bitmap.h"
29
#include "core/bitmap-interpolation.hpp"
30
#include "core/pixel-conversion.hpp"
31
#include "core/edge-coloring.h"
32
#include "core/generator-config.h"
33
#include "core/msdf-error-correction.h"
34
#include "core/render-sdf.h"
35
#include "core/rasterization.h"
36
#include "core/sdf-error-estimation.h"
37
#include "core/shape-description.h"
38
39
namespace msdfgen {
40
41
/// Generates a conventional single-channel signed distance field.
42
void generateSDF(const BitmapSection<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
43
44
/// Generates a single-channel signed perpendicular distance field.
45
void generatePSDF(const BitmapSection<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
46
47
/// Generates a multi-channel signed distance field. Edge colors must be assigned first! (See edgeColoringSimple)
48
void generateMSDF(const BitmapSection<float, 3> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
49
50
/// Generates a multi-channel signed distance field with true distance in the alpha channel. Edge colors must be assigned first.
51
void generateMTSDF(const BitmapSection<float, 4> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
52
53
// Old version of the function API's kept for backwards compatibility
54
void generateSDF(const BitmapSection<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
55
void generatePSDF(const BitmapSection<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
56
void generatePseudoSDF(const BitmapSection<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
57
void generateMSDF(const BitmapSection<float, 3> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
58
void generateMTSDF(const BitmapSection<float, 4> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
59
60
void generateSDF(const BitmapSection<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
61
void generatePSDF(const BitmapSection<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
62
void generatePseudoSDF(const BitmapSection<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
63
void generateMSDF(const BitmapSection<float, 3> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
64
void generateMTSDF(const BitmapSection<float, 4> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
65
66
// Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours.
67
void generateSDF_legacy(BitmapSection<float, 1> output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
68
void generatePSDF_legacy(BitmapSection<float, 1> output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
69
void generatePseudoSDF_legacy(BitmapSection<float, 1> output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
70
void generateMSDF_legacy(BitmapSection<float, 3> output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
71
void generateMTSDF_legacy(BitmapSection<float, 4> output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
72
73
}
74
75