aboutsummaryrefslogtreecommitdiff
path: root/src/BMPImage.cpp
diff options
context:
space:
mode:
authorBossCode45 <boss@tehbox.org>2025-06-28 00:44:40 +1200
committerBossCode45 <boss@tehbox.org>2025-07-24 12:48:21 +1200
commit3e4cad0bfd36536ffc870d16a6e26aac5049dd0b (patch)
tree3f0ecd09760267a108f5d97e43d31cfb8741cf55 /src/BMPImage.cpp
parent078b4e08fe3bccb7424dac76e158bf8bf48a182d (diff)
downloadtehimage-3e4cad0bfd36536ffc870d16a6e26aac5049dd0b.tar.gz
tehimage-3e4cad0bfd36536ffc870d16a6e26aac5049dd0b.zip
fixup: Updated some stuff
Mainly just cleaning up code
Diffstat (limited to 'src/BMPImage.cpp')
-rw-r--r--src/BMPImage.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/BMPImage.cpp b/src/BMPImage.cpp
index 71e5317..df2c745 100644
--- a/src/BMPImage.cpp
+++ b/src/BMPImage.cpp
@@ -1,5 +1,6 @@
#include "BMPImage.h"
+#include <cstdint>
#include <iostream>
using std::cout, std::endl;
@@ -14,19 +15,21 @@ 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(magic, sizeof(char), 2, fd);
+ fwrite(&fileSize, sizeof(uint32_t), 1, fd);
+ fwrite(zero, sizeof(char), 4, fd);
+ fwrite(&offset, sizeof(uint32_t), 1, fd);
+ fwrite(&headerSize, sizeof(uint32_t), 1, fd);
+
fwrite(&width, sizeof(uint16_t), 1, fd);
fwrite(&height, sizeof(uint16_t), 1, fd);
fwrite(&colorPlanes, sizeof(uint16_t), 1, fd);
@@ -36,10 +39,10 @@ int BMPImage::writeToFile(std::string filename)
{
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);
+ Pixel pixel = getPixel(x, y);
+ fwrite(&pixel.b, sizeof(uint8_t), 1, fd);
+ fwrite(&pixel.g, sizeof(uint8_t), 1, fd);
+ fwrite(&pixel.r, sizeof(uint8_t), 1, fd);
}
}