Improved error correction consistency for inverse Y-axis

This commit is contained in:
Chlumsky 2024-06-01 16:05:25 +02:00
parent cddd6c7308
commit 5ec8cef4c2
2 changed files with 9 additions and 12 deletions

View File

@ -113,25 +113,23 @@ in order to generate a distance field. Please note that all classes and function
Example: Example:
```c++ ```c++
#include "msdfgen.h" #include <msdfgen.h>
#include "msdfgen-ext.h" #include <msdfgen-ext.h>
using namespace msdfgen; using namespace msdfgen;
int main() { int main() {
FreetypeHandle *ft = initializeFreetype(); if (FreetypeHandle *ft = initializeFreetype()) {
if (ft) { if (FontHandle *font = loadFont(ft, "C:\\Windows\\Fonts\\arialbd.ttf")) {
FontHandle *font = loadFont(ft, "C:\\Windows\\Fonts\\arialbd.ttf");
if (font) {
Shape shape; Shape shape;
if (loadGlyph(shape, font, 'A')) { if (loadGlyph(shape, font, 'A', FONT_SCALING_EM_NORMALIZED)) {
shape.normalize(); shape.normalize();
// max. angle // max. angle
edgeColoringSimple(shape, 3.0); edgeColoringSimple(shape, 3.0);
// output width, height // output width, height
Bitmap<float, 3> msdf(32, 32); Bitmap<float, 3> msdf(32, 32);
// scale, translation // scale, translation (in em's)
SDFTransformation t(Projection(1.0, Vector2(4.0, 4.0)), Range(4.0)); SDFTransformation t(Projection(32.0, Vector2(0.125, 0.125)), Range(0.125));
generateMSDF(msdf, shape, t); generateMSDF(msdf, shape, t);
savePng(msdf, "output.png"); savePng(msdf, "output.png");
} }
@ -141,7 +139,6 @@ int main() {
} }
return 0; return 0;
} }
``` ```
## Using a multi-channel distance field ## Using a multi-channel distance field

View File

@ -129,10 +129,10 @@ void MSDFErrorCorrection::protectCorners(const Shape &shape) {
if (!(commonColor&(commonColor-1))) { if (!(commonColor&(commonColor-1))) {
// Find the four texels that envelop the corner and mark them as protected. // Find the four texels that envelop the corner and mark them as protected.
Point2 p = transformation.project((*edge)->point(0)); Point2 p = transformation.project((*edge)->point(0));
if (shape.inverseYAxis)
p.y = stencil.height-p.y;
int l = (int) floor(p.x-.5); int l = (int) floor(p.x-.5);
int b = (int) floor(p.y-.5); int b = (int) floor(p.y-.5);
if (shape.inverseYAxis)
b = stencil.height-b-2;
int r = l+1; int r = l+1;
int t = b+1; int t = b+1;
// Check that the positions are within bounds. // Check that the positions are within bounds.