use RG8Unorm format if ABGR4Unorm is not available

This commit is contained in:
Samo Z 2024-09-28 17:42:27 +02:00
parent 810168be48
commit 8c30bc805c
2 changed files with 48 additions and 4 deletions

View file

@ -720,6 +720,51 @@ public:
}
};
class TextureDecoder_R4G4_UNORM_To_RG8 : public TextureDecoder, public SingletonClass<TextureDecoder_R4G4_UNORM_To_RGBA8>
{
public:
sint32 getBytesPerTexel(LatteTextureLoaderCtx* textureLoader) override
{
return 2;
}
void decode(LatteTextureLoaderCtx* textureLoader, uint8* outputData) override
{
for (sint32 y = 0; y < textureLoader->height; y += textureLoader->stepY)
{
sint32 yc = y;
for (sint32 x = 0; x < textureLoader->width; x += textureLoader->stepX)
{
uint8* blockData = LatteTextureLoader_GetInput(textureLoader, x, y);
sint32 pixelOffset = (x + yc * textureLoader->width) * 2;
uint8 v0 = (*(uint8*)(blockData + 0));
uint8 red4 = (v0 >> 4) & 0xF;
uint8 green4 = (v0 & 0xF);
red4 = (red4 << 4) | red4;
green4 = (green4 << 4) | green4;
*(uint8*)(outputData + pixelOffset + 0) = red4;
*(uint8*)(outputData + pixelOffset + 1) = green4;
}
}
}
void decodePixelToRGBA(uint8* blockData, uint8* outputPixel, uint8 blockOffsetX, uint8 blockOffsetY) override
{
uint8 v0 = *(blockData + 0);
uint8 red4 = (v0 >> 4) & 0xF;
uint8 green4 = (v0 & 0xF);
red4 = (red4 << 4) | red4;
green4 = (green4 << 4) | green4;
*(outputPixel + 0) = red4;
*(outputPixel + 1) = green4;
*(outputPixel + 2) = 0;
*(outputPixel + 3) = 255;
}
};
class TextureDecoder_R4_G4_B4_A4_UNORM : public TextureDecoder, public SingletonClass<TextureDecoder_R4_G4_B4_A4_UNORM>
{
public: