Function SplitRGB
|
RGB color longs look like this: &H00BBGGRR. SplitRGB extracts the red, green and blue parts. The returns can be organized in various ways. Below you see two of them: (a) a return argument for each color part, (b) the function itself returns a struct (Type) containing the parts.
|
(a) Sub SplitRGB(ByVal lColor As Long, _
ByRef lRed As Long, _
ByRef lGreen As Long, _
ByRef lBlue As Long)
(b) Type RGB32
Red As Byte
Green As Byte
Blue As Byte
Pad As Byte
End Type
Function SplitRGB(ByVal lColor As Long) As RGB32
|
|
Code |
SplitRGB01 |
Public Sub SplitRGB01(ByVal lColor As Long, _
ByRef lRed As Long, _
ByRef lGreen As Long, _
ByRef lBlue As Long)
' by www.Abstractvb.com, Date: 3/9/2001 9:26:43 PM, 20010922
lColor = lColor And &HFFFFFF
lRed = lColor Mod &H100&
lColor = lColor \ &H100&
lGreen = lColor Mod &H100&
lColor = lColor \ &H100&
lBlue = lColor Mod &H100&
End Sub
|
SplitRGB02 |
Public Sub SplitRGB02(ByVal lColor As Long, _
ByRef lRed As Long, _
ByRef lGreen As Long, _
ByRef lBlue As Long)
' by Donald, donald@xbeat.net, 20010922
lRed = lColor And &HFF
lGreen = (lColor And &HFF00&) \ &H100&
lBlue = (lColor And &HFF0000) \ &H10000
End Sub
|
SplitRGB03 |
Public Function SplitRGB03(ByVal lColor As Long) As RGB32
' by Donald, donald@xbeat.net, 20010922
With SplitRGB03
.Red = lColor And &HFF
.Green = (lColor And &HFF00&) \ &H100&
.Blue = (lColor And &HFF0000) \ &H10000
End With
End Function
|
SplitRGB04 |
Public Function SplitRGB04(ByVal lColor As Long) As RGB32
' by Karl E. Peterson, http://www.mvps.org/vb, 20011119
Call CopyMemory(SplitRGB04, lColor, 4&)
End Function
|
Calls |
1 | lColor = &HFF0000
|
2 | lColor = &HFF00&
|
3 | lColor = &HFF&
|
Charts |
|
VB5 Charts |
|
Call 1 |
2 | 1.72 | 0.094µs |
1 | 1.00 | 0.055µs |
3 | 3.89 | 0.213µs |
4 | 8.09 | 0.443µs |
|
Call 2 |
2 | 1.71 | 0.094µs |
1 | 1.00 | 0.055µs |
3 | 3.90 | 0.213µs |
4 | 8.11 | 0.443µs |
|
Call 3 |
2 | 1.71 | 0.094µs |
1 | 1.00 | 0.055µs |
3 | 3.90 | 0.213µs |
4 | 8.10 | 0.443µs |
|
|
VB6 Charts |
|
Call 1 |
2 | 1.45 | 0.083µs |
1 | 1.00 | 0.058µs |
3 | 3.35 | 0.193µs |
4 | 7.50 | 0.432µs |
|
Call 2 |
2 | 1.45 | 0.083µs |
1 | 1.00 | 0.057µs |
3 | 3.35 | 0.193µs |
4 | 7.51 | 0.432µs |
|
Call 3 |
2 | 1.45 | 0.084µs |
1 | 1.00 | 0.058µs |
3 | 3.35 | 0.193µs |
4 | 7.51 | 0.432µs |
|
|
Notes & Conclusions |
The result is no surprise for speedcorers, but maybe for those who think "API" is synonymous to "speed".
|
Got comments? |
 |
|