Yashied

_GDIPlus_BitmapCreateBitmapWithAlpha()

12 posts in this topic

#1 ·  Posted (edited)

This small function allows you to add an alpha channel (mask) to the specified GDI+ bitmap (see screenshots). Source bitmap and mask may be of any color depth. The output bitmap is always 32 bits-per-pixel with alpha channel. Optionally, the alpha channel may be generated from any channel of the specified mask (1 - Red, 2 - Green, 3 - Blue, or 0 - Alpha). The example below is written for Autoit 3.3.12.0.

 

post_img_094.pngpost_img_095.pngpost_img_096.png

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
$hResult = _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, 1)
_GDIPlus_ImageSaveToFile($hResult, @ScriptDir & '\Image+Alpha.png')
_GDIPlus_BitmapDispose($hResult)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, $iChannel = 0)

    Local $hGraphics, $hBmp[2], $bProc, $tProc, $pProc, $Size1, $Size2, $Lenght, $Result
    Local $tData[2] = [$GDIP_ILMWRITE, $GDIP_ILMREAD]

    $Size1 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hBitmap, 'float*', 0, 'float*', 0)
    If (@Error) Or ($Size1[0]) Then
        Return 0
    EndIf
    $Size2 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hAlpha, 'float*', 0, 'float*', 0)
    If (@Error) Or ($Size2[0]) Then
        Return 0
    EndIf
    $hBmp[0] = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $Size1[2], $Size1[3], $GDIP_PXF32ARGB)
    If ($Size1[2] = $Size2[2]) And ($Size1[3] = $Size2[3]) Then
        $hBmp[1] = $hAlpha
    Else
        $hBmp[1] = _GDIPlus_BitmapCreateFromScan0($Size1[2], $Size1[3], $GDIP_PXF32ARGB)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBmp[1])
        _GDIPlus_GraphicsClear($hGraphics, 0)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hAlpha, 0, 0, $Size1[2], $Size1[3])
        _GDIPlus_GraphicsDispose($hGraphics)
    EndIf
    If ($iChannel < 0) Or ($iChannel > 3) Then
        $iChannel = 0
    EndIf
    For $i = 0 To 1
        $tData[$i] = _GDIPlus_BitmapLockBits($hBmp[$i], 0, 0, $Size1[2], $Size1[3], $tData[$i], $GDIP_PXF32ARGB)
    Next
    If @AutoItX64 Then
        $bProc = Binary('0x48894C240848895424104C894424184C894C24205541574831C0505050504883EC2848837C24600074054831C0EB0748C7C0010000004821C00F858100000048837C24680074054831C0EB0748C7C0010000004821C07555837C24700074054831C0EB0748C7C0010000004821C0752A4C637C24784D21FF7C0D4C637C24784983FF037F02EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C0740B4831C04863C0E9950000004C8B7C24604983C7034C897C24284C8B7C246848634424784929C74983C7034C897C243048C7442438000000004C637C247049FFCF4C3B7C24387C4A488B6C24284C0FB67D00488B6C2430480FB645004C0FAFF84C89F848C7C1FF000000489948F7F94989C74C89F850488B6C24305888450048834424280448834424300448FF44243871A748C7C0010000004863C0EB034831C04883C448415F5DC3')
    Else
        $bProc = Binary('0x555331C0505050837C241800740431C0EB05B80100000021C07568837C241C00740431C0EB05B80100000021C07545837C242000740431C0EB05B80100000021C075228B5C242421DB7C0B8B5C242483FB037F02EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C0740431C0EB6B8B5C241883C303891C248B5C241C2B5C242483C303895C2404C7442408000000008B5C24204B3B5C24087C368B2C240FB65D008B6C24040FB645000FAFD889D8B9FF00000099F7F989C3538B6C240458884500830424048344240404FF44240871BFB801000000EB0231C083C40C5B5DC21000')
    EndIf
    $Length = BinaryLen($bProc)
    $pProc = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $Length, 'dword', 0x1000, 'dword', 0x0040)
    $tProc = DllStructCreate('byte[' & $Length & ']', $pProc[0])
    DllStructSetData($tProc, 1, $bProc)
    $Result = DllCallAddress('uint', $pProc[0], 'ptr', $tData[0].Scan0, 'ptr', $tData[1].Scan0, 'uint', $Size1[2] * $Size1[3], 'uint', $iChannel)
    If Not $Result[0] Then
        ; Nothing
    EndIf
    DllCall('kernel32.dll', 'int', 'VirtualFree', 'ptr', $pProc[0], 'ulong_ptr', 0, 'dword', 0x4000)
    For $i = 0 To 1
        _GDIPlus_BitmapUnlockBits($hBmp[$i], $tData[$i])
    Next
    If $hBmp[1] <> $hAlpha Then
        _GDIPlus_BitmapDispose($hBmp[1])
    EndIf
    Return $hBmp[0]
