For BMP, read in bytes 18 through 21 to get the width, and bytes 22 though 25 to get the height.
For PNG, read in the dimensions from the file's IHDR chunk, which looks to start after the first eight bytes of the file, and the eight bytes of the header of the IHDR chunk itself. Bytes 16 through 19 would give the width, and bytes 20 through 23 give the height.
Likewise, for TGA, you could read the first 18 bytes (with advised notes) into a TGA header struct
and then dereference the struct instance's width
and height
properties.
Within C++, you can use standard C I/O (e.g., fopen()
fseek()
and fread()
) to open, move and read bytes from a file pointer. You wouldn't have to read in the entire file: just move to the correct byte offset and then read in the correct number of bytes.