#ifndef SHADER_AUTOMATON_COLOR_H #define SHADER_AUTOMATON_COLOR_H #include #include #include #include #include #include #include enum class ColorSpace { CIELAB, CIELUV, OKLAB, }; struct Color { Color() : colorspace(default_colorspace){} Color(const Color&)=default; Color(double v1, double v2, double v3, ColorSpace colorspace) : v1(v1), v2(v2), v3(v3), colorspace(colorspace) {} Color(double v1, double v2, double v3) : Color(v1, v2, v3, default_colorspace) {} Color(std::array values, ColorSpace colorspace) : Color(values[0], values[1], values[2], colorspace) {} explicit Color(std::array values) : Color(values, default_colorspace) {} double v1{}; double v2{}; double v3{}; ColorSpace colorspace; [[nodiscard]] std::array values() const; [[nodiscard]] std::array to_rgb() const; [[nodiscard]] std::array to_normalized_rgb() const; static Color from_rgb(double red, double green, double blue, ColorSpace colorspace); static Color from_rgb(std::array rgb, ColorSpace colorspace); static Color from_rgb(std::array rgb, ColorSpace colorspace); static Color from_normalized_rgb(double red, double green, double blue, ColorSpace colorspace); static Color from_normalized_rgb(std::array rgb, ColorSpace colorspace); static Color from_rgb(uint8_t red, uint8_t green, uint8_t blue); static Color from_rgb(std::array rgb); static Color from_rgb(double red, double green, double blue); static Color from_rgb(std::array rgb); static Color from_normalized_rgb(double red, double green, double blue); static Color from_normalized_rgb(std::array rgb); static void set_default_colorspace(ColorSpace colorspace); private: static ColorSpace default_colorspace; }; //struct ColorMap { // ~ColorMap() { // if (this->owned_data) { // delete this->data; // } // } // // virtual std::string convertToRgbCode(const std::string &val) { // throw std::runtime_error("not implemented in base class"); // }; // // size_t length; // const float *data{}; // bool owned_data = false; //}; // //struct RgbColorMap : ColorMap { // RgbColorMap(size_t length, const float data[], bool normalized = false, bool take_ownership = false) { // this->length = length; // if (normalized) { // if (take_ownership) { // this->owned_data = true; // } // this->data = data; // } else { // auto normalized_data = new float[length * 3]; // for (size_t i = 0; i < length * 3; ++i) { // normalized_data[i] = data[i] / 255.f; // } // this->data = normalized_data; // this->owned_data = true; // if (take_ownership) { // delete data; // } // } // } // // std::string convertToRgbCode(const std::string &val) override { // return val; // }; //}; //struct CieLabColorMap : ColorMap { // CieLabColorMap(size_t length, const float data[], bool take_ownership = false) { // this->length = length; // this->data = data; // this->owned_data = take_ownership; // } // // std::string convertToRgbCode(const std::string &val) override { // return CieLabColor::convertToRgbCode(val); // }; //}; #endif // SHADER_AUTOMATON_COLOR_H