EndFunc   ;==>_GDIPlus_BitmapCreateBitmapWithAlpha

Function + Example

Previous downloads: 47

GDIPlus_BitmapCreateBitmapWithAlpha.zip

Edited by Yashied
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If @AutoItVersion <> '3.3.12.0' Then

?? small typo ??

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Can you post the ASM code please (if possible with comments)?

Thanks.

Br,

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

....

;~If @AutoItVersion <> '3.3.12.0' Then
;~  MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
;~EndIf

....

 

this should do: (from >here)

; use 3 digits for each portion of the version without dots
; (Leading zeros are not needed)
; 3.3.12.0 -> 003.003.012.000 -> 3003012000

If _AutoItVersion() < 3003012000 Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

Func _AutoItVersion()
    Local $aAutoItV = StringSplit(@AutoItVersion, ".", 2)
    Return StringFormat("%03i%03i%03i%03i", $aAutoItV[0], $aAutoItV[1], $aAutoItV[2], $aAutoItV[3])
EndFunc   ;==>_AutoItVersion

p.s.

sorry for the little offtopic hijacking

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Excellent code. I too would like to "study" the ASM code. -_0


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

this should do: (from >here)

; use 3 digits for each portion of the version without dots
; (Leading zeros are not needed)
; 3.3.12.0 -> 003.003.012.000 -> 3003012000

If _AutoItVersion() < 3003012000 Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

Func _AutoItVersion()
    Local $aAutoItV = StringSplit(@AutoItVersion, ".", 2)
    Return StringFormat("%03i%03i%03i%03i", $aAutoItV[0], $aAutoItV[1], $aAutoItV[2], $aAutoItV[3])
EndFunc   ;==>_AutoItVersion

p.s.

sorry for the little offtopic hijacking

 

I was just wondering how to solve the "task", which @Yashied want to use.

 

EDIT:

My example.

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I was just wondering how to solve the "task", which @Yashied want to use.

 

... I've already thought >few days ago :) ...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I too would like to "study" the ASM code.

I didn't write ASM code, I wrote and compiled DLL in other language and then retrieved a binary code of appropriate function. In AutoIt this function looks like this, but in AutoIt it takes a lot of time.

Func _AddAlpha($pBits1, $pBits2, $iWidth, $iHeght, $iChannel)
    If (Not $pBits1) Or (Not $pBits2) Or ($iChannel < 0) Or ($iChannel > 3) Then Return 0
    Local $iOffset = 3 - $iChannel
    For $i = 0 To $iWidth * $iHeght * 4 - 4 Step 4
        Local $tData1 = DllStructCreate('byte', $pBits1 + $i + 3)
        Local $tData2 = DllStructCreate('byte', $pBits2 + $i + $iOffset)
        DllStructSetData($tData1, 1, DllStructGetData($tData1, 1) * DllStructGetData($tData2, 1) / 255)
    Next
    Return 1
EndFunc

