msdfgen: Update to 1.13
Remove unused `export-svg` and `save-*` files.
This commit is contained in:
75
thirdparty/msdfgen/core/rasterization.cpp
vendored
75
thirdparty/msdfgen/core/rasterization.cpp
vendored
@@ -6,58 +6,60 @@
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
void rasterize(BitmapSection<float, 1> output, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
output.reorient(shape.getYAxisOrientation());
|
||||
Scanline scanline;
|
||||
for (int y = 0; y < output.height; ++y) {
|
||||
int row = shape.inverseYAxis ? output.height-y-1 : y;
|
||||
shape.scanline(scanline, projection.unprojectY(y+.5));
|
||||
for (int x = 0; x < output.width; ++x)
|
||||
*output(x, row) = (float) scanline.filled(projection.unprojectX(x+.5), fillRule);
|
||||
*output(x, y) = (float) scanline.filled(projection.unprojectX(x+.5), fillRule);
|
||||
}
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 1> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
void distanceSignCorrection(BitmapSection<float, 1> sdf, const Shape &shape, const Projection &projection, float sdfZeroValue, FillRule fillRule) {
|
||||
sdf.reorient(shape.getYAxisOrientation());
|
||||
float doubleSdfZeroValue = sdfZeroValue+sdfZeroValue;
|
||||
Scanline scanline;
|
||||
for (int y = 0; y < sdf.height; ++y) {
|
||||
int row = shape.inverseYAxis ? sdf.height-y-1 : y;
|
||||
shape.scanline(scanline, projection.unprojectY(y+.5));
|
||||
for (int x = 0; x < sdf.width; ++x) {
|
||||
bool fill = scanline.filled(projection.unprojectX(x+.5), fillRule);
|
||||
float &sd = *sdf(x, row);
|
||||
if ((sd > .5f) != fill)
|
||||
sd = 1.f-sd;
|
||||
float &sd = *sdf(x, y);
|
||||
if ((sd > sdfZeroValue) != fill)
|
||||
sd = doubleSdfZeroValue-sd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <int N>
|
||||
static void multiDistanceSignCorrection(const BitmapRef<float, N> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
static void multiDistanceSignCorrection(BitmapSection<float, N> sdf, const Shape &shape, const Projection &projection, float sdfZeroValue, FillRule fillRule) {
|
||||
int w = sdf.width, h = sdf.height;
|
||||
if (!(w && h))
|
||||
return;
|
||||
sdf.reorient(shape.getYAxisOrientation());
|
||||
float doubleSdfZeroValue = sdfZeroValue+sdfZeroValue;
|
||||
Scanline scanline;
|
||||
bool ambiguous = false;
|
||||
std::vector<char> matchMap;
|
||||
matchMap.resize(w*h);
|
||||
char *match = &matchMap[0];
|
||||
for (int y = 0; y < h; ++y) {
|
||||
int row = shape.inverseYAxis ? h-y-1 : y;
|
||||
shape.scanline(scanline, projection.unprojectY(y+.5));
|
||||
for (int x = 0; x < w; ++x) {
|
||||
bool fill = scanline.filled(projection.unprojectX(x+.5), fillRule);
|
||||
float *msd = sdf(x, row);
|
||||
float *msd = sdf(x, y);
|
||||
float sd = median(msd[0], msd[1], msd[2]);
|
||||
if (sd == .5f)
|
||||
if (sd == sdfZeroValue)
|
||||
ambiguous = true;
|
||||
else if ((sd > .5f) != fill) {
|
||||
msd[0] = 1.f-msd[0];
|
||||
msd[1] = 1.f-msd[1];
|
||||
msd[2] = 1.f-msd[2];
|
||||
else if ((sd > sdfZeroValue) != fill) {
|
||||
msd[0] = doubleSdfZeroValue-msd[0];
|
||||
msd[1] = doubleSdfZeroValue-msd[1];
|
||||
msd[2] = doubleSdfZeroValue-msd[2];
|
||||
*match = -1;
|
||||
} else
|
||||
*match = 1;
|
||||
if (N >= 4 && (msd[3] > .5f) != fill)
|
||||
msd[3] = 1.f-msd[3];
|
||||
if (N >= 4 && (msd[3] > sdfZeroValue) != fill)
|
||||
msd[3] = doubleSdfZeroValue-msd[3];
|
||||
++match;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +67,6 @@ static void multiDistanceSignCorrection(const BitmapRef<float, N> &sdf, const Sh
|
||||
if (ambiguous) {
|
||||
match = &matchMap[0];
|
||||
for (int y = 0; y < h; ++y) {
|
||||
int row = shape.inverseYAxis ? h-y-1 : y;
|
||||
for (int x = 0; x < w; ++x) {
|
||||
if (!*match) {
|
||||
int neighborMatch = 0;
|
||||
@@ -74,10 +75,10 @@ static void multiDistanceSignCorrection(const BitmapRef<float, N> &sdf, const Sh
|
||||
if (y > 0) neighborMatch += *(match-w);
|
||||
if (y < h-1) neighborMatch += *(match+w);
|
||||
if (neighborMatch < 0) {
|
||||
float *msd = sdf(x, row);
|
||||
msd[0] = 1.f-msd[0];
|
||||
msd[1] = 1.f-msd[1];
|
||||
msd[2] = 1.f-msd[2];
|
||||
float *msd = sdf(x, y);
|
||||
msd[0] = doubleSdfZeroValue-msd[0];
|
||||
msd[1] = doubleSdfZeroValue-msd[1];
|
||||
msd[2] = doubleSdfZeroValue-msd[2];
|
||||
}
|
||||
}
|
||||
++match;
|
||||
@@ -86,29 +87,41 @@ static void multiDistanceSignCorrection(const BitmapRef<float, N> &sdf, const Sh
|
||||
}
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
multiDistanceSignCorrection(sdf, shape, projection, fillRule);
|
||||
void distanceSignCorrection(BitmapSection<float, 3> sdf, const Shape &shape, const Projection &projection, float sdfZeroValue, FillRule fillRule) {
|
||||
multiDistanceSignCorrection(sdf, shape, projection, sdfZeroValue, fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
multiDistanceSignCorrection(sdf, shape, projection, fillRule);
|
||||
void distanceSignCorrection(BitmapSection<float, 4> sdf, const Shape &shape, const Projection &projection, float sdfZeroValue, FillRule fillRule) {
|
||||
multiDistanceSignCorrection(sdf, shape, projection, sdfZeroValue, fillRule);
|
||||
}
|
||||
|
||||
// Legacy API
|
||||
|
||||
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
void rasterize(const BitmapSection<float, 1> &output, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
rasterize(output, shape, Projection(scale, translate), fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 1> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
void distanceSignCorrection(BitmapSection<float, 1> sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, projection, .5f, fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(BitmapSection<float, 3> sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, projection, .5f, fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(BitmapSection<float, 4> sdf, const Shape &shape, const Projection &projection, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, projection, .5f, fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapSection<float, 1> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, Projection(scale, translate), fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
void distanceSignCorrection(const BitmapSection<float, 3> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, Projection(scale, translate), fillRule);
|
||||
}
|
||||
|
||||
void distanceSignCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
void distanceSignCorrection(const BitmapSection<float, 4> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule) {
|
||||
distanceSignCorrection(sdf, shape, Projection(scale, translate), fillRule);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user