Advertisement
qwertz19281

Gambas3 Get similarity of two colors

Sep 7th, 2014
1,317
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Gets the similarity in Float from 0 to 1 - outdated
  2.  
  3. Public Function getColorSimilarity(a As Integer, b As Integer) As Float
  4.  
  5.  
  6. Dim Ra As Integer = Lsr(a, 16) And &HFF
  7.  
  8. Dim Ga As Integer = Lsr(a, 8) And &HFF
  9.  
  10. Dim Ba As Integer = a And &HFF
  11.  
  12. Dim Rb As Integer = Lsr(b, 16) And &HFF
  13.  
  14. Dim Gb As Integer = Lsr(b, 8) And &HFF
  15.  
  16. Dim Bb As Integer = b And &HFF
  17.  
  18. 'Message(CStr(Ra) & "#" & CStr(Ga) & "#" & CStr(Ba), "OH NO!")
  19.  
  20. Dim RProb As Integer = 255 - CInt(BigNum(Ra, Rb) - LittleNum(Ra, Rb))
  21. Dim GProb As Integer = 255 - CInt(BigNum(Ga, Gb) - LittleNum(Ga, Gb))
  22. Dim BProb As Integer = 255 - CInt(BigNum(Ba, Bb) - LittleNum(Ba, Bb))
  23.  
  24. Dim outa As Float = CFloat(RProb + GProb + BProb) / CFloat(255 * 3)
  25.  
  26. 'Message(CStr(RProb) & "#" & CStr(GProb) & "#" & CStr(BProb), "OK")
  27. Return outa
  28. End
  29.  
  30. Public Function LittleNum(a As Integer, b As Integer) As Integer
  31.  
  32.   If a > b Then
  33.     Return b
  34.   End If
  35.  
  36.   If a < b Then
  37.     Return a
  38.   End If
  39.  
  40.   If a = b Then
  41.     Return a
  42.   End If
  43. End
  44.  
  45. Public Function BigNum(a As Integer, b As Integer) As Integer
  46.  
  47.   If a > b Then
  48.     Return a
  49.   End If
  50.  
  51.   If a < b Then
  52.     Return b
  53.   End If
  54.  
  55.   If a = b Then
  56.     Return a
  57.   End If
  58. End
Advertisement
RAW Paste Data Copied
Advertisement