Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/msdfgen/msdfgen.h
9896 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/save-bmp.h"
38
#include "core/save-tiff.h"
39
#include "core/save-rgba.h"
40
#include "core/save-fl32.h"
41
#include "core/shape-description.h"
42
#include "core/export-svg.h"
43
44
namespace msdfgen {
45
46
/// Generates a conventional single-channel signed distance field.
47
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
48
49
/// Generates a single-channel signed perpendicular distance field.
50
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
51
52
/// Generates a multi-channel signed distance field. Edge colors must be assigned first! (See edgeColoringSimple)
53
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
54
55
/// Generates a multi-channel signed distance field with true distance in the alpha channel. Edge colors must be assigned first.
56
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
57
58
// Old version of the function API's kept for backwards compatibility
59
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
60
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
61
void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
62
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
63
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
64
65
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
66
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
67
void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
68
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
69
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
70
71
// Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours.
72
void generateSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
73
void generatePSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
74
void generatePseudoSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
75
void generateMSDF_legacy(const BitmapRef<float, 3> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
76
void generateMTSDF_legacy(const BitmapRef<float, 4> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
77
78
}
79
80