Retrieving binary code:

#Include <WinAPIEx.au3>

$File = FileOpenDialog('Select File', @ScriptDir, 'Libraries (*.dll)|All Files (*.*)', 1 + 2)
If Not $File Then
    Exit
EndIf
$hModule = _WinAPI_LoadLibrary($File)
If Not $hModule Then
    MsgBox(0x00040010, 'Error', 'Unable to load ' & StringRegExpReplace($File, '^.*\\', '') & '.')
    Exit
EndIf
Do
    $pFirst = _WinAPI_GetProcAddress($hModule, 'First')
    If @Error Then
        MsgBox(0x00040010, 'Error', '"First()" procedure not found.')
        ExitLoop
    EndIf
    $pLast = _WinAPI_GetProcAddress($hModule, 'Last')
    If @Error Then
        MsgBox(0x00040010, 'Error', '"Last()" procedure not found.')
        ExitLoop
    EndIf
    $tData = DllStructCreate('byte[' & Number($pLast - $pFirst) & ']', $pFirst)
    If @Error Then
        MsgBox(0x00040010, 'Error', 'Invalid addresses.')
        ExitLoop
    EndIf
    $Code = String(DllStructGetData($tData, 1))
    ConsoleWrite($Code & @CR)
    ClipPut($Code)
Until 1
_WinAPI_FreeLibrary($hModule)

Here Alpha.dll (x86) for example.

Edited by Yashied

Share this post


Link to post
Share on other sites

Ah OK, thanks.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I've decided to experiment and wrote a version of this function by using threads (up to 4). Yes, it reduced the time to perform external function, but unfortunately most of the time consuming _GDIPlus... function. Nevertheless, if anyone is interested here is a function.

 

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
$hResult = _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, 1)
_GDIPlus_ImageSaveToFile($hResult, @ScriptDir & '\Image+Alpha.png')
_GDIPlus_BitmapDispose($hResult)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()

