forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scale and translation arguments refactored as Projection, generator c…
…onfiguration WIP
- Loading branch information
Showing
17 changed files
with
335 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
#include "Projection.h" | ||
|
||
namespace msdfgen { | ||
|
||
Projection::Projection() : scale(1), translate(0) { } | ||
|
||
Projection::Projection(const Vector2 &scale, const Vector2 &translate) : scale(scale), translate(translate) { } | ||
|
||
Point2 Projection::project(const Point2 &coord) const { | ||
return scale*(coord+translate); | ||
} | ||
|
||
Point2 Projection::unproject(const Point2 &coord) const { | ||
return coord/scale-translate; | ||
} | ||
|
||
Vector2 Projection::projectVector(const Vector2 &vector) const { | ||
return scale*vector; | ||
} | ||
|
||
Vector2 Projection::unprojectVector(const Vector2 &vector) const { | ||
return vector/scale; | ||
} | ||
|
||
double Projection::projectX(double x) const { | ||
return scale.x*(x+translate.x); | ||
} | ||
|
||
double Projection::projectY(double y) const { | ||
return scale.y*(y+translate.y); | ||
} | ||
|
||
double Projection::unprojectX(double x) const { | ||
return x/scale.x-translate.x; | ||
} | ||
|
||
double Projection::unprojectY(double y) const { | ||
return y/scale.y-translate.y; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
#pragma once | ||
|
||
#include "Vector2.h" | ||
|
||
namespace msdfgen { | ||
|
||
/// A transformation from shape coordinates to pixel coordinates. | ||
class Projection { | ||
|
||
public: | ||
Projection(); | ||
Projection(const Vector2 &scale, const Vector2 &translate); | ||
/// Converts the shape coordinate to pixel coordinate. | ||
Point2 project(const Point2 &coord) const; | ||
/// Converts the pixel coordinate to shape coordinate. | ||
Point2 unproject(const Point2 &coord) const; | ||
/// Converts the vector to pixel coordinate space. | ||
Vector2 projectVector(const Vector2 &vector) const; | ||
/// Converts the vector from pixel coordinate space. | ||
Vector2 unprojectVector(const Vector2 &vector) const; | ||
/// Converts the X-coordinate from shape to pixel coordinate space. | ||
double projectX(double x) const; | ||
/// Converts the Y-coordinate from shape to pixel coordinate space. | ||
double projectY(double y) const; | ||
/// Converts the X-coordinate from pixel to shape coordinate space. | ||
double unprojectX(double x) const; | ||
/// Converts the Y-coordinate from pixel to shape coordinate space. | ||
double unprojectY(double y) const; | ||
|
||
private: | ||
Vector2 scale; | ||
Vector2 translate; | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#pragma once | ||
|
||
#define MSDFGEN_DEFAULT_ARTIFACT_PATCHER_MIN_IMPROVE_RATIO 1.001 | ||
|
||
namespace msdfgen { | ||
|
||
/// The configuration of the distance field generator algorithm. | ||
struct GeneratorConfig { | ||
/// Specifies whether to use the version of the algorithm that supports overlapping contours with the same winding. May be set to false to improve performance when no such contours are present. | ||
bool overlapSupport; | ||
|
||
inline explicit GeneratorConfig(bool overlapSupport = true) : overlapSupport(overlapSupport) { } | ||
}; | ||
|
||
/// The configuration of the artifact patcher that processes the generated MSDF and fixes potential interpolation errors. | ||
struct ArtifactPatcherConfig { | ||
/// The mode of operation. | ||
enum Mode { | ||
DISABLED, | ||
INDISCRIMINATE, | ||
EDGE_PRIORITY, | ||
EDGE_ONLY | ||
} mode; | ||
/// The minimum ratio of improvement required to patch a pixel. Must be greater than or equal to 1. | ||
double minImproveRatio; | ||
|
||
inline explicit ArtifactPatcherConfig(Mode mode = EDGE_PRIORITY, double minImproveRatio = MSDFGEN_DEFAULT_ARTIFACT_PATCHER_MIN_IMPROVE_RATIO) : mode(mode), minImproveRatio(minImproveRatio) { } | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#pragma once | ||
|
||
#include "Vector2.h" | ||
#include "Shape.h" | ||
#include "Projection.h" | ||
#include "BitmapRef.hpp" | ||
#include "generator-config.h" | ||
|
||
namespace msdfgen { | ||
|
||
void msdfPatchArtifacts(const BitmapRef<float, 3> &sdf, const Shape &shape, const Projection &projection, double range, const GeneratorConfig &generatorConfig = GeneratorConfig(), const ArtifactPatcherConfig &config = ArtifactPatcherConfig()); | ||
void msdfPatchArtifacts(const BitmapRef<float, 4> &sdf, const Shape &shape, const Projection &projection, double range, const GeneratorConfig &generatorConfig = GeneratorConfig(), const ArtifactPatcherConfig &config = ArtifactPatcherConfig()); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.