I am converting my most used VB routines into a dll. First started with combining Red, Green and Blue values into a DWORD with the RGB Macro that I turned in a proc:


GetRGB proc RedColor:BYTE, GreenColor:BYTE, BlueColor:BYTE
xor eax, eax
mov al, BlueColor ; blue
rol eax, 8
mov al, GreenColor ; green
rol eax, 8
mov al, RedColor ; red

ret
GetRGB endp

Now I am trying to reverse this to extract each color value, this is what I have and it all works:


GetBlue proc RGBColor:DWORD
xor eax, eax
mov eax, RGBColor
ror eax, 16
ret
GetBlue endp

GetGreen proc RGBColor:DWORD
xor eax, eax
mov eax, RGBColor
ror eax, 8
ret
GetGreen endp

GetRed proc RGBColor:DWORD
xor eax, eax
mov eax, RGBColor
and eax, 255
ret
GetRed endp

Couldn't figure out how to get Red with either ror/rol so I did what we do in VB: RGBColor And 255 which gives the Red value. Is there a better way to do what I am trying to do? It feels good to actually make something with MASM! hehe

The VB declarations I am using if interested are:


Private Declare Function GetBlue Lib "TestASM.dll" (ByVal RGBColor As Long) As Byte
Private Declare Function GetGreen Lib "TestASM.dll" (ByVal RGBColor As Long) As Byte
Private Declare Function GetRed Lib "TestASM.dll" (ByVal RGBColor As Long) As Byte



Posted on 2002-06-13 20:03:31 by Gunner
GetBlue proc RGBColor:DWORD

movzx eax, BYTE PTR [RGBColor + 2]
ret
GetBlue endp

GetGreen proc RGBColor:DWORD
movzx eax, BYTE PTR [RGBColor + 1]
ret
GetGreen endp

GetRed proc RGBColor:DWORD
movzx eax, BYTE PTR [RGBColor + 0]
ret
GetRed endp
Here is another possiblity. Code looks okay, but you don't need to clear EAX with XOR EAX,EAX before loading the RGB value - just load the register with the RGB value. It is nice to see you come over from the dark side. :grin:
Posted on 2002-06-13 21:47:05 by bitRAKE
Gunner,

Welcome on board, we seem to have a few people who are from New York.

Just something that you may already know is that RGB values are often set as constants using what is called COLORREF format which is in HEX.

A COLORREF value is structured as follows.


00BBGGRR hex

Where BB is the blue byte, GG the green and RR the red. When a function requires a COLORREF value, if its not going to change in the program, a constant in this format is easy to use and efficient code.

Regards,

hutch@movsd.com
Posted on 2002-06-14 08:39:08 by hutch--