new image class
This commit is contained in:
parent
379bfb0a14
commit
2cf82d4da9
2 changed files with 61 additions and 12 deletions
|
@ -70,8 +70,8 @@ struct matrix final {
|
||||||
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
||||||
static_assert(idx < Rows, "Out of bounds access to a member.");
|
static_assert(idx < Rows, "Out of bounds access to a member.");
|
||||||
// TODO: use forward_like when clang is catching up
|
// TODO: use forward_like when clang is catching up
|
||||||
// return std::forward_like<decltype(self)>(self.m_[idx]);
|
return std::forward_like<decltype(self)>(self.m_[idx]);
|
||||||
return std::forward<decltype(self)>(self).m_[idx];
|
// return std::forward<decltype(self)>(self).m_[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto diagonal() const noexcept -> diag_type {
|
constexpr auto diagonal() const noexcept -> diag_type {
|
||||||
|
|
|
@ -6,19 +6,20 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <pw/core/image.hpp>
|
#include <pw/core/image.hpp>
|
||||||
|
#include <pw/core/size.hpp>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct image_layout {
|
struct image_layout {
|
||||||
|
|
||||||
enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH };
|
enum struct pixel_layout { RGB8, RGBA8, LUM8, DEPTH };
|
||||||
|
|
||||||
static constexpr auto bits_per_channel(pixel_layout layout) {
|
static constexpr auto bits_per_channel(pixel_layout layout) {
|
||||||
constexpr static auto lut =
|
constexpr static auto lut = std::array{
|
||||||
std::array{std::make_tuple(RGB8, sizeof(std::uint8_t) << 3),
|
std::make_tuple(pixel_layout::RGB8, sizeof(std::uint8_t) << 3),
|
||||||
std::make_tuple(RGBA8, sizeof(std::uint8_t) << 3),
|
std::make_tuple(pixel_layout::RGBA8, sizeof(std::uint8_t) << 3),
|
||||||
std::make_tuple(LUM8, sizeof(std::uint8_t) << 3),
|
std::make_tuple(pixel_layout::LUM8, sizeof(std::uint8_t) << 3),
|
||||||
std::make_tuple(DEPTH, sizeof(float) << 3)};
|
std::make_tuple(pixel_layout::DEPTH, sizeof(float) << 3)};
|
||||||
|
|
||||||
const auto iter = std::find_if(
|
const auto iter = std::find_if(
|
||||||
std::begin(lut), std::end(lut),
|
std::begin(lut), std::end(lut),
|
||||||
|
@ -26,16 +27,53 @@ struct image_layout {
|
||||||
|
|
||||||
return iter != std::end(lut) ? std::get<1>(*iter) : 0u;
|
return iter != std::end(lut) ? std::get<1>(*iter) : 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr auto channels(pixel_layout layout) {
|
||||||
|
constexpr static auto lut =
|
||||||
|
std::array{std::make_tuple(pixel_layout::RGB8, 3),
|
||||||
|
std::make_tuple(pixel_layout::RGBA8, 4),
|
||||||
|
std::make_tuple(pixel_layout::LUM8, 1),
|
||||||
|
std::make_tuple(pixel_layout::DEPTH, 1)};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
size<int32_t> size_{};
|
||||||
|
pixel_layout layout_{pixel_layout::RGB8};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct image_new {
|
||||||
|
|
||||||
|
using buffer_type = std::vector<uint8_t>;
|
||||||
|
using size_type = pw::size<int32_t>;
|
||||||
|
|
||||||
|
image_layout layout;
|
||||||
|
buffer_type buffer{};
|
||||||
|
|
||||||
|
static constexpr auto make(const image_new::size_type& size_,
|
||||||
|
image_layout::pixel_layout layout_)
|
||||||
|
-> image_new {
|
||||||
|
|
||||||
|
return {.layout{.layout_ = layout_},
|
||||||
|
.buffer{buffer_type{
|
||||||
|
static_cast<buffer_type::value_type>(
|
||||||
|
(image_layout::bits_per_channel(layout_) >> 3) *
|
||||||
|
size_.area() * image_layout::channels(layout_)),
|
||||||
|
buffer_type::value_type{0}}}};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pw
|
} // namespace pw
|
||||||
|
|
||||||
auto main() -> int {
|
auto main() -> int {
|
||||||
|
|
||||||
auto val = pw::image_layout::bits_per_channel(
|
std::print("RGB8 = {}bits per channel\n",
|
||||||
pw::image_layout::pixel_layout::RGB8);
|
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",
|
std::print("DEPTH = {}bits per channel\n",
|
||||||
pw::image_layout::bits_per_channel(
|
pw::image_layout::bits_per_channel(
|
||||||
pw::image_layout::pixel_layout::DEPTH));
|
pw::image_layout::pixel_layout::DEPTH));
|
||||||
|
@ -43,5 +81,16 @@ auto main() -> int {
|
||||||
pw::image_layout::bits_per_channel(
|
pw::image_layout::bits_per_channel(
|
||||||
pw::image_layout::pixel_layout::LUM8));
|
pw::image_layout::pixel_layout::LUM8));
|
||||||
|
|
||||||
|
std::print(
|
||||||
|
"RGB8 = {}channels\n",
|
||||||
|
pw::image_layout::channels(pw::image_layout::pixel_layout::RGB8));
|
||||||
|
std::print(
|
||||||
|
"DEPTH = {}channels\n",
|
||||||
|
pw::image_layout::channels(pw::image_layout::pixel_layout::DEPTH));
|
||||||
|
std::print(
|
||||||
|
"LUM8 = {}channels\n",
|
||||||
|
pw::image_layout::channels(pw::image_layout::pixel_layout::LUM8));
|
||||||
// pw::image
|
// pw::image
|
||||||
|
|
||||||
|
pw::image_new::make(pw::iamge, image_layout::pixel_layout layout_)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue