Advertisement
honey_the_codewitch

pixel metadata

Mar 14th, 2022
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 KB | None | 0 0
  1. using type = pixel<ChannelTraits...>;
  2. // the type used for doing intermediary conversions to different formats when no explicit conversion is implemented
  3. using rgb_conversion_type = pixel<channel_traits<channel_name::R,16>,channel_traits<channel_name::G,16>,channel_traits<channel_name::B,16>,channel_traits<channel_name::A,16>>;
  4. // the integer type of the pixel
  5. using int_type = bits::uintx<bits::get_word_size(helpers::bit_depth<ChannelTraits...>::value)>;
  6. // the number of channels
  7. constexpr static const size_t channels = sizeof...(ChannelTraits);
  8. // the total bit depth of the pixel
  9. constexpr static const size_t bit_depth = helpers::bit_depth<ChannelTraits...>::value;
  10. // the minimum number of bytes needed to store the pixel
  11. constexpr static const size_t packed_size = (bit_depth+7) / 8;
  12. // true if the pixel is a whole number of bytes
  13. constexpr static const bool byte_aligned = 0==bit_depth/8.0 - (size_t)(bit_depth/8);
  14. // the total size in bits, including padding
  15. constexpr static const size_t total_size_bits = sizeof(int_type)*8;
  16. // the packed size, in bits
  17. constexpr static const size_t packed_size_bits = packed_size*8;
  18. // the count of bits to the right that are unused
  19. constexpr static const size_t pad_right_bits = total_size_bits-bit_depth;
  20. // the mask of the pixel's value
  21. constexpr static const int_type mask = int_type(int_type(~int_type(0))<<(pad_right_bits));
  22.  
  23. // the pixel value, in platform native format
  24. int_type native_value;
  25. ...
  26. // retrieves a channel's metadata by index
  27. template<int Index> using channel_by_index = typename helpers::channel_by_index_impl<type,Index,channels,0,ChannelTraits...>::type;
  28. // retrieves a channel's metadata by index in cases where the checked version will cause an error
  29. template<int Index> using channel_by_index_unchecked = typename helpers::channel_by_index_unchecked_impl<type,Index,channels,0,ChannelTraits...>::type;
  30. // gets the index of the channel by the channel name
  31. template<typename Name> using channel_index_by_name = typename helpers::channel_index_by_name_impl<0,Name,ChannelTraits...>;
  32. // gets the channel by name
  33. template<typename Name> using channel_by_name = channel_by_index<helpers::channel_index_by_name_impl<0,Name,ChannelTraits...>::value>;
  34. // retrieves a channel's metadata by name in cases where the checked version will cause an error
  35. template<typename Name> using channel_by_name_unchecked = channel_by_index_unchecked<channel_index_by_name<Name>::value>;
  36.  
  37. // returns true if the pixel contains channels with each name
  38. template<typename... ChannelNames> using has_channel_names = typename helpers::has_channel_names_impl<type,ChannelNames...>;
  39. // returns true if this channel is a subset of the other
  40. template<typename PixelRhs> using is_subset_of = typename helpers::is_subset_pixel_impl<PixelRhs,ChannelTraits...>;
  41. // returns true if this channel is a superset of the other
  42. template<typename PixelRhs> using is_superset_of = typename PixelRhs::template is_subset_of<type>;
  43. // returns true if the two pixels have channels with the same names, regardless of order
  44. template<typename PixelRhs> using unordered_equals = typename helpers::unordered_equals_pixel_impl<type,PixelRhs>;
  45. // returns true if the two pixels have channels with the same names, in the same order
  46. template<typename PixelRhs> using equals = typename helpers::equals_pixel_impl<PixelRhs,ChannelTraits...>;
  47. // returns true if the two pixels are exactly the same
  48. template<typename PixelRhs> using equals_exact = typename helpers::is_same<type,PixelRhs>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement