Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic CMake Support, Fix Conversion Test Compilation #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_compile_definitions(qoixx INTERFACE QOIXX_DECODE_WITH_TABLES=${QOIXX_USE_TABLES})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be -DQOIXX_DECODE_WITH_TABLES=ON , but QOIXX_DECODE_WITH_TABLES must be 0 or 1 . Please fix this

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()
8 changes: 4 additions & 4 deletions src/qoiconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct overloaded : Fs...{
template<typename... Fs> overloaded(Fs...) -> overloaded<Fs...>;

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<const void*>(image.pixels.get()), image.width, image.height, image.channels);
},
Expand All @@ -94,13 +94,13 @@ static inline void write_png(const std::filesystem::path& file_path, const image
static_cast<int>(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<const std::byte*>(image.pixels.get()),
Expand All @@ -116,7 +116,7 @@ static inline void write_qoi(const std::filesystem::path& file_path, const image
[](const std::pair<std::vector<std::byte>, qoixx::qoi::desc>& image){
return std::make_tuple(image.first.data(), image.first.size(), image.second);
}
), image);
}, image);
const auto encoded = qoixx::qoi::encode<std::vector<std::byte>>(ptr, size, desc);
save_file(file_path, encoded);
}
Expand Down