Func _GDIPlus_BitmapCreateBitmapWithAlpha($hBitmap, $hAlpha, $iChannel = 0)

    Local $hGraphics, $hBmp[2], $hThread, $iThread, $tParams, $bProc, $tProc, $pProc, $aSize1, $aSize2, $aLength, $iLength, $iOffset, $aResult
    Local $tData[2] = [$GDIP_ILMWRITE, $GDIP_ILMREAD]

    $aSize1 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hBitmap, 'float*', 0, 'float*', 0)
    If (@Error) Or ($aSize1[0]) Then
        Return 0
    EndIf
    $aSize2 = DllCall($__g_hGDIPDll, 'uint', 'GdipGetImageDimension', 'handle', $hAlpha, 'float*', 0, 'float*', 0)
    If (@Error) Or ($aSize2[0]) Then
        Return 0
    EndIf
    $hBmp[0] = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $aSize1[2], $aSize1[3], $GDIP_PXF32ARGB)
    If ($aSize1[2] = $aSize2[2]) And ($aSize1[3] = $aSize2[3]) Then
        $hBmp[1] = $hAlpha
    Else
        $hBmp[1] = _GDIPlus_BitmapCreateFromScan0($aSize1[2], $aSize1[3], $GDIP_PXF32ARGB)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBmp[1])
        _GDIPlus_GraphicsClear($hGraphics, 0)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hAlpha, 0, 0, $aSize1[2], $aSize1[3])
        _GDIPlus_GraphicsDispose($hGraphics)
    EndIf
    If ($iChannel < 0) Or ($iChannel > 3) Then
        $iChannel = 0
    EndIf
    For $i = 0 To 1
        $tData[$i] = _GDIPlus_BitmapLockBits($hBmp[$i], 0, 0, $aSize1[2], $aSize1[3], $tData[$i], $GDIP_PXF32ARGB)
    Next
    If @AutoItX64 Then
        $bProc = Binary('0x48894C24085541574831C0505050504883EC28488B6C246048837D000074054831C0EB0748C7C0010000004821C00F8591000000488B6C246048837D080074054831C0EB0748C7C0010000004821C07561488B6C2460837D100074054831C0EB0748C7C0010000004821C07532488B6C24604C637D144D21FF7C11488B6C24604C637D144983FF037F02EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000EB034831C04821C0740B4831C04863C0E9A5000000488B6C24604C8B7D004983C7034C897C2428488B6C24604C8B7D08488B6C2460486345144929C74983C7034C897C243048C744243800000000488B6C24604C637D1049FFCF4C3B7C24387C4A488B6C24284C0FB67D00488B6C2430480FB645004C0FAFF84C89F848C7C1FF000000489948F7F94989C74C89F850488B6C24305888450048834424280448834424300448FF44243871A348C7C0010000004863C0EB034831C04883C448415F5DC3')
    Else
        $bProc = Binary('0x555331C05050508B6C2418837D0000740431C0EB05B80100000021C075748B6C2418837D0400740431C0EB05B80100000021C0754E8B6C2418837D0800740431C0EB05B80100000021C075288B6C24188B5D0C21DB7C0E8B6C24188B5D0C83FB037F02EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C07502EB07B801000000EB0231C021C0740431C0EB778B6C24188B5D0083C303891C248B6C24188B5D048B6C24182B5D0C83C303895C2404C7442408000000008B6C24188B5D084B3B5C24087C368B2C240FB65D008B6C24040FB645000FAFD889D8B9FF00000099F7F989C3538B6C240458884500830424048344240404FF44240871BCB801000000EB0231C083C40C5B5DC20400')
    EndIf
    $iLength = BinaryLen($bProc)
    $pProc = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $iLength, 'dword', 0x1000, 'dword', 0x0040)
    $tProc = DllStructCreate('byte[' & $iLength & ']', $pProc[0])
    DllStructSetData($tProc, 1, $bProc)
    $iLength = $aSize1[2] * $aSize1[3]
    Select
        Case $iLength > 2 ^ 24
            $iThread = 4
        Case $iLength > 2 ^ 20
            $iThread = 2
        Case Else
            $iThread = 1
    EndSelect
    Dim $aLength[$iThread]
    Dim $tParams[$iThread]
    Dim $hThread[$iThread]
    If $iThread = 1 Then
        $aLength[0] = $iLength
    Else
        $aLength[0] = Floor($iLength / $iThread)
        $aLength[$iThread - 1] = $iLength - $aLength[0] * ($iThread - 1)
        For $i = 1 To $iThread - 2
            $aLength[$i] = $aLength[0]
        Next
    EndIf
    $iOffset = 0
    For $i = 0 To $iThread - 1
        $tParams[$i] = DllStructCreate('ptr;ptr;uint;uint')
        DllStructSetData($tParams[$i], 1, $tData[0].Scan0 + $iOffset)
        DllStructSetData($tParams[$i], 2, $tData[1].Scan0 + $iOffset)
        DllStructSetData($tParams[$i], 3, $aLength[$i])
        DllStructSetData($tParams[$i], 4, $iChannel)
        $iOffset+= 4 * $aLength[$i]
        $aResult = DllCall('kernel32.dll', 'handle', 'CreateThread', 'ptr', 0, 'dword_ptr', 0, 'ptr', $pProc[0], 'struct*', $tParams[$i], 'dword', 0, 'ptr', 0)
        If (Not @Error) And ($aResult[0]) Then
            $hThread[$i] = $aResult[0]
        Else
            $hThread[$i] = 0
        EndIf
    Next
    While 1
        $iLength = 0
        For $i = 0 To $iThread - 1
            If $hThread[$i] Then
                $aResult = DllCall('kernel32.dll', 'bool', 'GetExitCodeThread', 'handle', $hThread[$i], 'dword*', 0)
                If (@Error) Or (Not $aResult[0]) Or ($aResult[2] <> 259) Then
                    DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $hThread[$i])
                    $hThread[$i] = 0
                Else
                    $iLength += 1
                EndIf
            EndIf
        Next
        If Not $iLength Then
            ExitLoop
        EndIf
    WEnd
    $aResult = DllCall('kernel32.dll', 'int', 'VirtualFree', 'ptr', $pProc[0], 'ulong_ptr', 0, 'dword', 0x4000)
    If (@Error) Or (Not $aResult[0]) Then
        ; Nothing
    EndIf
    For $i = 0 To 1
        _GDIPlus_BitmapUnlockBits($hBmp[$i], $tData[$i])
    Next
    If $hBmp[1] <> $hAlpha Then
        _GDIPlus_BitmapDispose($hBmp[1])
    EndIf
    Return $hBmp[0]
