| 1 | |
| 2 | #pragma once |
| 3 | |
| 4 | /* |
| 5 | * MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR |
| 6 | * --------------------------------------------- |
| 7 | * A utility by Viktor Chlumsky, (c) 2014 - 2022 |
| 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/arithmetics.hpp" |
| 19 | #include "core/Vector2.h" |
| 20 | #include "core/Projection.h" |
| 21 | #include "core/Scanline.h" |
| 22 | #include "core/Shape.h" |
| 23 | #include "core/BitmapRef.hpp" |
| 24 | #include "core/Bitmap.h" |
| 25 | #include "core/bitmap-interpolation.hpp" |
| 26 | #include "core/pixel-conversion.hpp" |
| 27 | #include "core/edge-coloring.h" |
| 28 | #include "core/generator-config.h" |
| 29 | #include "core/msdf-error-correction.h" |
| 30 | #include "core/render-sdf.h" |
| 31 | #include "core/rasterization.h" |
| 32 | #include "core/sdf-error-estimation.h" |
| 33 | #include "core/save-bmp.h" |
| 34 | #include "core/save-tiff.h" |
| 35 | #include "core/shape-description.h" |
| 36 | |
| 37 | namespace msdfgen { |
| 38 | |
| 39 | /// Generates a conventional single-channel signed distance field. |
| 40 | void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, double range, const GeneratorConfig &config = GeneratorConfig()); |
| 41 | |
| 42 | /// Generates a single-channel signed pseudo-distance field. |
| 43 | void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, double range, const GeneratorConfig &config = GeneratorConfig()); |
| 44 | |
| 45 | /// Generates a multi-channel signed distance field. Edge colors must be assigned first! (See edgeColoringSimple) |
| 46 | void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, const Projection &projection, double range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig()); |
| 47 | |
| 48 | /// Generates a multi-channel signed distance field with true distance in the alpha channel. Edge colors must be assigned first. |
| 49 | void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, const Projection &projection, double range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig()); |
| 50 | |
| 51 | // Old version of the function API's kept for backwards compatibility |
| 52 | void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true); |
| 53 | void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true); |
| 54 | void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true); |
| 55 | void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true); |
| 56 | |
| 57 | // Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours. |
| 58 | void generateSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate); |
| 59 | void generatePseudoSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate); |
| 60 | void generateMSDF_legacy(const BitmapRef<float, 3> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig()); |
| 61 | void generateMTSDF_legacy(const BitmapRef<float, 4> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig()); |
| 62 | |
| 63 | } |
| 64 | |