aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan <boss@tehbox.org>2026-04-30 16:22:34 +1200
committerDylan <boss@tehbox.org>2026-04-30 16:22:34 +1200
commitdc12c3562d858cbe38a99cd751fee2917b8e122e (patch)
tree6ea8f5694396008627788861343d0e22bc0676ad
parentb1eeaeb1e899dab64ce7bd21611e072cbca4107c (diff)
downloadtehimage-dc12c3562d858cbe38a99cd751fee2917b8e122e.tar.gz
tehimage-dc12c3562d858cbe38a99cd751fee2917b8e122e.zip
feat: Added support for another BMP header
Also improved error handling slightly
-rw-r--r--src/BMPImage.cpp50
-rw-r--r--test/main.cpp1
2 files changed, 38 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;
diff --git a/test/main.cpp b/test/main.cpp
index 6e4cb91..6cd6d74 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -58,6 +58,7 @@ int main(int argc, char* argv[])
TehImage::BMPImage bmp;
bmp.readFromFile(infile);
+ bmp.writeToFile(outfile);
// TehImage::PNGImage png;