Jump to content
Sign in to follow this  
spudw2k

Plasma_kIt

Recommended Posts

spudw2k

Here's a fun tool I put together.  It's a Plasma sandbox.  More features to come.

This page was a useful resource for learning about this kind of Plasma implementation.

Warning! Not Epileptic Friendly (probably)! Use at own Risk!
I tried to curve the "default/initial" Plasma patterns so they aren't too erratic.  That doesn't mean you can't alter the Plasmas to be more erratic.  If you are sensitive to flashing colors and lights, use due caution.  

#Region - Includes and Globals
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <Misc.au3>

;#include <Array.au3>

Opt("GUIOnEventMode", 1)
Local $hDLL = DllOpen("user32.dll")

Global Const $iWinMinWidth = @DesktopWidth * .25
Global Const $iWinMinHeight = @DesktopHeight * .25
Global $bIsPlaying = True, $bIsDrawing = False
Global $hTimerFPS
Global $iRows = 16, $iCols = 16
Global $iDisplayPlasma = 0, $iSelectPlasma = 0

Global $aPlasmaShapes[4] = ["($iX)", "($iY)", "($iX + $iY)", "Sqrt(($iX * $iX) + ($iY * $iY))"]
;~ Global $aPlasmas[4][7] = [[0, Random(6, 14, 1), 0, 0, 1, 0, 0], [1, Random(6, 14, 1), 0, 0, 0, 0, 0], [2, Random(8, 16,1 ), 0, 0, 1, 0, 0], [3, Random(8, 16, 1), 0, 0, Random(0,1,1), 0, 0]] ;Sine Wave | Spread | Position | Rotation | Spread Motion | Position Motion | Rotation Motion
Global $aPlasmas[4][7] = [[0, Random(6, 14, 1), 0, 0, 0, 0, 0], [1, Random(6, 14, 1), 0, 0, 0, 0, 0], [2, Random(8, 16,1 ), 0, 0, 0, 0, 0], [3, Random(8, 16, 1), 0, 0, 0, 0, 0]] ;Sine Wave | Spread | Position | Rotation | Spread Motion | Position Motion | Rotation Motion

Global $aPallete[256]
Global $aPalleteSettings[3][3] = [[0, 128, 128], [-1.75, 128, 128], [1.75, 128, 128]] ;Position | Spread | Value
Global $aPalleteDefaults = $aPalleteSettings
Global $iPalleteShift = 0, $bPalleteShift = True, $iPalletShiftDirection = -5
#EndRegion - Includes and Globals
#Region - Main GUI
Global $aGUI[1] = ["id|hWnd"]
Global Enum $hGUI = 1, $idMnuFile, $idMnuFileExit, $idMnuFilePlay, $idMnuOptions, $idMnuOptionsPallete, $idMnuOptionsPalleteShift, $idMnuOptionsEditor, $idMnuOptionsZoom, $idMnuOptionsZoomIn, $idMnuOptionsZoomOut, $iGUILast
ReDim $aGUI[$iGUILast]
Global Const $sVersion = "0.1"
Global Const $sTitle = "Plasma_kIt - Version " & $sVersion

$aGUI[$hGUI] = GUICreate($sTitle, $iWinMinWidth, $iWinMinHeight, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$aGUI[$idMnuFile] = GUICtrlCreateMenu("&File")
$aGUI[$idMnuFilePlay] = GUICtrlCreateMenuItem("&Pause", $aGUI[$idMnuFile])
GUICtrlSetOnEvent(-1, "_PlayToggle")
$aGUI[$idMnuFileExit] = GUICtrlCreateMenuItem("E&xit", $aGUI[$idMnuFile])
GUICtrlSetOnEvent(-1, "_Exit")
$aGUI[$idMnuOptions] = GUICtrlCreateMenu("&Options")
$aGUI[$idMnuOptionsPallete] = GUICtrlCreateMenuItem("Pallete Mixer", $aGUI[$idMnuOptions])
GUICtrlSetOnEvent(-1, "_GUIPallete_Show")
$aGUI[$idMnuOptionsPalleteShift] = GUICtrlCreateMenuItem("Pallete Shift", $aGUI[$idMnuOptions])
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetOnEvent(-1, "_GUIPallete_ShiftToggle")
$aGUI[$idMnuOptionsEditor] = GUICtrlCreateMenuItem("Plasma Editor", $aGUI[$idMnuOptions])
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_Show")
$aGUI[$idMnuOptionsZoom] = GUICtrlCreateMenu("Zoom", $aGUI[$idMnuOptions])
$aGUI[$idMnuOptionsZoomIn] = GUICtrlCreateMenuItem("Zoom In" & @TAB & "+", $aGUI[$idMnuOptionsZoom])
GUICtrlSetOnEvent(-1, "_Zoom")
$aGUI[$idMnuOptionsZoomOut] = GUICtrlCreateMenuItem("Zoom Out" & @TAB & "-", $aGUI[$idMnuOptionsZoom])
GUICtrlSetOnEvent(-1, "_Zoom")
_GDIPlus_Startup() ;Start GDI+ UDF
Global Const $hDC = _WinAPI_GetDC($aGUI[$hGUI])
Global Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, @DesktopWidth, @DesktopHeight)
Global Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC)
Global Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap)
$hBackbuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer)
;_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)
$hBrush = _GDIPlus_BrushCreateSolid(0x00000000) ;Brush for Coloring/Painting LED Pixels

Local $aAccelKeys[5][2] = [["{+}", $aGUI[$idMnuOptionsZoomIn]], ["{NUMPADADD}", $aGUI[$idMnuOptionsZoomIn]], ["{-}", $aGUI[$idMnuOptionsZoomOut]], ["{NUMPADSUB}", $aGUI[$idMnuOptionsZoomOut]], ["{pause}", $aGUI[$idMnuFilePlay]]]
GUISetAccelerators($aAccelKeys)
#EndRegion - Main GUI
#Region - Pallete Mixer GUI
Global $aGUIPallete[1] = ["id|hWnd"]
Global Enum $hGUIPallete = 1, $idSliderRPosition, $idSliderRValue, $idSliderRSpread, $idSliderGPosition, $idSliderGValue, _
        $idSliderGSpread, $idSliderBPosition, $idSliderBValue, $idSliderBSpread, $idBtnResetPallete, $iGUIPalleteLast
