| 124 | } |
| 125 | |
| 126 | void IMAGE::LoadCompressedTGA (FILE* pFile) |
| 127 | { |
| 128 | int iCurrentPixel = 0; |
| 129 | int iCurrentByte = 0; |
| 130 | unsigned char ucBuffer[4] = {255, 255, 255, 255}; |
| 131 | const int iPixelCount = m_iImageWidth * m_iImageHeight; |
| 132 | |
| 133 | unsigned int* pIntPointer = (unsigned int*) &m_Pixels[0]; |
| 134 | unsigned int* pIntBuffer = (unsigned int*) &ucBuffer[0]; |
| 135 | |
| 136 | do |
| 137 | { |
| 138 | unsigned char ucChunkHeader = 0; |
| 139 | |
| 140 | fread (&ucChunkHeader, sizeof (unsigned char), 1, pFile); |
| 141 | |
| 142 | if (ucChunkHeader < 128) |
| 143 | { |
| 144 | // If the header is < 128, it means it is the number of RAW color packets minus 1 |
| 145 | // that follow the header |
| 146 | // add 1 to get number of following color values |
| 147 | |
| 148 | ucChunkHeader++; |
| 149 | |
| 150 | // Read RAW color values |
| 151 | for (int i = 0; i < (int) ucChunkHeader; ++i) |
| 152 | { |
| 153 | fread (&ucBuffer[0], m_iBytesPerPixel, 1, pFile); |
| 154 | |
| 155 | // if this is an 8-Bit TGA only, store the one channel in all four channels |
| 156 | // if it is a 24-Bit TGA (3 channels), the fourth channel stays at 255 all the time, since the 4th value in ucBuffer is never overwritten |
| 157 | if (m_iBytesPerPixel == 1) |
| 158 | { |
| 159 | ucBuffer[1] = ucBuffer[0]; |
| 160 | ucBuffer[2] = ucBuffer[0]; |
| 161 | ucBuffer[3] = ucBuffer[0]; |
| 162 | } |
| 163 | |
| 164 | // copy all four values in one operation |
| 165 | (*pIntPointer) = (*pIntBuffer); |
| 166 | |
| 167 | ++pIntPointer; |
| 168 | ++iCurrentPixel; |
| 169 | } |
| 170 | } |
| 171 | else // chunkheader > 128 RLE data, next color reapeated (chunkheader - 127) times |
| 172 | { |
| 173 | ucChunkHeader -= 127; // Subteact 127 to get rid of the ID bit |
| 174 | |
| 175 | // read the current color |
| 176 | fread (&ucBuffer[0], m_iBytesPerPixel, 1, pFile); |
| 177 | |
| 178 | // if this is an 8-Bit TGA only, store the one channel in all four channels |
| 179 | // if it is a 24-Bit TGA (3 channels), the fourth channel stays at 255 all the time, since the 4th value in ucBuffer is never overwritten |
| 180 | if (m_iBytesPerPixel == 1) |
| 181 | { |
| 182 | ucBuffer[1] = ucBuffer[0]; |
| 183 | ucBuffer[2] = ucBuffer[0]; |
nothing calls this directly
no outgoing calls
no test coverage detected