/* ======================================================================== * * Filename: main.cpp * Description: data file renderer * Author: Diego Estrada * Version: 0.0.1 * * ======================================================================== */ #include #include #include #include #include #include #include #include #include #include #include namespace ra = std::ranges; namespace vi = ra::views; template using ref = T&; template using ptr = T*; struct Bytes { std::vector bytes; auto read_file(ref file_path) { auto input = std::ifstream(file_path, std::ios::binary); bytes = std::vector( (std::istreambuf_iterator(input)), (std::istreambuf_iterator())); input.close(); } }; template struct Map { std::vector map; Map() { for (auto& e : map) e = ' '; } auto operator () (size_t x, size_t y, char c) { std::cout << (x & 0xFF) << ' ' << y << '\n'; if (x < _rows && y < _cols) map[x + (y * _cols)] = c; } auto rows() const -> size_t { return _rows; } auto cols() const -> size_t { return _cols; } }; struct Graph { Map<0xFF, 0xFF> mp; Graph(ref b) : mp() { auto view = vi::slide(b.bytes, 2); auto const mapper = [this](ra::viewable_range auto&& r) { std::cout << r.size() << std::endl; [[maybe_unused]] auto const i = r[0]; [[maybe_unused]] auto const j = r[1]; mp(i & 0xFF, j & 0xFF, '.'); }; ra::for_each(view, mapper); } auto show() const -> void { for(size_t i = 0; i < mp.map.size(); ++i) { if (i % mp.cols() == 0) std::cout << std::endl; std::cout << mp.map.at(i); } } }; auto main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) -> int { auto k = Bytes(); // k.read_file("Makefile"); k.read_file("/home/Michorron/Media/Pictures/Wallpapers/totoro.jpeg"); auto g = Graph(k); g.show(); return 0; }