EndFunc   ;==>_GDIPlus_BitmapCreateBitmapWithAlpha
Edited by Yashied

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I added an experimental ASM version:

 

#Include <GDIPlus.au3>

If StringRegExpReplace(@AutoItVersion, '(?<!\d)(\d)(?!\d)', '0\1') < '03.03.12.00' Then
    MsgBox(16, 'Error', 'Require AutoIt 3.3.12.0 or later.')
EndIf

If FileExists(@ScriptDir & '\Image+AlphaASM.png') Then FileDelete(@ScriptDir & '\Image+AlphaASM.png')
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Image.png')
$hAlpha = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Alpha.png')
_GDIPlus_BitmapCreateBitmapWithAlphaASM($hBitmap, $hAlpha)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & '\Image+AlphaASM.png')
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hAlpha)
_GDIPlus_Shutdown()
ShellExecute(@ScriptDir & '\Image+AlphaASM.png')

Func _GDIPlus_BitmapCreateBitmapWithAlphaASM($hBitmap, $hBitmap_AlphaMask) ;coded by UEZ build 2015-02-26
    Local $fTimer_All = TimerInit()
    Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    If _GDIPlus_ImageGetWidth($hBitmap_AlphaMask) <> $iWidth Or _GDIPlus_ImageGetHeight($hBitmap) <> $iHeight Then Return SetError(1, 0, 0)
    Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
    Local Const $pScan = $tBitmapData.Scan0
    Local Const $iStride = $tBitmapData.Stride
    Local Const $tPixelData = DllStructCreate("dword[" & (Abs($iStride * $iHeight)) & "]", $pScan)

    Local Const $tBitmapAlphaMaskData = _GDIPlus_BitmapLockBits($hBitmap_AlphaMask, 0, 0, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    Local Const $pScanAlpha = $tBitmapAlphaMaskData.Scan0
    Local Const $iStrideAlpha = $tBitmapAlphaMaskData.Stride
    Local Const $tPixelAlphaMaskData = DllStructCreate("dword[" & (Abs($iStrideAlpha * $iHeight)) & "]", $pScanAlpha)

    Local $fTimer_ASM = TimerInit()
    Local $tCodeBuffer = DllStructCreate("byte ASM[46]")
    $tCodeBuffer.ASM = "0x8B7424048B4C24088B7C240C8B0625FFFFFF008B1F81E30000FF00C1E30809D8890683C60483C70483E90177DFC3"
    DllCall("user32.dll", "ptr", "CallWindowProcW", "ptr", DllStructGetPtr($tCodeBuffer), _
                          "ptr", DllStructGetPtr($tPixelData), _
                          "int", $iWidth * $iHeight , _
                          "ptr", DllStructGetPtr($tPixelAlphaMaskData), "int",0)
    ConsoleWrite("ASM: " & TimerDiff($fTimer_ASM) & " ms." & @CRLF)

    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
    _GDIPlus_BitmapUnlockBits($hBitmap_AlphaMask, $tBitmapData)
    ConsoleWrite("Overall: " & TimerDiff($fTimer_All) & " ms." & @CRLF)
    Return 1
EndFunc

#cs ASM
      .data:0x00000000    8b742404        mov    esi,DWORD PTR [esp+0x4]  ;start address of the bitmap
      .data:0x00000004    8b4c2408        mov    ecx,DWORD PTR [esp+0x8]  ;number of pixel -> $iWidth * $iHeight
      .data:0x00000008    8b7c240c        mov    edi,DWORD PTR [esp+0xc]  ;start address of the alpha mask bitmap
      .data:0x0000000c
      .data:0x0000000c        loc_0000000c:
┏▶  .data:0x0000000c    8b06            mov    eax,DWORD PTR [esi]      ;get the pixel from the bitmap
┃     .data:0x0000000e    25ffffff00      and    eax,0xffffff             ;remove alpha channel
┃     .data:0x00000013    8b1f            mov    ebx,DWORD PTR [edi]      ;get the pixel from alpha mask bitmap
┃     .data:0x00000015    81e30000ff00    and    ebx,0xff0000             ;get red value only because r=g=b (greyscale). This will be our alpha channel
┃     .data:0x0000001b    c1e308          shl    ebx,0x8                  ;shift the value to the alpha channel place AArrggbb
┃     .data:0x0000001e    09d8            or     eax,ebx                  ;add the alpha channel value to the bitmap pixel
┃     .data:0x00000020    8906            mov    DWORD PTR [esi],eax      ;write the pixel to the bitmap -> should be a greyscaled color value
┃     .data:0x00000022    83c604          add    esi,0x4                  ;address next pixel: 3 Byte = 1 dword = 1 Pixel
┃     .data:0x00000025    83c704          add    edi,0x4                  ;address next pixel: 3 Byte = 1 dword = 1 Pixel
┃     .data:0x00000028    83e901          sub    ecx,0x1                  ;counter (next pixel)
┗     .data:0x0000002b    77df            ja     loc_0000000c             ;jump as long as counter is not zero
      .data:0x0000002d    c3              ret
 

My results for the images on op:

ASM: 0.196242006627889 ms.

Overall: 8.97499269224327 ms.

 

 

Maybe a MMX/SSE and/or 64-bit version(s) will follow... ;)

 

Br,

UEZ

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

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

  • Similar Content

    • c.haslam
      By c.haslam
      In my code, the mouse wheel causes the line to move up and down. It does move down to where the picture is, but is not seen there. This can be observed by scrolling down to the picture, and then up again: the line reappears as expected.
      How can I get the line to show on the picture? This seems to be a matter of transparency, but I have not found a way of getting the background of $graphLine to be transparent.
      The code is now:
      #include <ButtonConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars',1) Global Const $MK_SHIFT = 0x4 Global Const $MK_CONTROL = 0x8 GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Global $gY0,$gY1,$gForm1,$glblLine,$glblPic main() Func main() $gForm1 = GUICreate("Form1", 623, 601, 192, 114) $glblLine = GUICtrlCreateLabel("", 8, 8, 604, 137) $glblPic = GUICtrlCreateLabel("", 8, 8, 589, 500) Local $btn = GUICtrlCreateButton("Rotate", 472, 560, 65, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $oldY0,$oldY1 _GDIPlus_Startup() Local $h = GUICtrlGetHandle($glblLine) ; limit graphics to area of $label Local $GraphicLine = _GDIPlus_GraphicsCreateFromHWND($h) Local $hPen = _GDIPlus_PenCreate(0xFF000000,2) Local $image = _GDIPlus_ImageLoadFromFile('H:\a\P5130021.jpg') Local $h = GUICtrlGetHandle($glblPic) Local $GraphicPic = _GDIPlus_GraphicsCreateFromHWND($h) _GDIPlus_GraphicsDrawImage($GraphicPic,$image,0,0) $gY0 = 67 $gY1 = 67 _GDIPlus_GraphicsClear($GraphicLine,0) _GDIPlus_GraphicsDrawLine($GraphicLine, 10, $gY0, 350, $gY1, $hPen) ; Loop until the user exits. While True If $gY0<>$oldY0 Or $gY1<>$oldY1 Then _GDIPlus_GraphicsClear($GraphicLine,0xFFD4D0C8) _GDIPlus_GraphicsDrawLine($GraphicLine, 10, $gY0, 590, $gY1, $hPen) $oldY0 = $gY0 $oldY1 = $gY1 Else Switch GUIGetMsg() Case $GUI_EVENT_CLOSE,$btn Exit EndSwitch EndIf WEnd ; Clean up resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($GraphicLine) _GDIPlus_Shutdown() EndFunc Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local Const $ymax=500 Local $vec = GUIGetCursorInfo($gForm1) If $vec[4] = $glblLine Or $vec[4]=$glblPic Then Local $iDelta = BitShift($wParam, 16) ; positive = up Local $iKeys = _WinAPI_LoWord($wParam) If BitAND($iKeys,$MK_CONTROL)=$MK_CONTROL Then If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then ; do nothing Else If $iDelta > 0 And $gY0>3 Then $gY0 -= 1 If $iDelta < 0 And $gY0<$ymax Then $gY0 += 1 EndIf Else If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then If $iDelta > 0 And $gY1>3 Then $gY1 -= 1 If $iDelta < 0 And $gY1<$ymax Then $gY1 += 1 Else If $iDelta > 0 And $gY0>3 Then $gY0 -= 1 If $iDelta < 0 And $gY0<$ymax Then $gY0 += 1 If $iDelta > 0 And $gY1>3 Then $gY1 -= 1 If $iDelta < 0 And $gY1<$ymax Then $gY1 += 1 EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEWHEEL Some other questions:
      Do I really need GDI+, or is there a simpler way? My code creates Graphics (canvases?) from labels. Is this legitimate? I have found MSDN to be un-helpful in learning GDI+. Is there a better learning tool?
    • spudw2k
      By 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
    • SimTheNo1
      By SimTheNo1
      I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
      For now I already have discovered here and there some mind blowing  Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
       WinAPI  GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University.  Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
      Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
      Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
      createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y)  writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
      The problem with explaining screenshots:
       VOIPConnect full Window  Part of Window with control to monitor for changes  Exact location of area where actual changes occur and have to be processed  It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide. 
      To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
      This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus. 
    • timmalos
      By timmalos
      Hey all.
      I'm trying to know when my user clicks on a Rect drawn via GDI+. Everything is almost working except I have a strange behaviour in the "order" clicks are fired.
      I created a simplified code to help :
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled _GDIPlus_Startup() Global $hGUI, $hGraphics Global $iWidth = 1024, $iHeight = 762 createGUI() draw() While 1 Sleep(10) WEnd Func createGUI() $hGUI = GUICreate("Current CasparCG Output", $iWidth,$iHeight) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetBkColor(0x000000) GUISetState(@SW_SHOW) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) EndFunc ;==>Example Func draw() ;_WinAPI_draw($hGUI,"","",BitOR($RDW_ERASE,$RDW_INVALIDATE,$RDW_UPDATENOW)) _GDIPlus_GraphicsClear($hGraphics) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 15, 1) $hPen = _GDIPlus_PenCreate(0xFFFEDCFF, 2) ;color format AARRGGBB (hex) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) $hBrushString = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF00FF) ;color format AARRGGBB (hex) For $i = 1 to 2 Local $x = 0.25 Local $y = 0.25 Local $w = 0.5 Local $h = 0.5 Local $title = "Layer "&$i If $x >= -1 And $x <= 1 Then $x *= $iWidth If $y >= -1 And $y <= 1 Then $y *= $iHeight If $w >= -1 And $w <= 1 Then $w *= $iWidth If $h >= -1 And $h <= 1 Then $h *= $iHeight $hItem = GUICtrlCreateLabel("", $x,$y,$w,$h) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetOnEvent($hItem,"_gui_layer_clicked") ConsoleWrite("Created label with handle="&$hItem&" $i= " & $i&@CRLF) _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, $w, $h,$hBrush) _GDIPlus_GraphicsDrawRect($hGraphics, $x, $y, $w, $h,$hPen) $tLayout = _GDIPlus_RectFCreate($x, $y, $w, $h) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $title, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $title, $hFont, $aInfo[0], $hFormat, $hBrushString) Next _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_FontDispose($hFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrushString) Return 1 EndFunc Func _gui_layer_clicked() ConsoleWrite("Clicked on " & @GUI_CtrlId&@CRLF) EndFunc Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit EndSelect EndFunc ;==>SpecialEvents What happens there :
      We have two rectangles, with the one labelled "2" is front and, the one labelled "1" in background. However when we click, the fired label is the one created first (in the background) and not the second one (in the front).
      Is it normal ?
      If yes, is there any way to change this order ? If I create another label after a first one on the same coords, I would the second one to be fired instead of the first one (This is a simplified code I can't just invert the label order creation easily)
       
      Thanks for your help
       
    • InunoTaishou
      By InunoTaishou
      Struggling a bit to get this GDI+ function converted to AutoIt.
      #include <GDIPlus.au3> _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile("F:\DCIM\Camera\20170515_111804.jpg") Global $tBufferSize = DllStructCreate("uint") Global $tProperties = DllStructCreate("uint") _GDIPlus_GetPropertySize($hImage, $tBufferSize, $tProperties) Global $tAllItems = DllStructCreate("struct;char[" & DllStructGetData($tBufferSize, 1) & "];endstruct") _GDIPlus_GetAllPropertyItems($hImage, $tBufferSize, $tProperties, $tPropertyItem) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Func _GDIPlus_GetAllPropertyItems(ByRef $hImage, Const $tTotalBufferSize, Const $tNumProperties, ByRef $tAllItems) If (Not IsDllStruct($tPropertyItem)) Then Return SetError(-1, 0, "") Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetAllPropertyItems", "hwnd", $hImage, "unit", DllStructGetData($tTotalBufferSize, 1), "uint", DllStructGetData($tNumProperties, 1), "ptr", DllStructGetPtr($tAllItems)) If (@error) Then Return SetError(@error, @extended, ConsoleWrite("@Error = " & @error & @LF)) If ($aResult[0]) Then Return SetError($aResult[0], @extended, "") Return $aResult[0] EndFunc ;==>_GDIPlus_GetAllPropertyItems Func _GDIPlus_GetPropertySize(Const ByRef $hImage, ByRef $tTotalBufferSize, ByRef $tNumProperties) If (Not IsDllStruct($tTotalBufferSize)) Then Return SetError(-1, 0, "") If (Not IsDllStruct($tNumProperties)) Then Return SetError(-2, 0, "") Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipGetPropertySize", "hwnd", $hImage, "uint_ptr", DllStructGetPtr($tTotalBufferSize), "uint_ptr", DllStructGetPtr($tNumProperties)) If (@error) Then Return SetError(@error, @extended, "") If ($aResult[0]) Then Return SetError($aResult[0], 0, "") Return $aResult[0] EndFunc ;==>_GDIPlus_GetPropertySize Got the GetPropertySize function to work, gives me the correct buffer size and the property count, but I cannot figure out how to get the struct for the all items.
      Function on MSDN:
      https://msdn.microsoft.com/en-us/library/windows/desktop/ms535372(v=vs.85).aspx
      Struct needed:
      PropertyItem class:
      https://msdn.microsoft.com/en-us/library/windows/desktop/ms534493(v=vs.85).aspx
      Found other topics about this function in other languages where they used a blank string as the buffer, so I tried using a char array, which doesn't work. Just cannot figure out how to create the struct buffer to hold the data.