From 86f45a084a99ca322237f98fdd5bb1c9b637fd64 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Tue, 16 Jul 2024 18:51:14 +0200 Subject: [PATCH] first sweeping through size and image --- CMakeLists.txt | 4 +- src/core/include/pw/core/aabb.hpp | 5 +-- src/core/include/pw/core/globals.hpp | 1 + src/core/include/pw/core/image.hpp | 55 +++++++++++++--------------- src/core/include/pw/core/size.hpp | 39 +++++++++----------- src/core/src/image.cpp | 13 +++---- 6 files changed, 54 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1f52cb..898f21e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,13 @@ cmake_minimum_required(VERSION 3.28) project(pixwerx) # -# pixwerx ist C++23 +# pixwerx is C++23 # set (CMAKE_CXX_STANDARD 23) +# # internal cmake modules +# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH}) # boilerplate locations for build diff --git a/src/core/include/pw/core/aabb.hpp b/src/core/include/pw/core/aabb.hpp index e447a48..3976af6 100644 --- a/src/core/include/pw/core/aabb.hpp +++ b/src/core/include/pw/core/aabb.hpp @@ -23,12 +23,9 @@ #ifndef PW_CORE_AABB_HPP #define PW_CORE_AABB_HPP -#include "vector.hpp" -#include -#include #include -#include +#include #include namespace pw { diff --git a/src/core/include/pw/core/globals.hpp b/src/core/include/pw/core/globals.hpp index 3844bb3..a5cfb02 100644 --- a/src/core/include/pw/core/globals.hpp +++ b/src/core/include/pw/core/globals.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index 6fd14d7..7194d1b 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -8,8 +8,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -29,58 +29,55 @@ namespace pw { class image { -public: + public: + using size_type = pw::size; image() = default; - using data_t = std::byte; + using data_t = std::byte; - enum pixel_layout { - RGB8, - RGBA8, - LUM, - DEPTH, - HDR - }; + enum pixel_layout { RGB8, RGBA8, LUM, DEPTH, HDR }; + image(const size_type& s, pixel_layout t, + const data_t* ptr = nullptr); - image(const size& s, pixel_layout t, const data_t *ptr = nullptr); + bool create(const size_type& s, pixel_layout t, + const data_t* ptr = nullptr); - bool create(const size& s, pixel_layout t, const data_t *ptr = nullptr); + void release(bool release_memory = false); - void release(bool release_memory = false); + const data_t* data() const { return _data.data(); } + data_t* data() { return _data.data(); } - const data_t *data() const { return _data.data(); } - data_t *data() { return _data.data(); } - - const float *data_float() const { return reinterpret_cast(_data.data()); } - float *data_float() { return reinterpret_cast(_data.data());} + const float* data_float() const { + return reinterpret_cast(_data.data()); + } + float* data_float() { return reinterpret_cast(_data.data()); } pixel_layout layout() const; - void set_layout(const pixel_layout &layout); + void set_layout(const pixel_layout& layout); uint64_t change_count() const; - void set_change_count(const uint64_t &change_count); + void set_change_count(const uint64_t& change_count); static uint32_t bytes_per_pixel(pixel_layout t); static uint32_t components(pixel_layout t); - ::pw::size size() const; + size_type size() const { return _size; } void generate_noise(); bool is_valid() const; -protected: + protected: - ::pw::size _size { 0, 0 }; - pixel_layout _layout { pixel_layout::RGB8 }; - uint64_t _change_count { 0 }; - - std::vector _data; + size_type _size{.width = 0, .height = 0}; + pixel_layout _layout{pixel_layout::RGB8}; + uint64_t _change_count{0}; + std::vector _data; }; -} +} // namespace pw #endif diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp index 7e0d651..70f21ca 100644 --- a/src/core/include/pw/core/size.hpp +++ b/src/core/include/pw/core/size.hpp @@ -8,8 +8,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -23,33 +23,30 @@ #ifndef PW_CORE_SIZE_HPP #define PW_CORE_SIZE_HPP +#include #include +#include namespace pw { -template -struct size_ { +template struct size { - using value_type = T_; + using value_type = Scalar; + Scalar width, height; - T_ width,height; - - size_() = default; - - size_(T_ w,T_ h) : width(w), height(h) {} - - T_ area() const { return std::abs(width * height); } - - template - size_ cast() const { return size_(static_cast(width),static_cast(height)); } + constexpr auto area() const noexcept -> Scalar { + if constexpr (std::is_unsigned_v) { + return width * height; + } else { + return std::abs(width * height); + } + } + template constexpr auto operator()() const noexcept { + return Other{width, height}; + } }; -typedef size_ size; - -typedef size_ sizef; -typedef size_ sized; - -} +} // namespace pw #endif diff --git a/src/core/src/image.cpp b/src/core/src/image.cpp index 83ce110..295f915 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -1,13 +1,14 @@ #include "pw/core/image.hpp" #include "pw/core/debug.hpp" +#include #include #include #include namespace pw { -image::image(const ::pw::size &s, +image::image(const ::pw::size &s, image::pixel_layout t, const data_t *ptr) { @@ -16,11 +17,11 @@ image::image(const ::pw::size &s, } } -bool image::create(const ::pw::size &s, +bool image::create(const ::pw::size &s, image::pixel_layout t, const data_t *ptr) { - size_t n = bytes_per_pixel(t) * s.area(); + const auto n = bytes_per_pixel(t) * s.area(); _size = s; _layout = t; @@ -52,7 +53,7 @@ void image::generate_noise() void image::release(bool release_memory) { _data.clear(); - _size = pw::size(); + _size = size_type{}; if (release_memory) _data.shrink_to_fit(); } @@ -95,10 +96,6 @@ uint32_t image::components(image::pixel_layout t) return 0; } -::pw::size image::size() const -{ - return _size; -} image::pixel_layout image::layout() const {