From 49d83600e01b2651aa3331455ace832f193b9734 Mon Sep 17 00:00:00 2001 From: Archivist Date: Thu, 1 Aug 2024 09:14:55 +0000 Subject: [PATCH] Update 'cordiceps.cpp' --- cordiceps.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cordiceps.cpp b/cordiceps.cpp index 791e3fa..1279497 100644 --- a/cordiceps.cpp +++ b/cordiceps.cpp @@ -30,7 +30,7 @@ target_link_libraries(cordiceps PUBLIC raylib_static) #include "raylib.h" std::string slurp(const char* filename) { - std::ifstream file{filename}; + std::ifstream file{filename, std::ios_base::binary}; std::stringstream data; file >> data.rdbuf(); return data.str(); @@ -57,7 +57,7 @@ std::string from_bits(std::vector data) { for(int idx = 0; idx < 32; ++idx) size_bits[idx] = data[idx]; uint32_t size = size_bits.to_ulong(); if(std::endian::native == std::endian::little) size = std::byteswap(size); - + std::cerr << "Decoded expected " << size << " bytes" << std::endl; for(auto composite : data | std::views::drop(32) | std::views::chunk(8)) { char c = 0; for(auto b : composite) { @@ -75,6 +75,7 @@ void encode(const char* pic, const char* data_source) { auto image = LoadImage(pic); auto raw_data = slurp(data_source); uint32_t size = raw_data.size(); + std::cerr << "Writing expected " << size << " bytes" << std::endl; if(std::endian::native == std::endian::little) size = std::byteswap(size); std::bitset<32> size_bits; size_bits = size; @@ -121,10 +122,19 @@ void decode(const char* pic) { } } UnloadImage(image); - std::cout << from_bits(raw_bits); + auto data = from_bits(raw_bits); + std::cerr << "Printing expected " << data.size() << " bytes" << std::endl; + std::ofstream{"cordiceps.out", std::ios_base::binary} << data; +} + +void CustomLog(int msgType, const char *text, va_list args) +{ + fprintf(stderr, text, args); } int main(int argc, char** argv) { + SetTraceLogLevel(LOG_ERROR); + SetTraceLogCallback(CustomLog); if(argc <= 1) { perror("arguments missing, expected: picture then datafile for coding, picture for decoding"); }