diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b7a5c..94751c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,6 @@ set(CMAKE_CXX_STANDARD 23) add_subdirectory(file_reader) -add_library(lily_png STATIC library.cpp) +add_library(lily_png STATIC lily_png.cpp) target_link_libraries(lily_png file_read) diff --git a/file_reader b/file_reader index ff45377..35c9579 160000 --- a/file_reader +++ b/file_reader @@ -1 +1 @@ -Subproject commit ff45377ffe6580049c1e125c478fe03d46cedec3 +Subproject commit 35c95790edb62100e8f05d27f2cbe52ee11109df diff --git a/library.cpp b/lily_png.cpp similarity index 80% rename from library.cpp rename to lily_png.cpp index 3589b69..5745cff 100644 --- a/library.cpp +++ b/lily_png.cpp @@ -1,4 +1,4 @@ -#include "library.h" +#include "lily_png.h" #include @@ -23,7 +23,7 @@ static metadata parse_metadata(buffer &data) return m; } -char * read_png(const std::string &file_path) +buffer read_png(const std::string &file_path) { unsigned char magic[9] = {137, 80, 78, 71, 13, 10, 26, 10}; file_reader reader(file_path); @@ -36,6 +36,7 @@ char * read_png(const std::string &file_path) if (memcmp(magic, std::get<0>(head_tup).data, 8) != 0) throw std::runtime_error("File is not a png"); metadata meta{0}; + buffer image_data{0}; while (true) { buffer chunk_type{0}; @@ -54,5 +55,16 @@ char * read_png(const std::string &file_path) std::println("Size received {}", ree.first); if (strcmp("IHDR", std::get<1>(chunk_head).data) == 0) meta = parse_metadata(std::get<0>(data)); + else if (strcmp("IDAT", std::get<1>(chunk_head).data) == 0) + { + buffer &temp_buf = std::get<0>(data); + image_data.write(temp_buf.data, temp_buf.size); + } + else if (strcmp("IEND",std::get<1>(chunk_head).data) == 0) + break; } + std::println("Image data size {}", image_data.size); + std::println("Image data allocated {}", image_data.allocated); + std::println("Allocations {}", image_data.allocations); + return image_data; } diff --git a/library.h b/lily_png.h similarity index 82% rename from library.h rename to lily_png.h index cdd2e8e..f1ff778 100644 --- a/library.h +++ b/lily_png.h @@ -14,4 +14,4 @@ struct metadata char interface; }; -char *read_png(const std::string &file_path); \ No newline at end of file +buffer read_png(const std::string &file_path); \ No newline at end of file