commit ee3fc9cf5720fe687fc13c8331c768d6444d7741
parent 8fe5e6726a2cf65aa020ca00b28f87bfc1814bd2
Author: Andrew Laack <andrew@laack.co>
Date: Fri, 18 Jul 2025 12:13:07 -0500
Fixed stratified test by updating chunk size calculation.
Diffstat:
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/chunk.cpp b/src/chunk.cpp
@@ -137,6 +137,7 @@ Chunk::Chunk(std::string filename, uint start, uint x, uint y) {
std::ifstream file;
file.open(filename, std::ios::binary);
+ LOG("SEEKING: " + std::to_string(start))
file.seekg(start);
std::string filenameEncoded = "";
@@ -146,7 +147,7 @@ Chunk::Chunk(std::string filename, uint start, uint x, uint y) {
}
uint bytesToLoad = ((x * y) / 8) - (IMAGE_HEADER_SIZE + filenameEncoded.size());
- uint fSize = std::filesystem::file_size(filename);
+ uint fSize = std::filesystem::file_size(filename) - start;
if (fSize < bytesToLoad){
bytesToLoad = fSize;
@@ -196,7 +197,6 @@ void Chunk::writeChunk() {
LOG(this->header.filename)
-
if(this->header.chunkNumber == 0){
bool deleteExisting = std::filesystem::remove(this->header.filename);
if(deleteExisting){
@@ -210,8 +210,9 @@ void Chunk::writeChunk() {
std::ofstream outFile;
std::vector<char> bytes = this->chunk;
- if(this->header.chunkNumber != 1) {
+ if(this->header.chunkNumber != 0) {
outFile.open(this->header.filename, std::ios::binary | std::ios::app);
+ LOG("FILE APPENDING")
} else {
outFile.open(this->header.filename, std::ios::binary | std::ios::out);
}
@@ -219,6 +220,8 @@ void Chunk::writeChunk() {
for(uint i = 0 ; i < bytes.size(); ++i) {
outFile.write(&bytes[i], 1);
}
+ LOG("WROTE " + std::to_string(bytes.size()) + " CHARS")
+ LOG("HEADER STATES " + std::to_string(this->header.characters) + " CHARS")
}
void Chunk::writeChunk(std::string filename) {
@@ -335,6 +338,7 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi
// these are the bits that have been added.
this->written = added / 8;
+ LOG("ADDED TO IMAGE: " + std::to_string(this->written))
LOG("FINISHED WRITING " + std::to_string(added / 8) + " CHARACTER BYTES")
if (added<target){
diff --git a/src/decode.cpp b/src/decode.cpp
@@ -13,12 +13,12 @@ void writeSingleFile(std::string filename){
}
-
// This loads each file from the directory into memory.
// it then orders them by file name then chunk number and writes
// them back to the original file.
void writeDirectory(std::string dirName){
+
LOG("WRITING DIRECTORY")
std::vector<std::string> filenames;
@@ -54,6 +54,15 @@ void writeDirectory(std::string dirName){
for (Chunk chunk : chunks){
LOG(std::to_string(chunk.getChunkNumber()) + " - " + chunk.getFilename());
}
+
+ // write in order
+
+ for (Chunk chunk : chunks){
+ LOG("WRITING CHUNK ")
+ LOG(std::to_string(chunk.getChunkNumber()) + " - " + chunk.getFilename());
+ chunk.writeChunk();
+ }
+
}
int main(int argc, char* argv[]) {
diff --git a/src/encode.cpp b/src/encode.cpp
@@ -32,11 +32,10 @@ int main(int argc, char* argv[]) {
LOG("STARTING AT BYTE " + std::to_string(start))
Chunk chunk = Chunk(source, start, x, y);
std::string fname = destinationWithoutExtension + std::to_string(itr) + ".pbm";
- // std::string filename, uint chunkNumber, std::string originalFilename, uint x, uint y
chunk.writeImage(fname, itr, source, x, y);
start += chunk.written;
- LOG(start)
+ LOG("START: " + std::to_string(start))
itr += 1;
}