From 76dda1f2c837dbe4cdf375575bf74fc18a728fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 12 Dec 2025 22:39:53 +0100 Subject: [PATCH] msdfgen: Update to 1.13 Remove unused `export-svg` and `save-*` files. --- modules/msdfgen/SCsub | 1 + .../gdextension_build/SConstruct | 1 + .../gdextension_build/SConstruct | 1 + thirdparty/README.md | 8 +- thirdparty/msdfgen/core/Bitmap.h | 14 +- thirdparty/msdfgen/core/Bitmap.hpp | 77 ++++++- thirdparty/msdfgen/core/BitmapRef.hpp | 129 +++++++++++- thirdparty/msdfgen/core/Contour.cpp | 18 +- thirdparty/msdfgen/core/Contour.h | 4 +- .../msdfgen/core/MSDFErrorCorrection.cpp | 126 ++++++------ thirdparty/msdfgen/core/MSDFErrorCorrection.h | 14 +- thirdparty/msdfgen/core/Shape.cpp | 22 +- thirdparty/msdfgen/core/Shape.h | 11 +- thirdparty/msdfgen/core/YAxisOrientation.h | 17 ++ .../msdfgen/core/bitmap-interpolation.hpp | 4 +- thirdparty/msdfgen/core/contour-combiners.cpp | 2 +- .../core/convergent-curve-ordering.cpp | 140 +++++++++++++ .../msdfgen/core/convergent-curve-ordering.h | 11 + thirdparty/msdfgen/core/edge-segments.cpp | 64 +++--- thirdparty/msdfgen/core/edge-segments.h | 8 +- thirdparty/msdfgen/core/edge-selectors.cpp | 3 +- thirdparty/msdfgen/core/export-svg.cpp | 79 ------- thirdparty/msdfgen/core/export-svg.h | 11 - .../msdfgen/core/msdf-error-correction.cpp | 45 ++-- .../msdfgen/core/msdf-error-correction.h | 36 ++-- thirdparty/msdfgen/core/msdfgen.cpp | 83 ++++---- thirdparty/msdfgen/core/rasterization.cpp | 75 ++++--- thirdparty/msdfgen/core/rasterization.h | 21 +- thirdparty/msdfgen/core/render-sdf.cpp | 18 +- thirdparty/msdfgen/core/render-sdf.h | 18 +- thirdparty/msdfgen/core/save-bmp.cpp | 173 ---------------- thirdparty/msdfgen/core/save-bmp.h | 16 -- thirdparty/msdfgen/core/save-fl32.cpp | 39 ---- thirdparty/msdfgen/core/save-fl32.h | 12 -- thirdparty/msdfgen/core/save-rgba.cpp | 133 ------------ thirdparty/msdfgen/core/save-rgba.h | 16 -- thirdparty/msdfgen/core/save-tiff.cpp | 194 ------------------ thirdparty/msdfgen/core/save-tiff.h | 13 -- .../msdfgen/core/sdf-error-estimation.cpp | 50 +++-- .../msdfgen/core/sdf-error-estimation.h | 27 +-- thirdparty/msdfgen/core/shape-description.cpp | 54 ++++- thirdparty/msdfgen/msdfgen.h | 43 ++-- .../0001-remove-unused-save-features.patch | 17 ++ 43 files changed, 807 insertions(+), 1041 deletions(-) create mode 100644 thirdparty/msdfgen/core/YAxisOrientation.h create mode 100644 thirdparty/msdfgen/core/convergent-curve-ordering.cpp create mode 100644 thirdparty/msdfgen/core/convergent-curve-ordering.h delete mode 100644 thirdparty/msdfgen/core/export-svg.cpp delete mode 100644 thirdparty/msdfgen/core/export-svg.h delete mode 100644 thirdparty/msdfgen/core/save-bmp.cpp delete mode 100644 thirdparty/msdfgen/core/save-bmp.h delete mode 100644 thirdparty/msdfgen/core/save-fl32.cpp delete mode 100644 thirdparty/msdfgen/core/save-fl32.h delete mode 100644 thirdparty/msdfgen/core/save-rgba.cpp delete mode 100644 thirdparty/msdfgen/core/save-rgba.h delete mode 100644 thirdparty/msdfgen/core/save-tiff.cpp delete mode 100644 thirdparty/msdfgen/core/save-tiff.h create mode 100644 thirdparty/msdfgen/patches/0001-remove-unused-save-features.patch diff --git a/modules/msdfgen/SCsub b/modules/msdfgen/SCsub index 55c1394e302..734564806ae 100644 --- a/modules/msdfgen/SCsub +++ b/modules/msdfgen/SCsub @@ -23,6 +23,7 @@ if env["builtin_msdfgen"]: "core/Scanline.cpp", "core/Shape.cpp", "core/contour-combiners.cpp", + "core/convergent-curve-ordering.cpp", "core/edge-coloring.cpp", "core/edge-segments.cpp", "core/edge-selectors.cpp", diff --git a/modules/text_server_adv/gdextension_build/SConstruct b/modules/text_server_adv/gdextension_build/SConstruct index c85d349e71a..bf814b8be79 100644 --- a/modules/text_server_adv/gdextension_build/SConstruct +++ b/modules/text_server_adv/gdextension_build/SConstruct @@ -130,6 +130,7 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]: "core/Scanline.cpp", "core/Shape.cpp", "core/contour-combiners.cpp", + "core/convergent-curve-ordering.cpp", "core/edge-coloring.cpp", "core/edge-segments.cpp", "core/edge-selectors.cpp", diff --git a/modules/text_server_fb/gdextension_build/SConstruct b/modules/text_server_fb/gdextension_build/SConstruct index 5a0adef7c5a..a8d11261909 100644 --- a/modules/text_server_fb/gdextension_build/SConstruct +++ b/modules/text_server_fb/gdextension_build/SConstruct @@ -125,6 +125,7 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]: "core/Scanline.cpp", "core/Shape.cpp", "core/contour-combiners.cpp", + "core/convergent-curve-ordering.cpp", "core/edge-coloring.cpp", "core/edge-segments.cpp", "core/edge-selectors.cpp", diff --git a/thirdparty/README.md b/thirdparty/README.md index 62fe3e0f573..98e3e6a3758 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -850,15 +850,19 @@ Collection of single-file libraries used in Godot components. ## msdfgen - Upstream: https://github.com/Chlumsky/msdfgen -- Version: 1.12.1 (6574da1310df433c97ca0fddcab7e463c31e58f8, 2025) +- Version: 1.13 (1874bcf7d9624ccc85b4bc9a85d78116f690f35b, 2025) - License: MIT Files extracted from the upstream source: - `msdfgen.h` -- Files in `core/` folder +- Files in `core/` folder, minus `export-svg.*` and `save-*.*` files - `LICENSE.txt` +Patches: + +- `0001-remove-unused-save-features.patch` ([GH-113965](https://github.com/godotengine/godot/issues/113965)) + ## openxr diff --git a/thirdparty/msdfgen/core/Bitmap.h b/thirdparty/msdfgen/core/Bitmap.h index 9a08749f47f..05c305d648a 100644 --- a/thirdparty/msdfgen/core/Bitmap.h +++ b/thirdparty/msdfgen/core/Bitmap.h @@ -1,6 +1,7 @@ #pragma once +#include "YAxisOrientation.h" #include "BitmapRef.hpp" namespace msdfgen { @@ -11,14 +12,16 @@ class Bitmap { public: Bitmap(); - Bitmap(int width, int height); - Bitmap(const BitmapConstRef &orig); + Bitmap(int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION); + explicit Bitmap(const BitmapConstRef &orig); + explicit Bitmap(const BitmapConstSection &orig); Bitmap(const Bitmap &orig); #ifdef MSDFGEN_USE_CPP11 Bitmap(Bitmap &&orig); #endif ~Bitmap(); Bitmap &operator=(const BitmapConstRef &orig); + Bitmap &operator=(const BitmapConstSection &orig); Bitmap &operator=(const Bitmap &orig); #ifdef MSDFGEN_USE_CPP11 Bitmap &operator=(Bitmap &&orig); @@ -38,10 +41,17 @@ public: #endif operator BitmapRef(); operator BitmapConstRef() const; + operator BitmapSection(); + operator BitmapConstSection() const; + /// Returns a reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + BitmapSection getSection(int xMin, int yMin, int xMax, int yMax); + /// Returns a constant reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + BitmapConstSection getConstSection(int xMin, int yMin, int xMax, int yMax) const; private: T *pixels; int w, h; + YAxisOrientation yOrientation; }; diff --git a/thirdparty/msdfgen/core/Bitmap.hpp b/thirdparty/msdfgen/core/Bitmap.hpp index 9404357788d..afb53942ffa 100644 --- a/thirdparty/msdfgen/core/Bitmap.hpp +++ b/thirdparty/msdfgen/core/Bitmap.hpp @@ -7,28 +7,41 @@ namespace msdfgen { template -Bitmap::Bitmap() : pixels(NULL), w(0), h(0) { } +Bitmap::Bitmap() : pixels(NULL), w(0), h(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } template -Bitmap::Bitmap(int width, int height) : w(width), h(height) { +Bitmap::Bitmap(int width, int height, YAxisOrientation yOrientation) : w(width), h(height), yOrientation(yOrientation) { pixels = new T[N*w*h]; } template -Bitmap::Bitmap(const BitmapConstRef &orig) : w(orig.width), h(orig.height) { +Bitmap::Bitmap(const BitmapConstRef &orig) : w(orig.width), h(orig.height), yOrientation(orig.yOrientation) { pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } template -Bitmap::Bitmap(const Bitmap &orig) : w(orig.w), h(orig.h) { +Bitmap::Bitmap(const BitmapConstSection &orig) : w(orig.width), h(orig.height), yOrientation(orig.yOrientation) { + pixels = new T[N*w*h]; + T *dst = pixels; + const T *src = orig.pixels; + int rowLength = N*w; + for (int y = 0; y < h; ++y) { + memcpy(dst, src, sizeof(T)*rowLength); + dst += rowLength; + src += orig.rowStride; + } +} + +template +Bitmap::Bitmap(const Bitmap &orig) : w(orig.w), h(orig.h), yOrientation(orig.yOrientation) { pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } #ifdef MSDFGEN_USE_CPP11 template -Bitmap::Bitmap(Bitmap &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h) { +Bitmap::Bitmap(Bitmap &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h), yOrientation(orig.yOrientation) { orig.pixels = NULL; orig.w = 0, orig.h = 0; } @@ -36,25 +49,46 @@ Bitmap::Bitmap(Bitmap &&orig) : pixels(orig.pixels), w(orig.w), h(or template Bitmap::~Bitmap() { - delete [] pixels; + delete[] pixels; } template Bitmap &Bitmap::operator=(const BitmapConstRef &orig) { if (pixels != orig.pixels) { - delete [] pixels; + delete[] pixels; w = orig.width, h = orig.height; + yOrientation = orig.yOrientation; pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } return *this; } +template +Bitmap &Bitmap::operator=(const BitmapConstSection &orig) { + if (orig.pixels && orig.pixels >= pixels && orig.pixels < pixels+N*w*h) + return *this = Bitmap(orig); + delete[] pixels; + w = orig.width, h = orig.height; + yOrientation = orig.yOrientation; + pixels = new T[N*w*h]; + T *dst = pixels; + const T *src = orig.pixels; + int rowLength = N*w; + for (int y = 0; y < h; ++y) { + memcpy(dst, src, sizeof(T)*rowLength); + dst += rowLength; + src += orig.rowStride; + } + return *this; +} + template Bitmap &Bitmap::operator=(const Bitmap &orig) { if (this != &orig) { - delete [] pixels; + delete[] pixels; w = orig.w, h = orig.h; + yOrientation = orig.yOrientation; pixels = new T[N*w*h]; memcpy(pixels, orig.pixels, sizeof(T)*N*w*h); } @@ -65,9 +99,10 @@ Bitmap &Bitmap::operator=(const Bitmap &orig) { template Bitmap &Bitmap::operator=(Bitmap &&orig) { if (this != &orig) { - delete [] pixels; + delete[] pixels; pixels = orig.pixels; w = orig.w, h = orig.h; + yOrientation = orig.yOrientation; orig.pixels = NULL; } return *this; @@ -106,12 +141,32 @@ Bitmap::operator const T *() const { template Bitmap::operator BitmapRef() { - return BitmapRef(pixels, w, h); + return BitmapRef(pixels, w, h, yOrientation); } template Bitmap::operator BitmapConstRef() const { - return BitmapConstRef(pixels, w, h); + return BitmapConstRef(pixels, w, h, yOrientation); +} + +template +Bitmap::operator BitmapSection() { + return BitmapSection(pixels, w, h, yOrientation); +} + +template +Bitmap::operator BitmapConstSection() const { + return BitmapConstSection(pixels, w, h, yOrientation); +} + +template +BitmapSection Bitmap::getSection(int xMin, int yMin, int xMax, int yMax) { + return BitmapSection(pixels+N*(w*yMin+xMin), xMax-xMin, yMax-yMin, N*w, yOrientation); +} + +template +BitmapConstSection Bitmap::getConstSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapConstSection(pixels+N*(w*yMin+xMin), xMax-xMin, yMax-yMin, N*w, yOrientation); } } diff --git a/thirdparty/msdfgen/core/BitmapRef.hpp b/thirdparty/msdfgen/core/BitmapRef.hpp index cb17f95dcb8..6e93fe98363 100644 --- a/thirdparty/msdfgen/core/BitmapRef.hpp +++ b/thirdparty/msdfgen/core/BitmapRef.hpp @@ -1,41 +1,154 @@ #pragma once -#include "base.h" +#include "YAxisOrientation.h" namespace msdfgen { /// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. template +struct BitmapRef; +/// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. +template +struct BitmapConstRef; +/// Reference to a 2D image bitmap with non-contiguous rows of pixels. Pixel storage not owned or managed by the object. Can represent e.g. a section of a larger bitmap, bitmap with padded rows, or vertically flipped bitmap (rowStride can be negative). +template +struct BitmapSection; +/// Constant reference to a 2D image bitmap with non-contiguous rows of pixels. Pixel storage not owned or managed by the object. Can represent e.g. a section of a larger bitmap, bitmap with padded rows, or vertically flipped bitmap (rowStride can be negative). +template +struct BitmapConstSection; + +template struct BitmapRef { T *pixels; int width, height; + YAxisOrientation yOrientation; - inline BitmapRef() : pixels(NULL), width(0), height(0) { } - inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { } + inline BitmapRef() : pixels(NULL), width(0), height(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } + inline BitmapRef(T *pixels, int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), yOrientation(yOrientation) { } inline T *operator()(int x, int y) const { return pixels+N*(width*y+x); } + /// Returns a reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapSection getSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapSection(pixels+N*(width*yMin+xMin), xMax-xMin, yMax-yMin, N*width, yOrientation); + } + + /// Returns a constant reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getConstSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapConstSection(pixels+N*(width*yMin+xMin), xMax-xMin, yMax-yMin, N*width, yOrientation); + } + }; -/// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. -template +template struct BitmapConstRef { const T *pixels; int width, height; + YAxisOrientation yOrientation; - inline BitmapConstRef() : pixels(NULL), width(0), height(0) { } - inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { } - inline BitmapConstRef(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { } + inline BitmapConstRef() : pixels(NULL), width(0), height(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } + inline BitmapConstRef(const T *pixels, int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), yOrientation(yOrientation) { } + inline BitmapConstRef(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height), yOrientation(orig.yOrientation) { } inline const T *operator()(int x, int y) const { return pixels+N*(width*y+x); } + /// Returns a constant reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapConstSection(pixels+N*(width*yMin+xMin), xMax-xMin, yMax-yMin, N*width, yOrientation); + } + + /// Returns a constant reference to a rectangular section of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getConstSection(int xMin, int yMin, int xMax, int yMax) const { + return getSection(xMin, yMin, xMax, yMax); + } + +}; + +template +struct BitmapSection { + + T *pixels; + int width, height; + /// Specifies the difference between the beginnings of adjacent pixel rows as the number of T elements, can be negative. + int rowStride; + YAxisOrientation yOrientation; + + inline BitmapSection() : pixels(NULL), width(0), height(0), rowStride(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } + inline BitmapSection(T *pixels, int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), rowStride(N*width), yOrientation(yOrientation) { } + inline BitmapSection(T *pixels, int width, int height, int rowStride, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), rowStride(rowStride), yOrientation(yOrientation) { } + inline BitmapSection(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height), rowStride(N*orig.width), yOrientation(orig.yOrientation) { } + + inline T *operator()(int x, int y) const { + return pixels+rowStride*y+N*x; + } + + /// Returns a reference to a rectangular subsection of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapSection getSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapSection(pixels+rowStride*yMin+N*xMin, xMax-xMin, yMax-yMin, rowStride, yOrientation); + } + + /// Returns a constant reference to a rectangular subsection of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getConstSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapConstSection(pixels+rowStride*yMin+N*xMin, xMax-xMin, yMax-yMin, rowStride, yOrientation); + } + + /// Makes sure that the section's Y-axis orientation matches the argument by potentially reordering its rows. + inline void reorient(YAxisOrientation newYAxisOrientation) { + if (yOrientation != newYAxisOrientation) { + pixels += rowStride*(height-1); + rowStride = -rowStride; + yOrientation = newYAxisOrientation; + } + } + +}; + +template +struct BitmapConstSection { + + const T *pixels; + int width, height; + /// Specifies the difference between the beginnings of adjacent pixel rows as the number of T elements, can be negative. + int rowStride; + YAxisOrientation yOrientation; + + inline BitmapConstSection() : pixels(NULL), width(0), height(0), rowStride(0), yOrientation(MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) { } + inline BitmapConstSection(const T *pixels, int width, int height, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), rowStride(N*width), yOrientation(yOrientation) { } + inline BitmapConstSection(const T *pixels, int width, int height, int rowStride, YAxisOrientation yOrientation = MSDFGEN_Y_AXIS_DEFAULT_ORIENTATION) : pixels(pixels), width(width), height(height), rowStride(rowStride), yOrientation(yOrientation) { } + inline BitmapConstSection(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height), rowStride(N*orig.width), yOrientation(orig.yOrientation) { } + inline BitmapConstSection(const BitmapConstRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height), rowStride(N*orig.width), yOrientation(orig.yOrientation) { } + inline BitmapConstSection(const BitmapSection &orig) : pixels(orig.pixels), width(orig.width), height(orig.height), rowStride(orig.rowStride), yOrientation(orig.yOrientation) { } + + inline const T *operator()(int x, int y) const { + return pixels+rowStride*y+N*x; + } + + /// Returns a constant reference to a rectangular subsection of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getSection(int xMin, int yMin, int xMax, int yMax) const { + return BitmapConstSection(pixels+rowStride*yMin+N*xMin, xMax-xMin, yMax-yMin, rowStride, yOrientation); + } + + /// Returns a constant reference to a rectangular subsection of the bitmap specified by bounds (excluding xMax, yMax). + inline BitmapConstSection getConstSection(int xMin, int yMin, int xMax, int yMax) const { + return getSection(xMin, yMin, xMax, yMax); + } + + /// Makes sure that the section's Y-axis orientation matches the argument by potentially reordering its rows. + inline void reorient(YAxisOrientation newYAxisOrientation) { + if (yOrientation != newYAxisOrientation) { + pixels += rowStride*(height-1); + rowStride = -rowStride; + yOrientation = newYAxisOrientation; + } + } + }; } diff --git a/thirdparty/msdfgen/core/Contour.cpp b/thirdparty/msdfgen/core/Contour.cpp index 57293dc58be..aade65e5934 100644 --- a/thirdparty/msdfgen/core/Contour.cpp +++ b/thirdparty/msdfgen/core/Contour.cpp @@ -24,19 +24,19 @@ EdgeHolder &Contour::addEdge() { return edges.back(); } -static void boundPoint(double &l, double &b, double &r, double &t, Point2 p) { - if (p.x < l) l = p.x; - if (p.y < b) b = p.y; - if (p.x > r) r = p.x; - if (p.y > t) t = p.y; +static void boundPoint(double &xMin, double &yMin, double &xMax, double &yMax, Point2 p) { + if (p.x < xMin) xMin = p.x; + if (p.y < yMin) yMin = p.y; + if (p.x > xMax) xMax = p.x; + if (p.y > yMax) yMax = p.y; } -void Contour::bound(double &l, double &b, double &r, double &t) const { +void Contour::bound(double &xMin, double &yMin, double &xMax, double &yMax) const { for (std::vector::const_iterator edge = edges.begin(); edge != edges.end(); ++edge) - (*edge)->bound(l, b, r, t); + (*edge)->bound(xMin, yMin, xMax, yMax); } -void Contour::boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const { +void Contour::boundMiters(double &xMin, double &yMin, double &xMax, double &yMax, double border, double miterLimit, int polarity) const { if (edges.empty()) return; Vector2 prevDir = edges.back()->direction(1).normalize(true); @@ -48,7 +48,7 @@ void Contour::boundMiters(double &l, double &b, double &r, double &t, double bor if (q > 0) miterLength = min(1/sqrt(q), miterLimit); Point2 miter = (*edge)->point(0)+border*miterLength*(prevDir+dir).normalize(true); - boundPoint(l, b, r, t, miter); + boundPoint(xMin, yMin, xMax, yMax, miter); } prevDir = (*edge)->direction(1).normalize(true); } diff --git a/thirdparty/msdfgen/core/Contour.h b/thirdparty/msdfgen/core/Contour.h index 4cae48fad75..53ceb8eda57 100644 --- a/thirdparty/msdfgen/core/Contour.h +++ b/thirdparty/msdfgen/core/Contour.h @@ -21,9 +21,9 @@ public: /// Creates a new edge in the contour and returns its reference. EdgeHolder &addEdge(); /// Adjusts the bounding box to fit the contour. - void bound(double &l, double &b, double &r, double &t) const; + void bound(double &xMin, double &yMin, double &xMax, double &yMax) const; /// Adjusts the bounding box to fit the contour border's mitered corners. - void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const; + void boundMiters(double &xMin, double &yMin, double &xMax, double &yMax, double border, double miterLimit, int polarity) const; /// Computes the winding of the contour. Returns 1 if positive, -1 if negative. int winding() const; /// Reverses the sequence of edges on the contour. diff --git a/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp b/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp index d1b10ef10fa..940db3d492c 100644 --- a/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp +++ b/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp @@ -87,17 +87,15 @@ public: Point2 shapeCoord, sdfCoord; const float *msd; bool protectedFlag; - inline ShapeDistanceChecker(const BitmapConstRef &sdf, const Shape &shape, const Projection &projection, DistanceMapping distanceMapping, double minImproveRatio) : distanceFinder(shape), sdf(sdf), distanceMapping(distanceMapping), minImproveRatio(minImproveRatio) { + inline ShapeDistanceChecker(const BitmapConstSection &sdf, const Shape &shape, const Projection &projection, DistanceMapping distanceMapping, double minImproveRatio) : distanceFinder(shape), sdf(sdf), distanceMapping(distanceMapping), minImproveRatio(minImproveRatio) { texelSize = projection.unprojectVector(Vector2(1)); - if (shape.inverseYAxis) - texelSize.y = -texelSize.y; } inline ArtifactClassifier classifier(const Vector2 &direction, double span) { return ArtifactClassifier(this, direction, span); } private: ShapeDistanceFinder > distanceFinder; - BitmapConstRef sdf; + BitmapConstSection sdf; DistanceMapping distanceMapping; Vector2 texelSize; double minImproveRatio; @@ -105,10 +103,11 @@ private: MSDFErrorCorrection::MSDFErrorCorrection() { } -MSDFErrorCorrection::MSDFErrorCorrection(const BitmapRef &stencil, const SDFTransformation &transformation) : stencil(stencil), transformation(transformation) { +MSDFErrorCorrection::MSDFErrorCorrection(const BitmapSection &stencil, const SDFTransformation &transformation) : stencil(stencil), transformation(transformation) { minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio; minImproveRatio = ErrorCorrectionConfig::defaultMinImproveRatio; - memset(stencil.pixels, 0, sizeof(byte)*stencil.width*stencil.height); + for (int y = 0; y < stencil.height; ++y) + memset(stencil(0, y), 0, sizeof(byte)*stencil.width); } void MSDFErrorCorrection::setMinDeviationRatio(double minDeviationRatio) { @@ -120,6 +119,7 @@ void MSDFErrorCorrection::setMinImproveRatio(double minImproveRatio) { } void MSDFErrorCorrection::protectCorners(const Shape &shape) { + stencil.reorient(shape.getYAxisOrientation()); for (std::vector::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) if (!contour->edges.empty()) { const EdgeSegment *prevEdge = contour->edges.back(); @@ -131,8 +131,6 @@ void MSDFErrorCorrection::protectCorners(const Shape &shape) { Point2 p = transformation.project((*edge)->point(0)); int l = (int) floor(p.x-.5); int b = (int) floor(p.y-.5); - if (shape.inverseYAxis) - b = stencil.height-b-2; int r = l+1; int t = b+1; // Check that the positions are within bounds. @@ -189,8 +187,9 @@ static void protectExtremeChannels(byte *stencil, const float *msd, float m, int } template -void MSDFErrorCorrection::protectEdges(const BitmapConstRef &sdf) { +void MSDFErrorCorrection::protectEdges(const BitmapConstSection &sdf) { float radius; + stencil.reorient(sdf.yOrientation); // Horizontal texel pairs radius = float(PROTECTION_RADIUS_TOLERANCE*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)), 0)).length()); for (int y = 0; y < sdf.height; ++y) { @@ -251,9 +250,11 @@ void MSDFErrorCorrection::protectEdges(const BitmapConstRef &sdf) { } void MSDFErrorCorrection::protectAll() { - byte *end = stencil.pixels+stencil.width*stencil.height; - for (byte *mask = stencil.pixels; mask < end; ++mask) - *mask |= (byte) PROTECTED; + for (int y = 0; y < stencil.height; ++y) { + byte *mask = stencil(0, y); + for (int x = 0; x < stencil.width; ++x) + *mask++ |= (byte) PROTECTED; + } } /// Returns the median of the linear interpolation of texels a, b at t. @@ -273,16 +274,6 @@ static float interpolatedMedian(const float *a, const float *l, const float *q, )); } -/// Determines if the interpolated median xm is an artifact. -static bool isArtifact(bool isProtected, double axSpan, double bxSpan, float am, float bm, float xm) { - return ( - // For protected texels, only report an artifact if it would cause fill inversion (change between positive and negative distance). - (!isProtected || (am > .5f && bm > .5f && xm <= .5f) || (am < .5f && bm < .5f && xm >= .5f)) && - // This is an artifact if the interpolated median is outside the range of possible values based on its distance from a, b. - !(xm >= am-axSpan && xm <= am+axSpan && xm >= bm-bxSpan && xm <= bm+bxSpan) - ); -} - /// Checks if a linear interpolation artifact will occur at a point where two specific color channels are equal - such points have extreme median values. template static bool hasLinearArtifactInner(const ArtifactClassifier &artifactClassifier, float am, float bm, const float *a, const float *b, float dA, float dB) { @@ -390,7 +381,8 @@ static bool hasDiagonalArtifact(const ArtifactClassifier &artifactClassifier, fl } template -void MSDFErrorCorrection::findErrors(const BitmapConstRef &sdf) { +void MSDFErrorCorrection::findErrors(const BitmapConstSection &sdf) { + stencil.reorient(sdf.yOrientation); // Compute the expected deltas between values of horizontally, vertically, and diagonally adjacent texels. double hSpan = minDeviationRatio*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)), 0)).length(); double vSpan = minDeviationRatio*transformation.unprojectVector(Vector2(0, transformation.distanceMapping(DistanceMapping::Delta(1)))).length(); @@ -418,7 +410,9 @@ void MSDFErrorCorrection::findErrors(const BitmapConstRef &sdf) { } template