mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-07-06 21:25:59 +00:00
CTextureEncoder: Make use of unsigned stream helpers
This commit is contained in:
parent
3d60eee5b4
commit
a1f7459a8d
@ -6,10 +6,10 @@ CTextureEncoder::CTextureEncoder() = default;
|
|||||||
void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
|
void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
|
||||||
{
|
{
|
||||||
// Only DXT1->CMPR supported at the moment
|
// Only DXT1->CMPR supported at the moment
|
||||||
rTXTR.WriteLong((uint) mOutputFormat);
|
rTXTR.WriteULong(static_cast<uint>(mOutputFormat));
|
||||||
rTXTR.WriteShort(mpTexture->mWidth);
|
rTXTR.WriteUShort(mpTexture->mWidth);
|
||||||
rTXTR.WriteShort(mpTexture->mHeight);
|
rTXTR.WriteUShort(mpTexture->mHeight);
|
||||||
rTXTR.WriteLong(mpTexture->mNumMipMaps);
|
rTXTR.WriteULong(mpTexture->mNumMipMaps);
|
||||||
|
|
||||||
uint32 MipW = mpTexture->Width() / 4;
|
uint32 MipW = mpTexture->Width() / 4;
|
||||||
uint32 MipH = mpTexture->Height() / 4;
|
uint32 MipH = mpTexture->Height() / 4;
|
||||||
@ -19,8 +19,11 @@ void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
|
|||||||
for (uint32 iMip = 0; iMip < mpTexture->mNumMipMaps; iMip++)
|
for (uint32 iMip = 0; iMip < mpTexture->mNumMipMaps; iMip++)
|
||||||
{
|
{
|
||||||
for (uint32 iBlockY = 0; iBlockY < MipH; iBlockY += 2)
|
for (uint32 iBlockY = 0; iBlockY < MipH; iBlockY += 2)
|
||||||
|
{
|
||||||
for (uint32 iBlockX = 0; iBlockX < MipW; iBlockX += 2)
|
for (uint32 iBlockX = 0; iBlockX < MipW; iBlockX += 2)
|
||||||
|
{
|
||||||
for (uint32 iImgY = iBlockY; iImgY < iBlockY + 2; iImgY++)
|
for (uint32 iImgY = iBlockY; iImgY < iBlockY + 2; iImgY++)
|
||||||
|
{
|
||||||
for (uint32 iImgX = iBlockX; iImgX < iBlockX + 2; iImgX++)
|
for (uint32 iImgX = iBlockX; iImgX < iBlockX + 2; iImgX++)
|
||||||
{
|
{
|
||||||
uint32 SrcPos = ((iImgY * MipW) + iImgX) * 8;
|
uint32 SrcPos = ((iImgY * MipW) + iImgX) * 8;
|
||||||
@ -28,12 +31,19 @@ void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
|
|||||||
|
|
||||||
ReadSubBlockCMPR(Image, rTXTR);
|
ReadSubBlockCMPR(Image, rTXTR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MipOffset += MipW * MipH * 8;
|
MipOffset += MipW * MipH * 8;
|
||||||
MipW /= 2;
|
MipW /= 2;
|
||||||
MipH /= 2;
|
MipH /= 2;
|
||||||
if (MipW < 2) MipW = 2;
|
|
||||||
if (MipH < 2) MipH = 2;
|
if (MipW < 2)
|
||||||
|
MipW = 2;
|
||||||
|
|
||||||
|
if (MipH < 2)
|
||||||
|
MipH = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +59,9 @@ void CTextureEncoder::ReadSubBlockCMPR(IInputStream& rSource, IOutputStream& rDe
|
|||||||
|
|
||||||
for (uint32 iByte = 0; iByte < 4; iByte++)
|
for (uint32 iByte = 0; iByte < 4; iByte++)
|
||||||
{
|
{
|
||||||
uint8 Byte = rSource.ReadByte();
|
uint8 Byte = rSource.ReadUByte();
|
||||||
Byte = ((Byte & 0x3) << 6) | ((Byte & 0xC) << 2) | ((Byte & 0x30) >> 2) | ((Byte & 0xC0) >> 6);
|
Byte = ((Byte & 0x3) << 6) | ((Byte & 0xC) << 2) | ((Byte & 0x30) >> 2) | ((Byte & 0xC0) >> 6);
|
||||||
rDest.WriteByte(Byte);
|
rDest.WriteUByte(Byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user