Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool GetImageDimensionFromFile(const std::string& fileName, int& width, int& height)
- {
- std::ifstream in(fileName.c_str(), std::ios::binary);
- std::uint32_t temp = 0;
- bool suc = false;
- if (!in.is_open()) {
- return false;
- }
- width = height = 0;
- auto fmt = GetCxImageFormatFromFilename(fileName);
- switch (fmt) {
- case CXIMAGE_FORMAT_PNG:
- in.seekg(16);
- in.read(reinterpret_cast<char*>(&width), 4);
- in.read(reinterpret_cast<char*>(&height), 4);
- width = ntohl(width);
- height = ntohl(height);
- suc = true;
- break;
- case CXIMAGE_FORMAT_BMP:
- in.seekg(14);
- in.read(reinterpret_cast<char*>(&temp), 4);
- if (temp == 40) {
- // Windows Format
- in.read(reinterpret_cast<char*>(&width), 4);
- in.read(reinterpret_cast<char*>(&height), 4);
- suc = true;
- }
- else if (temp == 20) {
- // MAC Format
- in.read(reinterpret_cast<char*>(&width), 2);
- in.read(reinterpret_cast<char*>(&height), 2);
- suc = true;
- }
- break;
- case CXIMAGE_FORMAT_TGA:
- in.seekg(12);
- in.read(reinterpret_cast<char*>(&width), 2);
- in.read(reinterpret_cast<char*>(&height), 2);
- suc = true;
- break;
- }
- if (in.eof()) {
- return false;
- }
- return suc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement