1 | |
2 | #pragma once |
3 | |
4 | #include <cstdlib> |
5 | #include "BitmapRef.hpp" |
6 | |
7 | #ifndef MSDFGEN_PUBLIC |
8 | #define MSDFGEN_PUBLIC // for DLL import/export |
9 | #endif |
10 | |
11 | namespace msdfgen { |
12 | |
13 | /// The configuration of the MSDF error correction pass. |
14 | struct ErrorCorrectionConfig { |
15 | /// The default value of minDeviationRatio. |
16 | static MSDFGEN_PUBLIC const double defaultMinDeviationRatio; |
17 | /// The default value of minImproveRatio. |
18 | static MSDFGEN_PUBLIC const double defaultMinImproveRatio; |
19 | |
20 | /// Mode of operation. |
21 | enum Mode { |
22 | /// Skips error correction pass. |
23 | DISABLED, |
24 | /// Corrects all discontinuities of the distance field regardless if edges are adversely affected. |
25 | INDISCRIMINATE, |
26 | /// Corrects artifacts at edges and other discontinuous distances only if it does not affect edges or corners. |
27 | EDGE_PRIORITY, |
28 | /// Only corrects artifacts at edges. |
29 | EDGE_ONLY |
30 | } mode; |
31 | /// Configuration of whether to use an algorithm that computes the exact shape distance at the positions of suspected artifacts. This algorithm can be much slower. |
32 | enum DistanceCheckMode { |
33 | /// Never computes exact shape distance. |
34 | DO_NOT_CHECK_DISTANCE, |
35 | /// Only computes exact shape distance at edges. Provides a good balance between speed and precision. |
36 | CHECK_DISTANCE_AT_EDGE, |
37 | /// Computes and compares the exact shape distance for each suspected artifact. |
38 | ALWAYS_CHECK_DISTANCE |
39 | } distanceCheckMode; |
40 | /// The minimum ratio between the actual and maximum expected distance delta to be considered an error. |
41 | double minDeviationRatio; |
42 | /// The minimum ratio between the pre-correction distance error and the post-correction distance error. Has no effect for DO_NOT_CHECK_DISTANCE. |
43 | double minImproveRatio; |
44 | /// An optional buffer to avoid dynamic allocation. Must have at least as many bytes as the MSDF has pixels. |
45 | byte *buffer; |
46 | |
47 | inline explicit ErrorCorrectionConfig(Mode mode = EDGE_PRIORITY, DistanceCheckMode distanceCheckMode = CHECK_DISTANCE_AT_EDGE, double minDeviationRatio = defaultMinDeviationRatio, double minImproveRatio = defaultMinImproveRatio, byte *buffer = NULL) : mode(mode), distanceCheckMode(distanceCheckMode), minDeviationRatio(minDeviationRatio), minImproveRatio(minImproveRatio), buffer(buffer) { } |
48 | }; |
49 | |
50 | /// The configuration of the distance field generator algorithm. |
51 | struct GeneratorConfig { |
52 | /// Specifies whether to use the version of the algorithm that supports overlapping contours with the same winding. May be set to false to improve performance when no such contours are present. |
53 | bool overlapSupport; |
54 | |
55 | inline explicit GeneratorConfig(bool overlapSupport = true) : overlapSupport(overlapSupport) { } |
56 | }; |
57 | |
58 | /// The configuration of the multi-channel distance field generator algorithm. |
59 | struct MSDFGeneratorConfig : GeneratorConfig { |
60 | /// Configuration of the error correction pass. |
61 | ErrorCorrectionConfig errorCorrection; |
62 | |
63 | inline MSDFGeneratorConfig() { } |
64 | inline explicit MSDFGeneratorConfig(bool overlapSupport, const ErrorCorrectionConfig &errorCorrection = ErrorCorrectionConfig()) : GeneratorConfig(overlapSupport), errorCorrection(errorCorrection) { } |
65 | }; |
66 | |
67 | } |
68 | |