Inverted Red and Blue channels for TGA loading

This commit is contained in:
trotFunky 2019-09-30 19:19:44 +02:00
parent 94bc1228f1
commit 01ad1a2317
2 changed files with 16 additions and 1 deletions

View file

@ -71,7 +71,9 @@ bool Texture::load_tga(const std::string& filename, uint8_t*& data_array)
bool Texture::load_rgb_tga(const std::string& rgb_filename)
{
return load_tga(rgb_filename,image_data);
bool return_value = load_tga(rgb_filename,image_data);
invert_channels(0,2);
return return_value;
}
bool Texture::load_rgba_tga(const std::string& rgb_filename, const std::string& mask_filename)
@ -117,3 +119,14 @@ bool Texture::load_rgba_tga(const std::string& rgb_filename, const std::string&
return true;
}
void Texture::invert_channels(uint8_t first_channel, uint8_t second_channel)
{
uint8_t increment = color_bits/8;
for (int i = 0;i<width*height;i++)
{
uint8_t temp = image_data[i*increment+first_channel];
image_data[i*increment+first_channel] = image_data[i*increment+second_channel];
image_data[i*increment+second_channel] = temp;
}
}

View file

@ -32,6 +32,8 @@ public:
private:
/// Load and RGB TGA image file to an array
bool load_tga(const std::string& filename, uint8_t*& data_array);
void invert_channels(uint8_t first_channel,uint8_t second_channel);
};