font2png: Parse background color
Decode background color from font blobs
This commit is contained in:
11
font2png.cc
11
font2png.cc
@@ -24,6 +24,7 @@ struct Font {
|
|||||||
unsigned numChars;
|
unsigned numChars;
|
||||||
unsigned charHeight;
|
unsigned charHeight;
|
||||||
unsigned maxCharWidth;
|
unsigned maxCharWidth;
|
||||||
|
uint8_t bgColor;
|
||||||
std::vector<Image> chars;
|
std::vector<Image> chars;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,8 +32,9 @@ struct FontHeader { // little endian
|
|||||||
uint32_t unknown1; // (always)? "1.\0\0"
|
uint32_t unknown1; // (always)? "1.\0\0"
|
||||||
uint32_t entries;
|
uint32_t entries;
|
||||||
uint32_t charWidth;
|
uint32_t charWidth;
|
||||||
uint32_t unknown3; // (always)? 0x000000ff
|
uint8_t bgColor;
|
||||||
};
|
char unknown3[3];
|
||||||
|
} __attribute__((__packed__));
|
||||||
|
|
||||||
Font parseFont(FILE* file, size_t length)
|
Font parseFont(FILE* file, size_t length)
|
||||||
{
|
{
|
||||||
@@ -89,6 +91,7 @@ Font parseFont(FILE* file, size_t length)
|
|||||||
ret.numChars = header.entries;
|
ret.numChars = header.entries;
|
||||||
ret.charHeight = char_width;
|
ret.charHeight = char_width;
|
||||||
ret.maxCharWidth = 0;
|
ret.maxCharWidth = 0;
|
||||||
|
ret.bgColor = header.bgColor;
|
||||||
for (auto const& index : indices) {
|
for (auto const& index : indices) {
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
if (fseeko(file, index, SEEK_SET) != 0)
|
if (fseeko(file, index, SEEK_SET) != 0)
|
||||||
@@ -160,12 +163,12 @@ Image makeFontImage(Font const& font)
|
|||||||
unsigned charNo = c_y*charsPerLine+c_x;
|
unsigned charNo = c_y*charsPerLine+c_x;
|
||||||
if (charNo > font.numChars) {
|
if (charNo > font.numChars) {
|
||||||
for (unsigned x = 0;x < font.maxCharWidth;++x)
|
for (unsigned x = 0;x < font.maxCharWidth;++x)
|
||||||
ret.data.push_back(0xff);
|
ret.data.push_back(font.bgColor);
|
||||||
} else {
|
} else {
|
||||||
for (unsigned x = 0;x < font.chars[charNo].width;++x)
|
for (unsigned x = 0;x < font.chars[charNo].width;++x)
|
||||||
ret.data.push_back(font.chars[charNo].data[y*font.chars[charNo].width+x]);
|
ret.data.push_back(font.chars[charNo].data[y*font.chars[charNo].width+x]);
|
||||||
for (unsigned x = font.chars[charNo].width; x < font.maxCharWidth;++x)
|
for (unsigned x = font.chars[charNo].width; x < font.maxCharWidth;++x)
|
||||||
ret.data.push_back(0xff);
|
ret.data.push_back(font.bgColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user