45#ifndef UFO_VISION_COLOR_AVERAGE_HPP
46#define UFO_VISION_COLOR_AVERAGE_HPP
49#include <ufo/vision/color/arithmetic.hpp>
50#include <ufo/vision/color/concepts.hpp>
51#include <ufo/vision/color/convert.hpp>
52#include <ufo/vision/color/type_traits.hpp>
53#include <ufo/vision/color/weight.hpp>
92template <std::ranges::input_range R>
93 requires Color<std::ranges::range_value_t<R>>
94[[nodiscard]]
constexpr std::ranges::range_value_t<R>
average(R&& r)
96 using C = std::ranges::range_value_t<R>;
100 if constexpr (std::same_as<C, D>) {
101 return std::ranges::fold_left(r, D{}, std::plus{});
103 auto sum = std::ranges::fold_left(
104 r | std::views::transform([](C c) {
return addWeight(c); }), D{}, std::plus{});
108 auto sum = std::ranges::fold_left(
109 r | std::views::transform([](C c) {
return convert<D>(c); }), D{}, std::plus{});
110 return convert<C>(
sum);
122template <std::input_iterator InputIt, std::sentinel_for<InputIt> Sentinel>
123 requires Color<std::iter_value_t<InputIt>>
124[[nodiscard]]
constexpr std::iter_value_t<InputIt>
average(InputIt first, Sentinel last)
126 return average(std::ranges::subrange(std::move(first), std::move(last)));
136[[nodiscard]]
constexpr C
average(std::initializer_list<C> il)
138 return average(std::ranges::subrange(il));
Colors that include a weight channel.
Colors with a floating-point channel type.
constexpr add_weight_t< C > addWeight(C color, float w=1.0f) noexcept
Returns a copy of color with a weight field set to w.
constexpr remove_weight_t< C > removeWeight(C color) noexcept
Returns a copy of color with the weight field removed.
constexpr C average(C a, C const &b)
Computes the average of two colors.
@ Weight
Include an accumulation weight.
All vision-related classes and functions.
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
constexpr T sum(Vec< Dim, T > const &v) noexcept
Computes the sum of all elements in a vector.
Primary template - intentionally undefined.