Added RGB and RGBA image support to BMFont loader

This commit is contained in:
Uneven Prankster 2025-01-26 18:30:20 -03:00
parent f6f31a9f21
commit b4583ce18c

View File

@ -2227,8 +2227,10 @@ static Font LoadBMFont(const char *fileName)
{ {
imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i])); imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));
if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) PixelFormat format = imFonts[i].format;
{ if (format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8)
continue;
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel // Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
Image imFontAlpha = { Image imFontAlpha = {
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2), .data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),
@ -2238,16 +2240,22 @@ static Font LoadBMFont(const char *fileName)
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA .format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
}; };
int stride = 1;
if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8){
stride = 3;
}else if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8){
stride = 4;
}
for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++) for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
{ {
((unsigned char *)(imFontAlpha.data))[p] = 0xff; ((unsigned char *)(imFontAlpha.data))[p] = 0xff;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi]; ((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi * stride];
} }
UnloadImage(imFonts[i]); UnloadImage(imFonts[i]);
imFonts[i] = imFontAlpha; imFonts[i] = imFontAlpha;
} }
}
Image fullFont = imFonts[0]; Image fullFont = imFonts[0];
for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]); for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]);