| 1 |  | 
|---|
| 2 | #pragma once | 
|---|
| 3 |  | 
|---|
| 4 | #include "Projection.h" | 
|---|
| 5 | #include "Shape.h" | 
|---|
| 6 | #include "BitmapRef.hpp" | 
|---|
| 7 |  | 
|---|
| 8 | namespace msdfgen { | 
|---|
| 9 |  | 
|---|
| 10 | /// Performs error correction on a computed MSDF to eliminate interpolation artifacts. This is a low-level class, you may want to use the API in msdf-error-correction.h instead. | 
|---|
| 11 | class MSDFErrorCorrection { | 
|---|
| 12 |  | 
|---|
| 13 | public: | 
|---|
| 14 | /// Stencil flags. | 
|---|
| 15 | enum Flags { | 
|---|
| 16 | /// Texel marked as potentially causing interpolation errors. | 
|---|
| 17 | ERROR = 1, | 
|---|
| 18 | /// Texel marked as protected. Protected texels are only given the error flag if they cause inversion artifacts. | 
|---|
| 19 | PROTECTED = 2 | 
|---|
| 20 | }; | 
|---|
| 21 |  | 
|---|
| 22 | MSDFErrorCorrection(); | 
|---|
| 23 | explicit MSDFErrorCorrection(const BitmapRef<byte, 1> &stencil, const Projection &projection, double range); | 
|---|
| 24 | /// Sets the minimum ratio between the actual and maximum expected distance delta to be considered an error. | 
|---|
| 25 | void setMinDeviationRatio(double minDeviationRatio); | 
|---|
| 26 | /// Sets the minimum ratio between the pre-correction distance error and the post-correction distance error. | 
|---|
| 27 | void setMinImproveRatio(double minImproveRatio); | 
|---|
| 28 | /// Flags all texels that are interpolated at corners as protected. | 
|---|
| 29 | void protectCorners(const Shape &shape); | 
|---|
| 30 | /// Flags all texels that contribute to edges as protected. | 
|---|
| 31 | template <int N> | 
|---|
| 32 | void protectEdges(const BitmapConstRef<float, N> &sdf); | 
|---|
| 33 | /// Flags all texels as protected. | 
|---|
| 34 | void protectAll(); | 
|---|
| 35 | /// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF only. | 
|---|
| 36 | template <int N> | 
|---|
| 37 | void findErrors(const BitmapConstRef<float, N> &sdf); | 
|---|
| 38 | /// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF and comparison with the exact shape distance. | 
|---|
| 39 | template <template <typename> class ContourCombiner, int N> | 
|---|
| 40 | void findErrors(const BitmapConstRef<float, N> &sdf, const Shape &shape); | 
|---|
| 41 | /// Modifies the MSDF so that all texels with the error flag are converted to single-channel. | 
|---|
| 42 | template <int N> | 
|---|
| 43 | void apply(const BitmapRef<float, N> &sdf) const; | 
|---|
| 44 | /// Returns the stencil in its current state (see Flags). | 
|---|
| 45 | BitmapConstRef<byte, 1> getStencil() const; | 
|---|
| 46 |  | 
|---|
| 47 | private: | 
|---|
| 48 | BitmapRef<byte, 1> stencil; | 
|---|
| 49 | Projection projection; | 
|---|
| 50 | double invRange; | 
|---|
| 51 | double minDeviationRatio; | 
|---|
| 52 | double minImproveRatio; | 
|---|
| 53 |  | 
|---|
| 54 | }; | 
|---|
| 55 |  | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|