diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f7137f4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.14) +project(qoixx LANGUAGES CXX) + +option(QOIXX_USE_TABLES "QOIXX will use precomputed tables to increase runtime preformance." ON) +option(QOIXX_BUILD_TESTS "QOIXX will build samples and tests." ON) + +add_library(qoixx INTERFACE) +add_library(qoixx::qoixx ALIAS qoixx) +target_include_directories(qoixx INTERFACE $) +target_compile_definitions(qoixx INTERFACE QOIXX_DECODE_WITH_TABLES=${QOIXX_USE_TABLES}) +set_target_properties(qoixx PROPERTIES CXX_STANDARD 20) + +if (QOIXX_BUILD_TESTS) + set(STB ".dependencies/stb") + set(QOI ".dependencies/qoi") + set(DOCTEST ".dependencies/doctest/doctest") + + add_executable(qoibench "src/qoibench.cpp") + target_link_libraries(qoibench qoixx::qoixx) + target_include_directories(qoibench PUBLIC ${STB} ${QOI}) + set_target_properties(qoibench PROPERTIES CXX_STANDARD 20) + + add_executable(qoiconv "src/qoiconv.cpp") + target_link_libraries(qoiconv qoixx::qoixx) + target_include_directories(qoiconv PUBLIC ${STB} ${QOI}) + set_target_properties(qoiconv PROPERTIES CXX_STANDARD 20) + + add_executable(qoitest "src/test.cpp") + target_link_libraries(qoitest qoixx::qoixx) + target_include_directories(qoitest PUBLIC ${DOCTEST}) + set_target_properties(qoitest PROPERTIES CXX_STANDARD 20) + + install(TARGETS qoibench qoiconv + RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin") +endif() diff --git a/src/qoiconv.cpp b/src/qoiconv.cpp index 3f7819c..c202954 100644 --- a/src/qoiconv.cpp +++ b/src/qoiconv.cpp @@ -82,7 +82,7 @@ struct overloaded : Fs...{ template overloaded(Fs...) -> overloaded; static inline void write_png(const std::filesystem::path& file_path, const image& image){ - auto [ptr, w, h, c] = std::visit(overloaded( + auto [ptr, w, h, c] = std::visit(overloaded{ [](const stbi_png& image){ return std::make_tuple(reinterpret_cast(image.pixels.get()), image.width, image.height, image.channels); }, @@ -94,13 +94,13 @@ static inline void write_png(const std::filesystem::path& file_path, const image static_cast(image.second.channels) ); } - ), image); + }, image); if(!::stbi_write_png(file_path.string().c_str(), w, h, c, ptr, 0)) throw std::runtime_error("write_png: Couldn't write/encode " + file_path.string()); } static inline void write_qoi(const std::filesystem::path& file_path, const image& image){ - auto [ptr, size, desc] = std::visit(overloaded( + auto [ptr, size, desc] = std::visit(overloaded{ [](const stbi_png& image){ return std::make_tuple( reinterpret_cast(image.pixels.get()), @@ -116,7 +116,7 @@ static inline void write_qoi(const std::filesystem::path& file_path, const image [](const std::pair, qoixx::qoi::desc>& image){ return std::make_tuple(image.first.data(), image.first.size(), image.second); } - ), image); + }, image); const auto encoded = qoixx::qoi::encode>(ptr, size, desc); save_file(file_path, encoded); }