Problem solving in C++ (not a question, programming or otherwise)
-
I love solving problems using template metaprogramming. It's probably a bad thing, because I tend to gravitate toward it unless I stop myself. In this case, I have a good reason for it. I need to do color model conversions at compile time. A pixel has channels, like Red Green and Blue, or Hue Saturation Value, or Y U V, etc It may also have a metachannel of sorts called an alpha channel. It might even have no-op channels that do nothing but take up space (for in memory padding) The presence of no-op channels and alpha channel makes things sort of complicated when determining the color model. I have
rgb_pixel<16>::has_channel_names::value
For example (which resolves to true in the above case) for determining the color model - RGB as above in this case. In order to be more robust, I need to have a different version of that template like, has_color_model or something. But also, it's a tricky problem to solve with templates. That's what I like. Sane people play sudoku. Solved it. Not so bad, because I have other helpers.
template class is_color_model_inner_impl;
template
class is_color_model_inner_impl {
using chidx = typename PixelType::template channel_index_by_name;
public:
constexpr static const bool value = (-1!= chidx::value) &&
PixelType::template channel_by_index_unchecked::color_channel &&
is_color_model_inner_impl::value;
};
template
class is_color_model_inner_impl {
public:
constexpr static const bool value = true;
};template class is_color_model_impl {
public:
constexpr static const bool value = sizeof...(ChannelNames)==PixelType::color_channels && is_color_model_inner_impl::value;
};Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
I love solving problems using template metaprogramming. It's probably a bad thing, because I tend to gravitate toward it unless I stop myself. In this case, I have a good reason for it. I need to do color model conversions at compile time. A pixel has channels, like Red Green and Blue, or Hue Saturation Value, or Y U V, etc It may also have a metachannel of sorts called an alpha channel. It might even have no-op channels that do nothing but take up space (for in memory padding) The presence of no-op channels and alpha channel makes things sort of complicated when determining the color model. I have
rgb_pixel<16>::has_channel_names::value
For example (which resolves to true in the above case) for determining the color model - RGB as above in this case. In order to be more robust, I need to have a different version of that template like, has_color_model or something. But also, it's a tricky problem to solve with templates. That's what I like. Sane people play sudoku. Solved it. Not so bad, because I have other helpers.
template class is_color_model_inner_impl;
template
class is_color_model_inner_impl {
using chidx = typename PixelType::template channel_index_by_name;
public:
constexpr static const bool value = (-1!= chidx::value) &&
PixelType::template channel_by_index_unchecked::color_channel &&
is_color_model_inner_impl::value;
};
template
class is_color_model_inner_impl {
public:
constexpr static const bool value = true;
};template class is_color_model_impl {
public:
constexpr static const bool value = sizeof...(ChannelNames)==PixelType::color_channels && is_color_model_inner_impl::value;
};Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
honey the codewitch wrote:
rgb_pixel<16>::has_channel_names<channel_name::R, channel_name::G, channel_name::B>::value
Maybe
has_channel_channels
? :laugh: (But kinda serious.)Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver
-
honey the codewitch wrote:
rgb_pixel<16>::has_channel_names<channel_name::R, channel_name::G, channel_name::B>::value
Maybe
has_channel_channels
? :laugh: (But kinda serious.)Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver
I ended up going with
is_color_model<>
which makes perfect sense in my library's vernacular where a color model is a composition of color channels with particular names.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix