Image format information #128, warning fix #129

This commit is contained in:
Chlumsky 2025-05-31 13:17:46 +02:00
parent f7eb7efdad
commit 30b6f4fd1a
7 changed files with 43 additions and 39 deletions

View File

@ -79,13 +79,17 @@ If no character set or glyph set is provided, and `-allglyphs` is not used, the
- `png` – a compressed PNG image
- `bmp` – an uncompressed BMP image
- `tiff` – an uncompressed floating-point TIFF image
- `rgba` – an uncompressed [RGBA](https://github.com/bzotto/rgba_bitmap) file
- `fl32` – an uncompressed floating-point FL32 file
- `text` – a sequence of pixel values in plain text
- `textfloat` – a sequence of floating-point pixel values in plain text
- `bin` – a sequence of pixel values encoded as raw bytes of data
- `binfloat` – a sequence of pixel values encoded as raw 32-bit floating-point values
- `binfloat` – a sequence of pixel values encoded as raw 32-bit floating-point values (little endian, `binfloatbe` for big endian)
If format is not specified, it may be deduced from the extension of the `-imageout` argument or other clues.
Please note that all color values must be interpreted as if they were linear (not sRGB) like the alpha channel, even if the image format implies otherwise.
### Atlas dimensions
`-dimensions <width> <height>` &ndash; sets fixed atlas dimensions

View File

@ -1,24 +1,16 @@
#include "DynamicAtlas.h"
namespace msdf_atlas {
#include "utils.hpp"
static int ceilPOT(int x) {
if (x > 0) {
int y = 1;
while (y < x)
y <<= 1;
return y;
}
return 0;
}
namespace msdf_atlas {
template <class AtlasGenerator>
DynamicAtlas<AtlasGenerator>::DynamicAtlas() : side(0), spacing(0), glyphCount(0), totalArea(0) { }
template <class AtlasGenerator>
template <typename... ARGS>
DynamicAtlas<AtlasGenerator>::DynamicAtlas(int minSide, ARGS... args) : side(ceilPOT(minSide)), spacing(0), glyphCount(0), totalArea(0), packer(side+spacing, side+spacing), generator(side, side, args...) { }
DynamicAtlas<AtlasGenerator>::DynamicAtlas(int minSide, ARGS... args) : side(minSide > 0 ? ceilToPOT(minSide) : 0), spacing(0), glyphCount(0), totalArea(0), packer(side+spacing, side+spacing), generator(side, side, args...) { }
template <class AtlasGenerator>
DynamicAtlas<AtlasGenerator>::DynamicAtlas(AtlasGenerator &&generator) : side(0), spacing(0), glyphCount(0), totalArea(0), generator((AtlasGenerator &&) generator) { }

View File

@ -2,23 +2,10 @@
#include "GridAtlasPacker.h"
#include <algorithm>
#include "utils.hpp"
namespace msdf_atlas {
static int floorPOT(int x) {
int y = 1;
while (x >= y && y<<1)
y <<= 1;
return y>>1;
}
static int ceilPOT(int x) {
int y = 1;
while (x > y && y<<1)
y <<= 1;
return y;
}
static bool squareConstraint(DimensionsConstraint constraint) {
switch (constraint) {
case DimensionsConstraint::SQUARE:
@ -51,9 +38,9 @@ void GridAtlasPacker::lowerToConstraint(int &width, int &height, DimensionsConst
case DimensionsConstraint::POWER_OF_TWO_RECTANGLE:
case DimensionsConstraint::POWER_OF_TWO_SQUARE:
if (width > 0)
width = floorPOT(width);
width = floorToPOT(width);
if (height > 0)
height = floorPOT(height);
height = floorToPOT(height);
break;
}
}
@ -76,9 +63,9 @@ void GridAtlasPacker::raiseToConstraint(int &width, int &height, DimensionsConst
case DimensionsConstraint::POWER_OF_TWO_RECTANGLE:
case DimensionsConstraint::POWER_OF_TWO_SQUARE:
if (width > 0)
width = ceilPOT(width);
width = ceilToPOT(width);
if (height > 0)
height = ceilPOT(height);
height = ceilToPOT(height);
break;
}
}

View File

@ -8,7 +8,6 @@ namespace msdf_atlas {
/*
* Copies a rectangular section from source bitmap to destination bitmap.
* Width and height are not checked and must not exceed bitmap bounds!
*/
void blit(const msdfgen::BitmapRef<byte, 1> &dst, const msdfgen::BitmapConstRef<byte, 1> &src, int dx, int dy, int sx, int sy, int w, int h);

View File

@ -451,27 +451,27 @@ int main(int argc, const char *const *argv) {
#endif
if (ARG_IS("bmp"))
config.imageFormat = ImageFormat::BMP;
else if (ARG_IS("tiff"))
else if (ARG_IS("tiff") || ARG_IS("tif"))
config.imageFormat = ImageFormat::TIFF;
else if (ARG_IS("rgba"))
config.imageFormat = ImageFormat::RGBA;
else if (ARG_IS("fl32"))
config.imageFormat = ImageFormat::FL32;
else if (ARG_IS("text"))
else if (ARG_IS("text") || ARG_IS("txt"))
config.imageFormat = ImageFormat::TEXT;
else if (ARG_IS("textfloat"))
else if (ARG_IS("textfloat") || ARG_IS("txtfloat"))
config.imageFormat = ImageFormat::TEXT_FLOAT;
else if (ARG_IS("bin"))
else if (ARG_IS("bin") || ARG_IS("binary"))
config.imageFormat = ImageFormat::BINARY;
else if (ARG_IS("binfloat"))
else if (ARG_IS("binfloat") || ARG_IS("binfloatle"))
config.imageFormat = ImageFormat::BINARY_FLOAT;
else if (ARG_IS("binfloatbe"))
config.imageFormat = ImageFormat::BINARY_FLOAT_BE;
else {
#ifndef MSDFGEN_DISABLE_PNG
ABORT("Invalid image format. Valid formats are: png, bmp, tiff, rgba, fl32, text, textfloat, bin, binfloat");
ABORT("Invalid image format. Valid formats are: png, bmp, tiff, rgba, fl32, text, textfloat, bin, binfloat, binfloatbe");
#else
ABORT("Invalid image format. Valid formats are: bmp, tiff, rgba, fl32, text, textfloat, bin, binfloat");
ABORT("Invalid image format. Valid formats are: bmp, tiff, rgba, fl32, text, textfloat, bin, binfloat, binfloatbe");
#endif
}
imageFormatName = arg;

22
msdf-atlas-gen/utils.hpp Normal file
View File

@ -0,0 +1,22 @@
#pragma once
namespace msdf_atlas {
/// Floor positive integer to nearest lower or equal power of two
inline int floorToPOT(int x) {
int y = 1;
while (x >= y && y<<1)
y <<= 1;
return y>>1;
}
/// Ceil positive integer to nearest higher or equal power of two
inline int ceilToPOT(int x) {
int y = 1;
while (x > y && y<<1)
y <<= 1;
return y;
}
}

@ -1 +1 @@
Subproject commit 5a88b0c2b95033f7eee826b27c48d399d544d814
Subproject commit 03889564a50452fa2e0b0a60973b5057001b391b