Results 1 to 1 of 1

Thread: Formula needed for Correct Hue in RGB->HSB.

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Formula needed for Correct Hue in RGB->HSB.

    I've answered my original question up to one point; the hue value. I'm using this formula converted from this page: http://www.cs.rit.edu/~ncs/color/t_convert.html to convert it. Here's my attempt to translate it into VB:
    VB Code:
    1. Function RGBtoHSB(R As Single, G As Single, B As Single, H As Long, S As Single, V As Single)
    2. Dim Mini As Single, Maxi As Single, Delta As Single
    3.    
    4.     Mini = Min(R, G, B)
    5.     Maxi = Max(R, G, B)
    6.    
    7.     V = Maxi
    8.     Delta = Maxi - Mini
    9.    
    10.     If Maxi <> 0 Then
    11.         S = Delta / Maxi
    12.     Else
    13.         S = 0
    14.         H = -1
    15.         Exit Function
    16.     End If
    17.  
    18.     If R = Maxi Then
    19.         H = (G - B) / Delta
    20.     ElseIf G = Maxi Then
    21.         H = 2 + (B - R) / Delta
    22.     Else
    23.          H = 4 + (R - G) / Delta
    24.     End If
    25.  
    26.     H = H * 60
    27.     If H < 0 Then H = H + 360
    28.  
    29. End Function
    30.  
    31. Function Max(R As Single, G As Single, B As Single) As Single
    32.     If R > G Then
    33.         If R > B Then
    34.             Max = R
    35.         Else
    36.             Max = B
    37.         End If
    38.     Else
    39.         If G > B Then
    40.             Max = G
    41.         Else
    42.             Max = B
    43.         End If
    44.     End If
    45. End Function
    46.  
    47. Function Min(R As Single, G As Single, B As Single) As Single
    48.     If R < G Then
    49.         If R < B Then
    50.             Min = R
    51.         Else
    52.             Min = B
    53.         End If
    54.     Else
    55.         If G < B Then
    56.             Min = G
    57.         Else
    58.             Min = B
    59.         End If
    60.     End If
    61. End Function
    I'm assuming that's how the Max and Min functions should be, but that's where my problem may lie.
    Last edited by Sastraxi; Nov 25th, 2001 at 12:29 AM.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width