diff --git a/.gitignore b/.gitignore index 475b51b..28420b9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ x64/ *.suo *.VC.opendb *.VC.db +bin/msdf-atlas-gen bin/*.lib output.png out/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 035d97a..d7d4480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +## Version 1.2 (2021-05-29) + +- Updated to MSDFgen 1.9. +- Multiple fonts or font sizes can now be compiled into a single atlas. +- Added `-yorigin` option to choose if Y-coordinates increase from bottom to top or from top to bottom. +- Added `-coloringstrategy` option to select MSDF edge coloring heuristic. +- Shadron preview now properly loads floating-point image outputs in full range mode. + ## Version 1.1 (2020-10-18) - Updated to MSDFgen 1.8. diff --git a/README.md b/README.md index db2b680..c8c54ef 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,8 @@ Any non-empty subset of the following may be specified: ### Distance field generator settings - `-angle ` – sets the minimum angle between adjacent edges to be considered a corner. Append D for degrees (`msdf` / `mtsdf` only) -- `-errorcorrection ` – sets the threshold used to detect and correct potential artifacts. 0 disables error correction (`msdf` / `mtsdf` only) +- `-coloringstrategy ` – selects the edge coloring heuristic (`msdf` / `mtsdf` only) +- `-errorcorrection ` – selects the error correction algorithm. Use `help` as mode for more information (`msdf` / `mtsdf` only) - `-miterlimit ` – sets the miter limit that limits the extension of each glyph's bounding box due to very sharp corners (`psdf` / `msdf` / `mtsdf` only) - `-overlap` – switches to distance field generator with support for overlapping contours - `-nopreprocess` – disables path preprocessing which resolves self-intersections and overlapping contours @@ -116,6 +117,8 @@ Any non-empty subset of the following may be specified: - `-seed ` – sets the initial seed for the edge coloring heuristic - `-threads ` – sets the number of threads for the parallel computation (0 = auto) +Use `-help` for an exhaustive list of options. + ## Character set specification syntax The character set file is a text file with UTF-8 or ASCII encoding. diff --git a/msdf-atlas-gen.aps b/msdf-atlas-gen.aps index 2e23cf8..154da62 100644 Binary files a/msdf-atlas-gen.aps and b/msdf-atlas-gen.aps differ diff --git a/msdf-atlas-gen.rc b/msdf-atlas-gen.rc index dba59c3..49499c6 100644 Binary files a/msdf-atlas-gen.rc and b/msdf-atlas-gen.rc differ diff --git a/msdf-atlas-gen/GlyphGeometry.cpp b/msdf-atlas-gen/GlyphGeometry.cpp index 8a9c441..5ee557a 100644 --- a/msdf-atlas-gen/GlyphGeometry.cpp +++ b/msdf-atlas-gen/GlyphGeometry.cpp @@ -47,8 +47,8 @@ bool GlyphGeometry::load(msdfgen::FontHandle *font, double geometryScale, unicod return false; } -void GlyphGeometry::edgeColoring(double angleThreshold, unsigned long long seed) { - msdfgen::edgeColoringInkTrap(shape, angleThreshold, seed); +void GlyphGeometry::edgeColoring(void (*fn)(msdfgen::Shape &, double, unsigned long long), double angleThreshold, unsigned long long seed) { + fn(shape, angleThreshold, seed); } void GlyphGeometry::wrapBox(double scale, double range, double miterLimit) { diff --git a/msdf-atlas-gen/GlyphGeometry.h b/msdf-atlas-gen/GlyphGeometry.h index 7127bbc..748baed 100644 --- a/msdf-atlas-gen/GlyphGeometry.h +++ b/msdf-atlas-gen/GlyphGeometry.h @@ -17,7 +17,7 @@ class GlyphGeometry { bool load(msdfgen::FontHandle *font, double geometryScale, msdfgen::GlyphIndex index, bool preprocessGeometry = true); bool load(msdfgen::FontHandle *font, double geometryScale, unicode_t codepoint, bool preprocessGeometry = true); /// Applies edge coloring to glyph shape - void edgeColoring(double angleThreshold, unsigned long long seed); + void edgeColoring(void (*fn)(msdfgen::Shape &, double, unsigned long long), double angleThreshold, unsigned long long seed); /// Computes the dimensions of the glyph's box as well as the transformation for the generator function void wrapBox(double scale, double range, double miterLimit); /// Sets the glyph's box's position in the atlas diff --git a/msdf-atlas-gen/main.cpp b/msdf-atlas-gen/main.cpp index 74603b9..5c13f0e 100644 --- a/msdf-atlas-gen/main.cpp +++ b/msdf-atlas-gen/main.cpp @@ -1,8 +1,8 @@ /* -* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.1 (2020-10-18) - standalone console program +* MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.2 (2021-05-29) - standalone console program * -------------------------------------------------------------------------------------------------- -* A utility by Viktor Chlumsky, (c) 2020 +* A utility by Viktor Chlumsky, (c) 2020 - 2021 * */ @@ -26,7 +26,8 @@ using namespace msdf_atlas; #define DEFAULT_PIXEL_RANGE 2.0 #define SDF_ERROR_ESTIMATE_PRECISION 19 #define GLYPH_FILL_RULE msdfgen::FILL_NONZERO -#define MCG_MULTIPLIER 6364136223846793005ull +#define LCG_MULTIPLIER 6364136223846793005ull +#define LCG_INCREMENT 1442695040888963407ull #ifdef MSDFGEN_USE_SKIA #define TITLE_SUFFIX " & Skia" @@ -94,6 +95,8 @@ GLYPH CONFIGURATION DISTANCE FIELD GENERATOR SETTINGS -angle Specifies the minimum angle between adjacent edges to be considered a corner. Append D for degrees. (msdf / mtsdf only) + -coloringstrategy + Selects the strategy of the edge coloring heuristic. -errorcorrection Changes the MSDF/MTSDF error correction mode. Use -errorcorrection help for a list of valid modes. -errordeviationratio @@ -201,6 +204,8 @@ struct Configuration { double pxRange; double angleThreshold; double miterLimit; + void (*edgeColoring)(msdfgen::Shape &, double, unsigned long long); + bool expensiveColoring; unsigned long long coloringSeed; GeneratorAttributes generatorAttributes; bool preprocessGeometry; @@ -263,6 +268,7 @@ int main(int argc, const char * const *argv) { config.imageType = ImageType::MSDF; config.imageFormat = ImageFormat::UNSPECIFIED; config.yDirection = YDirection::BOTTOM_UP; + config.edgeColoring = msdfgen::edgeColoringInkTrap; config.kerning = true; const char *imageFormatName = nullptr; int fixedWidth = -1, fixedHeight = -1; @@ -547,6 +553,15 @@ int main(int argc, const char * const *argv) { argPos += 2; continue; } + ARG_CASE("-coloringstrategy", 1) { + if (!strcmp(argv[argPos+1], "simple")) config.edgeColoring = msdfgen::edgeColoringSimple, config.expensiveColoring = false; + else if (!strcmp(argv[argPos+1], "inktrap")) config.edgeColoring = msdfgen::edgeColoringInkTrap, config.expensiveColoring = false; + else if (!strcmp(argv[argPos+1], "distance")) config.edgeColoring = msdfgen::edgeColoringByDistance, config.expensiveColoring = true; + else + puts("Unknown coloring strategy specified."); + argPos += 2; + continue; + } ARG_CASE("-miterlimit", 1) { double m; if (!(parseDouble(m, argv[++argPos]) && m >= 0)) @@ -891,10 +906,18 @@ int main(int argc, const char * const *argv) { // Edge coloring if (config.imageType == ImageType::MSDF || config.imageType == ImageType::MTSDF) { - unsigned long long glyphSeed = config.coloringSeed; - for (GlyphGeometry &glyph : glyphs) { - glyphSeed *= MCG_MULTIPLIER; - glyph.edgeColoring(config.angleThreshold, glyphSeed); + if (config.expensiveColoring) { + Workload([&glyphs, &config](int i, int threadNo) -> bool { + unsigned long long glyphSeed = (LCG_MULTIPLIER*(config.coloringSeed^i)+LCG_INCREMENT)*!!config.coloringSeed; + glyphs[i].edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed); + return true; + }, glyphs.size()).finish(config.threadCount); + } else { + unsigned long long glyphSeed = config.coloringSeed; + for (GlyphGeometry &glyph : glyphs) { + glyphSeed *= LCG_MULTIPLIER; + glyph.edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed); + } } } diff --git a/msdf-atlas-gen/msdf-atlas-gen.h b/msdf-atlas-gen/msdf-atlas-gen.h index b3482ac..cf24d54 100644 --- a/msdf-atlas-gen/msdf-atlas-gen.h +++ b/msdf-atlas-gen/msdf-atlas-gen.h @@ -2,9 +2,9 @@ #pragma once /* - * MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.1 (2020-10-18) + * MULTI-CHANNEL SIGNED DISTANCE FIELD ATLAS GENERATOR v1.2 (2021-05-29) * --------------------------------------------------------------------- - * A utility by Viktor Chlumsky, (c) 2020 + * A utility by Viktor Chlumsky, (c) 2020 - 2021 * * Generates compact bitmap font atlases using MSDFGEN. * @@ -39,4 +39,4 @@ #include "json-export.h" #include "shadron-preview-generator.h" -#define MSDF_ATLAS_VERSION "1.1" +#define MSDF_ATLAS_VERSION "1.2"