8 #include <nap/numeric.h>
9 #include <utility/dllexport.h>
10 #include <glm/glm.hpp>
46 BaseColor(
int channels,
int size) : mChannels(channels), mValueSize(size) { }
51 bool operator==(
const BaseColor& rhs) =
delete;
52 bool operator!=(
const BaseColor& rhs) =
delete;
77 virtual bool isPointer()
const = 0;
100 Converter getConverter(
const BaseColor& target)
const;
130 virtual const void* getData(
int channel)
const = 0;
136 virtual void* getData(
int channel) = 0;
141 int size()
const {
return mChannels * mValueSize; }
175 static void convertColor(
const BaseColor& source,
BaseColor& target,
const Converter& converter);
200 template<
typename T,
int CHANNELS>
221 Color(
const std::array<T, CHANNELS>& colors) :
352 const void*
getData(
int channel)
const override;
357 void*
getData(
int channel)
override;
436 operator glm::vec3() {
return toVec3(); }
452 Color<T, 4>({ red, green, blue, alpha }) { }
460 Color<T, 4>({rgb[0], rgb[1], rgb[2], alpha}) { }
527 operator glm::vec4() {
return toVec4(); }
609 template<
typename T,
int CHANNELS>
616 template<
typename T,
int CHANNELS>
619 for (
auto i = 0; i < CHANNELS; i++)
621 if (mValues[i] != rhs.
mValues[i])
627 template<
typename T,
int CHANNELS>
630 std::hash<Color<T, CHANNELS>> lhs_hash;
631 std::hash<Color<T, CHANNELS>> rhs_hash;
633 return lhs_hash(*
this) < rhs_hash(rhs);
636 template<
typename T,
int CHANNELS>
639 int idx =
static_cast<int>(channel);
640 assert(idx < CHANNELS);
644 template<
typename T,
int CHANNELS>
647 int idx =
static_cast<int>(channel);
648 assert(idx < CHANNELS);
652 template<
typename T,
int CHANNELS>
655 int idx =
static_cast<int>(channel);
656 assert(idx < CHANNELS);
657 mValues[idx] = value;
660 template<
typename T,
int CHANNELS>
663 assert(channel < CHANNELS);
664 return &(mValues[channel]);
667 template<
typename T,
int CHANNELS>
670 assert(channel < CHANNELS);
671 return &(mValues[channel]);
674 template<
typename T,
int CHANNELS>
677 return std::is_pointer<T>();
684 assert(!(color.isPointer()));
689 template<
typename T,
int CHANNELS>
692 memcpy(mValues.data(), data,
sizeof(T) * CHANNELS);
695 template<
typename T,
int CHANNELS>
699 for (
int i = 0; i < CHANNELS; i++)
701 float diff = (float)(this->mValues[i]) - (float)(other.
mValues[i]);
740 struct hash <
nap::Color<nap::uint8, 1>>
750 struct hash<
nap::RColor<nap::uint8>>
760 struct hash<
nap::Color<nap::uint8, 3>>
774 struct hash<
nap::RGBColor<nap::uint8>>
784 struct hash<
nap::Color<nap::uint8, 4>>
797 struct hash<
nap::RGBAColor<nap::uint8>>
806 struct hash<
nap::Color<nap::uint16, 1>>
816 struct hash<
nap::RColor<nap::uint16>>
826 struct hash<
nap::Color<nap::uint16, 3>>
839 struct hash<
nap::RGBColor<nap::uint16>>
849 struct hash<
nap::Color<nap::uint16, 4>>
862 struct hash<
nap::RGBAColor<nap::uint16>>
871 struct hash<
nap::Color<float, 1>>
881 struct hash<
nap::RColor<float>>
891 struct hash<
nap::Color<float, 3>>
898 return value1 ^ value2 ^ value3;
904 struct hash<
nap::RGBColor<float>>
914 struct hash<
nap::Color<float, 4>>
922 return value1 ^ value2 ^ value3 ^ value4;
927 struct hash<
nap::RGBAColor<float>>
940 return hash<int>()(
static_cast<int>(v));