CTextureEncoder: Make use of unsigned stream helpers
@@ -6,10 +6,10 @@ CTextureEncoder::CTextureEncoder() = default;
void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
{
// Only DXT1->CMPR supported at the moment
- rTXTR.WriteLong((uint) mOutputFormat);
- rTXTR.WriteShort(mpTexture->mWidth);
- rTXTR.WriteShort(mpTexture->mHeight);
- rTXTR.WriteLong(mpTexture->mNumMipMaps);
+ rTXTR.WriteULong(static_cast<uint>(mOutputFormat));
+ rTXTR.WriteUShort(mpTexture->mWidth);
+ rTXTR.WriteUShort(mpTexture->mHeight);
+ rTXTR.WriteULong(mpTexture->mNumMipMaps);
uint32 MipW = mpTexture->Width() / 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 iBlockY = 0; iBlockY < MipH; iBlockY += 2)
+ {
for (uint32 iBlockX = 0; iBlockX < MipW; iBlockX += 2)
+ {
for (uint32 iImgY = iBlockY; iImgY < iBlockY + 2; iImgY++)
+ {
for (uint32 iImgX = iBlockX; iImgX < iBlockX + 2; iImgX++)
{
uint32 SrcPos = ((iImgY * MipW) + iImgX) * 8;
@@ -28,12 +31,19 @@ void CTextureEncoder::WriteTXTR(IOutputStream& rTXTR)
ReadSubBlockCMPR(Image, rTXTR);
}
+ }
+ }
+ }
MipOffset += MipW * MipH * 8;
MipW /= 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++)
{
- uint8 Byte = rSource.ReadByte();
+ uint8 Byte = rSource.ReadUByte();
Byte = ((Byte & 0x3) << 6) | ((Byte & 0xC) << 2) | ((Byte & 0x30) >> 2) | ((Byte & 0xC0) >> 6);
- rDest.WriteByte(Byte);
+ rDest.WriteUByte(Byte);
}
}
