Advertisement
Java_Volume1 Graphics #93579

Get Red, Green and Blue colour values from a Long - FAST

This procedure takes a Long colour value and splits it into it's component Red, Green and Blue values.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Sub GetRGB(ByVal lngColour As Long, _
     Optional ByRef intRed As Integer, _
     Optional ByRef intGreen As Integer, _
     Optional ByRef intBlue As Integer)
 'Convert Long to RGB:
 
          '  Sys Cols, Blue , Green , Red
 Const RED_MASK As Long = 255  'Binary: 00000000,00000000,00000000,11111111
 Const GREEN_MASK As Long = 65280 'Binary: 00000000,00000000,11111111,00000000
 Const BLUE_MASK As Long = 16711680 'Binary: 00000000,11111111,00000000,00000000
 Const MAX_COLOUR As Long = 16777216 'Binary: 01111111,11111111,11111111,11111111
 
 'if the lngcolour value is greater than acceptable
 'then half the value
 If (lngColour > MAX_COLOUR) Or _
  (lngColour < -MAX_COLOUR) Then
  'system colour range
  Exit Sub
 End If
 
 'get the red, green and blue values
 intRed = (lngColour And RED_MASK)
 intGreen = (lngColour And GREEN_MASK) / 256 'shift 8 bits to the right
 intBlue = (lngColour And BLUE_MASK) / 65536 'shift 16 bits to the right
End Sub
Original Comments (3)
Recovered from Wayback Machine