Jump to content

_GDIPlus_BitmapApplyFilter v0.9.8 build 2024-04-17 beta


UEZ
 Share

Recommended Posts

No, now you are not a newbie in FreeBasic, but an advanced user :thumbsup:

The effects are beautiful and your work is fantastic!
Succeed to adapt GDI functions used with AutoIt in FreeBASIC is downright genial!
The execution time is so fast !

A so small dll who can give so great effects, you deserve to be named the GDI King ! :party:

Thanks a lot ! :)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Looks impresive.

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

@wakillon / @mLipok: thanks for your feedback!

 

Small Update:

  • Added UDF headers
  • speeded up OilPainting, Dilatation, Erosion and Kuwahara functions (GdipBitmapGetPixel / GdipBitmapSetPixel is too slow)

 

I compiled the DLL with SSE2 option. I hope it will work also 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

When I understood multi threading properly I will add it to some of the functions.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Just now, wakillon said:

UEZ, please do a pause for avoid a brain overheating ! ;)

Multi theading is more for women... :P

 

I think I've understood the concept of mt but I need to do several tests to fully cover it.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

9 minutes ago, wakillon said:

Pff...and you said you were a newbie !
What modesty ! :D

But that's the truth. I started with FB 3-4 weeks ago because I "tasted blood" to speed up that GDI+ stuff and I must say it is very powerful like a stallion. ;)

Not too hard to learn because it has similar AutoIt syntax like most BASIC languages.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

9 minutes ago, Jardz said:

Truly amazing!! Thank you UEZ!

I'd love to know the steps you did to achieve unsharp masking in GDI+ :blink:

 

The issue is not GDI+ but speed. You have to calculate each pixel separately which is a pain doing it with AutoIt.

Doing it with AutoIt takes ~10-15 times longer!

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

This is how convolution works in AutoIt using GDI+

#include <GDIPlus.au3>

Global $sFile = FileOpenDialog("Select an image", "", "Image (*.jpg;*.png;*.bmp;*.gif)")
If @error Then Exit

_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If @error Then
    _GDIPlus_Shutdown()
    Exit
EndIf

Global $aMatrix_Unsharp_3x3[3][3] = [[-1, -1, -1], _
                                     [-1,  9, -1], _
                                     [-1, -1, -1]]

Global $aDim = _GDIPlus_ImageGetDimension($hImage)
Global $hGUI = GUICreate("GDI+", $aDim[0], $aDim[1])
Global $iPic = GUICtrlCreatePic("", 0, 0, $aDim[0], $aDim[1])

Global Const $STM_SETIMAGE = 0x0172
Global $fTimer = TimerInit()
Global $hBitmap = _GDIPlus_BitmapApplyFilter_Convolution($hImage, $aMatrix_Unsharp_3x3)
ConsoleWrite("Finished in " & TimerDiff($fTimer) & " ms." & @CRLF)
Global $hBmp_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp_GDI))

GUISetState()

Do
Until GUIGetMsg() = -3

_WinAPI_DeleteObject($hBmp_GDI)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()


Func _GDIPlus_BitmapApplyFilter_Convolution($hImage, $aMatrix, $fFactor = 1.0, $fBias = 0.0)
    If Not IsPtr($hImage) Then Return SetError(1, 0, 0)
    If Not IsArray($aMatrix) Then Return SetError(2, 0, 0)
    If UBound($aMatrix, 2) < 3 Then Return SetError(3, 0, 0)
    Local $aDim = _GDIPlus_ImageGetDimension($hImage)
    If @error Then Return SetError(4, 0, 0)
    Local $iW = $aDim[0], $iH = $aDim[1]
    Local $filterHeight = UBound($aMatrix), $filterWidth = UBound($aMatrix, 2)
    Local $tConvolution = DllStructCreate("float fMatrix[" & $filterHeight * $filterWidth & "]"), $iX, $iY, $i = 1
    For $iY = 0 To $filterHeight - 1
        For $iX = 0 To $filterWidth - 1
            $tConvolution.fMatrix(($i)) = $aMatrix[$iY][$iX]
            $i += 1
        Next
    Next

    Local $fW = $filterWidth / 2, $fH = $filterHeight / 2, $iRowOffset

    Local $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH)
    Local $tPixel = DllStructCreate("int argb[" & $iW * $iH & "]", $tBitmapData.Scan0)

    Local $hBitmap_Converted = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $tBitmapData_Convolution = _GDIPlus_BitmapLockBits($hBitmap_Converted, 0, 0, $iW, $iH, $GDIP_ILMWRITE, $GDIP_PXF32ARGB)
    Local $tPixel_Convolution = DllStructCreate("int argb[" & $iW * $iH & "]", $tBitmapData_Convolution.Scan0)

    Local $filterX, $filterY, $fRedSum, $fRedSumX, $fRedSumY, $fGreenSum, $fGreenSumX, $fGreenSumY, $fBlueSum, $fBlueSumX, $fBlueSumY, $fSum, _
          $imageX, $imageY, $c, $iARGB, $iR, $iG, $iB, $fMatrix
    For $iY = 0 To $iH - 1
        $iRowOffset = $iY * $iW + 1
        For $iX = 0 To $iW - 1
            $fRedSum = 0.0
            $fRedSumX = 0.0
            $fRedSumY = 0.0
            $fGreenSum = 0.0
            $fGreenSumX = 0.0
            $fGreenSumY = 0.0
            $fBlueSum = 0.0
            $fBlueSumX = 0.0
            $fBlueSumY = 0.0
            $fSum = 0.0
            $i = 1
            For $filterY = 0 To $filterHeight - 1
                For $filterX = 0 To $filterWidth - 1
                    $imageX = 1 + Mod(Int($iX - $fW + $filterX + $iW), $iW)
                    $imageY = 1 + Mod(Int($iY - $fH + $filterY + $iH), $iH)
                    $c = $tPixel.argb(($imageY * $iW + $imageX))
                    $iR = BitAND(BitShift($c, 16), 0xFF)
                    $iG = BitAND(BitShift($c, 8), 0xFF)
                    $iB = BitAND($c, 0xFF)
                    $fMatrix = $tConvolution.fMatrix(($i))
                    $fRedSum += $iR * $fMatrix
                    $fGreenSum += $iG * $fMatrix
                    $fBlueSum += $iB * $fMatrix
                    $fSum += $fMatrix
                    $i += 1
                Next
            Next
            $fSum = $fSum <= 0 ? 1.0 : $fSum
            $iARGB = 0xFF000000 + _
                     BitShift(Min(Abs(Int($fFactor * $fRedSum / $fSum + $fBias)), 255), -16) + _
                     BitShift(Min(Abs(Int($fFactor * $fGreenSum / $fSum + $fBias)), 255), -8) + _
                              Min(Abs(Int($fFactor * $fBlueSum / $fSum + $fBias)), 255)
            $tPixel_Convolution.argb(($iRowOffset + $iX)) = $iARGB
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData_Convolution)
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
    Return $hBitmap_Converted
EndFunc

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc

Compare the speed to the DLL version. ^_^

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • UEZ changed the title to _GDIPlus_BitmapApplyFilter v0.9.8 build 2024-04-17 beta

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
 Share

×
×
  • Create New...