TommyDDR Posted August 5, 2020 Posted August 5, 2020 (edited) Hello, i'm dealing with GDIPlus and i would like to know if i'm doing something wrong or if it's simply GDIPlus calls speed limits : expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include "./include/2d.au3" Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $gui Global $taille[2] = [400, 400] Global $hBackbuffer = _createCanvas($taille[0], $taille[1]) GUISetOnEvent($GUI_EVENT_CLOSE, quit, $2d_Gui) Global $pos = 0 While 1 Local $tim = TimerInit() loop() ConsoleWrite(TimerDiff($tim) & @CRLF) WEnd Func loop() Local $width = 2 For $y = 0 To $taille[1] - 1 Step $width For $x = 0 To $taille[0] - 1 Step $width Local $r = ($x / $taille[0]) * 255 Local $b = ($y / $taille[1]) * 255 Local $color = rgbToRGB($r, Random(0, 255, 1), $b) Local $brush = _GDIPlus_BrushCreateSolid($color) _GDIPlus_GraphicsFillRect($hBackbuffer, $x, $y, $width, $width, $brush) _GDIPlus_BrushDispose($brush) Next Next _show() EndFunc Func rgbToRGB($r, $g, $b) Return BitOR(BitShift(255, -24), BitShift($r, -16), BitShift($g, -8), $b) EndFunc Func quit() Exit EndFunc #include <GDIPlus.au3> #include <WindowsConstants.au3> #include-once _GDIPlus_Startup() Global $2d_Gui Global $2d_hGraphic Global $2d_hBitmap Global $2d_hBackBuffer Global $2d_width Global $2d_height OnAutoItExitRegister(_freeRessources) Func _createCanvas($width, $height) $2d_width = $width $2d_height = $height $2d_Gui = GUICreate("", $width, $height, Default, Default, $WS_POPUP) GUISetState(@SW_SHOW, $2d_Gui) $2d_hGraphic = _GDIPlus_GraphicsCreateFromHWND($2d_Gui) $2d_hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $2d_hGraphic) $2d_hBackBuffer = _GDIPlus_ImageGetGraphicsContext($2d_hBitmap) Return $2d_hBackBuffer EndFunc Func _show() _GDIPlus_GraphicsDrawImageRect($2d_hGraphic, $2d_hBitmap, 0, 0, $2d_width, $2d_height) EndFunc Func _freeRessources() _GDIPlus_GraphicsDispose($2d_hBackBuffer) _GDIPlus_BitmapDispose($2d_hBitmap) _GDIPlus_GraphicsDispose($2d_hGraphic) _GDIPlus_Shutdown() EndFunc I only have 1 image per 2.3sec (40 000 brush created, fill rect, brush diposed per loop) Edited August 5, 2020 by TommyDDR Code color _GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Nine Posted August 5, 2020 Posted August 5, 2020 I tested with a different approach, using a struct of 400*400 pixels. Filling the structure pixel by pixel like you did, and saving the result into file using _GDIPlus_BitmapCreateFromScan0 / _GDIPlus_ImageSaveToFile function. Result 1.2 sec. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Nine Posted August 5, 2020 Posted August 5, 2020 With a little optimization, I was able to get result under 1 sec (~0.94 sec). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
TommyDDR Posted August 6, 2020 Author Posted August 6, 2020 Thank you for your reply. Can you post the code here ? _GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Nine Posted August 6, 2020 Posted August 6, 2020 There : expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <GDIPlus.au3> Global $size = 400 Global $__g_tStruct, $__g_tString, $__g_iWidth, $__g_iHeight _GDIPlus_Startup() _GetScreen_Initialize($size, $size) $timer = TimerInit() loop() ConsoleWrite(TimerDiff($timer) & @CRLF) $2d_Gui = GUICreate("", $size, $size, Default, Default, $WS_POPUP) GUISetState(@SW_SHOW, $2d_Gui) $2d_hGraphic = _GDIPlus_GraphicsCreateFromHWND($2d_Gui) $2d_hBitmap =_GetScreen_GetBitMap() $2d_hBackBuffer = _GDIPlus_ImageGetGraphicsContext($2d_hBitmap) _GDIPlus_GraphicsDrawImageRect($2d_hGraphic, $2d_hBitmap, 0, 0, $size, $size) While True If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop WEnd _GDIPlus_GraphicsDispose($2d_hBackBuffer) _GDIPlus_BitmapDispose($2d_hBitmap) _GDIPlus_GraphicsDispose($2d_hGraphic) ;_GetScreen_SaveFile("Test.jpg") ;ConsoleWrite(TimerDiff($timer) & @CRLF) _GDIPlus_Shutdown() Func loop() Local $width = 2, $r, $b, $color For $y = 0 To $size - 1 Step $width $b = Int(($y / $size) * 255) For $x = 0 To $size - 1 Step $width $r = Int(($x / $size) * 255) $color = rgbToRGB($r, Random(0, 255, 1), $b) ;ConsoleWrite (Hex($color) & @CRLF) _GetScreen_SetPixelEX($x, $y, $color) _GetScreen_SetPixelEX($x + 1, $y, $color) _GetScreen_SetPixelEX($x, $y + 1, $color) _GetScreen_SetPixelEX($x + 1, $y + 1, $color) Next Next EndFunc ;==>loop Func rgbToRGB($r, $g, $b) Return Dec("FF" & Hex($r, 2) & Hex($g, 2) & Hex($b, 2)) EndFunc ;==>rgbToRGB Func _GetScreen_SetPixelEX($iX, $iY, $iValue) DllStructSetData($__g_tStruct, "color", $iValue, ($iY * $__g_iWidth) + $iX + 1) EndFunc ;==>_GetScreen_SetPixel Func _GetScreen_Initialize($iWidth, $iHeight) $__g_iWidth = $iWidth $__g_iHeight = $iHeight $__g_tStruct = DllStructCreate("int color [" & $iWidth * $iHeight & "]") EndFunc ;==>_GetScreen_Initialize Func _GetScreen_GetBitMap() Return _GDIPlus_BitmapCreateFromScan0($__g_iWidth, $__g_iHeight, $GDIP_PXF32ARGB, $__g_iWidth * 4, DllStructGetPtr($__g_tStruct, "color")) EndFunc ;==>_GetScreen_GetBitMap I extracted the _GetScreen_* functions from a personal (unpublished) UDF that I made to fast capture part of the screen. InnI 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now