diff options
| author | Dylan <boss@tehbox.org> | 2026-04-30 16:22:34 +1200 |
|---|---|---|
| committer | Dylan <boss@tehbox.org> | 2026-04-30 16:22:34 +1200 |
| commit | dc12c3562d858cbe38a99cd751fee2917b8e122e (patch) | |
| tree | 6ea8f5694396008627788861343d0e22bc0676ad /src/BMPImage.cpp | |
| parent | b1eeaeb1e899dab64ce7bd21611e072cbca4107c (diff) | |
| download | tehimage-dc12c3562d858cbe38a99cd751fee2917b8e122e.tar.gz tehimage-dc12c3562d858cbe38a99cd751fee2917b8e122e.zip | |
feat: Added support for another BMP header
Also improved error handling slightly
Diffstat (limited to 'src/BMPImage.cpp')
| -rw-r--r-- | src/BMPImage.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/BMPImage.cpp b/src/BMPImage.cpp index b45ff3f..1835f4f 100644 --- a/src/BMPImage.cpp +++ b/src/BMPImage.cpp @@ -29,36 +29,60 @@ namespace TehImage uint32_t headerSize = reader.readData<uint32_t>(); + // BITMAPCOREHEADER + if(headerSize == 12) + { + width = reader.readData<uint16_t>(); + height = reader.readData<uint16_t>(); + uint16_t colorPlanes = reader.readData<uint16_t>(); + bpp = reader.readData<uint16_t>(); + } // BITMAPINFOHEADER - if(headerSize == 40) + else if(headerSize == 40) { width = reader.readData<uint32_t>(); height = reader.readData<uint32_t>(); uint16_t colorPlanes = reader.readData<uint16_t>(); bpp = reader.readData<uint16_t>(); uint32_t compressionMethod = reader.readData<uint32_t>(); + if(compressionMethod != 0) + { + cout << "Compression method not supported: " << compressionMethod << endl; + return 1; + } uint32_t size = reader.readData<uint32_t>(); uint32_t horrRes = reader.readData<uint32_t>(); uint32_t vertRes = reader.readData<uint32_t>(); uint32_t paletteSize = reader.readData<uint32_t>(); uint32_t importantColors = reader.readData<uint32_t>(); + // cout << compressionMethod << " " << size << endl; + } + else + { + cout << "Header type not supported: " << headerSize << endl; + return 1; + } - pixels = std::make_unique<Pixel[]>(width * height); + + if(bpp != 24) + { + cout << "bpp not supported: " << bpp << endl; + return 1; + } - for(int y = height-1; y >= 0; y--) + pixels = std::make_unique<Pixel[]>(width * height); + for(int y = height-1; y >= 0; y--) + { + for(int x = 0; x < width; x++) { - for(int x = 0; x < width; x++) - { - Pixel& pixel = (*this)[x,y]; - pixel.b = reader.readByte(); - pixel.g = reader.readByte(); - pixel.r = reader.readByte(); - pixel.a = 255; - } + Pixel& pixel = (*this)[x,y]; + pixel.b = reader.readByte(); + pixel.g = reader.readByte(); + pixel.r = reader.readByte(); + pixel.a = 255; } - - // cout << compressionMethod << " " << size << endl; } + // cout << "Not implemented" << endl; return 2; |
