commit a0715f6de63b1242af01eb5640248bc06496475f
parent db362f5b03be6a846abcd0a556511d5bee178cb9
Author: Andrew Laack <andrew@laack.co>
Date: Thu, 10 Jul 2025 23:58:31 -0500
Added header to output file.
Diffstat:
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/chunk.cpp b/src/chunk.cpp
@@ -155,11 +155,6 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi
std::vector<char> data = chunk.getChunk();
- // todo:
- // update to take into account header information
- if (x * y < data.size() * 8){
- throw std::invalid_argument("x and y dimensions are too small for the chunk.");
- }
std::string firstLine = "P1\n";
std::string comment = "# Encoded with Andrew's awesome .tga encoder.\n";
@@ -192,6 +187,7 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi
std::string image = firstLine + comment + dims;
+
std::string header = chunkNumberEncoded + charactersEncoded + filenameLengthEncoded + filenameEncoded;
std::cout << chunkNumberEncoded.size() << " - " << chunkNumberEncoded << std::endl;
@@ -201,10 +197,27 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi
std::cout << "HEADER: " << header << std::endl;
+ if (x * y < (data.size() * 8) + header.size()){
+ throw std::invalid_argument("x and y dimensions are too small for the chunk.");
+ }
+
+ uint xPos = 0;
+
+ for (char bit : header){
+ if (xPos == x){
+ image.append("\n");
+ xPos = 0;
+ }
+ image += bit;
+ image.append(" ");
+ xPos += 1;
+ }
+
+ std::cout << image << std::endl;
+
int target = x * y;
int added = 0;
- uint xPos = 0;
for (char chr : data){
std::string current = std::bitset<8>(chr).to_string();
for (int i = 0 ; i < 8; ++i){