コード例 #1
0
ファイル: Colour.cpp プロジェクト: elfchief/gnssview
Colour  Colour::asRGB()
{
	Colour c(this);
	
	switch (space)
	{
		case RGB:
			c.space = RGB;
			break;
		case XYZ:
		
			c.space = RGB;
		
			c.x =    3.240479 * x    - 1.537150 * y  - 0.498535 * z;
    	c.y = -  0.969256 * x    + 1.875991 * y  + 0.041556 * z;
    	c.z =    0.055648 * x    - 0.204043 * y  + 1.057311 * z;
			
			break;
		case HSV:
		
			c.space = HSV;
			
			// H is given on [0, 6] or UNDEFINED. S and V are given on [0, 1].
  		// RGB are each returned on [0, 1].

  		float m, n, f;
  		int i;

  		if(x == -1 ) {c.x=c.y=c.z=z;}

  		i = (int)floorf(x);
  		f = x - i;

  		if(!(i & 1)) f = 1 - f; // if i is even


  		m = z * (1 - y);
  		n = z * (1 - y * f);
  		switch (i)
			{
    		case 6:
    		case 0: c.x=z; c.y=n;  c.z=m;
     			break;
   		 	case 1: c.x=n; c.y=z;  c.z=m;
      		break;
    		case 2: c.x=m, c.y=z;  c.z=n;
     		 break;
    		case 3: c.x=m, c.y=n;  c.z=z;
     		 break;    
    		case 4: c.x=n, c.y=m;  c.z=z;
      		break;    
    		case 5: c.x=z, c.y=m;  c.z=n;
      		break;    
  		}
		
			break;
			
		case xyY:
			// FIXME do this directly
			Colour xyz = asXYZ();
			c = xyz.asRGB();
			break;
	}
	return c;
}