Improved Shadron preview with floating-point atlas
This commit is contained in:
parent
60789b8cf3
commit
c9ab9974ce
|
|
@ -591,6 +591,12 @@ int main(int argc, const char * const *argv) {
|
||||||
printf("Warning: Output image file extension does not match the image's actual format (%s)!\n", imageFormatName);
|
printf("Warning: Output image file extension does not match the image's actual format (%s)!\n", imageFormatName);
|
||||||
}
|
}
|
||||||
imageFormatName = nullptr; // No longer consistent with imageFormat
|
imageFormatName = nullptr; // No longer consistent with imageFormat
|
||||||
|
bool floatingPointFormat = (
|
||||||
|
config.imageFormat == ImageFormat::TIFF ||
|
||||||
|
config.imageFormat == ImageFormat::TEXT_FLOAT ||
|
||||||
|
config.imageFormat == ImageFormat::BINARY_FLOAT ||
|
||||||
|
config.imageFormat == ImageFormat::BINARY_FLOAT_BE
|
||||||
|
);
|
||||||
|
|
||||||
// Load font
|
// Load font
|
||||||
class FontHolder {
|
class FontHolder {
|
||||||
|
|
@ -699,42 +705,35 @@ int main(int argc, const char * const *argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool floatingPoint = (
|
|
||||||
config.imageFormat == ImageFormat::TIFF ||
|
|
||||||
config.imageFormat == ImageFormat::TEXT_FLOAT ||
|
|
||||||
config.imageFormat == ImageFormat::BINARY_FLOAT ||
|
|
||||||
config.imageFormat == ImageFormat::BINARY_FLOAT_BE
|
|
||||||
);
|
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
switch (config.imageType) {
|
switch (config.imageType) {
|
||||||
case ImageType::HARD_MASK:
|
case ImageType::HARD_MASK:
|
||||||
if (floatingPoint)
|
if (floatingPointFormat)
|
||||||
success = makeAtlas<float, float, 1, scanlineGenerator>(glyphs, font, config);
|
success = makeAtlas<float, float, 1, scanlineGenerator>(glyphs, font, config);
|
||||||
else
|
else
|
||||||
success = makeAtlas<byte, float, 1, scanlineGenerator>(glyphs, font, config);
|
success = makeAtlas<byte, float, 1, scanlineGenerator>(glyphs, font, config);
|
||||||
break;
|
break;
|
||||||
case ImageType::SOFT_MASK:
|
case ImageType::SOFT_MASK:
|
||||||
case ImageType::SDF:
|
case ImageType::SDF:
|
||||||
if (floatingPoint)
|
if (floatingPointFormat)
|
||||||
success = makeAtlas<float, float, 1, sdfGenerator>(glyphs, font, config);
|
success = makeAtlas<float, float, 1, sdfGenerator>(glyphs, font, config);
|
||||||
else
|
else
|
||||||
success = makeAtlas<byte, float, 1, sdfGenerator>(glyphs, font, config);
|
success = makeAtlas<byte, float, 1, sdfGenerator>(glyphs, font, config);
|
||||||
break;
|
break;
|
||||||
case ImageType::PSDF:
|
case ImageType::PSDF:
|
||||||
if (floatingPoint)
|
if (floatingPointFormat)
|
||||||
success = makeAtlas<float, float, 1, psdfGenerator>(glyphs, font, config);
|
success = makeAtlas<float, float, 1, psdfGenerator>(glyphs, font, config);
|
||||||
else
|
else
|
||||||
success = makeAtlas<byte, float, 1, psdfGenerator>(glyphs, font, config);
|
success = makeAtlas<byte, float, 1, psdfGenerator>(glyphs, font, config);
|
||||||
break;
|
break;
|
||||||
case ImageType::MSDF:
|
case ImageType::MSDF:
|
||||||
if (floatingPoint)
|
if (floatingPointFormat)
|
||||||
success = makeAtlas<float, float, 3, msdfGenerator>(glyphs, font, config);
|
success = makeAtlas<float, float, 3, msdfGenerator>(glyphs, font, config);
|
||||||
else
|
else
|
||||||
success = makeAtlas<byte, float, 3, msdfGenerator>(glyphs, font, config);
|
success = makeAtlas<byte, float, 3, msdfGenerator>(glyphs, font, config);
|
||||||
break;
|
break;
|
||||||
case ImageType::MTSDF:
|
case ImageType::MTSDF:
|
||||||
if (floatingPoint)
|
if (floatingPointFormat)
|
||||||
success = makeAtlas<float, float, 4, mtsdfGenerator>(glyphs, font, config);
|
success = makeAtlas<float, float, 4, mtsdfGenerator>(glyphs, font, config);
|
||||||
else
|
else
|
||||||
success = makeAtlas<byte, float, 4, mtsdfGenerator>(glyphs, font, config);
|
success = makeAtlas<byte, float, 4, mtsdfGenerator>(glyphs, font, config);
|
||||||
|
|
@ -766,7 +765,7 @@ int main(int argc, const char * const *argv) {
|
||||||
std::vector<unicode_t> previewText;
|
std::vector<unicode_t> previewText;
|
||||||
utf8Decode(previewText, config.shadronPreviewText);
|
utf8Decode(previewText, config.shadronPreviewText);
|
||||||
previewText.push_back(0);
|
previewText.push_back(0);
|
||||||
if (generateShadronPreview(font, glyphs.data(), glyphs.size(), config.imageType, config.width, config.height, config.pxRange, previewText.data(), config.imageFilename, config.shadronPreviewFilename))
|
if (generateShadronPreview(font, glyphs.data(), glyphs.size(), config.imageType, config.width, config.height, config.pxRange, previewText.data(), config.imageFilename, floatingPointFormat, config.shadronPreviewFilename))
|
||||||
puts("Shadron preview script generated.");
|
puts("Shadron preview script generated.");
|
||||||
else {
|
else {
|
||||||
result = 1;
|
result = 1;
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ static std::string relativizePath(const char *base, const char *target) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool generateShadronPreview(msdfgen::FontHandle *font, const GlyphGeometry *glyphs, int glyphCount, ImageType atlasType, int atlasWidth, int atlasHeight, double pxRange, const unicode_t *text, const char *imageFilename, const char *outputFilename) {
|
bool generateShadronPreview(msdfgen::FontHandle *font, const GlyphGeometry *glyphs, int glyphCount, ImageType atlasType, int atlasWidth, int atlasHeight, double pxRange, const unicode_t *text, const char *imageFilename, bool fullRange, const char *outputFilename) {
|
||||||
double texelWidth = 1./atlasWidth;
|
double texelWidth = 1./atlasWidth;
|
||||||
double texelHeight = 1./atlasHeight;
|
double texelHeight = 1./atlasHeight;
|
||||||
FILE *file = fopen(outputFilename, "w");
|
FILE *file = fopen(outputFilename, "w");
|
||||||
|
|
@ -88,7 +88,7 @@ bool generateShadronPreview(msdfgen::FontHandle *font, const GlyphGeometry *glyp
|
||||||
fprintf(file, "image Atlas = file(\"%s\")", relativizePath(outputFilename, imageFilename).c_str());
|
fprintf(file, "image Atlas = file(\"%s\")", relativizePath(outputFilename, imageFilename).c_str());
|
||||||
else
|
else
|
||||||
fprintf(file, "image Atlas = file()");
|
fprintf(file, "image Atlas = file()");
|
||||||
fprintf(file, " : filter(%s), map(repeat);\n", atlasType == ImageType::HARD_MASK ? "nearest" : "linear");
|
fprintf(file, " : %sfilter(%s), map(repeat);\n", fullRange ? "full_range(true), " : "", atlasType == ImageType::HARD_MASK ? "nearest" : "linear");
|
||||||
fprintf(file, "const vec2 txRange = vec2(%.9g, %.9g);\n\n", pxRange*texelWidth, pxRange*texelHeight);
|
fprintf(file, "const vec2 txRange = vec2(%.9g, %.9g);\n\n", pxRange*texelWidth, pxRange*texelHeight);
|
||||||
{
|
{
|
||||||
msdfgen::FontMetrics fontMetrics;
|
msdfgen::FontMetrics fontMetrics;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@
|
||||||
namespace msdf_atlas {
|
namespace msdf_atlas {
|
||||||
|
|
||||||
/// Generates a Shadron script that displays a string using the generated atlas
|
/// Generates a Shadron script that displays a string using the generated atlas
|
||||||
bool generateShadronPreview(msdfgen::FontHandle *font, const GlyphGeometry *glyphs, int glyphCount, ImageType atlasType, int atlasWidth, int atlasHeight, double pxRange, const unicode_t *text, const char *imageFilename, const char *outputFilename);
|
bool generateShadronPreview(msdfgen::FontHandle *font, const GlyphGeometry *glyphs, int glyphCount, ImageType atlasType, int atlasWidth, int atlasHeight, double pxRange, const unicode_t *text, const char *imageFilename, bool fullRange, const char *outputFilename);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
msdfgen
2
msdfgen
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9d22335ea093422d7bf212d31bfaa6adcb9b89f0
|
Subproject commit ae7fc5e7a53828949f3bd15006c96ef1a97b5105
|
||||||
Loading…
Reference in New Issue