Skip to content

Instantly share code, notes, and snippets.

@nweddle
Forked from G33kDude/XKCLOUD.ahk
Last active August 29, 2015 14:18
Show Gist options
  • Save nweddle/a430c81a31ae3bec3cb9 to your computer and use it in GitHub Desktop.
Save nweddle/a430c81a31ae3bec3cb9 to your computer and use it in GitHub Desktop.
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
SetMouseDelay, 2
CoordMode, Mouse, Screen
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, ExitSub
return
^+x::
MouseGetPos, StartX, StartY
FileSelectFile, FilePath
pBitmap := Gdip_CreateBitmapFromFile(FilePath)
Width := Gdip_GetImageWidth(pBitmap)
Height := Gdip_GetImageHeight(pBitmap)
Gdip_LockBits(pBitmap, x, y, Width, Height, Stride, Scan0, BitmapData)
n := 2
StartX += (445-Width*n)/2
StartY += (330-Height*n)/2
Loop, %Height%
{
y := A_Index - 1
Loop, %Width%
{
x := A_Index - 1
ARGB := Gdip_GetLockBitPixel(Scan0, x, y, Stride)
Average := Round(((ARGB>>16&0xFF) + (ARGB>>8&0xFF) + (ARGB&0xFF)) / 3)
Gdip_SetLockBitPixel(Average, Scan0, x, y, Stride)
}
}
Loop, %Height%
{
y := A_Index - 1
Loop, %Width%
{
x := A_Index - 1
Shade := Gdip_GetLockBitPixel(Scan0, x, y, Stride)
NewShade := Shade > 0x7F ? 0xFF : 0
Error := Shade - NewShade
ShiftLockBitPixel(Error * 7/16, Scan0, x+1, y, Stride, Width, Height)
ShiftLockBitPixel(Error * 3/16, Scan0, x-1, y+1, Stride, Width, Height)
ShiftLockBitPixel(Error * 5/16, Scan0, x, y+1, Stride, Width, Height)
ShiftLockBitPixel(Error * 1/16, Scan0, x+1, y+1, Stride, Width, Height)
if NewShade
MouseClick, Left, StartX+x*n, StartY+y*n, 1, 0
}
}
Gdip_UnlockBits(pBitmap, BitmapData)
Gdip_DisposeImage(pBitmap)
return
ExitSub:
Gdip_Shutdown(pToken)
ExitApp
Return
ShiftLockBitPixel(Offset, Scan0, x, y, Stride, w, h)
{
if (x < 0 || x >= w || y >= h || y < 0)
return
Pixel := Gdip_GetLockBitPixel(Scan0, x, y, Stride)
Gdip_SetLockBitPixel(Clamp(Pixel+Offset, 0, 0xFF), Scan0, x, y, Stride)
}
Clamp(Var, Min, Max)
{
return Var < Min ? Min : Var > Max ? Max : Var
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment