From 22ab3197455d5b18152c5619d458ea260f9e0a26 Mon Sep 17 00:00:00 2001 From: namark <namark@disroot.org> Date: Wed, 22 Apr 2020 02:18:14 +0400 Subject: [PATCH] Floating get for 1 and 2 byte pixel view. --- source/simple/graphical/pixels.cpp | 5 +++++ source/simple/graphical/pixels.h | 19 +++++++++++++++++-- source/simple/graphical/pixels.hpp | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/simple/graphical/pixels.cpp b/source/simple/graphical/pixels.cpp index 2655779..bac00b7 100644 --- a/source/simple/graphical/pixels.cpp +++ b/source/simple/graphical/pixels.cpp @@ -37,6 +37,7 @@ SIMPLE_GRAPHICAL_PIXEL_WRITER_SET(rgba_pixel, rgb_vector, rgb_vector) SIMPLE_GRAPHICAL_PIXEL_WRITER_SET(rgba_pixel, rgba_vector, rgba_vector) SIMPLE_GRAPHICAL_PIXEL_WRITER_SET(rgba_pixel, rgb_vector, rgba_pixel) SIMPLE_GRAPHICAL_PIXEL_WRITER_SET(rgba_pixel, rgba_vector, rgba_pixel) +// SIMPLE_GRAPHICAL_PIXEL_WRITER_SET(uint16_t, float, uint16_t) // TODO #undef SIMPLE_GRAPHICAL_PIXEL_WRITER_SET using namespace pixel_view_details; #define SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(Tag,Pixel,Vector) \ @@ -46,10 +47,14 @@ SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, rgb_pixel, rgb_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, rgb_pixel, rgba_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, rgba_pixel, rgb_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, rgba_pixel, rgba_vector) +SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, uint16_t, float) +SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::reader, pixel_byte, float) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, rgb_pixel, rgb_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, rgb_pixel, rgba_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, rgba_pixel, rgb_vector) SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, rgba_pixel, rgba_vector) +SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, uint16_t, float) +SIMPLE_GRAPHICAL_PIXEL_VIEW_GET(tag::writer, pixel_byte, float) #undef SIMPLE_GRAPHICAL_PIXEL_VIEW_GET } // namespace simple::graphical diff --git a/source/simple/graphical/pixels.h b/source/simple/graphical/pixels.h index a932b7d..b62093b 100644 --- a/source/simple/graphical/pixels.h +++ b/source/simple/graphical/pixels.h @@ -21,6 +21,21 @@ namespace simple::graphical namespace pixel_view_details { + template <typename Pixel> + struct pixel_fraction { using type = rgba_vector; }; + + template <> + struct pixel_fraction<rgba_pixel> { using type = rgba_vector; }; + template <> + struct pixel_fraction<rgb_pixel> { using type = rgb_vector; }; + template <> + struct pixel_fraction<uint16_t> { using type = float; }; + template <> + struct pixel_fraction<pixel_byte> { using type = float; }; + + template <typename Pixel> + using pixel_fraction_t = typename pixel_fraction<Pixel>::type; + class tag { public: @@ -73,10 +88,10 @@ namespace simple::graphical auto get(int2 position) const -> std::conditional_t<std::is_same_v<Pixel,RawType>, const Pixel&, Pixel>; - template <typename ColorVector = rgba_vector> + template <typename ColorVector = pixel_fraction_t<Pixel>> Pixel get(float2 position) const; - template <typename ColorVector = rgba_vector> + template <typename ColorVector = pixel_fraction_t<Pixel>> Pixel get(float2 position, range2D spread) const; impl(const impl & other, range2D range); diff --git a/source/simple/graphical/pixels.hpp b/source/simple/graphical/pixels.hpp index 23fc9be..813d935 100644 --- a/source/simple/graphical/pixels.hpp +++ b/source/simple/graphical/pixels.hpp @@ -116,7 +116,7 @@ namespace simple::graphical const float2 size(this->size()); assert(float2::one(-1) < position && position < size); - return get(position, + return get<ColorVector>(position, { int2(position < float2::zero()), int2::one(2) - int2(position > (size - 1)) @@ -217,7 +217,7 @@ namespace simple::graphical const float2 size(this->size()); assert(float2::one(-1) < position && position < size); - set(pixel, position, + set<ColorVector>(pixel, position, { int2(position < float2::zero()), int2::one(2) - int2(position > (size - 1)) -- GitLab