Reading and writing TGA file on windows producing incorrect output

259 views Asked by At

This basic example is working on macOS with the same TGA file but for some reason on windows with this particular file the output is as in the provided image.

std::ifstream input_file("C:\\Users\\Michael\\Desktop\\earth.tga", std::ios::binary);

input_file.seekg(0, std::ios::end);
std::size_t length = input_file.tellg();
input_file.seekg(0, std::ios::beg);
std::vector<char> data(length);
input_file.read(data.data(), length);

std::ofstream output_file("C:\\Users\\Michael\\Desktop\\output.tga", std::ofstream::out);

output_file.write(data.data(), data.size());

earth.tga:

earth.tga

output.tga:

enter image description here

Other tga files that I've tried work fine. What difference with ifstream on windows could be causing the issue? You can find the tga here https://people.math.sc.edu/Burkardt/data/tga/tga.html

0

There are 0 answers