Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Created May 13, 2015 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save G33kDude/348e094c6a94c7e17e5c to your computer and use it in GitHub Desktop.
Save G33kDude/348e094c6a94c7e17e5c to your computer and use it in GitHub Desktop.
#NoEnv
SetBatchLines, -1
Input := Clipboard
Input := StrSplit(Input, "`n", "`r")
Size := StrSplit(Input.Remove(1), " ")
Scale := 5
Gui, +hWndhWnd
Gui, Show, % "w" Size.1 * Scale "h" Size.2 * Scale
hDC := DllCall("GetDC", "UPtr", hWnd, "UPtr")
hMemDC := DllCall("CreateCompatibleDC", "UPtr", hDC, "UPtr")
hBitmap := DllCall("CreateCompatibleBitmap", "UPtr", hDC, "Int", Size.1 * Scale, "Int", Size.2 * Scale, "UPtr")
DllCall("SelectObject", "UPtr", hMemDC, "UPtr", hBitmap)
for i, Note in Input
{
Note := StrSplit(Note, " ")
Input[i] := Note
if Note.1 > Highest
Highest := Note.1
}
Shades := {0: 0}
for each, Note in Input
{
Shade := Round(Note.1 / Highest * 0xFF)
Shades[Shade] := Note.1
hBrush := DllCall("CreateSolidBrush", "UInt", Shade, "UPtr")
hPen := DllCall("CreatePen", "Int", 0, "Int", 1, "UInt", Shade, "UPtr")
DllCall("SelectObject", "UPtr", hMemDC, "UPtr", hBrush, "UPtr")
DllCall("SelectObject", "UPtr", hMemDC, "UPtr", hPen, "UPtr")
DllCall("Rectangle", "UPtr", hMemDC
, "Int", Note.2 * Scale, "Int", Note.3 * Scale
, "Int", (Note.2+Note.4) * Scale, "Int", (Note.3+Note.5) * Scale)
DllCall("DeleteObject", "UPtr", hBrush)
DllCall("DeleteObject", "UPtr", hPen)
}
OnMessage(0xF, "WM_PAINT")
WM_PAINT()
Count := []
Loop, % Size[1]
{
x := A_Index-1
Loop, % Size[2]
{
y := A_Index-1
Shade := DllCall("GetPixel", "UPtr", hDC, "Int", x*Scale, "Int", y*scale)
Color := Shades[Shade]
Count[Color] := Round(Count[Color]) + 1
}
}
for Color, Amount in Count
Out .= Color " " Amount "`n"
MsgBox, % Out
return
GuiClose:
ExitApp
return
WM_PAINT()
{
Global
DllCall("BitBlt", "UPtr", hDC, "Int", 0, "Int", 0
, "Int", Size.1 * Scale, "Int", Size.2 * Scale, "UPtr", hMemDC
, "Int", 0, "Int", 0, "UInt", 0xCC0020) ;SRCCOPY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment