aboutsummaryrefslogtreecommitdiff
path: root/src/BMPImage.cpp
diff options
context:
space:
mode:
authorBossCode45 <boss@tehbox.org>2025-06-27 17:58:36 +1200
committerBossCode45 <boss@tehbox.org>2025-07-24 12:48:21 +1200
commit078b4e08fe3bccb7424dac76e158bf8bf48a182d (patch)
treea4f84f3fc346053c1c41990be4cc0867ab206cf5 /src/BMPImage.cpp
parenteed164fa72297efb69b624f3c58cb5deb339a974 (diff)
downloadtehimage-078b4e08fe3bccb7424dac76e158bf8bf48a182d.tar.gz
tehimage-078b4e08fe3bccb7424dac76e158bf8bf48a182d.zip
feat: Made it so that you can now convert between image subclasses
Also added the bitmap image subclass note: this is pretty hacky in how it works
Diffstat (limited to 'src/BMPImage.cpp')
-rw-r--r--src/BMPImage.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/BMPImage.cpp b/src/BMPImage.cpp
new file mode 100644
index 0000000..71e5317
--- /dev/null
+++ b/src/BMPImage.cpp
@@ -0,0 +1,49 @@
+#include "BMPImage.h"
+
+#include <iostream>
+
+using std::cout, std::endl;
+
+int BMPImage::readFromFile(std::string filename)
+{
+ cout << "Not implemented" << endl;
+ return 2;
+};
+
+int BMPImage::writeToFile(std::string filename)
+{
+ FILE* fd = fopen(filename.c_str(), "w");
+ char magic[] = "BM";
+ fwrite(magic, sizeof(char), 2, fd);
+ uint32_t fileSize = 14 + 12 + width*height*/*(bitDepth/8)*/8*3;
+ fwrite(&fileSize, sizeof(uint32_t), 1, fd);
+ char zero[] = "\0\0\0\0";
+ fwrite(zero, sizeof(char), 4, fd);
+ uint32_t offset = 26;
+ fwrite(&offset, sizeof(uint32_t), 1, fd);
+ uint32_t headerSize = 12;
+ fwrite(&headerSize, sizeof(uint32_t), 1, fd);
+ uint16_t width = this->width;
+ uint16_t height = this->height;
+ uint16_t colorPlanes = 1;
+ uint16_t bitsPerPixel = /*bitDepth*/8*3;
+ fwrite(&width, sizeof(uint16_t), 1, fd);
+ fwrite(&height, sizeof(uint16_t), 1, fd);
+ fwrite(&colorPlanes, sizeof(uint16_t), 1, fd);
+ fwrite(&bitsPerPixel, sizeof(uint16_t), 1, fd);
+
+ for(int y = height-1; y >= 0; y--)
+ {
+ for(int x = 0; x < width; x++)
+ {
+ Pixel<uint8_t> pixel = getPixel<uint8_t>(x, y);
+ fwrite(&pixel.b, bitDepth/8, 1, fd);
+ fwrite(&pixel.g, bitDepth/8, 1, fd);
+ fwrite(&pixel.r, bitDepth/8, 1, fd);
+ }
+ }
+
+ fclose(fd);
+
+ return 0;
+};