ReDim $aGUIPallete[$iGUIPalleteLast]
$aGUIPallete[$hGUIPallete] = GUICreate("Pallete Mixer", 338, 260, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIPallete_Hide")
$aGUIPallete[$idSliderRPosition] = GUICtrlCreateSlider(8, 132, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 20, -20)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
$aGUIPallete[$idSliderRValue] = GUICtrlCreateSlider(48, 56, 33, 73, BitOR($TBS_VERT, $TBS_ENABLESELRANGE))
GUICtrlSetLimit(-1, 128, 0)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
$aGUIPallete[$idSliderRSpread] = GUICtrlCreateSlider(8, 168, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 24, 2)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")

$aGUIPallete[$idSliderGPosition] = GUICtrlCreateSlider(120, 132, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 20, -20)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
$aGUIPallete[$idSliderGValue] = GUICtrlCreateSlider(160, 56, 33, 73, BitOR($TBS_VERT, $TBS_ENABLESELRANGE))
GUICtrlSetLimit(-1, 128, 0)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
$aGUIPallete[$idSliderGSpread] = GUICtrlCreateSlider(120, 168, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 24, 2)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")

$aGUIPallete[$idSliderBPosition] = GUICtrlCreateSlider(232, 132, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 20, -20)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
GUICtrlSetData(-1, 9)
$aGUIPallete[$idSliderBValue] = GUICtrlCreateSlider(272, 56, 33, 73, BitOR($TBS_VERT, $TBS_ENABLESELRANGE))
GUICtrlSetLimit(-1, 128, 0)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")
$aGUIPallete[$idSliderBSpread] = GUICtrlCreateSlider(232, 168, 97, 33, $TBS_ENABLESELRANGE)
GUICtrlSetLimit(-1, 24, 2)
GUICtrlSetData(-1, 11)
;~ GUICtrlSetOnEvent(-1, "_GUIPallete_SettingsChange")

GUICtrlCreateLabel("RED", 46, 200, 30, 20)
GUICtrlCreateLabel("GREEN", 150, 200, 38, 20)
GUICtrlCreateLabel("BLUE", 268, 200, 30, 20)
$aGUIPallete[$idBtnResetPallete] = GUICtrlCreateButton("Reset", 136, 236, 67, 17)
GUICtrlSetOnEvent(-1, "_GUIPallete_Reset")

GUISetAccelerators($aAccelKeys)

Global Const $hDCPallete = _WinAPI_GetDC($aGUIPallete[$hGUIPallete])
Global Const $hHBitmapPallete = _WinAPI_CreateCompatibleBitmap($hDCPallete, 320, 40)
Global Const $hDC_backbufferPallete = _WinAPI_CreateCompatibleDC($hDCPallete)
Global Const $DC_objPallete = _WinAPI_SelectObject($hDC_backbufferPallete, $hHBitmapPallete)
Global Const $hBackbufferPallete = _GDIPlus_GraphicsCreateFromHDC($hDC_backbufferPallete)
Global $hBrushPallete = _GDIPlus_BrushCreateSolid(0xFF000000)
;~ _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)
_GUIPallete_Update()
_GUIPallete_Reset()
#EndRegion - Pallete Mixer GUI
#Region - Plasma Editor GUI
Global $aGUIPlasmaEditor[1] = ["id|hWnd"]
Global Enum $hGUIPlasmaEditor = 1, $idCmbPlasmaSelector, $idCmbPlasmaDisplay, $idBtnPlasmaAdd, $idBtnPlasmaDel, $idCmbPlasmaShape, $idSliderPlasmaSpread, $idCmbPlasmaSpread, $idSliderPlasmaRotation, $idCmbPlasmaRotation, $idSliderPlasmaPosition, $idCmbPlasmaPosition, $iGUIPlasmaEditorLast
ReDim $aGUIPlasmaEditor[$iGUIPlasmaEditorLast]

