Path: blob/master/thirdparty/msdfgen/core/MSDFErrorCorrection.h
9903 views
1#pragma once23#include "SDFTransformation.h"4#include "Shape.h"5#include "BitmapRef.hpp"67namespace msdfgen {89/// 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.10class MSDFErrorCorrection {1112public:13/// Stencil flags.14enum Flags {15/// Texel marked as potentially causing interpolation errors.16ERROR = 1,17/// Texel marked as protected. Protected texels are only given the error flag if they cause inversion artifacts.18PROTECTED = 219};2021MSDFErrorCorrection();22explicit MSDFErrorCorrection(const BitmapRef<byte, 1> &stencil, const SDFTransformation &transformation);23/// Sets the minimum ratio between the actual and maximum expected distance delta to be considered an error.24void setMinDeviationRatio(double minDeviationRatio);25/// Sets the minimum ratio between the pre-correction distance error and the post-correction distance error.26void setMinImproveRatio(double minImproveRatio);27/// Flags all texels that are interpolated at corners as protected.28void protectCorners(const Shape &shape);29/// Flags all texels that contribute to edges as protected.30template <int N>31void protectEdges(const BitmapConstRef<float, N> &sdf);32/// Flags all texels as protected.33void protectAll();34/// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF only.35template <int N>36void findErrors(const BitmapConstRef<float, N> &sdf);37/// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF and comparison with the exact shape distance.38template <template <typename> class ContourCombiner, int N>39void findErrors(const BitmapConstRef<float, N> &sdf, const Shape &shape);40/// Modifies the MSDF so that all texels with the error flag are converted to single-channel.41template <int N>42void apply(const BitmapRef<float, N> &sdf) const;43/// Returns the stencil in its current state (see Flags).44BitmapConstRef<byte, 1> getStencil() const;4546private:47BitmapRef<byte, 1> stencil;48SDFTransformation transformation;49double minDeviationRatio;50double minImproveRatio;5152};5354}555657