diff options
Diffstat (limited to 'meowpp/colors/RGB_Space.h')
-rw-r--r-- | meowpp/colors/RGB_Space.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/meowpp/colors/RGB_Space.h b/meowpp/colors/RGB_Space.h new file mode 100644 index 0000000..ea04598 --- /dev/null +++ b/meowpp/colors/RGB_Space.h @@ -0,0 +1,168 @@ +#ifndef colors_RGB_Space_H__ +#define colors_RGB_Space_H__ + +#include "Color3_Space.h" +#include "../geo/Vectors.h" +#include "../math/utility.h" + +#include <cstdlib> + +namespace meow { + +/*! + * @brief 以整數 \b Red, \b Green, \b Blue 三個值所組成的色彩空間 + * + * 其中範圍都介於0~255之間 + * + * @author cat_leopard + */ +class RGBi_Space: public Color3_Space<int> { +public: + RGBi_Space(): Color3_Space<int>(Vector3D<int>( 0, 0, 0), + Vector3D<int>(255, 255, 255), + Vector3D<int>( 0, 0, 0)) { + } + RGBi_Space(int c): Color3_Space<int>(Vector3D<int>( 0, 0, 0), + Vector3D<int>(255, 255, 255), + Vector3D<int>( c, c, c)) { + } + RGBi_Space(Vector3D<int> const& v): + Color3_Space<int>(Vector3D<int>( 0, 0, 0), + Vector3D<int>(255, 255, 255), + Vector3D<int>(v)) { + } + RGBi_Space(RGBi_Space const& b): Color3_Space<int>(b) { + } + ~RGBi_Space() { + } + int const& rgbMin(size_t i) const { return min(i); } + int const& rMin( ) const { return min(0); } + int const& gMin( ) const { return min(1); } + int const& bMin( ) const { return min(2); } + int const& rgbMax(size_t i) const { return max(i); } + int const& rMax( ) const { return max(0); } + int const& gMax( ) const { return max(1); } + int const& bMax( ) const { return max(2); } + int const& rgb(size_t i) const { return val(i); } + int const& r( ) const { return rgb(0); } + int const& g( ) const { return rgb(1); } + int const& b( ) const { return rgb(2); } + int const& rgb(size_t i, int c) { return val(i, c); } + int const& r( int c) { return rgb(0, c); } + int const& g( int c) { return rgb(1, c); } + int const& b( int c) { return rgb(2, c); } + int& rgbGet(size_t i) { return valGet(i); } + int& rGet( ) { return rgbGet(0); } + int& gGet( ) { return rgbGet(1); } + int& bGet( ) { return rgbGet(2); } + RGBi_Space& operator=(RGBi_Space const& b) { + copyFrom(b); + return *this; + } + RGBi_Space operator+(RGBi_Space const& b) const { + return RGBi_Space(val_ + b.val_); + } + RGBi_Space operator-(RGBi_Space const& b) const { + return RGBi_Space(val_ - b.val_); + } + RGBi_Space operator*(int c) const { + return RGBi_Space(val_ * c); + } + RGBi_Space operator/(int c) const { + return RGBi_Space(val_ / c); + } + int operator*(RGBi_Space const& b) const { + return val_ * b.val_; + } +}; + +/*! + * @brief 以浮點數\b Red, \b Green, \b Blue 三個值所組成的色彩空間 + * + * 其中範圍都介於0.0~1.0之間 + * + * @author cat_leopard + */ +class RGBf_Space: public Color3_Space<double> { +public: + RGBf_Space(): Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0), + Vector3D<double>(1.0, 1.0, 1.0), + Vector3D<double>(0.0, 0.0, 0.0)) { + } + RGBf_Space(double c): Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0), + Vector3D<double>(1.0, 1.0, 1.0), + Vector3D<double>( c, c, c)) { + } + RGBf_Space(Vector3D<double> const& v): + Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0), + Vector3D<double>(1.0, 1.0, 1.0), + Vector3D<double>(v)) { + } + RGBf_Space(RGBf_Space const& b): Color3_Space<double>(b) { + } + ~RGBf_Space() { + } + double const& rgbMin(size_t i) const { return min(i); } + double const& rMin( ) const { return min(0); } + double const& gMin( ) const { return min(1); } + double const& bMin( ) const { return min(2); } + double const& rgbMax(size_t i) const { return max(i); } + double const& rMax( ) const { return max(0); } + double const& gMax( ) const { return max(1); } + double const& bMax( ) const { return max(2); } + double const& rgb(size_t i) const { return val(i); } + double const& r( ) const { return rgb(0); } + double const& g( ) const { return rgb(1); } + double const& b( ) const { return rgb(2); } + double const& rgb(size_t i, double c) { return val(i, c); } + double const& r( double c) { return rgb(0, c); } + double const& g( double c) { return rgb(1, c); } + double const& b( double c) { return rgb(2, c); } + double& rgbGet(size_t i) { return valGet(i); } + double& rGet( ) { return rgbGet(0); } + double& gGet( ) { return rgbGet(1); } + double& bGet( ) { return rgbGet(2); } + RGBf_Space& operator=(RGBf_Space const& b) { + copyFrom(b); + return *this; + } + RGBf_Space operator+(RGBf_Space const& b) const { + return RGBf_Space(val_ + b.val_); + } + RGBf_Space operator-(RGBf_Space const& b) const { + return RGBf_Space(val_ - b.val_); + } + RGBf_Space operator*(double const& c) const { + return RGBf_Space(val_ * c); + } + RGBf_Space operator/(double const& c) const { + return RGBf_Space(val_ / c); + } + double operator*(RGBf_Space const& b) const { + return val_ * b.val_; + } +}; + +/*! + * @brief \c RGBi_Space to \c RGBf_Space + */ +inline void colorTransformate(RGBi_Space const& a, RGBf_Space* b) { + for (size_t i = 0; i < 3; ++i) { + b->rgb(i, ratioMapping<double>(a.rgbMin(i), a.rgbMax(i), a.rgb(i), + b->rgbMin(i), b->rgbMax(i))); + } +} + +/*! + * @brief \c RGBf_Space to \c RGBi_Space + */ +inline void colorTransformate(RGBf_Space const& a, RGBi_Space* b) { + for (size_t i = 0; i < 3; ++i) { + b->rgb(i, ratioMapping<double>(a.rgbMin(i), a.rgbMax(i), a.rgb(i), + b->rgbMin(i), b->rgbMax(i))); + } +} + +} // meow + +#endif // colors_RGB_Space_H__ |