commit d859dbed882c38d529800a01500ac4a9ad24a7d4
parent cbd557156b5f6cd51aa7f4f08784bc52978230f4
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 16 Jul 2025 22:59:06 -0500
Was it that easy?
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/chunk.cpp b/src/chunk.cpp
@@ -6,7 +6,7 @@
# include "../include/debug.h"
-const int IMAGE_HEADER_SIZE = 848;
+const int IMAGE_HEADER_SIZE = 48;
// read in saved chunk from file
Chunk::Chunk(std::string filename) {
@@ -64,9 +64,9 @@ Chunk::Chunk(std::string filename) {
// chunk number 4 bytes (16 bits)
// characters 4 bytes (16 bits)
// fnamelen 4 bytes (16 bits)
- // filename fnamelen (max 800 bits - 100 chars)
+ // filename fnamelen
//
- // 16 + 16 + 16 + 800 = 848
+ // 16 + 16 + 16 = 48
@@ -138,7 +138,13 @@ Chunk::Chunk(std::string filename, uint start, uint x, uint y) {
file.open(filename, std::ios::binary);
file.seekg(start);
- uint bytesToLoad = ((x * y) / 8) - IMAGE_HEADER_SIZE;
+ std::string filenameEncoded = "";
+
+ for (std::size_t i = 0; i < filename.size(); ++i) {
+ filenameEncoded += std::bitset<8>(filename.c_str()[i]).to_string();
+ }
+
+ uint bytesToLoad = ((x * y) / 8) - (IMAGE_HEADER_SIZE + filenameEncoded.size());
uint fSize = std::filesystem::file_size(filename);
if (fSize < bytesToLoad){