msdfgen.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. /*
  3. * MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR v1.5 (2017-07-23)
  4. * ---------------------------------------------------------------
  5. * A utility by Viktor Chlumsky, (c) 2014 - 2017
  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/save-bmp.h"
  22. #include "core/shape-description.h"
  23. #define MSDFGEN_VERSION "1.5"
  24. namespace msdfgen {
  25. /// Generates a conventional single-channel signed distance field.
  26. void generateSDF(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  27. /// Generates a single-channel signed pseudo-distance field.
  28. void generatePseudoSDF(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  29. /// Generates a multi-channel signed distance field. Edge colors must be assigned first! (see edgeColoringSimple)
  30. void generateMSDF(Bitmap<FloatRGB> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, double edgeThreshold = 1.00000001);
  31. // Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours.
  32. void generateSDF_legacy(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  33. void generatePseudoSDF_legacy(Bitmap<float> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate);
  34. void generateMSDF_legacy(Bitmap<FloatRGB> &output, const Shape &shape, double range, const Vector2 &scale, const Vector2 &translate, double edgeThreshold = 1.00000001);
  35. }