Jump to content
Sign in to follow this  
Josbe

Pixelfinder

Recommended Posts

Josbe

PIXEL FINDER ( Pixel Rect + GUI)

----------------------------------------------------

Now, I looking for a script maded by Larry about the colors(PIXEL RECT functions)

I had a idea from there, and I wrote this small script adapting Graphic Interface.

* In general: This show a mini-picture/preview from the screen (on mouse movement),

and show color values (HEX, HTML, RGB).

- You can copy some value pressing CTRL + SHIFT + number

*Requirement: AutoIt-GUI v102.18 or later.(tested in v102.18)

(I don't recommend to use in previous versions to v102.17)

Remark: Moving through the images, tends to fail getting wrong preview(Black), still I dunno if is:

- AutoIt (PixelGetColor function) or AutoIt-GUI limitation :huh2:

- Or some wrong code mine. :D

But...copy and test it! :lol:

(GUI is making a difference in AutoIt for do scripts)

Suggestions/Comments are welcome? :)

Sorry, I don't put any screenshot.

_PixelFinder()

Func _PixelFinder()
 $pixMouse= MouseGetPos()
 $curColor = PixelGetColor( $pixMouse[0], $pixMouse[1])
 $xScreen= $pixMouse[0]-10
 $yScreen= $pixMouse[1]-10
 $rectSize= 20
 $pixSize= 6

;// FORM ----------------------------------------------
 Global $titWin= "Pixel Finder"
 Global $YU= GUICreate($titWin, 330, 126, 150, 150)
 
; ===[ Arranging pixels ]===
 $rect = _LoadPixelRect( $xScreen, $yScreen, $xScreen + $rectSize, $yScreen + $rectSize)
 $FC= Ubound($rect)
 $x= 0
 $y= 0
 Dim $Lbls[$FC][$FC]
 For $a=0 to $FC - 1
    For $b=0 to $FC - 1 
        $Lbls[$a][$b]= GUISetControl("label", "", $x, $y, $pixSize, $pixSize)
        GUISetControlEx(-1, -1, "", "", 0x0, $rect[$a][$b])
        $x= $x + $pixSize
    Next
    $y= $y + $pixSize
    $x= 0
 Next
    
 GUIDefaultFont (8, 400, "verdana", 0)
 GUISetControl("group", "", 149, 3, 45, 51)
    
; ===[ Labels ]===
 $selColor= GUISetControl("label", "", 150, 10, 42, 42)
 GUISetControlEx(-1, -1, "", "", 0x0, $curColor )
 $infoX= GUISetControl("label", "x", 200, 10, 100, 12)
 $infoY= GUISetControl("label", "y", 200, 20, 100, 12)
 Global $infoTXT= GUISetControl("label", "Copy value (CTRL+SHIFT+#)", 135, 65, 170, 15, 0x1000)
 Global $infoCC= GUISetControl("label", "", 305, 65, 18, 15, 0x1000)
 $infoHEX= GUISetControl("label", "HEX", 135, 80, 150)
 $infoHTML= GUISetControl("label", "HTML", 135, 90, 150)
 $infoRGB= GUISetControl("label", "RGB", 135, 100, 150)

;===[ PROCESS START ]====
 HotKeySet("^+1", "_CopyHEX")
 HotKeySet("^+2", "_CopyHTML")
 HotKeySet("^+3", "_CopyRGB")
 HotKeySet("{PAUSE}", "_FreezeW")
 Global $_pauseSet = 0

 While GuiShow() AND GUIMSg(0) <> -3
   $pixMouse= MouseGetPos()
   $curColor = PixelGetColor( $pixMouse[0], $pixMouse[1])
   Global $col_HEX= Hex($curColor, 6)
   Global $col_HTML= StringRight($col_hex, 2) & StringMid($col_hex, 3, 2) & StringLeft($col_hex, 2)
   Global $col_RGB= _RGB($curColor)

  ; ===[ Updating info ]===
   GUISetControlEx($selColor, -1, "", "", 0x0, $curColor )
   GUIWrite($infoX, -1, "X: " & $pixMouse[0])
   GUIWrite($infoY, -1, "Y: " & $pixMouse[1])
   GUIWrite($infoHEX, -1, "1. HEX: " & $col_HEX)
   GUIWrite($infoHTML, -1, "2. HTML: #" & $col_HTML)
   GUIWrite($infoRGB, -1, "3. RGB: " & $col_RGB)
   
   If $_PauseSet = 0 then
     ;// Preview process
      $xScreen= $pixMouse[0]-10
      $yScreen= $pixMouse[1]-10
      $rect = _LoadPixelRect( $xScreen, $yScreen, $xScreen + $rectSize, $yScreen + $rectSize)
      $FC= Ubound($rect)
      $x= 0
      $y= 0
      
      For $a=0 to $FC - 1
         For $b=0 to $FC - 1 
            GUISetControlEx($Lbls[$a][$b], -1, "", "", 0x0, $rect[$a][$b])
            $x= $x + $pixSize
         Next
         $y= $y + $pixSize
         $x= 0
      Next
   EndIf
 Wend
EndFunc

Func _CopyHEX()
   ClipPut($col_HEX)
   GUIWrite($infoTXT, -1, "HEX value copied: " & $col_HEX)
   GUISetControlEx($infoCC, -1, "", "", 0x0, DEC($col_HEX))
EndFunc

Func _CopyHTML()
   ClipPut($col_HTML)
   GUIWrite($infoTXT, -1, "HTML value copied: " & $col_HTML)
   GUISetControlEx($infoCC, -1, "", "", 0x0, DEC($col_HEX))
EndFunc

Func _CopyRGB()
   ClipPut($col_RGB)
   GUIWrite($infoTXT, -1, "RGB copied: " & $col_RGB)
   GUISetControlEx($infoCC, -1, "", "", 0x0, DEC($col_HEX))
EndFunc

Func _FreezeW()
   If $_PauseSet = 0 then
      Global $_PauseSet = 1
      WinSetTitle($titWin, "", $titWin & " (freeze) ")
   else
      Global $_PauseSet = 0
      WinSetTitle($titWin, "", $titWin)
   EndIf
EndFunc

; _LoadPixelRect: maded by Lar. (thanks)
Func _LoadPixelRect($_NL, $_NT, $_NR, $_NB)
  If ($_NL > $_NR Or $_NT > $_NB) Then
     SetError(1)
     Return 0
  EndIf
  
  Dim $_APIXRECT[$_NB-$_NT+1][$_NR-$_NL+1]
  For $_NY = $_NT To $_NB
     For $_NX = $_NL To $_NR
        $_APIXRECT[$_NY-$_NT][$_NX-$_NL] = PixelGetColor($_NX,$_NY)
     Next
  Next
  
  Return $_APIXRECT
EndFunc

Func _RGB($_DColor)
 Local $R= BitAnd( BitShift( $_DColor, 16 ), 0xff )
 Local $G= BitAnd( BitShift( $_DColor, 8 ), 0xff )
 Local $B= BitAnd( $_DColor, 0xff )
 
 Return "(" & $B & ", " & $G & ", " & $R & ")"
EndFunc

EDIT1:

- Updated a Freeze function for freeze the preview. (pressing "PAUSE")

Edited by josbe

Share this post


Link to post
Share on other sites
Guest rathore

works great! ... nice script.

though i too had this problem

Moving through the images, tends to fail getting wrong preview(Black)

Share this post


Link to post
Share on other sites
Josbe

works great! ... nice script.

though i too had this problem

Yes, I have noticed that the mistake comes from an bad output from: PixelGetColor()

(After several calls or certain colors)

Like in the example:

$curColor = PixelGetColor ($pixMouse [0], $pixMouse [1])

I still don't know if is a function bug. :huh2::D

Share this post


Link to post
Share on other sites
jpm

Impressive. :D

I will remove the .17 version as suggested.

I play with 102.18C and after a while it stay black is that the pixelgetcolor problem

Share this post


Link to post
Share on other sites
CyberFunk Productions

very nice, good job!!!!!!!!!!1 :D

Share this post


Link to post
Share on other sites
CyberSlug

:D Excellent!!!! That looks *really* good, josbe!

For a long time, I used a pixel finder called Pixie, but I never found an easy way to copy the RGB color to the clipboard.

Three minor suggestions:

- the hex value should show the 0x prefix.

- add ability to copy all color formats to clipboard; maybe use Ctrl+Shift+zero

- add ability to keep window always on top. WinSetOnTop(...) is probably the easiest way to do this.

P.S.: You could also include other color models: HSV, HSL, CMY, CMYK are some of the others I've read about. But I do not want you to clutter your nice clean dialog!

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
jpm

AS I say in other thread I know how to fixe the black freeze due to gdi leaks

Share this post


Link to post
Share on other sites
CyberSlug

Here's an idea to reduce CPU load:

Replace the line $pixMouse= MouseGetPos() with this:

; only update when mouse cursor has changed
$previous = MouseGetPos()
sleep(250);you might want a smaller value here
$pixMouse = MouseGetPos()
If $previous[0] = $pixMouse[0] And $previous[1] = $pixMouse[1] Then ContinueLoop

(I have a laptop with a loud fan that kicks in at 100% CPU usage)


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Josbe

Three minor suggestions:

- the hex value should show the 0x prefix.

- add ability to copy all color formats to clipboard; maybe use Ctrl+Shift+zero

- add ability to keep window always on top. WinSetOnTop(...) is probably the easiest way to do this.

P.S.: You could also include other color models: HSV, HSL, CMY, CMYK are some of the others I've read about. But I do not want you to clutter your nice clean dialog!

@CyberSlug: I will keep in mind your ideas. Thxs.

About of another colors models,

when I was writing RGB function, I thought about this, but I left it to see if it was suggested for include it. I will include it. :D

EDT:

- add ability to copy all color formats to clipboard; maybe use Ctrl+Shift+zero

..you say: all in one line? :huh2: Edited by josbe

Share this post


Link to post
Share on other sites
SlimShady

I use it regularly. It's a nice program.

Share this post


Link to post
Share on other sites
emmanuel

so, would anyone want to compile that and make it available somewhere? I don't plan to go to the unstable AutoIt... you know, just if it's something you wanted to do...


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites
Josbe

@CyberSlug: Updates? Yeah. Recently I worked in some details and improvements.

Soon I will upload the new PixelFinder. Only I hope send it the Helpfile to Jon.(at last) :D:)

My work break my time for some AutoIt projects... :(:lol:

@emmanuel: The actual version works fine in the actual Unstable. But, don't panic to Unstable.. :huh2:...

You only need the Aut2Exe and AutoitSC.bin files for compile. Easy! :(

In the next upload I will include a compiled file.

@CyberSlug(or someone): Do you know any algorithm for RGB 2 HSL?

I found one, but HUE value return a wrong value when I translate to AutoIt. :(:)

Share this post


Link to post
Share on other sites
CyberSlug

@CyberSlug(or someone): Do you know any algorithm for RGB 2 HSL?

I found one, but HUE value return a wrong value when I translate to AutoIt. :)  :D

josbe, [ulr=http://130.113.54.154/~monger/hsl-rgb.html]look at step #4 at this site:

"If the max and min colors are the same (ie the color is some kind of grey), S is defined to be 0, and H is undefined but in programs usually written as 0"

I played with Windows' built-in color picker (mspaint.exe > colors menu > edit colors > define custom colors) and found this:

RGB = (76,76,76) shows up as HSL = (160,0,72)

However, changing the Hue makes no difference! I do not know what algorithm Microsoft uses... :huh2:


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
CyberSlug

I think the following will simulate Microsoft's algorithm:

Select
Case $r = $g And $g = $b ;all colors equal
  $Hue = 160

Case $r = $g ;red==green, ANY blue value
  $Hue = 40

Case $r = $b And $g > $b;red=blue, green largest
  $Hue = 80

Case $r = $b And $g < $b;red=blue, green smallest
  $Hue = 200

Case $g = $b And $r > $g;green=blue, red largest
  $Hue = 0

Case $g = $b And $r < $g;green=blue, red smallest
  $Hue = 120

Case Else
 ; use result from algorithm at the website....

EndSelect

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Josbe

Interesting, CyberS. Thxs :huh2:

I'll try it! :D

Actually, I was using this (from another site):

var_R = ( R / 255 )                     //RGB values = From 0 to 255
var_G = ( G / 255 )
var_B = ( B / 255 )

var_Min = min( var_R, var_G, var_B )    //Min. value of RGB
var_Max = max( var_R, var_G, var_B )    //Max. value of RGB
del_Max = var_Max - var_Min             //Delta RGB value

L = ( var_Max + var_Min ) / 2

if ( del_Max == 0 )                     //This is a gray, no chroma...
{
   H = 0                                //HSL results = From 0 to 1
   S = 0
}
else                                    //Chromatic data...
{
   if ( L < 0.5 ) S = del_Max / ( var_Max + var_Min )
   else           S = del_Max / ( 2 - var_Max - var_Min )

   del_R = ( ( ( var_Max - var_R ) / 6 ) + ( del_Max / 2 ) ) / del_Max
   del_G = ( ( ( var_Max - var_G ) / 6 ) + ( del_Max / 2 ) ) / del_Max
   del_B = ( ( ( var_Max - var_B ) / 6 ) + ( del_Max / 2 ) ) / del_Max

   if      ( var_R == var_Max ) H = del_B - del_G
   else if ( var_G == var_Max ) H = ( 1 / 3 ) + del_R - del_B
   else if ( var_B == var_Max ) H = ( 2 / 3 ) + del_G - del_R

   if ( H < 0 ); H += 1
   if ( H > 1 ); H -= 1
}

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.