Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Load GDI+
- DllCall("LoadLibrary", "str", "gdiplus")
- VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0) ; sizeof(GdiplusStartupInput) = 16, 24
- , NumPut(0x1, si, "uint")
- DllCall("gdiplus\GdiplusStartup", "ptr*", pToken:=0, "ptr", &si, "ptr", 0)
- Loop 1000 {
- QPC(1)
- pBitmap := from_screenshot0()
- old += QPC()
- DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap)
- ; ------------------
- QPC(1)
- pBitmap := from_screenshot1()
- new += QPC()
- DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap)
- }
- if (old > new)
- winner := "New Version wins by " old - new " and is " Abs(old - new)/new*100 "% faster."
- else
- winner := "Old Version wins by " new - old " and is " Abs(old - new)/old*100 "% faster."
- MsgBox % "Old Version:`t" old "`nNew Version:`t" new "`n" winner
- return
- Esc:: ExitApp
- QPC( R := 0 ) { ; By SKAN, http://goo.gl/nf7O4G, CD:01/Sep/2014 | MD:01/Sep/2014
- Static P := 0, F := 0, Q := DllCall( "QueryPerformanceFrequency", "Int64P",F )
- Return ! DllCall( "QueryPerformanceCounter","Int64P",Q ) + ( R ? (P:=Q)/F : (Q-P)/F )
- }
- from_screenshot0() {
- image := [0,0,A_ScreenWidth,A_ScreenHeight]
- ; struct BITMAPINFOHEADER - https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
- hdc := DllCall("CreateCompatibleDC", "ptr", 0, "ptr")
- VarSetCapacity(bi, 40, 0) ; sizeof(bi) = 40
- , NumPut( 40, bi, 0, "uint") ; Size
- , NumPut( image[3], bi, 4, "uint") ; Width
- , NumPut(-image[4], bi, 8, "int") ; Height - Negative so (0, 0) is top-left.
- , NumPut( 1, bi, 12, "ushort") ; Planes
- , NumPut( 32, bi, 14, "ushort") ; BitCount / BitsPerPixel
- hbm := DllCall("CreateDIBSection", "ptr", hdc, "ptr", &bi, "uint", 0, "ptr*", pBits:=0, "ptr", 0, "uint", 0, "ptr")
- obm := DllCall("SelectObject", "ptr", hdc, "ptr", hbm, "ptr")
- ; Retrieve the device context for the screen.
- sdc := DllCall("GetDC", "ptr", 0, "ptr")
- ; Copies a portion of the screen to a new device context.
- DllCall("gdi32\BitBlt"
- , "ptr", hdc, "int", 0, "int", 0, "int", image[3], "int", image[4]
- , "ptr", sdc, "int", image[1], "int", image[2], "uint", 0x00CC0020) ; SRCCOPY
- ; Release the device context to the screen.
- DllCall("ReleaseDC", "ptr", 0, "ptr", sdc)
- ; Convert the hBitmap to a Bitmap using a built in function as there is no transparency.
- DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "ptr", hbm, "ptr", 0, "ptr*", pBitmap:=0)
- ; Cleanup the hBitmap and device contexts.
- DllCall("SelectObject", "ptr", hdc, "ptr", obm)
- DllCall("DeleteObject", "ptr", hbm)
- DllCall("DeleteDC", "ptr", hdc)
- return pBitmap
- }
- from_screenshot1() {
- image := [0,0,A_ScreenWidth,A_ScreenHeight]
- ; struct BITMAPINFOHEADER - https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
- hdc := DllCall("CreateCompatibleDC", "ptr", 0, "ptr")
- VarSetCapacity(bi, 40, 0) ; sizeof(bi) = 40
- , NumPut( 40, bi, 0, "uint") ; Size
- , NumPut( image[3], bi, 4, "uint") ; Width
- , NumPut(-image[4], bi, 8, "int") ; Height - Negative so (0, 0) is top-left.
- , NumPut( 1, bi, 12, "ushort") ; Planes
- , NumPut( 32, bi, 14, "ushort") ; BitCount / BitsPerPixel
- hbm := DllCall("CreateDIBSection", "ptr", hdc, "ptr", &bi, "uint", 0, "ptr*", pBits:=0, "ptr", 0, "uint", 0, "ptr")
- obm := DllCall("SelectObject", "ptr", hdc, "ptr", hbm, "ptr")
- ; Retrieve the device context for the screen.
- sdc := DllCall("GetDC", "ptr", 0, "ptr")
- ; Copies a portion of the screen to a new device context.
- DllCall("gdi32\BitBlt"
- , "ptr", hdc, "int", 0, "int", 0, "int", image[3], "int", image[4]
- , "ptr", sdc, "int", image[1], "int", image[2], "uint", 0x00CC0020 | 0x40000000) ; SRCCOPY | CAPTUREBLT
- ; Release the device context to the screen.
- DllCall("ReleaseDC", "ptr", 0, "ptr", sdc)
- ; Convert the hBitmap to a Bitmap using a built in function as there is no transparency.
- DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "ptr", hbm, "ptr", 0, "ptr*", pBitmap:=0)
- ; Cleanup the hBitmap and device contexts.
- DllCall("SelectObject", "ptr", hdc, "ptr", obm)
- DllCall("DeleteObject", "ptr", hbm)
- DllCall("DeleteDC", "ptr", hdc)
- return pBitmap
- }
Add Comment
Please, Sign In to add comment