Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Created April 2, 2015 22:55
Show Gist options
  • Save G33kDude/b59b47c5391c4a974745 to your computer and use it in GitHub Desktop.
Save G33kDude/b59b47c5391c4a974745 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