$aGUIPlasmaEditor[$hGUIPlasmaEditor] = GUICreate("Plasma Editor", 419, 323, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIPlasmaEditor_Hide")
GUICtrlCreateLabel("Display", 16, 8, 95, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$aGUIPlasmaEditor[$idCmbPlasmaDisplay] = GUICtrlCreateCombo("", 16, 24, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "All Combined|Selected Plasma", "All Combined")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaDisplay")
GUICtrlCreateLabel("Selected Plasma", 24, 96, 120, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$aGUIPlasmaEditor[$idBtnPlasmaAdd] = GUICtrlCreateButton("Add Plasma", 160, 16, 113, 33)
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaAddRem")
GUICtrlSetState(-1, $GUI_DISABLE)
$aGUIPlasmaEditor[$idBtnPlasmaDel] = GUICtrlCreateButton("Remove Plasma", 296, 16, 113, 33)
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaAddRem")
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("Plasma Controls", 8, 64, 401, 249)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$aGUIPlasmaEditor[$idCmbPlasmaSelector] = GUICtrlCreateCombo("", 24, 112, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Plasma #1|Plasma #2|Plasma #3|Plasma #4", "Plasma #1")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaSelect")
GUICtrlCreateLabel("Shape", 174, 96, 35, 17)
$aGUIPlasmaEditor[$idCmbPlasmaShape] = GUICtrlCreateCombo("", 174, 112, 113, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Horizontal|Vertical|Diagonal|Circular", "Horizontal")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaSetShape")
GUICtrlCreateLabel("Spread", 24, 145, 38, 17)
$aGUIPlasmaEditor[$idSliderPlasmaSpread] = GUICtrlCreateSlider(16, 160, 257, 25, $TBS_FIXEDLENGTH)
GUICtrlSetLimit(-1, 255, 5)
$aGUIPlasmaEditor[$idCmbPlasmaSpread] = GUICtrlCreateCombo("", 280, 160, 113, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Static|Oscillate", "Static")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaSetSpread")
GUICtrlCreateLabel("Rotation", 24, 201, 44, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
$aGUIPlasmaEditor[$idSliderPlasmaRotation] = GUICtrlCreateSlider(16, 216, 257, 25, $TBS_FIXEDLENGTH)
GUICtrlSetState(-1, $GUI_DISABLE)
$aGUIPlasmaEditor[$idCmbPlasmaRotation] = GUICtrlCreateCombo("", 280, 216, 113, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Static|Oscillate", "Static")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaSetRotation")
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("Position", 24, 257, 41, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
$aGUIPlasmaEditor[$idSliderPlasmaPosition] = GUICtrlCreateSlider(16, 272, 257, 25, $TBS_FIXEDLENGTH)
GUICtrlSetLimit(-1, 127, -127)
GUICtrlSetState(-1, $GUI_DISABLE)
$aGUIPlasmaEditor[$idCmbPlasmaPosition] = GUICtrlCreateCombo("", 280, 272, 113, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Static|Oscillate", "Static")
GUICtrlSetOnEvent(-1, "_GUIPlasmaEditor_PlasmaSetPosition")
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)

_GUIPlasmaEditor_PlasmaSettingsLoad($iSelectPlasma)
;_GUIPlasmaEditor_PlasmaControlsLock()
GUISetAccelerators($aAccelKeys)
#EndRegion - Plasma Editor GUI
#Region - Initialization and Main Loop
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState(@SW_SHOW, $aGUI[$hGUI])

While 1
    If $bIsPlaying And Not $bIsDrawing Then _DrawScreen(_RenderPlasma())
    Sleep(10)
WEnd
#EndRegion - Initialization and Main Loop
#Region - Main GUI Functions
Func _DrawScreen($aPixels)
    ;If Function called while Drawing Return 0
    If $bIsDrawing Then Return 0
    ;Set Drawing Status Indictaor
    $bIsDrawing = True
    ;Create Timer for Drawing Performance/Duration
    Local $hTimer = TimerInit()
    ;Erase Bitmap Graphic
    _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
    ;Capture Client Window Size
    $aWinClientSize = WinGetClientSize($aGUI[$hGUI])
    ;Setup Variables
    Local $iPixelIndex = 0
    Local $iCol = $iCols
    Local $iRow = $iRows
    Local $iWidth = $aWinClientSize[0] / $iCol
    Local $iHeight = $aWinClientSize[1] / $iRow
    ;Draw Pixel Grid (Top-Left to Bottom Right)
    For $iY = 0 To $iRow - 1
        For $iX = 0 To $iCol - 1
            Local $dARGB = $aPixels[$iPixelIndex]
            ;Set Brush Color
            _GDIPlus_BrushSetSolidColor($hBrush, $dARGB)
            ;Draw "Pixel"
            _GDIPlus_GraphicsFillRect($hBackbuffer, $iX * $iWidth, $iY * $iHeight, $iWidth, $iHeight, $hBrush)
            ;Increment Pixel Counter
            $iPixelIndex += 1
            If $iPixelIndex = UBound($aPixels) Then $iPixelIndex = 0
        Next
    Next
    ;Draw Bitmap to Screen
    _WinAPI_BitBlt($hDC, 0, 0, $aWinClientSize[0], $aWinClientSize[1], $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI
    ;FPS Counter
    $hTimer = TimerDiff($hTimer)
;~  ConsoleWrite("Whole Process time: " & Round($hTimer / 1000, 3) & @CRLF)
    If $bIsPlaying Then
        If TimerDiff($hTimerFPS) >= 998 Then
            Local $iFPS = Round(1000 / $hTimer, 2)
            WinSetTitle($aGUI[$hGUI], "", $sTitle & "  (" & $iFPS & " FPS)  " & $iCols & " x " & $iRows)
            $hTimerFPS = TimerInit()
        EndIf
    Else
        ;Show FPS in Window Title
        WinSetTitle($aGUI[$hGUI], "", $sTitle)
    EndIf
    $bIsDrawing = False
EndFunc   ;==>_DrawScreen

Func _Exit()
    ; Clean up resources
    _GUIPallete_Exit()
    GUIDelete($aGUIPallete[$hGUIPallete])
    GUIDelete($aGUIPlasmaEditor[$hGUIPlasmaEditor])
    GUIDelete($aGUI[$hGUI])
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _WinAPI_SelectObject($hDC, $DC_obj)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_ReleaseDC($hGUI, $hDC)
    _GDIPlus_Shutdown()
    DllClose($hDLL)
    Exit
EndFunc   ;==>_Exit

Func _PlayToggle()
    ;Toggle Play State
    If Not $bIsPlaying Then
        ;Start Playing
        $bIsPlaying = True
        $hTimerFPS = TimerInit()
        GUICtrlSetData($aGUI[$idMnuFilePlay], "&Pause")
    Else
        ;Stop Playing
        $bIsPlaying = False
        GUICtrlSetData($aGUI[$idMnuFilePlay], "&Play")
    EndIf
EndFunc   ;==>_PlayToggle

Func _RenderPlasma()
    ;Setup Variables
    Local $aWorkPallete = $aPallete
    Local $iRow = $iRows
    Local $iCol = $iCols
    Local $iGridSize = $iRow * $iCol
    Local $aPixels[$iGridSize]
    Local $iIndex = 0
    Local $iPlasma = 0
    Local $iPlasmas
    Local $iDisplayPlasmaNumber = $iDisplayPlasma
    Local $iSine, $iSpread, $iPosition
    ;Loop Through Pixel Grid and Calculate Plasma(s)
    For $iY = 0 To $iRow - 1
        For $iX = 0 To $iCol - 1
            $iPlasmas = 0
            If Not $iDisplayPlasmaNumber Then
                For $iZ = 0 To UBound($aPlasmas) - 1
                    $iSine = $aPlasmas[$iZ][0]
                    ;Spread Motions
                    If $aPlasmas[$iZ][4] Then
                        $aPlasmas[$iZ][4] += ($aPlasmas[$iZ][1] * 0.00001125)
                        $iSpread = -7*Sin($aPlasmas[$iZ][4])+9
                    Else
                        $iSpread = $aPlasmas[$iZ][1]
                    EndIf
                    $iPosition = $aPlasmas[$iZ][2]
                    $iPlasma = Execute("128.0 + (128.0 * Sin(" & $aPlasmaShapes[$iSine] & " / " & $iSpread & "))")
                    $iPlasmas += $iPlasma
                Next
            Else
                $iSine = $aPlasmas[$iDisplayPlasmaNumber - 1][0]
                ;Spread Motions
                If $aPlasmas[$iDisplayPlasmaNumber - 1][4] Then
                    $aPlasmas[$iDisplayPlasmaNumber - 1][4] += ($aPlasmas[$iDisplayPlasmaNumber - 1][1] * 0.005)
                    $iSpread = Sin($aPlasmas[$iDisplayPlasmaNumber - 1][4])/2
                Else
                    $iSpread = $aPlasmas[$iDisplayPlasmaNumber - 1][1]
                EndIf
                $iPosition = $aPlasmas[$iDisplayPlasmaNumber - 1][2]
                ;$iPlasmas = Execute("128.0 + (128.0 * Sin(" & $aPlasmaShapes[$aPlasmas[$iDisplayPlasmaNumber - 1][0]] & " / " & $aPlasmas[$iDisplayPlasmaNumber - 1][1] & ") - " & $aPlasmas[$iDisplayPlasmaNumber - 1][2] & ")")
                $iPlasmas = Execute("128.0 + (128.0 * Sin(" & $aPlasmaShapes[$iSine] & " / " & $iSpread & "))")
            EndIf
            $iPlasma = Int($iPlasmas)
            ;Account for Pallete Shift
            $iPlasma += $iPalleteShift
            ;Wrap Pixel Pallete Color
            If $iPlasma >= 256 Then
                Do
                    $iPlasma -= 256
                Until $iPlasma < 256
            EndIf
            If $iPlasma <= -1 Then
                Do
                    $iPlasma += 256
                Until $iPlasma > -1
            EndIf
            ;Set Pixel Color value from Pallete
            $aPixels[$iIndex] = $aWorkPallete[$iPlasma]
            ;Increment Pixel Index Counter
            $iIndex += 1
            If $iIndex = $iGridSize Then $iIndex = 0
        Next
    Next
    ;Pallete Shift Logic
    If $bPalleteShift Then
        $iPalleteShift += $iPalletShiftDirection
        If $iPalleteShift >= 256 Then $iPalleteShift = 0
        If $iPalleteShift <= -1 Then $iPalleteShift = 255
    EndIf

    Return $aPixels
EndFunc   ;==>_RenderPlasma

Func _WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    ;Only Control Size of Main GUI
    If $hwnd <> $aGUI[$hGUI] Then Return Default
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo, 7, $iWinMinWidth) ; min X
    DllStructSetData($tagMaxinfo, 8, $iWinMinHeight) ; min Y
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO

Func _WM_NOTIFY($hwnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    ;Local $tInfo
    If Not _IsPressed("01", $hDLL) Then Return Default

    Switch $iIDFrom
        Case $aGUIPallete[$idSliderRPosition]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(0, -1, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderRValue]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(0, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderRSpread]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(0, -1, "", GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderGPosition]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(1, -1, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderGValue]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(1, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderGSpread]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(1, -1, "", GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderBPosition]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(2, -1, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderBValue]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(2, GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPallete[$idSliderBSpread]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    _GUIPallete_ColorSet(2, -1, "", GUICtrlRead($iIDFrom))
            EndSwitch
            Return 0
        Case $aGUIPlasmaEditor[$idSliderPlasmaSpread]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    $aPlasmas[$iSelectPlasma][1] = 0.2 * GUICtrlRead($iIDFrom)
            EndSwitch
            Return 0
        Case $aGUIPlasmaEditor[$idSliderPlasmaRotation]
            Switch $iCode
                Case $NM_CUSTOMDRAW

            EndSwitch
            Return 0
        Case $aGUIPlasmaEditor[$idSliderPlasmaPosition]
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    $aPlasmas[$iSelectPlasma - 1][2] = GUICtrlRead($iIDFrom)
            EndSwitch
            Return 0
    EndSwitch

    Return 0
EndFunc   ;==>_WM_NOTIFY

Func _Zoom()
    Local $bPlaying = $bIsPlaying
    If $bPlaying Then $bIsPlaying = False
    Local $iCtrlID = @GUI_CtrlId
    Switch $iCtrlID
        Case $aGUI[$idMnuOptionsZoomOut]
            $iCols += 2
            $iRows += 2
            If $iCols >= 4 * 8 Then $iCols = 4 * 8
            If $iRows >= 4 * 8 Then $iRows = 4 * 8
        Case $aGUI[$idMnuOptionsZoomIn]
            $iCols -= 2
            $iRows -= 2
            If $iCols <= 4 Then $iCols = 4
            If $iRows <= 4 Then $iRows = 4
    EndSwitch
    If $bPlaying Then $bIsPlaying = $bPlaying
EndFunc   ;==>_Zoom
#EndRegion - Main GUI Functions
#Region - Pallete Mixer GUI Functions
Func _GUIPallete_ColorSet($iColor, $iValue = -1, $iPosition = "", $iSpread = "")
    If $iValue >= 0 Then $aPalleteSettings[$iColor][2] = (128.0 - $iValue)
    If $iPosition Then $aPalleteSettings[$iColor][0] = (0.25 * $iPosition)
    If $iSpread Then $aPalleteSettings[$iColor][1] = ($iSpread ^ 2)
    Return _GUIPallete_Update()
EndFunc   ;==>_GUIPallete_ColorSet

Func _GUIPallete_Draw()
    ;Draw Color Pallete in Palette Mixer GUI
    _GDIPlus_GraphicsClear($hBackbufferPallete, 0xFF000000)
    Local $iX = 0
    For $iColor = 1 To 256
        Local $dARGB = $aPallete[$iColor - 1]
        ;Set Brush Color
        _GDIPlus_BrushSetSolidColor($hBrushPallete, $dARGB)
        ;Draw Color Bar to Bitmap
        _GDIPlus_GraphicsFillRect($hBackbufferPallete, $iX, 0, 320 / 256, 40, $hBrushPallete)
        $iX += (320 / 256)
    Next
    ;Write Bitmap to Screen
    Return _WinAPI_BitBlt($hDCPallete, 8, 8, 320, 40, $hDC_backbufferPallete, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI
EndFunc   ;==>_GUIPallete_Draw

Func _GUIPallete_Exit()
    ; Clean up resources
    GUIDelete()
    _GDIPlus_BrushDispose($hBrushPallete)
    _GDIPlus_GraphicsDispose($hBackbufferPallete)
    _WinAPI_SelectObject($hDCPallete, $DC_objPallete)
    _WinAPI_DeleteObject($hHBitmapPallete)
    _WinAPI_ReleaseDC($aGUIPallete[$hGUIPallete], $hDCPallete)
    Return 1
EndFunc   ;==>_GUIPallete_Exit

Func _GUIPallete_Hide()
    Return GUISetState(@SW_HIDE, $aGUIPallete[$hGUIPallete])
EndFunc   ;==>_GUIPallete_Hide

Func _GUIPallete_Reset()
    $aPalleteSettings = $aPalleteDefaults
    GUICtrlSetData($aGUIPallete[$idSliderRPosition], $aPalleteSettings[0][0] / 0.25)
    GUICtrlSetData($aGUIPallete[$idSliderRValue], 128 - $aPalleteSettings[0][2])
    GUICtrlSetData($aGUIPallete[$idSliderRSpread], Sqrt($aPalleteSettings[0][1]))
    GUICtrlSetData($aGUIPallete[$idSliderGPosition], $aPalleteSettings[1][0] / 0.25)
    GUICtrlSetData($aGUIPallete[$idSliderGValue], 128 - $aPalleteSettings[1][2])
    GUICtrlSetData($aGUIPallete[$idSliderGSpread], Sqrt($aPalleteSettings[1][1]))
    GUICtrlSetData($aGUIPallete[$idSliderBPosition], $aPalleteSettings[2][0] / 0.25)
    GUICtrlSetData($aGUIPallete[$idSliderBValue], 128 - $aPalleteSettings[2][2])
    GUICtrlSetData($aGUIPallete[$idSliderBSpread], Sqrt($aPalleteSettings[2][1]))
    Return _GUIPallete_Update()
EndFunc   ;==>_GUIPallete_Reset

Func _GUIPallete_ShiftToggle()
    ;Toggle Pallete Shift
    Local $iCtrlState = GUICtrlRead(@GUI_CtrlId)
    If BitAND($iCtrlState, $GUI_CHECKED) Then
        ;Disable PalleteShift
        $bPalleteShift = False
        GUICtrlSetState(@GUI_CtrlId, $GUI_UNCHECKED)
    Else
        ;Enable PalleteShift
        $bPalleteShift = True
        GUICtrlSetState(@GUI_CtrlId, $GUI_CHECKED)
    EndIf
EndFunc   ;==>_GUIPallete_ShiftToggle

Func _GUIPallete_Show()
    GUISetState(@SW_SHOW, $aGUIPallete[$hGUIPallete])
    _GUIPallete_Draw()
EndFunc   ;==>_GUIPallete_Show

Func _GUIPallete_Update()
    ;Re-Calculate Work Color Pallete
    For $iStep = 0 To 255
        Local $iR = Int($aPalleteSettings[0][2] + ($aPalleteSettings[0][2] * Sin((3.1415 * $iStep / $aPalleteSettings[0][1]) - $aPalleteSettings[0][0])))
        Local $iG = Int($aPalleteSettings[1][2] + ($aPalleteSettings[1][2] * Sin((3.1415 * $iStep / $aPalleteSettings[1][1]) - $aPalleteSettings[1][0])))
        Local $iB = Int($aPalleteSettings[2][2] + ($aPalleteSettings[2][2] * Sin((3.1415 * $iStep / $aPalleteSettings[2][1]) - $aPalleteSettings[2][0])))
        $aPallete[$iStep] = "0xFF" & Hex($iR, 2) & Hex($iG, 2) & Hex($iB, 2)
    Next
    Return _GUIPallete_Draw()
EndFunc   ;==>_GUIPallete_Update
#EndRegion - Pallete Mixer GUI Functions
#Region - Plasma Editor GUI Functions
Func _GUIPlasmaEditor_Hide()
    GUISetState(@SW_HIDE, $aGUIPlasmaEditor[$hGUIPlasmaEditor])
EndFunc   ;==>_GUIPlasmaEditor_Hide

Func _GUIPlasmaEditor_PlasmaAddRem()

EndFunc   ;==>_GUIPlasmaEditor_PlasmaAddRem

Func _GUIPlasmaEditor_PlasmaDisplay()
    Local $sSelection = GUICtrlRead($aGUIPlasmaEditor[$idCmbPlasmaDisplay])
    If $sSelection = "All Combined" Then
        $iDisplayPlasma = 0
    Else
        $iDisplayPlasma = _GUICtrlComboBox_GetCurSel($aGUIPlasmaEditor[$idCmbPlasmaSelector])+1
    EndIf
    Return $iDisplayPlasma
EndFunc   ;==>_GUIPlasmaEditor_PlasmaDisplay

Func _GUIPlasmaEditor_PlasmaSelect()
    Local $sSelection = GUICtrlRead($aGUIPlasmaEditor[$idCmbPlasmaSelector])
    $iSelectPlasma = _GUICtrlComboBox_GetCurSel($aGUIPlasmaEditor[$idCmbPlasmaSelector])
    _GUIPlasmaEditor_PlasmaDisplay()
    Return _GUIPlasmaEditor_PlasmaSettingsLoad($iSelectPlasma)
EndFunc   ;==>_GUIPlasmaEditor_PlasmaSelect

Func _GUIPlasmaEditor_PlasmaSetPosition()

EndFunc   ;==>_GUIPlasmaEditor_PlasmaSetPosition

Func _GUIPlasmaEditor_PlasmaSetRotation()

EndFunc   ;==>_GUIPlasmaEditor_PlasmaSetRotation

Func _GUIPlasmaEditor_PlasmaSetShape()
    $aPlasmas[$iSelectPlasma][0] = _GUICtrlComboBox_GetCurSel($aGUIPlasmaEditor[$idCmbPlasmaShape])
EndFunc   ;==>_GUIPlasmaEditor_PlasmaSetShape

Func _GUIPlasmaEditor_PlasmaSetSpread()
    $aPlasmas[$iSelectPlasma][4] = _GUICtrlComboBox_GetCurSel($aGUIPlasmaEditor[$idCmbPlasmaSpread])
EndFunc   ;==>_GUIPlasmaEditor_PlasmaSetSpread

Func _GUIPlasmaEditor_PlasmaSettingsLoad(ByRef $iPlasma)
    GUICtrlSetData($aGUIPlasmaEditor[$idSliderPlasmaSpread],$aPlasmas[$iPlasma][1]/0.2)
    _GUICtrlComboBox_SetCurSel($aGUIPlasmaEditor[$idCmbPlasmaShape],$aPlasmas[$iPlasma][0])
    If $aPlasmas[$iPlasma][4] Then
        _GUICtrlComboBox_SetCurSel($aGUIPlasmaEditor[$idCmbPlasmaSpread],1)
    Else
        _GUICtrlComboBox_SetCurSel($aGUIPlasmaEditor[$idCmbPlasmaSpread],0)
    EndIf
    Return 1
EndFunc   ;==>_GUIPlasmaEditor_PlasmaSettingsLoad

Func _GUIPlasmaEditor_Show()
    GUISetState(@SW_SHOW, $aGUIPlasmaEditor[$hGUIPlasmaEditor])
EndFunc   ;==>_GUIPlasmaEditor_Show
#EndRegion - Plasma Editor GUI Functions

edit: Minor tweaks

Edited by spudw2k
  • Like 2

Share this post


Link to post
Share on other sites
gil900

Looks cool.
It works slow in hgih resolution
I am not surprised, this is probably because Autoit is slow.
Anything related to image processing should not be done in Autoit unless you do it for fun..

This is the first time that I see code that written like my suggestion

Share this post


Link to post
Share on other sites
spudw2k

Thanks.  Yes, unfortunately higher res is much slower. I was considering porting my script at some point to VS2015, but that's going to be a bit of a learning curve for me.

I usually only use "Regions" when my scripts grow very big. I find them useful for organizing code as well.

Share this post


Link to post
Share on other sites
UEZ

I added the ASM code _ASM_DrawRectFilled  to speedup a little bit the draw function:

;coded by UEZ build 2016-02-12
#pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico")
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /pe /rm
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()
Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit, $pBitmap, $hHBitmap
Global Const $iW = 384, $iH = 256, $sTitle = "GDI+ Plasma v5"
Global Const $fPi = ACos(-1)
AutoItSetOption("GUIOnEventMode", 1)

GDIPlus_Plasmav5()

AutoItSetOption("GUIOnEventMode", 0)
_GDIPlus_Shutdown()


Func GDIPlus_Plasmav5()
    $bExit = False
    $hGUI = GUICreate($sTitle, $iW, $iH)
    GUISetState(@SW_SHOW, $hGUI)

    ;create canvas elements
    Local Const $hDC = _WinAPI_GetDC($hGUI)
    Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC)
    Local Const $hHBitmap = _WinAPI_BitmapCreateDIB($iW, $iH, $pBitmap)
    Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap)
    Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer)
;~  _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)

    Local Const $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xF0101010), _
                $hFormat_FPS = _GDIPlus_StringFormatCreate(), _
                $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _
                $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _
                $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 60, 16)

    $iFPS = 0
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About")

    Local $fTime = 0, $iSizeW = 8, $iSizeH = 8, $cx, $cy, $v, $iX, $iY, $f1, $iColor

    Local $tCodeBuffer = DllStructCreate("byte ASM[192]") ;reserve memory for ASM opcodes
    $tCodeBuffer.ASM = "0x8B7424048B7C2408558B6F1831C08B078985A800000083ADA8000000018B47048985AC00000083ADAC000000018B47088985B00000008B470C8985B40000008B47108985B80000008B47148985BC000000E8020000005DC3505351528B9DB00000008B8DB800000031C00385AC0000000385B4000000F7A5BC0000000385B00000000385A8000000890C8683ADB00000000177D4899DB000000083ADB40000000175C55A595B58C3000000000000000000000000000000000000000000000000" ;write opcodes into memory (struct) / length: 192
    Local $tRect = DllStructCreate("dword iPosX;dword iPosY;dword iW; dword iH;dword ARGB;dword iWidth;dword iBase")
    $tRect.iW = $iSizeW
    $tRect.iH = $iSizeH
    $tRect.iWidth = $iW
    $tRect.iBase = DllStructGetPtr($tCodeBuffer) ;pointer to asm code in the memory

    AdlibRegister("CalcFPS", 1000)

    Do
        For $iY = 0 To $iH - $iSizeH Step $iSizeH
            For $iX = 0 To $iW - $iSizeW Step $iSizeW

                $cx = $iX + 128 * Sin(Dist($fTime * 1.5, $iX, $iY, 32) / 48)
                $cy = $iY + 92 * Cos(Dist($iY, 128, $fTime * 2.5, 8) / 32)
                $v = Cos(Sqrt($cx * $cx + $cy * $cy) / 512 + $fTime)

                $f1 = $v * $fPi
                $tRect.ARGB = 0xFF000000 + _
                              BitShift((Abs(Cos($f1 / 2)) * 0xFF), -16) + _
                              BitShift((Abs(Sin($f1 * 2)) * 0xFF), -8) + _
                              Int(Abs(Cos($f1 / 1.5)) * 0xFF)

                $tRect.iPosX = $iX
                $tRect.iPosY = $iY

                DllCallAddress("uint:cdecl", $tRect.iBase, "ptr", $pBitmap, "struct*", $tRect)

                $fTime += 0.0000075

            Next
        Next

        _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS, $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS)
        _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY)

        $iFPS += 1
        If $bExit Then ExitLoop
    Until Not Sleep(10)

    AdlibUnRegister("CalcFPS")
    ;release resources
    _GDIPlus_FontDispose($hFont_FPS)
    _GDIPlus_FontFamilyDispose($hFamily_FPS)
    _GDIPlus_StringFormatDispose($hFormat_FPS)
    _GDIPlus_BrushDispose($hBrush_FPS)
    _GDIPlus_GraphicsDispose($hCanvas)
    _WinAPI_SelectObject($hDC, $DC_obj)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_ReleaseDC($hGUI, $hDC)
    GUIDelete($hGUI)
EndFunc   ;==>GDIPlus_Plasmav5

Func Dist($a, $b, $c, $d)
    Return Sqrt(($a - $c) * ($a - $c) + ($b - $d) * ($b - $d))
EndFunc

Func _Exit_About()
    $bExit = True
EndFunc   ;==>_Exit_About

Func CalcFPS() ;display FPS
    $iShowFPS = $iFPS
    $iFPS = 0
EndFunc   ;==>CalcFPS

Func _WinAPI_BitmapCreateDIB($iWidth, $iHeight, ByRef $pHBitmap)
    Local $tBMI = DllStructCreate($tagBITMAPINFO)
    $tBMI.biSize = DllStructGetSize($tBMI) - 4
    $tBMI.biWidth = $iWidth
    $tBMI.biHeight = -$iHeight
    $tBMI.biPlanes = 1
    $tBMI.biBitCount = 32
    Local $aResult = DllCall("gdi32.dll", "ptr", "CreateDIBSection", "hwnd", 0, "struct*", $tBMI, "uint", 0, "ptr*", 0, "ptr", 0, "uint", 0)
    $pHBitmap = $aResult[4]
    Return $aResult[0]
EndFunc

 

8x8 px @384x256: without ASM ~ 7 fps, with ASM ~13 fps.

 

Might be useful for you.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
spudw2k
On 2/12/2016 at 0:09 PM, UEZ said:

I added the ASM code _ASM_DrawRectFilled  to speedup a little bit the draw function:
...
Might be useful for you.

Last week I got around to checking out some of your examples and stumbled across the ASM examples including the  _ASM_DrawRectFilled func.  I was curious what impact it would have on my script.  I'll have to give it a shot. ;)

Edited by spudw2k

Share this post


Link to post
Share on other sites
gil900

Try to make this:

 

 

I didn't I imagined and expected that is the best game that included in Windows is the Magnifier tool.
it is very fun game.

Edited by gil900

Share this post


Link to post
Share on other sites
Lakes

Looks like a wind tunnel simulator. :)


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • JoeWagner
      By JoeWagner
      I'm building a tool to remotely monitor CPU usage on my server.
      I have a working tool but I have a few issues I'd like some help with.
      1. The app uses more system memory on a continual growth rate...  It eventually starts displaying strange artifacts and the background flashes between black and and white behind the GDI+ elements.  I determined this couldn't be left to run for any amount of time (greater than 15-20 minutes) - Very frustrating.
      I suspect it's because it keeps drawing new GDI+ elements to replace the previous cycle ... the $bar1 = "" is enough to remove the image and allow the new image to be drawn there, but I don't have a handle for the original GDI+ element to throw it away... Not sure where they go...
      I also suspect there could be a better way to do what I'm doing here, but from a problem solving perspective - this is what I came up with - I will accept suggestions for how better to accomplish the same / better or acceptable results  
      I will not however accept corrections on grammar, punctuation or commenting - I didn't comment this as I was going, I use the variables that make sense to me (or as they were when I lifted them from the scraps I found on the internet) and you can never be too careful with punctuation.
      2. I have a WMI query that is used to remotely pull the CPU data from the server - if I supply the wrong credentials the app crashes... I tried to make it show an error and go back to allow me to try again ... doesn't work. Any help with catching that error and preventing the crash would be super helpful. (works great if the credentials are correct; domain or local)
       
      The whole thing below... 
      #include <Date.au3> #include <WindowsConstants.au3> #include <GuiConstantsEX.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <GDIPlus.au3> Global $__g_hGDIPDll Global $graph[21] Global $timer, $timeout = 500 Global $hFlag = 0 $timer = TimerInit() $main = GUICreate("CPU Graph", 125, 220, Default, Default, Default, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $bar1 = GUICtrlCreatePic("", 10, 10, 5, 100) $bar2 = GUICtrlCreatePic("", 15, 10, 5, 100) $bar3 = GUICtrlCreatePic("", 20, 10, 5, 100) $bar4 = GUICtrlCreatePic("", 25, 10, 5, 100) $bar5 = GUICtrlCreatePic("", 30, 10, 5, 100) $bar6 = GUICtrlCreatePic("", 35, 10, 5, 100) $bar7 = GUICtrlCreatePic("", 40, 10, 5, 100) $bar8 = GUICtrlCreatePic("", 45, 10, 5, 100) $bar9 = GUICtrlCreatePic("", 50, 10, 5, 100) $bar10 = GUICtrlCreatePic("", 55, 10, 5, 100) $bar11 = GUICtrlCreatePic("", 60, 10, 5, 100) $bar12 = GUICtrlCreatePic("", 65, 10, 5, 100) $bar13 = GUICtrlCreatePic("", 70, 10, 5, 100) $bar14 = GUICtrlCreatePic("", 75, 10, 5, 100) $bar15 = GUICtrlCreatePic("", 80, 10, 5, 100) $bar16 = GUICtrlCreatePic("", 85, 10, 5, 100) $bar17 = GUICtrlCreatePic("", 90, 10, 5, 100) $bar18 = GUICtrlCreatePic("", 95, 10, 5, 100) $bar19 = GUICtrlCreatePic("", 100, 10, 5, 100) $bar20 = GUICtrlCreatePic("", 105, 10, 5, 100) $host = GUICtrlCreateInput("Host", 10, 115, 100, 20, $ES_AUTOHSCROLL) $user = GUICtrlCreateInput("User", 10, 140, 100, 20, $ES_AUTOHSCROLL) GUICtrlSetFont(-1, 8, 400) $pass = GUICtrlCreateInput("Pass", 10, 165, 100, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 8, 400) $start = GUICtrlCreateButton("Start", 10, 190, 100, 20, $BS_DEFPUSHBUTTON) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $start Then ConnectWMI() If $hFlag = 1 Then If TimerDiff($timer) > $timeout Then UpdateGraph() EndIf WEnd Func ConnectWMI() Global $hostname = GUICtrlRead($host) If Ping($hostname, 2000) = 0 Then Msgbox(0, "Error", "Unable to reach specified host") Return 0 EndIf Local $usr = GUICtrlRead($user) Local $pwd = GUICtrlRead($pass) Global $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") Global $objWMIService = $objSWbemLocator.ConnectServer($hostname, "root\cimv2", $usr, $pwd) If @error Then Msgbox(0, "Error", "Unable to connect to the Host with the supplied credentials") Return 0 EndIf $hFlag = 1 UpdateGraph() EndFunc Func UpdateGraph() $usage = _Processor_Usage() For $i = 1 to 19 $graph[$i] = $graph[$i+1] Next $graph[20] = $usage GUICtrlSetImage($bar1, "") CreateBar($bar1, $graph[1]) GUICtrlSetImage($bar2, "") CreateBar($bar2, $graph[2]) GUICtrlSetImage($bar3, "") CreateBar($bar3, $graph[3]) GUICtrlSetImage($bar4, "") CreateBar($bar4, $graph[4]) GUICtrlSetImage($bar5, "") CreateBar($bar5, $graph[5]) GUICtrlSetImage($bar6, "") CreateBar($bar6, $graph[6]) GUICtrlSetImage($bar7, "") CreateBar($bar7, $graph[7]) GUICtrlSetImage($bar8, "") CreateBar($bar8, $graph[8]) GUICtrlSetImage($bar9, "") CreateBar($bar9, $graph[9]) GUICtrlSetImage($bar10, "") CreateBar($bar10, $graph[10]) GUICtrlSetImage($bar11, "") CreateBar($bar11, $graph[11]) GUICtrlSetImage($bar12, "") CreateBar($bar12, $graph[12]) GUICtrlSetImage($bar13, "") CreateBar($bar13, $graph[13]) GUICtrlSetImage($bar14, "") CreateBar($bar14, $graph[14]) GUICtrlSetImage($bar15, "") CreateBar($bar15, $graph[15]) GUICtrlSetImage($bar16, "") CreateBar($bar16, $graph[16]) GUICtrlSetImage($bar17, "") CreateBar($bar17, $graph[17]) GUICtrlSetImage($bar18, "") CreateBar($bar18, $graph[18]) GUICtrlSetImage($bar19, "") CreateBar($bar19, $graph[19]) GUICtrlSetImage($bar20, "") CreateBar($bar20, $graph[20]) $timer = TimerInit() EndFunc Func _Processor_Usage() Dim $Col_Items = $objWMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor', 'WQL') Local $Obj_Item For $Obj_Item In $Col_Items Return $Obj_Item.PercentProcessorTime Next EndFunc Func CreateBar($target, $value) Local $width=5, $height=2 _GDIPlus_Startup() $hImage = DLL_BitmapCreate($width, $height*50) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;100 If $value > 98 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF00F2F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $width, $height, $hBrush) EndIf ;98 If $value > 96 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0182C") _GDIPlus_GraphicsFillRect($hGraphic, 0, 2, $width, $height, $hBrush) EndIf ;96 If $value > 94 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0212A") _GDIPlus_GraphicsFillRect($hGraphic, 0, 4, $width, $height, $hBrush) EndIf ;94 If $value > 92 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF02B28") _GDIPlus_GraphicsFillRect($hGraphic, 0, 6, $width, $height, $hBrush) EndIf ;92 If $value > 90 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF03426") _GDIPlus_GraphicsFillRect($hGraphic, 0, 8, $width, $height, $hBrush) EndIf ;90 If $value > 88 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF03E24") _GDIPlus_GraphicsFillRect($hGraphic, 0, 10, $width, $height, $hBrush) EndIf ;88 If $value > 86 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF04722") _GDIPlus_GraphicsFillRect($hGraphic, 0, 12, $width, $height, $hBrush) EndIf ;86 If $value > 84 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF05120") _GDIPlus_GraphicsFillRect($hGraphic, 0, 14, $width, $height, $hBrush) EndIf ;84 If $value > 82 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF05A1D") _GDIPlus_GraphicsFillRect($hGraphic, 0, 16, $width, $height, $hBrush) EndIf ;82 If $value > 80 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF0641B") _GDIPlus_GraphicsFillRect($hGraphic, 0, 18, $width, $height, $hBrush) EndIf ;80 If $value > 78 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF06D19") _GDIPlus_GraphicsFillRect($hGraphic, 0, 20, $width, $height, $hBrush) EndIf ;78 If $value > 76 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF07717") _GDIPlus_GraphicsFillRect($hGraphic, 0, 22, $width, $height, $hBrush) EndIf ;76 If $value > 74 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF08015") _GDIPlus_GraphicsFillRect($hGraphic, 0, 24, $width, $height, $hBrush) EndIf ;74 If $value > 72 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF08A13") _GDIPlus_GraphicsFillRect($hGraphic, 0, 26, $width, $height, $hBrush) EndIf ;72 If $value > 70 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09311") _GDIPlus_GraphicsFillRect($hGraphic, 0, 28, $width, $height, $hBrush) EndIf ;70 If $value > 68 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09311") _GDIPlus_GraphicsFillRect($hGraphic, 0, 30, $width, $height, $hBrush) EndIf ;68 If $value > 66 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFF09D0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 32, $width, $height, $hBrush) EndIf ;66 If $value > 64 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFECA20F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 34, $width, $height, $hBrush) EndIf ;64 If $value > 62 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE8A80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 36, $width, $height, $hBrush) EndIf ;62 If $value > 60 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE5AD0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 38, $width, $height, $hBrush) EndIf ;60 If $value > 58 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFE1B30F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 40, $width, $height, $hBrush) EndIf ;58 If $value > 56 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFDEB80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 42, $width, $height, $hBrush) EndIf ;56 If $value > 54 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFDABE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 44, $width, $height, $hBrush) EndIf ;54 If $value > 52 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFD6C30F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 46, $width, $height, $hBrush) EndIf ;52 If $value > 50 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFCFCE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 48, $width, $height, $hBrush) EndIf ;50 If $value > 48 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFCCD40F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 50, $width, $height, $hBrush) EndIf ;48 If $value > 46 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC8D90F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 52, $width, $height, $hBrush) EndIf ;46 If $value > 44 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC4DF0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 54, $width, $height, $hBrush) EndIf ;44 If $value > 42 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFC1E40F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 56, $width, $height, $hBrush) EndIf ;42 If $value > 40 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBDEA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 58, $width, $height, $hBrush) EndIf ;40 If $value > 38 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBAF00F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 60, $width, $height, $hBrush) EndIf ;38 If $value > 36 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFBAF00F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 62, $width, $height, $hBrush) EndIf ;36 If $value > 34 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFADEF0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 64, $width, $height, $hBrush) EndIf ;34 If $value > 32 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFFA1EE0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 66, $width, $height, $hBrush) EndIf ;32 If $value > 30 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF94ED0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 68, $width, $height, $hBrush) EndIf ;30 If $value > 28 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF88ED0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 70, $width, $height, $hBrush) EndIf ;28 If $value > 26 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF7CEC0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 72, $width, $height, $hBrush) EndIf ;26 If $value > 24 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF6FEB0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 74, $width, $height, $hBrush) EndIf ;24 If $value > 22 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF63EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 76, $width, $height, $hBrush) EndIf ;22 If $value > 20 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF56EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 78, $width, $height, $hBrush) EndIf ;20 If $value > 18 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF56EA0F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 80, $width, $height, $hBrush) EndIf ;18 If $value > 16 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF4AE90F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 82, $width, $height, $hBrush) EndIf ;16 If $value > 14 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF3EE80F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 84, $width, $height, $hBrush) EndIf ;14 If $value > 12 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF31E70F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 86, $width, $height, $hBrush) EndIf ;12 If $value > 10 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF25E70F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 88, $width, $height, $hBrush) EndIf ;10 If $value > 8 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF18E60F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 90, $width, $height, $hBrush) EndIf ;8 If $value > 6 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF0CE50F") _GDIPlus_GraphicsFillRect($hGraphic, 0, 92, $width, $height, $hBrush) EndIf ;6 If $value > 4 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E510") _GDIPlus_GraphicsFillRect($hGraphic, 0, 94, $width, $height, $hBrush) EndIf ;4 If $value > 2 Then $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E509") _GDIPlus_GraphicsFillRect($hGraphic, 0, 96, $width, $height, $hBrush) EndIf ;2 $hBrush = _GDIPlus_BrushCreateSolid("0xFF00E509") _GDIPlus_GraphicsFillRect($hGraphic, 0, 98, $width, $height, $hBrush) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) GUICtrlSendMsg($target, 0x172, 0, $hBitmap) _WinAPI_DeleteObject($hBitmap) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>_CreateBar Func DLL_BitmapCreate($width, $height) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $width, "int", $height, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Return $aResult[6] EndFunc ;==>DLL_BitmapCreate  
       
    • Pricehacker
      By Pricehacker
      Hello,
      I am making a program where the button is an image that "changes" when specific conditions are fullfilled. Problem is that these images have different dimensions and when a smaller picture is displayed over a bigger one both will be seen, therefore i would like the images to be hidden, invincible or, alternatively, deleted.
      I have tried using _GDIPlus_GraphicsClear() with no luck
      However that might just be me not using it right as im quite new to autoit
      Here is the code if you want to test run it:
      Thanks to everyone helping!
    • UEZ
      By UEZ
      AutoIt Windows Screenshooter
      Key Features:
      takes easily a screenshot from any visible window capture any region of the desktop incl. freehand capturing capture GUI controls and GUI menus separately capture a marked area every x seconds for a duration of y seconds create a GIF animation from saved frames (Vista or higher os required) capture to AVI file (without audio!) takes a screenshot from web sites (available only on Win7+ os and when Aero is enabled) put images to clipboard to paste to other applications easily color picker save image in different formats and also to PDF! add timestamp to saved images simple image editing options: greyscale, b&w, invert, rotate +-90° send image to printer and default email client preview of captured screens incl. zoom option multi monitor support display pixel color under mouse ruler basic image editor (paint, highlight, ellipse, rectangle, text and some graphic FX) watermark captured image no 3rd party tools or DLLs used - pure AutoIt! fully portable - no installation is needed multi language feature (Eng, Ger, Tur, Fra and Rus only) To do:
      capture content of scrollable window/control capture cascaded menus Due to DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) limitation some windows cannot be captured properly (GDI+, ProgDVB, etc.) but can take screenshots of hidden windows. One workaround is to use full screen capturing (F11/F12) or "Grab Screen" function! Or try double click with rmb on listview items (beta).
      Download source code (6295 downloads previously):  AutoIt Windows Screenshooter v1.81 Build 2018-08-12.7z (version 3.3.12.0+ needed!)
      You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Download compiled Exe only: 4shared / Media Fire / Softpedia (1.54mb)
      Distributing copies of the program in compiled format (exe) must be free of any fee!
      -----> click here to Donate!  
       
      (Current donators: 1. Cuong N.) 
      It is designed for Win7+ operating systems with AERO enabled! E.g. on WinXP machines some functions are not working properly and might crash the application!
      AV scanners may have a negative impact the execution of compiled exe and might report any malware. I guarantee that there is no malicious code in the source code / exe!!! 
      Main GUI:

       
       
      About Intro:

       
       
      Basic Image Editor:

       
       
      Watermark:

       
       
      Click link for an enhanced version of Watermark Image.
      Credits:
      main code by UEZ additional code (alphabetical order) by Authenticity, AutoItObject Team, Eemuli, Eukalyptus, funkey, _Kurt, martin, monoceres, ProgAndy, taietel, trancexx, Ward, wolf9228 and Yashied! mesale0077 for turkish translation wakillon for french translation AZJIO for russian translation Keys:
      Main GUI:
      User your mouse to scroll preview window or
      Numpad 8: Scroll preview window up
      Numpad 2: Scroll preview window down
      Numpad 4: Scroll preview window left
      Numpad 6: Scroll preview window right
      Numpad +: zoom in preview window or mousewheel down
      Numpad -: zoom out preview window or mousewheel up
      F1: capture again on last position
      F5: refresh Windows Name list
      PRINTSCREEN: take screenshot from whole screen
      ALT+PRINTSCR: take a screenshot from active window
      F10: Undo made changes with Image Editing function
      F11: take screenshot from whole screen incl mouse cursor
      F12: take screenshot from whole screen
      Ctrl+Alt+F9 start "Grab Screen" mode
      Ctrl+Alt+F12: take a screenshot from active window using alternative screenshot functionality (beta)!
      Ctrl+r: call ruler
      Ctrl+s: save current displayed image
      Ctrl+x: exit program
      ctrl+w: call web grab input field (availabe only when Aero is enabled)
      Ctrl+i: call image editor
      Ctrl+m: call watermark editor
      Ctrl+z: undo
      Only available on Vista+ os: double click with rmb on list items to use alternative screenshot functionality (beta)!
      When 'Grab Screen' is clicked you can hold down the ctrl key to switch to 'grab controls' mode. Control under mouse will be framed red.
      ctrl + shift will take the screenshot of appropriate control. To capture GUI menues you can press rmb which simulates the lmb. When a menu is opened press shift additionaly to capture it.
      Press and hold only the shift key to capture any region on the desktop using freehand capturing - release it so capture marked regions!
      Or just mark resizeable area which you want to grab. Press CTRL key to grab marked area or right mouse button to capture the marked area every x seconds for a duration of y seconds.
      When saving the image just enter the extension you whish to use (*.jpg;*.png;*.bmp;*.gif;*.tif;*.pdf). Big thanks to taietel for his PDF UDF!
      Image Editor:
      s: save
      c: copy
      n: send
      h: highlighter
      p: pen
      r: rectangle
      e: ellipse
      a: arrow
      o: color
      t: text
      g: text config
      Ctrl+z: undo
      Watermark editor:
      Ctrl+z: undo
       
      To start the app minimized just call it "Windows Screenshooter.exe /min"
      Maybe it is useful for someone...
      Any kind of comment is welcome.
      Br,
      UEZ
      Change log:
       
    • c.haslam
      By c.haslam
      I think that _GDIPlus_ImageGetPropertyItem should return a Property Item that can readily be set as a property of another image. Why would one want to do this? A script might (as one of mine does) edit an image of a .jpg file then write the result to a .jpg file. In editing it, in my case, the number of horizontal and vertical pixels change, and the date/time edited should be set as a property. All other property items remain the same. Other GDI+ users may change other properties.
      So an approach is to copy all the property items from image1 to image2, then update a few properties.
      M$ provides a Property Item class (id, length, pointer to an array of values) but _GDIPlus_ImageGetPropertyItem returns something different.
      I think that, wherever reasonable, UDFs that are wrappers for M$ methods should work like M$'s methods. _GDIPlus_ImageGetPropertyItem does not do this:
      While M$ returns 2 values for a value that is a ratio of 2 numbers,  _GDIPlus_ImageGetPropertyItem returns numerator/denominator as a single value (often a Double). _GDIPlus_ImageSetPropertyItem (when included in GDIPlus.au3) will be unable to set ratio property items properly because it cannot know what the numerator and denominator are. So copying such property items will not work properly. M$ has a Void* buffer where the buffer is an array of values but _GDIPlus_ImageGetPropertyItem() returns the values in the same 1-d array as id, length and type. M$'s approach produces a 1-d array with the same number of elements for all property items while _GDIPlus_ImageGetPropertyItem produces a 1-d array with various numbers of elements. To me, this is not good programming practice. For a photo from a Sony camera, the worst case has 1-d array with 67 elements. When combined into a 2-d array with the property items of all properties, there are 66 rows and 67 columns, with many elements not used. So I suggest that _GDIPlus_ImageGetPropertyItem look like this:
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: cGDIPlus_ImageGetPropertyItem ; Description ...: Gets a specified property item (piece of meta data) from an Image object ; Syntax ........: cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) ; Parameters ....: $hImage - Pointer to an image object ; $iPropID - Identifier of the property item to be retrieved ; Return values .: Success: Array containing the values of the property item ; [0] - identifier ; [1] - size, in bytes, of the value array ; [2] - type of value(s) in the value array ; [3] - value array ; Failure: Sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*). ; Author ........: Eukalyptus ; Modified ......: c.haslam ; Remarks .......: types: unsigned byte = 1, ASCII string = 2, unsigned short = 3, unsigned long = 4, ; unsinged rational = 5, undefined = 7, signed long = 9, signed rational = 10 ; Related .......: _GDIPlus_ImageGetPropertyIdList ; Link ..........: https://msdn.microsoft.com/en-us/library/windows/desktop/ms535390(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx, ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms534414(v=vs.85).aspx ; Example .......: Yes ; =============================================================================================================================== Func cGDIPlus_ImageGetPropertyItem($hImage, $iPropID) Local $iSize = __GDIPlus_ImageGetPropertyItemSize($hImage, $iPropID) If @error Then Return SetError(@error, @extended, -1) Local $tBuffer = DllStructCreate("byte[" & $iSize & "];") Local $pBuffer = DllStructGetPtr($tBuffer) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetPropertyItem", "handle", $hImage, "uint", _ $iPropID, "uint", $iSize, "struct*", $tBuffer) If @error Then Return SetError(@error, @extended, -1) If $aResult[0] Then Return SetError(10, $aResult[0], False) Local $tPropertyItem = DllStructCreate("int id; int length; short type; ptr pvalue;", $pBuffer) Local $iBytes = DllStructGetData($tPropertyItem, "length") Local $pValue = DllStructGetData($tPropertyItem, "pvalue") Local $aRet[4] Local $type = DllStructGetData($tPropertyItem,'type') Local $tValues, $iValues Switch $type Case 2 ;ASCII String $iValues = 1 $tValues = DllStructCreate("char[" & $iBytes & "];", $pValue) Case 3 ;Array of UShort $iValues = Int($iBytes / 2) $tValues = DllStructCreate("ushort[" & $iValues & "];", $pValue) Case 4, 5 ;Array of UInt / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("uint[" & $iValues & "];", $pValue) Case 9, 10 ;Array of Int / Fraction $iValues = Int($iBytes / 4) $tValues = DllStructCreate("int[" & $iValues & "];", $pValue) Case Else ;Array of Bytes $iValues = 1 $tValues = DllStructCreate("byte[" & $iBytes & "];", $pValue) EndSwitch $aRet[0] = DllStructGetData($tPropertyItem,'id') $aRet[1] = $iBytes $aRet[2] = $type Local $aVals[$iValues] If $type=2 Or $type=7 Then ; ASCII string or undefined $aVals[0] = DllStructGetData($tValues,1) Else For $i = 0 To $iValues-1 $aVals[$i] = DllStructGetData($tValues,1,$i+1) Next EndIf $aRet[3] = $aVals Return $aRet EndFunc And here is an example:
      #include <GDIPlus.au3> #include <Array.au3> Example() Func Example() _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(RegRead((@AutoItX64 = True ? "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt" : "HKLM\SOFTWARE\AutoIt v3\AutoIt"), "InstallDir") & "\Examples\GUI\Torus.png") If @error Then _GDIPlus_Shutdown() MsgBox(16, "", "An error has occured - unable to load image!", 30) Return False EndIf Local $ar = _GDIPlus_ImageGetPropertyIdList($hImage) Local $vPropNbrs[UBound($ar,1)-1] ; Extract ID numbers For $i = 1 To UBound($ar,1)-1 $vPropNbrs[$i-1] = $ar[$i][0] Next ; Get all property items Local $aPropItems[UBound($vPropNbrs)][4],$vPropItem For $i = 0 To UBound($vPropNbrs)-1 $vPropItem = cGDIPlus_ImageGetPropertyItem($hImage,$vPropNbrs[$i]) For $j = 0 To 3 $aPropItems[$i][$j] = $vPropItem[$j] Next Next ; Collapse values arrays so _ArrayDisplay can display them Local $ar = $aPropItems For $i = 0 To UBound($aPropItems,1)-1 $ar[$i][0] = '0x'&Hex($ar[$i][0],4) $ar[$i][3] = '' For $j = 0 To UBound($aPropItems[$i][3])-1 $ar[$i][3] &= ($aPropItems[$i][3])[$j]&'|' Next $ar[$i][3] = StringTrimRight($ar[$i][3],1) Next _ArrayDisplay($ar) _GDIPlus_Shutdown() EndFunc Unfortunately this example (based on one now in the Help) does not exercise most of the item types, but I do not know of a file with EXIF metadata that is on most PCs. I have tested this code by updating and adding property items to torus.jpg and to a photo taken by a Sony camera. The code for implementing and calling _GDIPlus_ImageSetPropertyItem will be fairly simple [see below].
       
      Your thoughts?
       
    • c.haslam
      By c.haslam
      I have a strange symptom of a problem somewhere in my code, or in a UDF: when I add code to get all properties of a GDI+ image to a 6000-line script,  the variable type of a parameter is reported as a pointer when the caller clearly has this argument as a string. If I comment out my code that gets the properties, the function properly sees the parameter as a string.
      [Edit: The reporting as a pointer and getting image properties are miles apart, both in where they are in the script code and in where they are run.]
      At this point, I am looking for clues as to why this is happening, so the hunt is on!
      I have noticed one odd thing, in _GDIPlus_ImageGetPropertyIdList() I see a line that begins Local $sPropertyTagInfo = . This "line" is split into 2 lines. SCiTE shows that the first line is 2454 characters and the second 2400. Adding these numbers I get 4854 characters.
      But the Help for AutoIt3 Limits/defaults says that MAXLINESIZE, Maximum size for a line of script, is 4096 characters.
      The line would exceed the limit if AutoIt considers the subject line to be 1 line and not 2 lines.
      My question: is this line legal? Is buffer overun possible?
×