From 30cc534a37513e1121a878beff179a6ac782e979 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Fri, 2 Aug 2024 22:58:15 +0200 Subject: [PATCH] fiddling around with new image layout storage --- .clang-format | 3 ++- src/core/tests/pwcore_test_image.cpp | 25 ++++++++++++++++++++++++- src/core/tests/pwcore_test_matrix.cpp | 1 - src/core/tests/pwcore_test_mesh.cpp | 8 ++++---- src/core/tests/pwcore_test_vector.cpp | 9 +++++++-- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.clang-format b/.clang-format index a730bb5..f0b9d64 100644 --- a/.clang-format +++ b/.clang-format @@ -8,6 +8,7 @@ Language: Cpp # Force pointers to the type for C++. DerivePointerAlignment: false PointerAlignment: Left + LambdaBodyIndentation: OuterScope -AlignArrayOfStructures: Left + AlignConsecutiveAssignments: true diff --git a/src/core/tests/pwcore_test_image.cpp b/src/core/tests/pwcore_test_image.cpp index fcf98df..2c66bb2 100644 --- a/src/core/tests/pwcore_test_image.cpp +++ b/src/core/tests/pwcore_test_image.cpp @@ -1,16 +1,39 @@ #include +#include #include +#include #include +#include namespace pw { struct image_layout { - enum pixel_layout { RGB8, RGBA, LUM, DEPTH }; + enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH }; + + static constexpr auto bits_per_channel(pixel_layout layout) { + constexpr auto lut = + std::array{std::make_tuple(RGB8, sizeof(std::uint8_t) << 3), + std::make_tuple(DEPTH, sizeof(float) << 3)}; + + const auto iter = std::find_if( + std::begin(lut), std::end(lut), + [&layout](const auto& v) { return std::get<0>(v) == layout; }); + + return iter != std::end(lut) ? std::get<1>(*iter) : 0u; + } }; } // namespace pw auto main() -> int { + auto val = pw::image_layout::bits_per_channel( + pw::image_layout::pixel_layout::RGB8); + + std::print("RGB8 = {}bits per channel\n", val); + std::print("DEPTH = {}bits per channel\n", + pw::image_layout::bits_per_channel( + pw::image_layout::pixel_layout::DEPTH)); + // pw::image } diff --git a/src/core/tests/pwcore_test_matrix.cpp b/src/core/tests/pwcore_test_matrix.cpp index a7c5730..94574c1 100644 --- a/src/core/tests/pwcore_test_matrix.cpp +++ b/src/core/tests/pwcore_test_matrix.cpp @@ -70,7 +70,6 @@ auto main() -> int { std::print("\nm44=[{}]\n", m44); - // auto m_init_ded = pw::matrix{ // {1, 2}, // {3, 4} diff --git a/src/core/tests/pwcore_test_mesh.cpp b/src/core/tests/pwcore_test_mesh.cpp index 5b11acc..20f6d20 100644 --- a/src/core/tests/pwcore_test_mesh.cpp +++ b/src/core/tests/pwcore_test_mesh.cpp @@ -18,10 +18,10 @@ auto main() -> int { auto geom = pw::primitives{ .vertices = {{1.2f, 2.4f, 4.8f}, {2.4f, 1.2f, 4.8f}, - {1.2f, 4.8f, 2.4f} }, - .indices = {0, 1, 2}, - .topology = pw::primitives::topology_type::triangle_list - }; + {1.2f, 4.8f, 2.4f}}, + .indices = {0, 1, 2}, + + .topology = pw::primitives::topology_type::triangle_list}; auto mesh = pw::mesh{ .geometry = geom, diff --git a/src/core/tests/pwcore_test_vector.cpp b/src/core/tests/pwcore_test_vector.cpp index 01c588d..7d8bc04 100644 --- a/src/core/tests/pwcore_test_vector.cpp +++ b/src/core/tests/pwcore_test_vector.cpp @@ -1,7 +1,7 @@ +#include #include #include -#include #include #include @@ -69,7 +69,12 @@ auto main() -> int { std::print("y: {}\n", vec3f.get<1>()); std::print("tuple size {}\n", std::tuple_size_v); - const auto& [x, y, z] = vec3f; + auto& [x, y, z] = vec3f; + std::print("x:{} y:{} z:{}\n", x, y, z); + + x++; + y--; + z = 0; std::print("x:{} y:{} z:{}\n", x, y, z); auto min_ab{vec3f.min(pw::vector{1.3f, 0.9f, 2.3f})};