Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/color.cc @ 5009

Last change on this file since 5009 was 5009, checked in by bensch, 19 years ago

orxonox/trunk: added class Color for easy color-transformation

File size: 1.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14
15   this code has been borrowed from:
16   http://www.easyrgb.com/math.php
17*/
18
19//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
20
21#include "color.h"
22
23using namespace std;
24
25Vector Color::RGBtoHSV (Vector RGB)
26{
27  Vector HSV;
28
29  float var_Min = min( RGB.x, RGB.y, RGB.z );    //Min. value of RGB
30  float var_Max = max( RGB.x, RGB.y, RGB.z );    //Max. value of RGB
31  float del_Max = var_Max - var_Min;             //Delta RGB value
32
33  flaot V = var_Max;
34
35  if ( del_Max == 0 )                     //This is a gray, no chroma...
36  {
37    HSV.x = 0                                //HSV results = 0 ÷ 1
38    HSV.y = 0
39  }
40  else                                    //Chromatic data...
41  {
42    HSV.y = del_Max / var_Max;
43
44    float del_R = ( ( ( var_Max - RGB.x ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
45    float del_G = ( ( ( var_Max - RGB.y ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
46    float del_B = ( ( ( var_Max - RGB.z ) / 6 ) + ( del_Max / 2 ) ) / del_Max;
47
48    if ( RGB.x == var_Max )
49      HSV.x = del_B - del_G;
50    else if ( var_G == var_Max )
51      HSV.x = ( 1 / 3 ) + del_R - del_B;
52    else if ( var_B == var_Max )
53      HSV.z = ( 2 / 3 ) + del_G - del_R;
54
55    if ( HSV.x < 0 ) ; HSV.x += 1;
56    if ( HSV.x > 1 ) ; HSV.x -= 1;
57  }
58  return HSV;
59}
60
61
62Vector Color::HSVtoRGB (Vector HSV)
63{
64
65}
Note: See TracBrowser for help on using the repository browser.