From dc12c3562d858cbe38a99cd751fee2917b8e122e Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 30 Apr 2026 16:22:34 +1200 Subject: feat: Added support for another BMP header Also improved error handling slightly --- src/BMPImage.cpp | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'src/BMPImage.cpp') 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(); + // BITMAPCOREHEADER + if(headerSize == 12) + { + width = reader.readData(); + height = reader.readData(); + uint16_t colorPlanes = reader.readData(); + bpp = reader.readData(); + } // BITMAPINFOHEADER - if(headerSize == 40) + else if(headerSize == 40) { width = reader.readData(); height = reader.readData(); uint16_t colorPlanes = reader.readData(); bpp = reader.readData(); uint32_t compressionMethod = reader.readData(); + if(compressionMethod != 0) + { + cout << "Compression method not supported: " << compressionMethod << endl; + return 1; + } uint32_t size = reader.readData(); uint32_t horrRes = reader.readData(); uint32_t vertRes = reader.readData(); uint32_t paletteSize = reader.readData(); uint32_t importantColors = reader.readData(); + // cout << compressionMethod << " " << size << endl; + } + else + { + cout << "Header type not supported: " << headerSize << endl; + return 1; + } - pixels = std::make_unique(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(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; -- cgit v1.2.3