rle files are now supported
This commit is contained in:
parent
11a8de82d4
commit
d97a917a5e
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
|
||||||
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
|
||||||
#define TEXTURE_NAME "Textures/dice.tga"
|
#define TEXTURE_NAME "Textures/texture32R.tga"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// public constructor/destructor
|
// public constructor/destructor
|
||||||
|
|
|
@ -12,8 +12,8 @@ TextureTGA::TextureTGA(const char * filePath)
|
||||||
throw std::invalid_argument(std::string("file not found: ") += filePath);
|
throw std::invalid_argument(std::string("file not found: ") += filePath);
|
||||||
|
|
||||||
// read in the header
|
// read in the header
|
||||||
std::uint8_t ui8x18Header[18] = { 0 };
|
std::uint8_t ui8x18Header[19] = { 0 };
|
||||||
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header));
|
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header)-1);
|
||||||
|
|
||||||
// extract all information from header
|
// extract all information from header
|
||||||
ui32IDLength = ui8x18Header[0];
|
ui32IDLength = ui8x18Header[0];
|
||||||
|
@ -56,7 +56,45 @@ TextureTGA::TextureTGA(const char * filePath)
|
||||||
// else if compressed 24 or 32 bit
|
// else if compressed 24 or 32 bit
|
||||||
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
else if (ui32PicType == 10 && (ui32BpP == 24 || ui32BpP == 32)) // compressed
|
||||||
{
|
{
|
||||||
throw std::invalid_argument("Invaild File Format! Don't compress the image.");
|
std::uint8_t tempChunkHeader;
|
||||||
|
std::uint8_t tempData[5];
|
||||||
|
int tempByteIndex = 0;
|
||||||
|
std::size_t tempPixelIndex = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempChunkHeader), sizeof(tempChunkHeader));
|
||||||
|
|
||||||
|
if (tempChunkHeader >> 7) // repeat count
|
||||||
|
{
|
||||||
|
// just use the first 7 bits
|
||||||
|
tempChunkHeader = (uint8_t(tempChunkHeader << 1) >> 1);
|
||||||
|
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP/8);
|
||||||
|
|
||||||
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
|
{
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[0];
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[1];
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[2];
|
||||||
|
if(ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // data count
|
||||||
|
{
|
||||||
|
// just use the first 7 bits
|
||||||
|
tempChunkHeader = (uint8_t(tempChunkHeader << 1) >> 1);
|
||||||
|
|
||||||
|
for (int i = 0; i <= tempChunkHeader; i++)
|
||||||
|
{
|
||||||
|
fsPicture.read(reinterpret_cast<char*>(&tempData), ui32BpP/8);
|
||||||
|
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[0];
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[1];
|
||||||
|
vui8Pixels[tempByteIndex++] = tempData[2];
|
||||||
|
if (ui32BpP == 32) vui8Pixels[tempByteIndex++] = tempData[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (tempByteIndex < ui32Size);
|
||||||
}
|
}
|
||||||
// not useable format
|
// not useable format
|
||||||
else
|
else
|
||||||
|
@ -65,19 +103,6 @@ TextureTGA::TextureTGA(const char * filePath)
|
||||||
throw std::invalid_argument("Invaild File Format! Required 24 or 31 Bit Image.");
|
throw std::invalid_argument("Invaild File Format! Required 24 or 31 Bit Image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//fix color mix
|
|
||||||
/*std::uint8_t temp;
|
|
||||||
std::uint32_t it = 0;
|
|
||||||
|
|
||||||
while (it + 2 < ui32Size)
|
|
||||||
{
|
|
||||||
temp = vui8Pixels[it];
|
|
||||||
vui8Pixels[it] = vui8Pixels[it + 2];
|
|
||||||
vui8Pixels[it + 2] = temp;
|
|
||||||
ui32BpP == 32 ? it += 4 : it += 3;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
fsPicture.close();
|
fsPicture.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue