Jump to content

Pixel Analyzer


cyberbit
 Share

Recommended Posts

Hi all,

I joined AutoIt yesterday and I'm loving it right now. To learn the interface I developed a quick little utility that I've been wanting for a while. It collects pixel data based on cursor location (mainly position and color). I hope this is useful to some people. More information in the script. The splash won't load on your end; I didn't have time to zip it. :D

#cs
=========Pixel Analyzer 1.0=========
= Programmed by D.J. Marcolesco =
= Copyright Plexa.Bit Games 2012 =
=----------------------------------=
= Usage: =
= The left dialog displays =
= the color under the hotpoint of =
= the cursor. =
= =
= The right dialog contains two =
= radio buttons, two standard =
= buttons, and several labels. =
= =
= RGB and hex color data are =
= represented, as well as the =
= current cursor coordinates. A =
= mouse-stalking tooltip displays =
= coordinates and the hex color. =
= =
= Inbuilt Copy and Lock funcs =
= are hotlinked to Ctrl + C and =
= Ctrl + L for convenience. =
= =
= The Copy function formats the =
= data for ease of use. "Locking" =
= will bypass the data parsing =
= loop to allow even further color =
= examination. =
= =
= The "Deflicker" option does =
= several things for the script. =
= Mainly, it eliminates annoying =
= flicker in the Data GUI (from =
= constant refreshing of labels). =
= It also tends to free up CPU, as =
= less time is spent churning the =
= parsing loop. =
= =
= I hope you find this small =
= script useful. Please comment! =
= The code isn't the prettiest, =
= but I did make this in about a =
= day. ^.^ Loving AutoIt! =
= =
= Regards, =
= D.J. Marcolesco (cyberbit) =
====================================
#ce

;Covering all my bases XD
#include 
#include 
#include 
#include 
#include 
Global $deflicker ;Sets whether or not the mouse must move before a pixel parse (also serves as an asthetic fold separator >.<)

;===============
;===Variables===
;===============

Local $pos
Local $col
Local $mx, $my
Local $X, $Y
Local $colgui, $datagui
Local $enrad, $disrad
Local $tip
Local $R, $G, $B, $H
Local $Rv, $Gv, $Bv, $Hv
Local $copybtn, $lockbtn
Local $escape = False
Local $lock = False
Local $mousemoved = True

;===================
;===Preliminaries===
;===================

;===File Stuff===
FileInstall("pixanal.png", "splash.png")
FileSetAttrib("splash.png", "+RASH")

;===Splash===
;SplashImageOn("Pixel Analyzer - By Plexa.Bit Games", "splash.png", 500, 500)
;Sleep(3500)
;SplashOff()

;===GUIs===
$colgui = GUICreate("Color", 50, 50, 15, 15, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$datagui = GUICreate("Data", 210, 50, 92, 15, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

;===Hot Keys===
HotKeySet("^l", "ToggleLock")
HotKeySet("^c", "CopyData")

;===Controls===

;Radio Buttons
$enrad = GUICtrlCreateRadio("Enable Tooltip", 5, 5)
$disrad = GUICtrlCreateRadio("Disable Tooltip", 5, 25)

;Labels
$R = GUICtrlCreateLabel("R:", 97, 3)
$G = GUICtrlCreateLabel(" G:", 94, 18)
$B = GUICtrlCreateLabel("B:", 97, 33)
$Rv = GUICtrlCreateLabel("255", 111, 3)
$Gv = GUICtrlCreateLabel("255", 111, 18)
$Bv = GUICtrlCreateLabel("255", 111, 33)
$H = GUICtrlCreateLabel("Hex:", 140, 3)
$Hv = GUICtrlCreateLabel("FFFFFF", 165, 3)
$pos = GUICtrlCreateLabel(" x: 9999 y: 9999", 132, 16)

;Buttons
$copybtn = GUICtrlCreateButton("Copy", 132, 30, Default, 19)
$lockbtn = GUICtrlCreateButton("Lock", 166, 30, 42, 19)

;===Stateage===

;GUIs
GUISetState(@SW_SHOW, $colgui)
GUISetState(@SW_SHOW, $datagui)

;Controls
GUICtrlSetState($enrad, $GUI_CHECKED)

;===============
;===Functions===
;===============

Func ToggleLock()
_GUICtrlButton_Click($lockbtn)
EndFunc
Func CopyData()
_GUICtrlButton_Click($copybtn)
EndFunc

;===============
;===Scripting===
;===============

MsgBox(0x40, "Info", "Place cursor in upper left hand corner of screen to abort. Ctrl+L will lock the data, Ctrl+C will copy the data", 7)

Local $flickeropt = MsgBox(0x40024, "Setting", "Deflicker?")

If $flickeropt = 6 Then ;Yes button clicked
$deflicker = True
ElseIf $flickeropt = 7 Then ;No button clicked
$deflicker = False
EndIf

;===Main Loop===
Do
Local $msg = GUIGetMsg() ;Get event from GUI

Switch $msg ;Parse GUI events
Case $lockbtn ;Lock button was pressed
If GUICtrlRead($lockbtn) = "Lock" Then
$lock = True
GUICtrlSetData($lockbtn, "Unlock")
ElseIf GUICtrlRead($lockbtn) = "Unlock" Then
$lock = False
GUICtrlSetData($lockbtn, "Lock")
EndIf
Case $copybtn ;Copy button was pressed
;===Format===
;Pixel Analyzer - Color @ x, y:
;Hex: 000000-FFFFFF
;R: 0-255
;G: 0-255
;B: 0-255
;Time: hh:mm:ss
Local $copy = "Pixel Analyzer - Color @ " & $mx & ", " & $my & ":" & @CRLF & "Hex: " & Hex($col, 6) & @CRLF & "R: " & GUICtrlRead($Rv) & @CRLF & "G: " & GUICtrlRead($Gv) & @CRLF & "B: " & GUICtrlRead($Bv) & @CRLF & "Time: " & _Date_Time_SystemTimeToTimeStr(_Date_Time_GetLocalTime())
ClipPut($copy) ;Put that big fat String into the system clipboard
EndSwitch

;If the user doesn't mind flicker, the GUI will parse pixels without limit
;If the user minds flicker, the GUI will parse pixels ONLY when the mouse changes position.
If $deflicker = True Then
If (MouseGetPos(0) = $mx) And (MouseGetPos(1) = $my) Then
$mousemoved = False
Else
$mousemoved = True
EndIf
EndIf

;Get mouse coordinates
$mx = MouseGetPos(0)
$my = MouseGetPos(1)

;Set the label data
If $lock = False AND $mousemoved = True Then
$col = PixelGetColor($mx, $my) ;Get the pixel color under cursor
GUICtrlSetData($Rv, _ColorGetRed($col))
GUICtrlSetData($Gv, _ColorGetGreen($col))
GUICtrlSetData($Bv, _ColorGetBlue($col))
GUICtrlSetData($Hv, Hex($col, 6)) ;Parse 8-digit hex value to 6-digit color
GUICtrlSetData($pos, " x: " & $mx & " y: " & $my)
GUISetBkColor($col, $colgui) ;Set background of color GUI to pixel color
EndIf

;Disable/enable tooltip based on radio buttons
If GUICtrlRead($enrad) = $GUI_CHECKED AND $mousemoved = True Then
If $lock = False Then
$tip = ToolTip("x: " & $mx & " y: " & $my & " c: " & Hex($col, 6), Default, Default, Default, Default, 4)
Else
ToolTip("") ;Hide tooltips
EndIf
ElseIf GUICtrlRead($disrad) = $GUI_CHECKED Then
ToolTip("")
EndIf

;Abort script if mouse is moved to upper-left corner of display
If $mx = 0 AND $my = 0 Then
$tip = ToolTip("")
Local $abort = MsgBox(0x40024, "Abort called", "Abort?")
If $abort = 6 Then $escape = True
EndIf
Until $escape = True ;Run main loop until and abort operation is called (i.e.; $escape = True)

Regards,

D.J. Marcolesco (cyberbit)

_ArrayConcatenate2D · Aero Flip 3D · EPOCH (destroy timestamps) · File Properties Modifier · _GetFileType · UpdateEngine<new> · In-line Case (_ICase) <new>

[hr]

50% of the time, it works all the time. -PezoFaSho

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...