Pārlūkot izejas kodu

Update 'cordiceps.cpp'

master
Archivist pirms 4 mēnešiem
vecāks
revīzija
49d83600e0
1 mainītis faili ar 13 papildinājumiem un 3 dzēšanām
  1. +13
    -3
      cordiceps.cpp

+ 13
- 3
cordiceps.cpp Parādīt failu

@ -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");
}

Notiek ielāde…
Atcelt
Saglabāt