Commit d97a917a authored by Anakin's avatar Anakin
Browse files

rle files are now supported

parent 11a8de82
......@@ -11,7 +11,7 @@
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
#define TEXTURE_NAME "Textures/dice.tga"
#define TEXTURE_NAME "Textures/texture32R.tga"
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
......
......@@ -12,8 +12,8 @@ TextureTGA::TextureTGA(const char * filePath)
throw std::invalid_argument(std::string("file not found: ") += filePath);
// read in the header
std::uint8_t ui8x18Header[18] = { 0 };
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header));
std::uint8_t ui8x18Header[19] = { 0 };
fsPicture.read(reinterpret_cast<char*>(&ui8x18Header), sizeof(ui8x18Header)-1);
// extract all information from header
ui32IDLength = ui8x18Header[0];
......@@ -56,7 +56,45 @@ TextureTGA::TextureTGA(const char * filePath)
// else if compressed 24 or 32 bit
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
else
......@@ -65,19 +103,6 @@ TextureTGA::TextureTGA(const char * filePath)
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();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment