first sweeping through size and image
This commit is contained in:
parent
c58f81d640
commit
86f45a084a
6 changed files with 54 additions and 63 deletions
|
@ -7,11 +7,13 @@ cmake_minimum_required(VERSION 3.28)
|
||||||
project(pixwerx)
|
project(pixwerx)
|
||||||
|
|
||||||
#
|
#
|
||||||
# pixwerx ist C++23
|
# pixwerx is C++23
|
||||||
#
|
#
|
||||||
set (CMAKE_CXX_STANDARD 23)
|
set (CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
#
|
||||||
# internal cmake modules
|
# internal cmake modules
|
||||||
|
#
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
# boilerplate locations for build
|
# boilerplate locations for build
|
||||||
|
|
|
@ -23,12 +23,9 @@
|
||||||
#ifndef PW_CORE_AABB_HPP
|
#ifndef PW_CORE_AABB_HPP
|
||||||
#define PW_CORE_AABB_HPP
|
#define PW_CORE_AABB_HPP
|
||||||
|
|
||||||
#include "vector.hpp"
|
|
||||||
#include <cstddef>
|
|
||||||
#include <numeric>
|
|
||||||
#include <pw/core/vector.hpp>
|
#include <pw/core/vector.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
@ -29,58 +29,55 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
class image {
|
class image {
|
||||||
public:
|
public:
|
||||||
|
using size_type = pw::size<std::size_t>;
|
||||||
|
|
||||||
image() = default;
|
image() = default;
|
||||||
|
|
||||||
using data_t = std::byte;
|
using data_t = std::byte;
|
||||||
|
|
||||||
enum pixel_layout {
|
enum pixel_layout { RGB8, RGBA8, LUM, DEPTH, HDR };
|
||||||
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(); }
|
const float* data_float() const {
|
||||||
data_t *data() { return _data.data(); }
|
return reinterpret_cast<const float*>(_data.data());
|
||||||
|
}
|
||||||
const float *data_float() const { return reinterpret_cast<const float*>(_data.data()); }
|
float* data_float() { return reinterpret_cast<float*>(_data.data()); }
|
||||||
float *data_float() { return reinterpret_cast<float*>(_data.data());}
|
|
||||||
|
|
||||||
pixel_layout layout() const;
|
pixel_layout layout() const;
|
||||||
void set_layout(const pixel_layout &layout);
|
void set_layout(const pixel_layout& layout);
|
||||||
|
|
||||||
uint64_t change_count() const;
|
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 bytes_per_pixel(pixel_layout t);
|
||||||
|
|
||||||
static uint32_t components(pixel_layout t);
|
static uint32_t components(pixel_layout t);
|
||||||
|
|
||||||
::pw::size size() const;
|
size_type size() const { return _size; }
|
||||||
|
|
||||||
void generate_noise();
|
void generate_noise();
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
::pw::size _size { 0, 0 };
|
size_type _size{.width = 0, .height = 0};
|
||||||
pixel_layout _layout { pixel_layout::RGB8 };
|
pixel_layout _layout{pixel_layout::RGB8};
|
||||||
uint64_t _change_count { 0 };
|
uint64_t _change_count{0};
|
||||||
|
|
||||||
std::vector<data_t> _data;
|
|
||||||
|
|
||||||
|
std::vector<data_t> _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace pw
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
@ -23,33 +23,30 @@
|
||||||
#ifndef PW_CORE_SIZE_HPP
|
#ifndef PW_CORE_SIZE_HPP
|
||||||
#define PW_CORE_SIZE_HPP
|
#define PW_CORE_SIZE_HPP
|
||||||
|
|
||||||
|
#include <asm-generic/errno.h>
|
||||||
#include <pw/core/globals.hpp>
|
#include <pw/core/globals.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
template <typename T_>
|
template <typename Scalar> struct size {
|
||||||
struct size_ {
|
|
||||||
|
|
||||||
using value_type = T_;
|
using value_type = Scalar;
|
||||||
|
Scalar width, height;
|
||||||
|
|
||||||
T_ width,height;
|
constexpr auto area() const noexcept -> Scalar {
|
||||||
|
if constexpr (std::is_unsigned_v<Scalar>) {
|
||||||
size_() = default;
|
return width * height;
|
||||||
|
} else {
|
||||||
size_(T_ w,T_ h) : width(w), height(h) {}
|
return std::abs(width * height);
|
||||||
|
}
|
||||||
T_ area() const { return std::abs(width * height); }
|
}
|
||||||
|
|
||||||
template <typename To_>
|
|
||||||
size_<To_> cast() const { return size_<To_>(static_cast<To_>(width),static_cast<To_>(height)); }
|
|
||||||
|
|
||||||
|
template <typename Other> constexpr auto operator()() const noexcept {
|
||||||
|
return Other{width, height};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef size_<int> size;
|
} // namespace pw
|
||||||
|
|
||||||
typedef size_<float> sizef;
|
|
||||||
typedef size_<double> sized;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
#include "pw/core/image.hpp"
|
#include "pw/core/image.hpp"
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
image::image(const ::pw::size &s,
|
image::image(const ::pw::size<std::size_t> &s,
|
||||||
image::pixel_layout t,
|
image::pixel_layout t,
|
||||||
const data_t *ptr)
|
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<std::size_t> &s,
|
||||||
image::pixel_layout t,
|
image::pixel_layout t,
|
||||||
const data_t *ptr)
|
const data_t *ptr)
|
||||||
{
|
{
|
||||||
size_t n = bytes_per_pixel(t) * s.area();
|
const auto n = bytes_per_pixel(t) * s.area();
|
||||||
_size = s;
|
_size = s;
|
||||||
_layout = t;
|
_layout = t;
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ void image::generate_noise()
|
||||||
void image::release(bool release_memory)
|
void image::release(bool release_memory)
|
||||||
{
|
{
|
||||||
_data.clear();
|
_data.clear();
|
||||||
_size = pw::size();
|
_size = size_type{};
|
||||||
|
|
||||||
if (release_memory) _data.shrink_to_fit();
|
if (release_memory) _data.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
@ -95,10 +96,6 @@ uint32_t image::components(image::pixel_layout t)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
::pw::size image::size() const
|
|
||||||
{
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
image::pixel_layout image::layout() const
|
image::pixel_layout image::layout() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue