Jump to content

Recommended Posts

Posted

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

Posted

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

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

Posted (edited)

I have tested previous version and latest for Kuwahara func and it's 6X faster

Edit : for a png (3200x2400) it's ~ 10X faster

Very good improvement ! :thumbsup:

Edited by wakillon

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

Posted
  On 6/25/2016 at 8:24 PM, wakillon said:

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

Expand  

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

Posted (edited)
  On 6/25/2016 at 8:32 PM, wakillon said:

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

Expand  

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

Posted
  On 7/11/2016 at 10:01 AM, Jardz said:

Truly amazing!! Thank you UEZ!

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

 

Expand  

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

Posted

Thanks UEZ,

I was hoping a function within GDI or GDI+ would do the hard work for me.

I was looking at MaskBlt in GDI but I don't think it would work.

 

 

Posted (edited)

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

Posted

Thanks UEZ that's brilliant!!

You weren't wrong about the speed :P

 

It'll take me a few days to fully understand it, but it will teach me a lot so thank you very much!!!

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
×
×
  • Create New...