2
0

msdfgen.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. /*
  3. * MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR v1.6 (2019-04-08)
  4. * ---------------------------------------------------------------
  5. * A utility by Viktor Chlumsky, (c) 2014 - 2019
  6. *
  7. * The technique used to generate multi-channel distance fields in this code
  8. * has been developed by Viktor Chlumsky in 2014 for his master's thesis,
  9. * "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
  10. * quality of sharp corners in glyphs and other 2D shapes in comparison to monochrome
  11. * distance fields. To reconstruct an image of the shape, apply the median of three
  12. * operation on the triplet of sampled distance field values.
  13. *
  14. */
  15. #include "core/arithmetics.hpp"
  16. #include "core/Vector2.h"
  17. #include "core/Shape.h"
  18. #include "core/Bitmap.h"
  19. #include "core/edge-coloring.h"
  20. #include "core/render-sdf.h"
  21. #include "core/rasterization.h"
  22. #include "core/save-bmp.h"
  23. #include "core/shape-description.h"
  24. #define MSDFGEN_VERSION "1.6"
  25. namespace msdfgen {
  26. /// Generates a conventional single-channel signed distance field.
  27. void generateSDF(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
  28. /// Generates a single-channel signed pseudo-distance field.
  29. void generatePseudoSDF(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
  30. /// Generates a multi-channel signed distance field. Edge colors must be assigned first! (See edgeColoringSimple)
  31. void generateMSDF(Bitmap<FloatRGB> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, double edgeThreshold = 1.001, bool overlapSupport = true);
  32. /// Resolves multi-channel signed distance field values that may cause interpolation artifacts. (Already called by generateMSDF)
  33. void msdfErrorCorrection(Bitmap<FloatRGB> &output, const Vector2 &threshold);
  34. // Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours.
  35. void generateSDF_legacy(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  36. void generatePseudoSDF_legacy(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  37. void generateMSDF_legacy(Bitmap<FloatRGB> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, double edgeThreshold = 1.001);
  38. }