|
-
Dec 5th, 2001, 08:47 AM
#1
Thread Starter
Fanatic Member
Here's some code, written in Delphi but easy to read and translate (just scream if you can't get it to work ):
http://homepages.borland.com/efg2lab...Colors/HSV.htm
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Dec 5th, 2001, 03:47 PM
#2
Good Ol' Platypus
I actually found a similar page that did this in C++ (almost EXACTLY the same!) I translated the code:
VB Code:
Function Max(R, G, B) As Single
If R > G Then
If R > B Then
Max = R
Else
Max = B
End If
Else
If G > B Then
Max = G
Else
Max = B
End If
End If
End Function
Function Min(R, G, B) As Single
If R < G Then
If R < B Then
Min = R
Else
Min = B
End If
Else
If G < B Then
Min = G
Else
Min = B
End If
End If
End Function
Function RGBtoHSB(R, G, B, H, S, V)
Dim Mini As Single, Maxi As Single, Delta As Single
R = BToS(R)
G = BToS(G)
B = BToS(B)
Mini = Min(R, G, B)
Maxi = Max(R, G, B)
V = Maxi
Delta = Maxi - Mini
If Maxi <> 0 Then
S = Delta / Maxi
Else
S = 0
H = -1
Exit Function
End If
If R = Maxi Then
H = (G - B) / Delta
ElseIf G = Maxi Then
H = 2 + (B - R) / Delta
Else
H = 4 + (R - G) / Delta
End If
H = H * 60
If H < 0 Then H = H + 360
S = S * 100
V = V * 100
End Function
Function HSBtoRGB(R, G, B, H, S, V)
Dim I As Integer
Dim F As Single, P As Single, Q As Single, T As Single
S = S / 100
V = V / 100
If S = 0 Then
R = G = B = V
Exit Function
End If
H = H / 60
I = Int(H)
F = H - I
P = V * (1 - S)
Q = V * (1 - S * F)
T = V * (1 - S * (1 - F))
Select Case I
Case 0
R = V
G = T
B = P
Case 1
R = Q
G = V
B = P
Case 2
R = P
G = V
B = T
Case 3
R = P
G = Q
B = V
Case 4
R = T
G = P
B = V
Case Else
R = V
G = P
B = Q
End Select
R = Round(R * 255)
G = Round(G * 255)
B = Round(B * 255)
End Function
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 5th, 2001, 04:01 PM
#3
Thread Starter
Fanatic Member
Well, the Delphi code has been translated from C code, so it's probably the same
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|