unlimited-storage

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit c32dd518384f2446acbd5a84981c5879f7f02f27
parent 4786ce3c8e82c653dae2cf85685c6c538890ba0a
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 16 Jul 2025 21:35:21 -0500

Updated chunk to overload and then state how much was written to the given frame. This is easier than calculating the size of the header, at least I think

Diffstat:
M.gitignore | 1+
Minclude/chunk.h | 4++--
Msrc/chunk.cpp | 32+++++++++++++++++---------------
Msrc/encode.cpp | 61++++++++++---------------------------------------------------
4 files changed, 30 insertions(+), 68 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ *.out *.txt *.tga +output/* diff --git a/include/chunk.h b/include/chunk.h @@ -24,7 +24,7 @@ private: Header header; public: - Chunk(std::string filename, uint start, uint size); + Chunk(std::string filename, uint start, uint x, uint y); Chunk(std::vector<char> chunkData); // read in the written chunk from pbm format. Chunk(std::string filename); @@ -35,7 +35,7 @@ public: void writeImage(std::string filename, uint chunkNumber, std::string originalFilename, uint x, uint y); void print(); std::string toString(); - uint end; + uint written; }; diff --git a/src/chunk.cpp b/src/chunk.cpp @@ -124,7 +124,7 @@ Chunk::Chunk(std::vector<char> chunkData) { this->chunk = chunkData; } -Chunk::Chunk(std::string filename, uint start, uint size) { +Chunk::Chunk(std::string filename, uint start, uint x, uint y) { std::ifstream file; @@ -132,23 +132,18 @@ Chunk::Chunk(std::string filename, uint start, uint size) { file.seekg(start); + uint bytesToLoad = (x * y) / 8; uint fSize = std::filesystem::file_size(filename); LOG("FILE SIZE: " + std::to_string(fSize)) + LOG("LOADING IN " + std::to_string(bytesToLoad) + " BYTES") - if (fSize < size){ - LOG("DON'T NEED ENTIRE SPACE") - size = fSize; - } - - std::vector<char> bytes(size); + std::vector<char> bytes(bytesToLoad); - file.read(bytes.data(), size); + file.read(bytes.data(), bytesToLoad); file.close(); this->chunk = bytes; - this->end = start + size; - } std::vector<char> Chunk::getChunk() { @@ -248,8 +243,6 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi LOG(filenameLengthEncoded.size() + " - " + filenameLengthEncoded) LOG(filenameEncoded.size() + " - " + filenameEncoded) - LOG("HEADER: " + header) - this->header.chunkNumber = chunkNumber; this->header.filename = filename; this->header.fnameLength = filenameEncoded.size(); @@ -268,13 +261,14 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi xPos += 1; } - LOG(image) - int target = x * y; int added = 0; - for (char chr : data) { + if (added > target){ + LOG("BREAKING") + break; + } std::string current = std::bitset<8>(chr).to_string(); for (int i = 0 ; i < 8; ++i) { if (xPos == x) { @@ -289,6 +283,14 @@ void Chunk::writeImage(std::string filename, uint chunkNumber, std::string origi } } + LOG(std::to_string(added)) + LOG(std::to_string(added)) + LOG(std::to_string(added)) + LOG(std::to_string(added)) + LOG(std::to_string(added)) + + this->written = added; + while (added < target) { if (xPos == x) { image += "\n"; diff --git a/src/encode.cpp b/src/encode.cpp @@ -24,64 +24,23 @@ int main(int argc, char* argv[]) { // how much space should we reserve for the header section // of the image? - const int HEADER_ALLOCATION = 400; - - int chunkSize = ((x * y) - HEADER_ALLOCATION); - - - uint end = 0; + uint start = 0; uint itr = 0; - std::vector<Chunk> chunks; - - while (end < std::filesystem::file_size(source)){ - LOG("READING CHUNK # " + std::to_string(itr)) - Chunk chunk = Chunk(source, end, chunkSize); - end = chunk.end; - chunks.push_back(chunk); - itr += 1; - LOG(end) - } - - std::string destinationWithoutExtension = destination.replace(destination.size() - 4, 4, ""); - uint i = 0; - for (auto chunk : chunks){ + while (start < std::filesystem::file_size(source)){ + LOG("READING CHUNK # " + std::to_string(itr)) + 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 - std::string chunkFname = destinationWithoutExtension + std::to_string(i) + ".pbm"; - LOG(chunkFname) - chunk.writeImage(chunkFname, i, source, x, y); - i += 1; - } + chunk.writeImage(fname, itr, source, x, y); + start += chunk.written; + LOG(start) - //std::vector<char> bytes = chunk.getChunk(); - //std::ofstream outFile; - //Chunk outChunk = Chunk(bytes); - //outChunk.writeImage(destination, 1, source, x, y); - - //Chunk readChunk = Chunk(destination); - - //std::string beforeChunk = readChunk.toString(); - //std::string afterChunk = outChunk.toString(); - - //if (beforeChunk == afterChunk) { - // LOG("CHUNKS MATCH") - //} else { - // LOG("CHUNKS DON'T MATCH") - //} - - - //// this writes out to a specific file. - //std::string destinationWithoutExtension = destination.replace(destination.size() - 4, 4, ""); - - //outChunk.writeChunk("after-" + destinationWithoutExtension + ".txt"); - //// this writes out to the file that was - //// specified in the .pbm header file. - //// readChunk.writeChunk(); + itr += 1; + } return 0; } - -