Click here to Skip to main content
16,010,114 members
Home / Discussions / C#
   

C#

 
GeneralCasting Repost Pin
leppie15-Aug-02 6:10
leppie15-Aug-02 6:10 
GeneralRe: Casting Repost Pin
Nick Parker15-Aug-02 10:44
protectorNick Parker15-Aug-02 10:44 
GeneralRe: Casting Repost Pin
leppie15-Aug-02 13:54
leppie15-Aug-02 13:54 
GeneralRe: Casting Repost Pin
Eric Gunnerson (msft)16-Aug-02 7:06
Eric Gunnerson (msft)16-Aug-02 7:06 
GeneralRe: Casting Repost Pin
leppie17-Aug-02 3:18
leppie17-Aug-02 3:18 
GeneralHLS to RGB and RGB to HLS Pin
Derek Lakin15-Aug-02 4:24
Derek Lakin15-Aug-02 4:24 
GeneralRe: HLS to RGB and RGB to HLS Pin
leppie15-Aug-02 6:35
leppie15-Aug-02 6:35 
GeneralRe: HLS to RGB and RGB to HLS Pin
leppie15-Aug-02 7:06
leppie15-Aug-02 7:06 
OK i found 2 variations:

From Anakrino:

public float GetBrightness() {
	float local0;
	float local1;
	float local2;
	float local3;
	float local4;

	local0 = (float) this.R / 255;
	local1 = (float) this.G / 255;
	local2 = (float) this.B / 255;
	local3 = local0;
	local4 = local0;
	if (local1 > local3)
		local3 = local1;
	if (local2 > local3)
		local3 = local2;
	if (local1 < local4)
		local4 = local1;
	if (local2 < local4)
		local4 = local2;
	return local3 + local4 / 2;
}

public float GetHue() {
	float local0;
	float local1;
	float local2;
	float local3;
	float local4;
	float local5;
	float local6;

	if (this.R == this.G && this.G == this.B)
		return 0;
	local0 = (float) this.R / 255;
	local1 = (float) this.G / 255;
	local2 = (float) this.B / 255;
	local6 = 0;
	local3 = local0;
	local4 = local0;
	if (local1 > local3)
		local3 = local1;
	if (local2 > local3)
		local3 = local2;
	if (local1 < local4)
		local4 = local1;
	if (local2 < local4)
		local4 = local2;
	local5 = local3 - local4;
	if (local0 == local3)
		local6 = local1 - local2 / local5;
	else {
		if (local1 == local3)
			local6 = 2 + local2 - local0 / local5;
		else 		if (local2 == local3)
			local6 = 4 + local0 - local1 / local5;
	}
	local6 = local6 * 60;
	if (local6 < 0)
		local6 += 360;
	return local6;
}

public float GetSaturation() {
	float local0;
	float local1;
	float local2;
	float local3;
	float local4;
	float local5;
	float local6;

	local0 = (float) this.R / 255;
	local1 = (float) this.G / 255;
	local2 = (float) this.B / 255;
	local6 = 0;
	local3 = local0;
	local4 = local0;
	if (local1 > local3)
		local3 = local1;
	if (local2 > local3)
		local3 = local2;
	if (local1 < local4)
		local4 = local1;
	if (local2 < local4)
		local4 = local2;
	if (local3 != local4) {
		local5 = local3 + local4 / 2;
		if ((double) local5 <= 0.5)
			local6 = local3 - local4 / local3 + local4;
		else
			local6 = local3 - local4 / 2 - local3 - local4;
	}
	return local6;
}


And from the MONO classes (very nice reference indeed Smile | :) ):

public float GetBrightness (){
   // Intensity is the normalized sum of the three RGB values.;
   return ((float)(r + g + b))/(255*3);
}

public float GetSaturation (){
   // S = 1 - I * Min(r,g,b)
   return (255 - (((float)(r + g +b))/3)*Math.Min(r,Math.Min(g,b)))/255;
}

public float GetHue (){
   float top = ((float)(2*r-g-b))/(2*255);
   float bottom = (float)Math.Sqrt(((r-g)*(r-g) + (r-b)*(g-b))/255);
  return (float)Math.Acos(top/bottom);
}


HTH Smile | :)

MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc
for more info. Big Grin | :-D
GeneralRe: HLS to RGB and RGB to HLS Pin
Derek Lakin15-Aug-02 19:58
Derek Lakin15-Aug-02 19:58 
GeneralActiveX and C# controls Pin
Shaun Wilde15-Aug-02 1:35
Shaun Wilde15-Aug-02 1:35 
GeneralRe: ActiveX and C# controls Pin
Andy Smith15-Aug-02 4:44
Andy Smith15-Aug-02 4:44 
GeneralClickety Pin
David Stone15-Aug-02 6:04
sitebuilderDavid Stone15-Aug-02 6:04 
GeneralRe: ActiveX and C# controls Pin
Shaun Wilde15-Aug-02 22:44
Shaun Wilde15-Aug-02 22:44 
GeneralRe: ActiveX and C# controls Pin
James T. Johnson16-Aug-02 2:17
James T. Johnson16-Aug-02 2:17 
Generaldynamic object creation using eval Pin
chajadan14-Aug-02 20:12
chajadan14-Aug-02 20:12 
GeneralRe: dynamic object creation using eval Pin
Stephane Rodriguez.14-Aug-02 22:04
Stephane Rodriguez.14-Aug-02 22:04 
QuestionAm I dreaming? Pin
leppie14-Aug-02 14:21
leppie14-Aug-02 14:21 
AnswerRe: Am I dreaming? Pin
Nick Hodapp14-Aug-02 14:48
sitebuilderNick Hodapp14-Aug-02 14:48 
GeneralRe: Am I dreaming? Pin
Ray Cassick14-Aug-02 15:28
Ray Cassick14-Aug-02 15:28 
GeneralRe: Am I dreaming? Pin
Nick Hodapp14-Aug-02 15:32
sitebuilderNick Hodapp14-Aug-02 15:32 
GeneralRe: Am I dreaming? Pin
leppie14-Aug-02 21:10
leppie14-Aug-02 21:10 
GeneralRe: Am I dreaming? Pin
SimonS14-Aug-02 22:48
SimonS14-Aug-02 22:48 
GeneralRe: Am I dreaming? Pin
leppie15-Aug-02 0:06
leppie15-Aug-02 0:06 
GeneralRe: Am I dreaming? Pin
Ray Cassick16-Aug-02 4:48
Ray Cassick16-Aug-02 4:48 
Generalhelp me Pin
imran_rafique14-Aug-02 10:31
imran_rafique14-Aug-02 10:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.