Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Problem solving in C++ (not a question, programming or otherwise)

Problem solving in C++ (not a question, programming or otherwise)

Scheduled Pinned Locked Moved The Lounge
designc++wpfcomgraphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • H honey the codewitch

      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

      D Offline
      D Offline
      David ONeil
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • D David ONeil

        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

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups