Skip to content

Commit

Permalink
feat(Texture): add support for A4R4G4B4 texture format
Browse files Browse the repository at this point in the history
Intended to fix Try/OpenGothic#668
  • Loading branch information
lmichaelis committed Aug 20, 2024
1 parent f6ded81 commit 037db91
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ namespace zenkit {
std::uint16_t g : 6;
std::uint16_t r : 5;
};

struct a4r4g4b4 {
std::uint16_t b : 4;
std::uint16_t g : 4;
std::uint16_t r : 4;
std::uint16_t a : 4;
};

struct a1r5g5b5 {
std::uint16_t b : 5;
std::uint16_t g : 5;
std::uint16_t r : 5;
std::uint16_t a : 1;
};
#pragma pack(pop)

/// \brief Calculates the size in bytes of a texture at the given mipmap level.
Expand Down Expand Up @@ -149,6 +163,16 @@ namespace zenkit {

break;
}
case TextureFormat::A4R4G4B4: {
for (auto i = 0u; i < width * height; ++i) {
conv[i * 4 + 2] = ((bytes[i * 2 + 0] >> 0) & 0x0F) * 17;
conv[i * 4 + 1] = ((bytes[i * 2 + 0] >> 4) & 0x0F) * 17;
conv[i * 4 + 0] = ((bytes[i * 2 + 1] >> 0) & 0x0F) * 17;
conv[i * 4 + 3] = ((bytes[i * 2 + 1] >> 4) & 0x0F) * 17;
}

break;
}
default:
throw ParserError {"texture",
"cannot convert format to rgba: " + std::to_string(static_cast<int32_t>(src))};
Expand Down

0 comments on commit 037db91

Please sign in to comment.