aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/colors/HSV_Space.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/colors/HSV_Space.h')
-rw-r--r--meowpp/colors/HSV_Space.h195
1 files changed, 0 insertions, 195 deletions
diff --git a/meowpp/colors/HSV_Space.h b/meowpp/colors/HSV_Space.h
deleted file mode 100644
index 4a5d24e..0000000
--- a/meowpp/colors/HSV_Space.h
+++ /dev/null
@@ -1,195 +0,0 @@
-#ifndef colors_HSV_Space_H__
-#define colors_HSV_Space_H__
-
-#include "Color3_Space.h"
-#include "../geo/Vectors.h"
-
-#include "RGB_Space.h"
-#include "YUV_Space.h"
-#include "HSL_Space.h"
-#include "../math/utility.h"
-
-#include <cstdlib>
-
-namespace meow {
-
-/*!
- * @brief 以浮點數\b Y(亮度), \b U(色度), \b V(濃度) 三個值所組成的色彩空間
- *
- * 其中範圍都介於0.0~1.0之間
- *
- * @author cat_leopard
- */
-class HSVf_Space: public Color3_Space<double> {
-public:
- HSVf_Space(): Color3_Space<double>(Vector3D<double>( 0.0, 0.0, 0.0),
- Vector3D<double>(PI*2.0, 1.0, 1.0),
- Vector3D<double>( 0.0, 0.0, 0.0)) {
- }
- HSVf_Space(double c): Color3_Space<double>(Vector3D<double>( 0.0, 0.0, 0.0),
- Vector3D<double>(PI*2.0, 1.0, 1.0),
- Vector3D<double>( c, c, c))
- { }
- HSVf_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)) {
- }
- HSVf_Space(HSV_Space const& b): Color3_Space<double>(b) {
- }
- ~HSVf_Space() {
- }
- double const& hsvMin(size_t i) const { return min(i); }
- double const& hMin( ) const { return min(0); }
- double const& sMin( ) const { return min(1); }
- double const& vMin( ) const { return min(2); }
- double const& hsvMax(size_t i) const { return max(i); }
- double const& hMax( ) const { return max(0); }
- double const& sMax( ) const { return max(1); }
- double const& vMax( ) const { return max(2); }
- double const& hsv(size_t i) const { return val(i); }
- double const& h( ) const { return hsv(0); }
- double const& s( ) const { return hsv(1); }
- double const& v( ) const { return hsv(2); }
- double const& hsv(size_t i, double c) { return val(i, c); }
- double const& h( double c) { return hsv(0, c); }
- double const& s( double c) { return hsv(1, c); }
- double const& v( double c) { return hsv(2, c); }
- double& hsvGet(size_t i) { return valGet(i); }
- double& hGet( ) { return hsvGet(0); }
- double& sGet( ) { return hsvGet(1); }
- double& vGet( ) { return hsvGet(2); }
- HSVf_Space& operator=(HSVf_Space const& b) {
- copyFrom(b);
- return *this;
- }
- HSVf_Space operator+(HSVf_Space const& b) const {
- return HSVf_Space(val_ + b.val_);
- }
- HSVf_Space operator-(HSVf_Space const& b) const {
- return HSVf_Space(val_ - b.val_);
- }
- HSVf_Space operator*(double const& c) const {
- return HSVf_Space(val_ * c);
- }
- HSVf_Space operator/(double const& c) const {
- return HSVf_Space(val_ / c);
- }
- double operator*(HSVf_Space const& b) const {
- return val_ * b.val_;
- }
-};
-
-/*!
- * @brief \c HSVf_Space to \c HSVf_Space
- */
-inline void colorTransformate(HSVf_Space const& in, HSVf_Space* out) {
- *out = in;
-}
-
-/*!
- * @brief \c RGBf_Space to \c HSVf_Space
- */
-inline void colorTransformate(RGBf_Space const& rgb, HSVf_Space* hsv) {
- double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r());
- double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g());
- double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b());
- double mx = std::max(std::max(r, g), b);
- double mn = std::min(std::min(r, g), b);
- double h, s, v;
- if (mx == mn ) h = 0;
- else if(mx == r && g >= b) h = PI/3.0 * (g-b) / (mx-mn);
- else if(mx == r && g < b) h = PI/3.0 * (g-b) / (mx-mn) + PI * 2.0;
- else if(mx == g ) h = PI/3.0 * (b-r) / (mx-mn) + PI/3.0*2.0;
- else h = PI/3.0 * (r-g) / (mx-mn) + PI/3.0*4.0;
- if(mx == 0) s = 0;
- else s = 1 - mn / mx;
- v = mx;
- hsv->h(h);
- hsv->s(s);
- hsv->v(v);
-}
-
-/*!
- * @brief \c YUVf_Space to \c HSVf_Space
- */
-inline void colorTransformate(YUVf_Space const& yuv, HSVf_Space* hsv) {
- RGBf_Space tmp;
- colorTransformate( yuv, &tmp);
- colorTransformate(*tmp, hsv);
-}
-
-/*!
- * @brief \c HSLf_Space to \c HSVf_Space
- */
-inline void colorTransformate(HSLf_Space const& hsl, HSVf_Space* hsv) {
- RGBf_Space tmp;
- colorTransformate( hsl, &tmp);
- colorTransformate(*tmp, hsv);
-}
-
-/*!
- * @brief \c HSVf_Space to \c RGBf_Space
- */
-inline void colorTransformate(HSVf_Space const& hsv, RGBf_Space* rgb) {
- double h = normalize(hsv.hMin(), hsv.hMax(), hsv.h()) * 360;
- double s = normalize(hsv.sMin(), hsv.sMax(), hsv.s());
- double v = normalize(hsv.vMin(), hsv.vMax(), hsv.v());
- int hi = (int)h / 60 % 6;
- double f = h / 60.0 - hi;
- double p = v * (1 - s);
- double q = v * (1 - f * s);
- double t = v * (1 - (1 - f) * s);
- double r, g, b;
- if (hi == 0){ r = v; g = t; b = p; }
- else if(hi == 1){ r = q; g = v; b = p; }
- else if(hi == 2){ r = p; g = v; b = t; }
- else if(hi == 3){ r = p; g = q; b = v; }
- else if(hi == 4){ r = t; g = p; b = v; }
- else { r = v; g = p; b = q; }
- rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r));
- rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g));
- rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b));
-}
-
-/*!
- * @brief \c HSVf_Space to \c YUVf_Space
- */
-inline void colorTransformate(HSVf_Space const& hsv, YUVf_Space* yuv) {
- RGBf_Space tmp;
- colorTransformate( hsv, &tmp);
- colorTransformate(*tmp, yuv);
-}
-
-/*!
- * @brief \c HSVf_Space to \c HSLf_Space
- */
-inline void colorTransformate(HSVf_Space const& hsv, HSLf_Space* hsl) {
- RGBf_Space tmp;
- colorTransformate( hsv, &tmp);
- colorTransformate(*tmp, hsl);
-}
-
-/*!
- * @brief \c HSVf_Space to \c RGBi_Space
- */
-inline void colorTransformate(HSVf_Space const& hsv, RGBi_Space* rgb) {
- RGBf_Space tmp;
- colorTransformate(hsv, &tmp);
- rgb->copyFrom(tmp);
-}
-
-
-/*!
- * @brief \c RGBi_Space to \c HSVf_Space
- */
-inline void colorTransformate(RGBi_Space const& rgb, HSVf_Space* hsv) {
- RGBf_Space tmp;
- tmp.copyFrom(rgb);
- colorTransformate(rgb, hsv);
-}
-
-} // meow
-
-
-#endif // colors_HSV_Space_H__