Last active
September 5, 2018 15:28
-
-
Save carmel4a/8943b11f38893a3c7c17918d8b521d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static bool get_next_byte( std::istream& stream, char&c, std::string& log_ ) | |
{ | |
if( !stream.eof() ) | |
{ | |
stream.get( c ); | |
log_ += c; | |
return true; | |
} | |
return false; | |
} | |
// Load TGA 2.0 | |
std::string TGAHelper::deserialize( std::filesystem::path p ) | |
{ | |
std::ifstream file; | |
std::string s; | |
file.open( p, std::ifstream::in | std::ifstream::binary ); | |
char c = '\0'; | |
Header header; | |
get_next_byte( file, c, s); // ID length | |
header.id_length = c; | |
get_next_byte( file, c, s ); // Color map type | |
header.colour_map_type = c; | |
get_next_byte( file, c, s ); | |
// works only on machine with byte > 3 bits | |
header.data_type_code = c & (-1u >> ( CHAR_BIT - 3 ) ); // Data type | |
header.RLE = (bool) (c & ( 1u << 4 ) ); // RLE compresion | |
file.close(); | |
s += '\0'; | |
return s; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment