Jump to content

RGB - Curious


Joel
 Share

Recommended Posts

I found some old scripts I used to work on and was comparing it to the autoit helpfile and noticed that RGB support appeared missing from the help file and it used to be in the old help file.

Here is an example code for using RGB arrays to find a color sequence and perform a function.

Anyone know why they removed it from the help file?

Just curious..

Hope the code helps someone as I've seen a few RGB or DEC questions about here.

While 1
   Sleep(100)
   Dim $a, $c, $d
   $a = PixelGetRGB(110,156);
   $c = PixelGetRGB(142,156);
   $d = PixelGetRGB(174,156);
   If $a[1] = 255 AND $a[2] = 255 AND $a[3] = 255 AND $c[1] = 255 AND $c[2] = 255 AND $c[3] = 255 AND $d[1] = 255 AND $d[2] = 255 AND $d[3] = 255 Then
   Sleep(2000);Sleep a bit
   Do your function here()
   EndIf
Wend

; Returns an array with element1=RED, element2=GREEN, element3=BLUE
Func PixelGetRGB($x, $y)
    $hex = Hex(PixelGetColor($x, $y), 6)
    $r = hexToDec(StringRight($hex, 2)) & "|"
    $g = hexToDec(StringMid($hex, 3,2)) & "|"
    $b = hexToDec(StringLeft($hex, 2))
    Return StringSplit($r & $g & $b, "|")
EndFunc

; Returns the decimal equivalent of a $hex string like "05ff"
Func hexToDec($hex)
    $dec = 0;running total
    $n = StringLen($hex);number of digits
    For $i = 1 to $n
    $d = StringMid($hex, $i, 1);digit
    Select
    Case $d >= "0" And $d <= "9"
        $dec = $dec + (Asc($d)-48) * 16 ^ ($n-$i)
    Case $d >= "A" And $d <= "G"
        $dec = $dec + (Asc($d)-55) * 16 ^ ($n-$i)
    Case $d >= "a" And $d <= "g"
        $dec = $dec + (Asc($d)-87) * 16 ^ ($n-$i)
    EndSelect
    Next
    Return $dec
EndFunc

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Link to comment
Share on other sites

In case someone looks at the code and goes huh?..

The a, b, c, arrays represent RGB values in the [1], [2], [3] events. I like using RGB values when noting events because it's easy to find a pointer value that is 255 in one of the color spectrums.

RGB is a bit more stable than using DEC to find a color sequence and trigger an event.

In any case, there are many programs you can use to find RGB values in a given screenshot or a given screen.

I hope that helps.

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Link to comment
Share on other sites

huh?

<{POST_SNAPBACK}>

A better example of how you would use this would be you are waiting for an event to occur on your screen. When the event occurs, the script would detect the RGB values at three coordinates and then run the function associated with the event.

So, for example..

You have a chat monitor running and have special chat text set to a specific color. You run the script and then 1 hour later the special chat text pops up. The script sees the RGB values at the coordinates you plugged in, and runs the function. The function could be a response, a reply, or anything else you want to designate.

$a = PixelGetRGB(110,156);
$c = PixelGetRGB(142,156);
$d = PixelGetRGB(174,156);

(110,156) are coordinates for the first RGB screen values. You can find these coordinates by using any type of color program - mspaint for example. As you hover your mouse over the area you want to check the first RGB values for, you find the coordinates are listed as (110,156).

(142,156) are the coordinates for the second RGB, etc.

If $a[1] = 255 AND $a[2] = 255 AND $a[3] = 255 AND $c[1] = 255 AND $c[2] = 255 AND $c[3] = 255 AND $d[1] = 255 AND $d[2] = 255 AND $d[3] = 255 Then
   Sleep(2000);Sleep a bit
   Do your function here()
   EndIf

So using the PixelgetRGB function in the first example post, you can use this if statement to find the RGB event. It basically says, in laymens terminology:

If Red on the first coordinate = 255 and Red on the second coordinate = 255 and Red on the third coordinate = 255 and Green on the first coordinate = 255 and Green on the second coordinate = 255, etc. Then sleep for 2 seconds and perform a function.

You can change the values above so that Red, Green, or Blue can be looking for anything inbetween so that allows you to have a wild card of sorts.

If $a[1] = 255 AND $a[2] = 255 AND $a[3] = 255 AND $c[1] < 255 > 155 AND $c[2] < 255 > 155 AND $c[3] < 255 > 155 AND $d[1] = 255 AND $d[2] = 255 AND $d[3] = 255 Then
   Sleep(2000);Sleep a bit
   Do your function here()
   EndIf

As you can see the value for green is looking at the three coordinates and searching for a value that is greater than 155 and less than 255.

If all values are true, the function occurs.

RGB is great for event handling.

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Link to comment
Share on other sites

I *think* Joel is saying the help file changed from version 3.0.100 to 3.0.102

The change in RGB versus BRG and the introduction of the Hex function allowed the example to be simplified....

Help file 3.0.100 example

$var = PixelGetColor( 10 , 100 )
MsgBox(0,"The decmial color is", $var)

$c =   PixelGetRGB(10,100)
MsgBox(0,"The RBG Pixel Color is", $c[1] & "," & $c[2] & "," & $c[3])
Exit

; Returns an array with element1=RED, element2=GREEN, element3=BLUE
Func PixelGetRGB($x, $y)
    $hex = Hex(PixelGetColor($x, $y), 6)
    $r = Dec(StringRight($hex, 2)) & "|"
    $g = Dec(StringMid($hex, 3,2)) & "|"
    $b = Dec(StringLeft($hex, 2))
    Return StringSplit($r & $g & $b, "|")
EndFunc

Current 3.0.103 example:

$var = PixelGetColor( 10 , 100 )
MsgBox(0,"The decmial color is", $var)
MsgBox(0,"The hex color is", Hex($var, 6))
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

I *think* Joel is saying the help file changed from version 3.0.100 to 3.0.102

The change in RGB versus BRG and the introduction of the Hex function allowed the example to be simplified....

Help file 3.0.100 example

$var = PixelGetColor( 10 , 100 )
MsgBox(0,"The decmial color is", $var)

$c =   PixelGetRGB(10,100)
MsgBox(0,"The RBG Pixel Color is", $c[1] & "," & $c[2] & "," & $c[3])
Exit

; Returns an array with element1=RED, element2=GREEN, element3=BLUE
Func PixelGetRGB($x, $y)
    $hex = Hex(PixelGetColor($x, $y), 6)
    $r = Dec(StringRight($hex, 2)) & "|"
    $g = Dec(StringMid($hex, 3,2)) & "|"
    $b = Dec(StringLeft($hex, 2))
    Return StringSplit($r & $g & $b, "|")
EndFunc

Current 3.0.103 example:

$var = PixelGetColor( 10 , 100 )
MsgBox(0,"The decmial color is", $var)
MsgBox(0,"The hex color is", Hex($var, 6))

<{POST_SNAPBACK}>

Cyber thanks!

That's what I was trying to find out. You clarified what I was getting at but also explained what I was looking for. So, essentially you are saying that the old version used BGR format and the new one can be set to either or using Colormode. You are also saying that it's more simplified now that they introduced the Hex function. After looking at the Hex function, it does look a lot easier now.

Thanks again!

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Link to comment
Share on other sites

So using your new example, it would look like this eh?

While 1
   Sleep(100)
   Dim $a, $c, $d
   $a = PixelGetRGB(110,156);
   $c = PixelGetRGB(142,156);
   $d = PixelGetRGB(174,156);
   If $a[1] = 255 AND $a[2] = 255 AND $a[3] = 255 AND $c[1] = 255 AND $c[2] = 255 AND $c[3] = 255 AND $d[1] = 255 AND $d[2] = 255 AND $d[3] = 255 Then
   Sleep(2000);Sleep a bit
   testfunction()
   EndIf
Wend

; Returns an array with element1=RED, element2=GREEN, element3=BLUE
Func PixelGetRGB($x, $y)
    $hex = Hex(PixelGetColor($x, $y), 6)
    $r = Dec(StringRight($hex, 2)) & "|"
    $g = Dec(StringMid($hex, 3,2)) & "|"
    $b = Dec(StringLeft($hex, 2))
    Return StringSplit($r & $g & $b, "|")
EndFunc

Func testfunction()
    Exit
    EndFunc

Let me know if that's correct Cyber if you have time.

[font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font]

Link to comment
Share on other sites

  • Administrators

From the beta version includes:

Func _ColorGetRed($nColor)
    Return BitAND( BitShift($nColor, 16), 0xff)
EndFunc  ;==>_ColorGetRed

Func _ColorGetGreen($nColor)
    Return BitAND( BitShift($nColor, 8), 0xff)
EndFunc  ;==>_ColorGetGreen

Func _ColorGetBlue($nColor)
    Return BitAND($nColor, 0xff)
EndFunc  ;==>_ColorGetBlue

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...