Schnellster Perlin-Noise Generator

  • Dass es am anfang schwarz ist liegt an der Helligkeit.
    Die ist zu beginn auf 0 eingestellt und wird mit jedem Bild um 1 erhöht, bis sie schließlich 255 erreicht.
    Man kann sie auch einfach auf 100 oder so stellen. Dann hat man beim ersten Bild direkt gute Wolken.

    Das mit dem Färben sollte kein Problem darstellen.
    Man kann ja als Parameter $Farbe1 und $Farbe2 einbauen. (mach ich gleich mal)


    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUICloseOnESC', 0)
    Opt('GUIOnEventMode', 0)
    ;~ Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    ;################## Hier Parameter bestimmen ###########################
    Global $hell = 120 ;Helligkeit des Bildes
    Global $Tiefe__ = 15 ;Tiefenwert
    Global $Seed = 9 ;Nummer des Bildes
    Global $F1 = 0xFF4040A0 ;Farbe 1
    Global $F2 = 0xFFFFFFFF ;Farbe 2
    Global $Size = 250 ; Welche Breite und Höhe soll das Bild haben ?
    Global $Stretch = 2 ;Um welchen Faktor wird das Bild vergrößert ?
    ;#######################################################################

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Global Const $Size = 200
    ;~ Global Const $Stretch = 2
    Global Const $Breite = $Size
    Global Const $Hoehe = $Size
    Global Const $Titel = 'Perlin'

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $WM_NCHITTEST = 0x0084 ; Fenster "Anfassen"
    Global Const $HTCAPTION = 2 ; Fenster "Anfassen"
    Global Const $WS_EX_LAYERED = 0x00080000
    Global Const $WS_POPUP = 0x80000000
    Global Const $SRCCOPY = 0x00CC0020
    Global Const $BLACKNESS = 0x00000042
    Global Const $DIB_RGB_COLORS = 0 ;Eine Absolut sinnlose Variable die aber immer fehlt.

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $h_NTDLL_DLL = DllOpen('ntdll.dll')
    Global Const $h_MSIMG32_DLL = DllOpen('msimg32.dll')
    Global Const $h_GDI32_DLL = DllOpen('gdi32.dll')
    Global Const $h_OLE32_DLL = DllOpen('ole32.dll')
    Global Const $h_USER32_DLL = DllOpen('user32.dll')
    Global Const $h_KERNEL32_DLL = DllOpen('kernel32.dll')

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $h_AlphaStruct = _GDI_AlphaBlend_GetStruct()

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGUI = GUICreate($Titel, $Breite * $Stretch, $Hoehe * $Stretch, _C($Breite * $Stretch, 1), _C($Hoehe * $Stretch, 0), $WS_POPUP, $WS_EX_LAYERED)
    GUISetBkColor(0xFF0000, $hGUI)
    WinSetTrans($hGUI, '', 255)
    GUISetOnEvent(-3, '_Exit', $hGUI)
    GUISetState(@SW_SHOW, $hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $hdc_GUI = _WinAPI_GetDC($hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Global $Backbuffer = _CreateImage($Breite*$Stretch, $Hoehe*$Stretch)
    Global $hDC_Backbuffer = DllStructGetData($Backbuffer, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ ;################## Hier Parameter bestimmen ###########################
    ;~ Global $hell = 120 ;Helligkeit des Bildes
    ;~ Global $Tiefe__ = 15 ;Tiefenwert
    ;~ Global $Seed = 9 ;Nummer des Bildes
    ;~ Global $F1 = 0xFF4040A0 ;Farbe 1
    ;~ Global $F2 = 0xFFFFFFFF ;Farbe 2
    ;~ ;#######################################################################

    [/autoit] [autoit][/autoit] [autoit]

    Global $Tiefe_ = 0
    Global $Timer = TimerInit()
    Global $Perlin = _CreatePerlin($Breite, $Hoehe, $Tiefe__, $Seed, $hell, $F1, $F2)
    Global $Diff = Int(TimerDiff($Timer))

    [/autoit] [autoit][/autoit] [autoit]

    Global $ImageSchrift_Zeit = _CreateImageSchrift('Size: ' & $Breite & 'x' & $Hoehe & ' px' & '|Helligkeit: ' & $hell & '|Tiefe: ' & $Tiefe_ & '|Benötigte Zeit: ' & $Diff & ' ms|Pixel pro ms: ' & Round($Breite*$Hoehe/$Diff, 2), 0xFF000000, 4) ; 4px große Schrift

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    OnAutoItExitRegister('_Exit')

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    $Seed = Random(0, 50000)
    _DrawImageStretch($hDC_Backbuffer, 0, 0, $Perlin, $Stretch)
    _DrawImageTrans($hDC_Backbuffer, 2*$Stretch, ($Hoehe - DllStructGetData($ImageSchrift_Zeit, 1, 3) - 1)*$Stretch, $ImageSchrift_Zeit, $Stretch)
    _DrawImage($hdc_GUI, 0, 0, $Backbuffer)
    _DeleteImage($Perlin)
    _DeleteImage($ImageSchrift_Zeit)
    $hell += 1
    If $hell > 255 Then $hell = 0
    $Timer = TimerInit()
    $Perlin = _CreatePerlin($Breite, $Hoehe, $Tiefe__, $Seed, $hell, $F1, $F2)
    $Diff = Int(TimerDiff($Timer))
    $ImageSchrift_Zeit = _CreateImageSchrift('Size: ' & $Breite & 'x' & $Hoehe & ' px' & '|Helligkeit: ' & $hell & '|Tiefe: ' & $Tiefe_ & '|Benötigte Zeit: ' & $Diff & ' ms|Pixel pro ms: ' & Round($Breite*$Hoehe/$Diff, 2), 0xFF000000, 4) ; 4px große Schrift
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zufall(ByRef $Z) ; Eine Pseudo Zufallszahl wird generiert.
    $Z = Mod((7141 * $Z + 54773), 259200)
    If $Z < 129600 Then Return 1 ; Nur mit 0 und 1
    Return 0
    EndFunc ;==>_Zufall

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zufall2(ByRef $Z) ; Eine Pseudo Zufallszahl wird generiert.
    $Z = Mod((7141 * $Z + 54773), 259200)
    Return $Z / 259200 ; Ein Kommawert zw 0 und 1
    EndFunc ;==>_Zufall

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreatePerlin($b, $h, $Tiefe = 15, $Nummer = 1, $Helligkeit = 100, $Farbe1 = 0xFF000000, $Farbe2 = 0xFFFFFFFF)
    If $Tiefe < 1 Then $Tiefe = 1
    If Int(_Log(_Min($b, $h),2)) - 1 <= Int($Tiefe) Then $Tiefe = Int(_Log(_Min($b, $h),2)) - 1 ;Überprüfung ob die Tiefe möglich ist bei der angegebenen Auflösung
    $Tiefe_ = $Tiefe
    Local $randx = Int($b/3) ; Ein Rand muss sein, da sonst unten und rechts alles dunkel ist
    Local $randy = Int($h/3) ; Und oben und links alles hell. Kommt durch das Vergrößern...
    $b += $randx
    $h += $randy
    Local $img = _CreateImage($b, $h) ;Bild erzeugen Hier liegen die ganzen Verpixelungen
    Local $hdc = DllStructGetData($img, 1, 1)
    Local $ptr = DllStructGetData($img, 1, 4)
    Local $hbmp = DllStructGetData($img, 1, 5)
    Local $struct = DllStructCreate('int['& $b * $h &']', $ptr)
    Local $ziel = _CreateImage($b, $h) ;Hier wird das Endergebnis zusammengebaut.
    Local $hdc_ziel = DllStructGetData($ziel, 1, 1)
    Local $tmpImg = _CreateImage($b, $h) ;Hier wird immer jeweils eine Ebene vergrößert.
    Local $Mode = 0
    $gr = _GDIPlus_GraphicsCreateFromHDC(DllStructGetData($tmpImg, 1, 1))
    _GDIPlus_GraphicsSetInterpolationMode($gr, 7)
    For $p = 0 To $Tiefe Step 1
    For $i = 0 To $b / 2 ^ ($Tiefe - $p) - 1 Step 1
    For $o = 0 To $h / 2 ^ ($Tiefe - $p) - 1 Step 1
    Switch _Zufall($Nummer)
    Case 1
    DllStructSetData($struct, 1, $Farbe2, $b * $i + $o + 1)
    Case 0
    DllStructSetData($struct, 1, $Farbe1, $b * $i + $o + 1)
    EndSwitch
    Next
    Next
    $Mode = 1
    $bm = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _GDIPlus_GraphicsDrawImageRectRect($gr, $bm, 0, 0, $b / 2 ^ ($Tiefe - $p), $h / 2 ^ ($Tiefe - $p), 0, 0, $b, $h)
    _GDIPlus_BitmapDispose($bm)
    _GDI_AlphaBlend($hdc_ziel, 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, $b, $h, _GDI_AlphaBlend_GetStruct(255 / 2 ^ $p))
    Next
    $b -= $randx
    $h -= $randy
    Local $tmpImg2 = _CreateImage($b, $h) ; Dieses Bild enthält das Endbild.
    _WinAPI_BitBlt(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, $hdc_ziel, $randx/2,$randy/2, $SRCCOPY) ;Es wird der Mittelteil ins Endbild kopiert. Ränder werden so beschnitten.
    Switch $Helligkeit
    Case 0 To 255/2
    _GDIPlus_GraphicsClear($gr, 0xFF000000) ; TmpImg1 wird nicht mehr gebraucht
    _GDI_AlphaBlend(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, 10,10, _GDI_AlphaBlend_GetStruct(255-$Helligkeit*2))
    Case 255/2 To 255
    _GDIPlus_GraphicsClear($gr, 0xFFFFFFFF) ; TmpImg1 wird nicht mehr gebraucht
    _GDI_AlphaBlend(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, 10,10, _GDI_AlphaBlend_GetStruct($Helligkeit*2 - 255))
    EndSwitch
    _GDIPlus_GraphicsDispose($gr)
    _DeleteImage($img)
    _DeleteImage($tmpImg)
    _DeleteImage($ziel)
    Return $tmpImg2
    EndFunc ;==>_PerlinNoise

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Return SetError(@error, @extended, False)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_SetStretchBltMode($hDC, $iMode)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Ret = DllCall($h_GDI32_DLL, 'int', 'SetStretchBltMode', 'hwnd', $hDC, 'int', $iMode)

    [/autoit] [autoit][/autoit] [autoit]

    If (@error) Or (Not $Ret[0]) Then
    Return SetError(1, 0, 0)
    EndIf
    Return 1
    EndFunc ;==>_WinAPI_SetStretchBltMode

    [/autoit] [autoit][/autoit] [autoit]

    #cs - Alte Perlin Noise Func

    [/autoit] [autoit][/autoit] [autoit]

    Func _PerlinNoise($b, $h, $Tiefe, $Helligkeit, $Nummer, $hGraphics, $hDC_Backbuffer)
    If $Tiefe < 1 Then $Tiefe = 1
    If Int(_Log(_Min($b, $h),2)) - 1 <= Int($Tiefe) Then $Tiefe = Int(_Log(_Min($b, $h),2)) - 1 ;Überprüfung ob die Tiefe möglich ist bei der angegebenen Auflösung
    $Tiefe_ = $Tiefe

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $b = Breite
    ;~ $h = Hoehe
    ;~ $Tiefe = Anzahl Bilder
    ;~ $Helligkeit = 0 - 255

    [/autoit] [autoit][/autoit] [autoit]

    Local $img = _CreateImage($b, $h) ;Bild erzeugen
    Local $hdc = DllStructGetData($img, 1, 1)
    Local $ptr = DllStructGetData($img, 1, 4)
    Local $struct = DllStructCreate('int['&$b * $h&']', $ptr)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $bmp = _GDIPlus_BitmapCreateFromGraphics($b, $h, $hGraphics)
    Local $hBu = _GDIPlus_ImageGetGraphicsContext($bmp)
    Local $col
    Local $bmp2 = _GDIPlus_BitmapCloneArea($bmp, 0, 0, $b, $h)
    Local $bbuffer = _GDIPlus_ImageGetGraphicsContext($bmp2)
    Local $hBuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Erhellen = 1, $Verdunkeln = 1
    $Helligkeit = _Betrag($Helligkeit)
    While $Helligkeit > 2
    $Helligkeit -= 1
    WEnd
    If $Helligkeit < 1 Then
    $Verdunkeln = $Helligkeit
    $Erhellen = 1
    Else
    $Erhellen = 1 - ($Helligkeit - 1)
    $Verdunkeln = 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $px = 0
    Local $pxges = 0

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To $Tiefe Step 1 ;p = BildNummern
    For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
    For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
    $pxges += 1
    Next
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To $Tiefe Step 1 ;p = BildNummern
    For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
    For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
    Switch _Zufall($Nummer)
    Case 0
    $col = '0x' & Hex((255 / 2 ^ $p) * $Erhellen, 2) & '000000'
    Case 1
    $col = '0x' & Hex((255 / 2 ^ $p) * $Verdunkeln, 2) & 'FFFFFF'
    EndSwitch
    DllCall($ghGDIPDll, 'int', 'GdipBitmapSetPixel', 'hwnd', $bmp, 'int', $x, 'int', $y, 'dword', $col)
    Next
    Next
    _GDIPlus_GraphicsDrawImageRectRect($bbuffer, $bmp, 0, 0, $b / 2 ^ ($Tiefe - $p), $h / 2 ^ ($Tiefe - $p), 0, 0, $b, $h)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Local $_ptr, $_hbmp
    Local $_hdc = _CreateNewBmp32($b, $h, $_ptr, $_hbmp)
    Local $gra = _GDIPlus_GraphicsCreateFromHDC($_hdc)
    _GDIPlus_GraphicsDrawImage($gra, $bmp2, 0, 0)
    _GDIPlus_GraphicsDispose($gra)
    _GDIPlus_GraphicsDispose($hBu)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_GraphicsDispose($bbuffer)
    _GDIPlus_BitmapDispose($bmp)
    _GDIPlus_BitmapDispose($bmp2)
    Local $a[3] = [$_hdc, $_hbmp, $_ptr]
    Return $a
    EndFunc ;==>_PerlinNoise

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit]

    #Region - Image Befehle (by Mars)

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImage($b, $h)
    Local $ptr, $hdc, $hbmp
    $hdc = _CreateNewBmp32($b, $h, $ptr, $hbmp)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImageRes($res)
    Local $ptr, $hdc, $hbmp, $b, $h
    $hdc = getDCfromRes32($res, $ptr, $hbmp, $b, $h)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImageRes

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImageSchrift($String, $Farbe = 0xFFFFFFFF, $Size_ = 5, $abs = 1)
    Local $size = _GetSize($String, $Size_, $abs)
    Local $b = $size[0]
    Local $h = $size[1]
    Local $ptr, $hbmp
    Local $hdc = _CreateNewBmp32($b, $h, $ptr, $hbmp)
    Local $hgr = _GDIPlus_GraphicsCreateFromHDC($hdc)
    _GDIPlus_GraphicsClear($hgr, 0x00000000)
    _GDIPlus_GraphicsDispose($hgr)
    _DrawSchrift($hdc, $String, $Size_, $Farbe, $abs)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImageSchrift

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImage($hdc, $x, $y, $struct, $yoffset = 0)
    _WinAPI_BitBlt($hdc, $x, $y + $yoffset, DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), DllStructGetData($struct, 1, 1), 0, 0, $SRCCOPY)
    EndFunc ;==>_DrawImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImageStretch($hdc, $x, $y, $struct, $Zoom = 1, $yoffset = 0)
    _WinAPI_StretchBlt($hdc, $x, $y, DllStructGetData($struct, 1, 2)*$Zoom, DllStructGetData($struct, 1, 3)*$Zoom, DllStructGetData($struct, 1, 1), 0, 0,DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), $SRCCOPY)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImageTrans($hdc, $x, $y, $struct, $Zoom = 1, $yoffset = 0)
    _GDI_AlphaBlend($hdc, $x, $y + $yoffset, DllStructGetData($struct, 1, 2)*$Zoom, DllStructGetData($struct, 1, 3)*$Zoom, DllStructGetData($struct, 1, 1), 0, 0, DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), $h_AlphaStruct)
    EndFunc ;==>_DrawImageTrans

    [/autoit] [autoit][/autoit] [autoit]

    Func _DeleteImage(ByRef $struct)
    _Delete_Bitmap32(DllStructGetData($struct, 1, 1), DllStructGetData($struct, 1, 5))
    $struct = 0
    EndFunc ;==>_DeleteImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _CopyImage($img)
    Local $hDC_img = DllStructGetData($img, 1, 1)
    Local $b_img = DllStructGetData($img, 1, 2)
    Local $h_img = DllStructGetData($img, 1, 3)
    Local $ret = _CreateImage($b_img, $h_img)
    _DrawImage(DllStructGetData($ret, 1, 1), 0, 0, $img, 0)
    Return $ret
    EndFunc ;==>_CopyImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _SaveImage($img)
    Local $Pfad = FileSaveDialog('BildSpeichern', @ScriptDir, '(*,.png)', Default, Hex(Random(256, 16 ^ 3, 1), 3) & '.png')
    If Not StringRight($Pfad, 4) = '.png' Then $Pfad &= '.png'
    _GDIPlus_Startup()
    Local $bm = _GDIPlus_BitmapCreateFromHBITMAP(DllStructGetData($img, 1, 5))
    _GDIPlus_ImageSaveToFile($bm, $Pfad)
    _GDIPlus_BitmapDispose($bm)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Save

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion - Image Befehle (by Mars)
    ;EndRegion - Image Befehle (by Mars)

    [/autoit] [autoit][/autoit] [autoit]

    #Region

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseDC($hGUI, $hdc_GUI)
    _DeleteImage($Backbuffer)
    _DeleteImage($Perlin)
    _DeleteImage($ImageSchrift_Zeit)
    DllClose($h_NTDLL_DLL)
    DllClose($h_MSIMG32_DLL)
    DllClose($h_GDI32_DLL)
    DllClose($h_OLE32_DLL)
    DllClose($h_USER32_DLL)
    DllClose($h_KERNEL32_DLL)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Log($x, $y) ; Logarithmus zur Basis y
    Return Log($x) / Log($y)
    EndFunc ;==>Log2

    [/autoit] [autoit][/autoit] [autoit]

    Func _Betrag($a)
    If $a > 0 Then Return $a
    Return -$a
    EndFunc ;==>_Betrag

    [/autoit] [autoit][/autoit] [autoit]

    Func _Min($a, $b)
    If $a > $b Then Return $b
    Return $a
    EndFunc ;==>_Min

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
    EndFunc ;==>WM_NCHITTEST

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawSchrift($hdc, $String, $px, $Farbe = 0xFFFF0000, $abs = 1)
    Local $FontPng = _SchriftRes($px)
    Local $Font
    Local $ptr, $hbmp, $imgBreite, $imgHoehe
    Local $hDC_Font = getDCfromRes32($FontPng, $ptr, $hbmp, $imgBreite, $imgHoehe)
    _Farbe($ptr, $Farbe, $imgBreite * $imgHoehe)
    Local $l = StringLen($String)
    Local $s = ''
    Local $x = 0, $y = 0, $nr = 0
    For $i = 1 To $l Step 1
    $s = StringMid($String, $i, 1)
    If $s = '|' Then
    $y += $px + $abs
    $x = 0
    Else
    $nr = _GetNr($s)
    If $nr <> 36 Then _WinAPI_StretchBlt($hdc, $x, $y, $px, $px, $hDC_Font, $nr * $px, 0, $px, $px, $SRCCOPY)
    $x += $px + $abs
    EndIf
    Next
    _Delete_Bitmap32($hDC_Font, $hbmp)
    EndFunc ;==>_DrawSchrift

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetSize($a, $px, $abs = 1)
    Local $l = StringLen($a)
    Local $s = ''
    Local $c = 0, $c2 = 0, $c3 = 0
    For $i = 1 To $l Step 1
    $c += 1
    If $c >= $c2 Then $c2 = $c
    $s = StringMid($a, $i, 1)
    If $s = '|' Then
    $c = 0
    $c3 += 1
    EndIf
    Next
    Local $ret[2] = [$c2 * ($px + $abs), ($c3 + 1) * ($px + $abs)] ;5px für den Buchstaben und einer für den Abstand, $c3 wird erhöht, da Zeile 0 sonst nicht mitgezählt wird.
    Return $ret
    EndFunc ;==>_GetSize

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetNr($a) ;Gibt die Nummer des Zeichens aus
    Local $b[36 + 23] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_', '.', ';', 'ä', 'ö', 'ü', '-', '§', '$', '%', '&', '#', '>', '<', '[', ']', '(', ')', '"', "'", '=', '+', ':']
    For $i = 0 To 35 + 23 Step 1
    If $a = $b[$i] Then Return $i
    Next
    Return 36 + 23
    EndFunc ;==>_GetNr

    [/autoit] [autoit][/autoit] [autoit]

    Func _Farbe($ptr, $col, $px)
    Local $_Struct = DllStructCreate('int[' & $px & ']', $ptr)
    For $i = 0 To $px Step 1
    If DllStructGetData($_Struct, 1, $i) = 0xFFFFFFFF Then
    DllStructSetData($_Struct, 1, $col, $i)
    Else
    DllStructSetData($_Struct, 1, 0x00000000, $i)
    EndIf
    Next
    EndFunc ;==>_Farbe

    [/autoit] [autoit][/autoit] [autoit]

    Func _SchriftRes($px) ;Enthält die png Bilder der Schriften als Ressourcen.
    Switch $px
    Case 4
    Return '0x89504E470D0A1A0A0000000D49484452000000EC000000040100000000A5BFEE56000000874944415468DE017C0083FF00FEFEFFF9FF98FDFFFFFF99999FEFF8F8FFFF0006660BF996C3BD7EA4F000009989888921A8BD9999C299B693231ACF999B000FF90BF42F3CC3A5A4044000FA89EEBF21E8BB9FAE3296B6FC2C7F393FFD004F996B024F3CC3A5000E00009FFEF8F9F69F9BF8D9F2F6F92FFFF2FF1F1FF449FF0BF996C3BD7E00F440068A47638487EBE40000000049454E44AE426082'
    Case 5
    Return '0x89504E470D0A1A0A0000000D49484452000001270000000501000000002F321765000000C94944415478DA01BE0041FF00FFFFEFFFF1FFE30DC7FFFFFFF8C6318FFDFFC3F0FFFFF0000A52815FC92AC0EFD7F9440000008C6118423120630AE6318C6048C6B1884410C21F8C6330001FFC4150265F21303A1544F908008DA11F7A1F207D0AD6318FFE48C6AEFFC5F7D3F10FE35000118C5D5F908A1E303A1400038000FC6118427120630ACE3F948248AAB1240500FC311C7F90009F8C4150493F21303A1400F908008FFFEFC3F1FBE3F8C7F0EC7E4F93F127FFFF93FF0FC3FF9091FFC15FA64AC0EFD7F80000002DA25C98C2B780160000000049454E44AE426082'
    EndSwitch
    EndFunc ;==>_SchriftRes

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalAlloc($iBytes, $iFlags = 0)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'handle', 'GlobalAlloc', 'uint', $iFlags, 'ulong_ptr', $iBytes)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalAlloc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalLock($hMem)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'ptr', 'GlobalLock', 'handle', $hMem)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalLock

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalUnlock($hMem)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'bool', 'GlobalUnlock', 'handle', $hMem)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalUnlock

    [/autoit] [autoit][/autoit] [autoit]

    Func _IsPressed($a)
    Local $b = DllCall($h_USER32_DLL, "short", "GetAsyncKeyState", "int", '0x' & $a)
    Return BitAND($b[0], 0x8000) <> 0
    EndFunc ;==>_IsPressed

    [/autoit] [autoit][/autoit] [autoit]

    Func _Delete_Bitmap32($hdc, $hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteDC($hdc)
    EndFunc ;==>_Delete_Bitmap32

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe DC und ptr und handle auf die Bitmapdaten
    ;by Andy
    Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
    Local $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", -$iHeight) ;minus =standard = bottomup
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
    Local $adib = DllCall($h_GDI32_DLL, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
    $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
    _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
    Return $hcdc ;DC der Bitmap zurückgeben
    EndFunc ;==>_CreateNewBmp32

    [/autoit] [autoit][/autoit] [autoit]

    Func getDCfromRes32($res, ByRef $ptr, ByRef $hbmp, ByRef $iwidth_file32, ByRef $iheight_file32);Erstellt eine 32-Bit Bitmap von Ressource Daten. + Breite und Höhe werden ermittelt
    _GDIPlus_Startup()
    Local $hBitmap = Load_BMP_From_Mem($res)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $iwidth_file32 = _GDIPlus_ImageGetWidth($hBitmap)
    $iheight_file32 = _GDIPlus_ImageGetHeight($hBitmap)
    ;by Andy
    Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
    Local $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
    DllStructSetData($tBMI, "Width", $iwidth_file32)
    DllStructSetData($tBMI, "Height", -$iheight_file32) ;minus =standard = bottomup
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
    Local $adib = DllCall($h_GDI32_DLL, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    _WinAPI_SelectObject($hcdc, $adib[0])
    ; copy the content of the bitmap into the buffer ...
    _WinAPI_GetDIBits($hcdc, $hbmp, 0, $iheight_file32, $adib[4], DllStructGetPtr($tBMI), $DIB_RGB_COLORS)
    $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
    $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
    ;_arraydisplay($adib)
    _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
    Return $hcdc ;DC der Bitmap zurückgeben
    EndFunc ;==>getDCfromRes32

    [/autoit] [autoit][/autoit] [autoit]

    Func Load_BMP_From_Mem($pic)
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream
    $memBitmap = Binary($pic)
    $len = BinaryLen($memBitmap)
    $hData = _MemGlobalAlloc($len, 0x0002)
    $pData = _MemGlobalLock($hData)
    $tMem = DllStructCreate("byte[" & $len & "]", $pData)
    DllStructSetData($tMem, 1, $memBitmap)
    _MemGlobalUnlock($hData)
    $hStream = _WinAPI_CreateStreamOnHGlobal($pData)
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream)
    $tMem = ""
    Return $hBitmapFromStream
    EndFunc ;==>Load_BMP_From_Mem

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
    EndFunc ;==>_WinAPI_StretchBlt

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDI_AlphaBlend_GetStruct($Alpha = 255)
    Local $struct = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($struct, 1, 0) ; 0 = AC_SRC_OVER
    DllStructSetData($struct, 2, 0) ; 0 "Must be Zero"
    DllStructSetData($struct, 3, $Alpha) ; Alpha fürs ganze Bild
    DllStructSetData($struct, 4, 1) ; 1 = Bild enthält einen Alphakanal
    Local $data = DllStructCreate("dword", DllStructGetPtr($struct))
    $data = DllStructGetData($data, 1)
    Return $data
    EndFunc ;==>_GDI_AlphaBlend_GetStruct

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDI_AlphaBlend($hDCDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hDCSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $blendFunction)
    DllCall($h_MSIMG32_DLL, 'int', 'AlphaBlend', _
    'ptr', $hDCDest, _ ; // handle to destination DC
    'int', $nXOriginDest, _ ; // x-coord of upper-left corner
    'int', $nYOriginDest, _ ; // y-coord of upper-left corner
    'int', $nWidthDest, _ ; // destination width
    'int', $nHeightDest, _ ; // destination height
    'ptr', $hDCSrc, _ ; // handle to source DC
    'int', $nXOriginSrc, _ ; // x-coord of upper-left corner
    'int', $nYOriginSrc, _ ; // y-coord of upper-left corner
    'int', $nWidthSrc, _ ; // source width
    'int', $nHeightSrc, _ ; // source height
    'dword', $blendFunction);$blendFunction) ; // alpha-blending function
    EndFunc ;==>_GDI_AlphaBlend

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    Local $aResult = DllCall($h_OLE32_DLL, "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    Return $aResult[3]
    EndFunc ;==>_WinAPI_CreateStreamOnHGlobal

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    Return $aResult[2]
    EndFunc ;==>_GDIPlus_BitmapCreateFromStream

    [/autoit] [autoit][/autoit] [autoit]

    Func _C($a, $b = 0) ;Gibt x/y Koords für ein Fenster damit es zentriert ist.
    If $b Then Return @DesktopWidth / 2 - $a / 2 ; Wenn b dann x
    Return @DesktopHeight / 2 - $a / 2 ; Sonst y
    EndFunc ;==>_C

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion

    [/autoit]

    Soo Fertig !
    Jetzt sollte direkt ein Bild zu sehen sein.
    Man kann jetzt alles Relevante in den ersten Paar Zeilen Skript einstellen. (dann muss man nicht suchen wo die Variablen sind um was zu verändern.)

  • heyho,
    ich hab mich mal an den Landschaften versucht^^
    autoit.de/wcf/attachment/12664/
    autoit.de/wcf/attachment/12665/
    links das von marsis Script erstellte Höhenprofil, rechts die Landschaft dazu^^

    Dazu in Marsis Script folgendes eintragen

    Spoiler anzeigen
    [autoit]

    ;################## Hier Parameter bestimmen ###########################
    Global $hell = 140 ;Helligkeit des Bildes
    Global $Tiefe__ = 20 ;Tiefenwert
    Global $Seed = 9 ;Nummer des Bildes
    Global $F1 = 0x00000000 ;Farbe 1
    Global $F2 = 0xFFFFFFFF ;Farbe 2
    Global $Size = 550 ; Welche Breite und Höhe soll das Bild haben ?
    Global $Stretch = 2 ;Um welchen Faktor wird das Bild vergrößert ?
    ;#######################################################################

    [/autoit]


    weiterhin ab Zeile 144 folgende 3 Zeilen einfügen:

    Spoiler anzeigen
    [autoit]

    ;EndSwitch

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_ImageSaveToFile(_GDIPlus_BitmapCreateFromHBITMAP(DllStructGetData($tmpImg2, 1, 5)), @ScriptDir & "\perlin.bmp")
    shellexecute("perlin.bmp")
    exit ;oder Messagebox, um ein "schönes" Höhenprofil auszusuchen

    [/autoit] [autoit][/autoit] [autoit]

    ; _GDIPlus_GraphicsDispose($gr)

    [/autoit]

    danach dann folgendes Script starten (lädt die Bitmap als Höhenprofil und zeichnet die Landschaft)

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include <GDIPlus.au3>
    #include <WindowsConstants.au3>
    #include <StructureConstants.au3>
    #include <GDIConstants.au3>
    #include <GDIp.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    Global $ptr, $iwidth, $iheight
    $hdc_bmp = getDCfromfile("perlin.bmp", $ptr)
    $struct = DllStructCreate("dword[" & $iwidth * $iheight & "]", $ptr) ;struct an bmp-position

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hgui = GUICreate("landschaftstest", 2 * $iwidth, 0.5 * $iheight)
    $hdc_gui = _WinAPI_GetDC($hgui)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hgui)
    $hPen = _GDIPlus_PenCreate()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _WinAPI_BitBlt($hdc_gui, 0, 0, $iwidth, $iheight, $hdc_bmp, 0, 0, $srccopy)

    [/autoit] [autoit][/autoit] [autoit]

    $hBrushVerlauf = _GDIPlus_LineBrushCreate(0, 0, 0, 120, 0xFF0000ff, 0xFFFFFFFF)
    _GDIPlus_GraphicsFillRect($hGraphic, $iwidth, 0, $iwidth, $iheight / 2, $hBrushVerlauf)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    For $h = 0 To $iheight - 1 ;zeilenweise pixel
    For $w = 1 To $iwidth
    $col = DllStructGetData($struct, 1, $iwidth * $h + $w);pixelfarbe aus bitmap
    $high = Dec(Hex($col, 2)) / 4 ;höhe aus farbe
    If $high < 28 Then ;wenn höhe <28 dann wasser
    $col = BitAND($col, 0xFF0000FF)
    ElseIf $high < 38 Then ;wenn höhe <38 dann wald
    $col = BitAND($col, 0xFF00FF00)
    EndIf
    ;ansonsten farbe=höhe
    $hPen = _GDIPlus_PenCreate($col)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iwidth + $w, 150 + $h / 3, $iwidth + $w, 150 + $h / 3 - $high, $hPen)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While GUIGetMsg() <> -3
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func getDCfromfile($bmpfile, ByRef $ptr) ;ptr to bitmapdata, it is possible to manipulate one pixel if needed
    $hbitmap = _GDIPlus_BitmapCreateFromFile($bmpfile)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hbitmap)
    $iwidth = _GDIPlus_ImageGetWidth($hbitmap)
    $iheight = _GDIPlus_ImageGetHeight($hbitmap)

    [/autoit] [autoit][/autoit] [autoit]

    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Width", $iwidth)
    DllStructSetData($tBMI, "Height", -$iheight)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32)
    $hdc = _WinAPI_GetDC(0)
    $hcdc = _WinAPI_CreateCompatibleDC($hdc)
    $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'ptr', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 1, 'ptr*', 0, 'ptr', 0, 'uint', 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; select object
    _WinAPI_SelectObject($hcdc, $adib[0])

    [/autoit] [autoit][/autoit] [autoit]

    ; copy the content of the bitmap into the buffer ...
    _WinAPI_GetDIBits($hdc, $hbmp, 0, $iheight, $adib[4], DllStructGetPtr($tBMI), 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; create the a dllstruct with the pointer $aDIB[4]
    $stride = 3 * $iwidth + Mod($iwidth, 4) ;number of bytes in one line (filled with some bytes, because it must be a multiple of four!)
    $tBits = DllStructCreate('byte[' & $stride * $iheight & ']', $adib[4])
    $ptr = DllStructGetPtr($tBits)
    _GDIPlus_BitmapDispose($hbitmap)
    _WinAPI_DeleteObject($adib[0])
    Return $hcdc ;MemoryDC of bitmap
    EndFunc ;==>getDCfromfile

    [/autoit]

    das ist "native" AutoIt, da sollten wir wesentlich mehr rausholen können^^

  • Soooooo xD

    Andy ich hab die Idee mit den Senkrechten Linien mal aufgegriffen und bissl was Drei Dimensionales gebastelt.

    Leider braucht man für den Spaß einen sehr leistungsfähigen Rechner und ein paar Dlls.
    Deshalb kommt alles in ein Rar Archiv...

    Aber es kommt schon was cooles dabei aus :P

  • Da bin ich dafür ! :P

    Ich vermute allerdings, dass das nicht "mal Eben" machbar ist.
    Schon gar keine 3D enigne...

    Da müsste man mal bei den 64K Demos gucken wie die Engine gebaut wird... (Und wie man sie anschließend verwendet^^)

  • Naja, die DLL-Funktionen kann man ja auch aus dem Assemblercode heraus aufrufen - eine eigene (moderne) Grafikengine in Assembler zu schreiben? Da braucht's schon andere Kaliber als mich oder Andy (wobei ich ihm das fast schon zutrauen würde ;)). Es geht hauptsächlich erstmal um die Berechnungen, und das GDI+ Zeug, was man rausschmeißen kann. Ich arbeite lieber direkt in einer Bitmap, das hat sich als schneller herausgestellt.

  • Ich merk schon, hier geht was^^
    Eine 3d-(Render)-Engine zu schreiben ist wahrscheinlich garnicht das grosse Problem, in einigen 4k-Demos wurde das in 200-300 Byte realisiert...Ich hatte einen einfachen Raytracer mal in AutoIt geschrieben, der war, ausser dass er sehr kompakt war, schnarchlangsam^^. Und die 3d-"Modelle" waren auch nicht von der Stange....

    In Assembler fehlt mir da zzt bissl der Antrieb und viel mehr noch der Background. Da haben es die OpenGL (und Konsorten)-Jungs und Mädels natürlich viel besser, Funktion aufrufen, fertig! Die eigentliche Arbeit macht dann die Grafikkarte.

    Zitat

    Ich arbeite lieber direkt in einer Bitmap, das hat sich als schneller herausgestellt.

    hehe, so siehts aus, da hat man eine einfache Reihe hintereinanderliegender dwords und kann(muss) sich was einfallen lassen^^

    Ich habe mein Landschaft-Script mal testweise dahingehend abgeändert, dass die "senkrechten Linien" nur noch aus den 3 "obersten" aufeinandergestapelten Pixeln bestehen, nicht mehr aus dem kompletten "Pfeiler".
    Also einfach so

    [autoit]

    _GDIPlus_GraphicsDrawLine($hGraphic, $iwidth + $w, 150 + $h / 4-$high+3, $iwidth + $w, 150 + $h / 4 - $high, $hPen)

    [/autoit]


    Das hat eigentlich einwandfrei funktioniert, allerdings natürlich nur, wenn keine "steilen" Übergänge entstehen.

    In asm sollte es kein Thema sein, aus der Perlin-Höhenkarte das komplette 3D-Bild in einigen Millisekunden zu erstellen. Die üblichen 3d-Funktionen wie bspw. rotieren, zoomen usw. wären dazu noch einigermassen billig, aber für Beleuchtung, Schatten, Nebel usw. wirds dann schon aufwendiger. Da haben dann die c++-er wesentlich bessere Karten, denn dafür gibts schon fix-und fertige Funktionen!

  • Das OpenGl Teil für AutoIt hab ich durch Zufall gefunden.

    Hab mich damit noch nie auseinander gesetzt. (kein GDI xD).
    Und mit etwas Glück hat das sogar geklappt. Aber ich könnte wetten, dass ich einige grobe Schnitzer drin habe.

    Im Prinzip würde ich das viel lieber nur mit GDI-Funcs bauen.
    Aber da hab ich das eine 3D beispiel nicht gefunden. (ich suchs nochmal. finde ich bestimmt. weiß eig wos ist^^)

    Ich wollte das so aufbauen:

    Der Boden wird Gekachelt mit Vierecken. Jede Ecke hat neben x und y Koords die Höhe z der Höhenkarte.
    --> Man hat eine Schräglage für jede einzelne Kachel.
    --> Man hat (wenn die Kantenlänge n Pixel breit ist) n² Pixel und (n-1)² Kacheln.
    --> Man kann JEDE Kachel einzeln mit einer Grafik versehen (Draw Image 4 Points)
    --> Am Winkel kann man auch die Beleuchtung festmachen.

    Das ist aber ein ganz schön großes Projekt... Das muss ich vertagen (für mich jedenfalls.) hab nicht sooo viel Zeit...

  • Zitat

    Im Prinzip würde ich das viel lieber nur mit GDI-Funcs bauen.

    So scheiden sich die Geister^^, ich würde viel lieber den Hintern hochbekommen und fit für den OpenGL-Kram werden...
    Dann ist es niucht mehr weit zu OpenCl, da sehe ich echtes Potenzial. Die Grafikkarten heutzutage sind derart brutal schnell durch massives Parallelisieren (wenn es der Algorithmus her gibt), da gewinnt ein Desktop-Prozessor nicht mal nen Blumenpott....

    Zitat

    Ich wollte das so aufbauen: *snip*

    Im Endeffekt braucht man die Kacheln nicht, in der kleinsten Version ist eine Kachel = ein Pixel! Wenn es ganz hart wird, ist jede Kachel 2x2 Pixel gross und man lässt anschliessend einen Filter drüberlaufen^^
    Eigentlich hängt es "nur" an der Höhenkarte, ob eine mehr oder weniger realistische Landschaft erzeugt wird, den "Höhen" dann Farben zuzuordnen ist dann wieder eine andere Sache.
    Die Beleuchtung bzw Schatten sind viel komplizierter, spätestens dann kommt man um einen Raytracer nicht mehr drumrum.
    Der "wandert" dann Pixel für Pixel vom aktuellen Pixel aus in Richtung "Sonne" und schaut auf diesem Weg (Linie) nach, ob das Pixel auf der Linie "höher" ist als die aktuelle Höhe des Pixels auf der Linie (urghs^^, muss mal ne Zeichnung machen^^)

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    2 Mal editiert, zuletzt von Andy (24. Februar 2011 um 21:37)

  • Auch wenn im Startpost steht, dass es keine asm Beschleunigung geben soll...
    naja..
    ich konnte nicht wiederstehen^^

    Das Resultat ist etwa 25 Mal so schnell wie vorher. --> ca. 1000 px/s statt 40^^

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <AssembleIt.au3>
    ;~ #include 'GlPluginUtils.au3'

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUICloseOnESC', 0)
    Opt('GUIOnEventMode', 0)
    ;~ Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    ;################## Hier Parameter bestimmen ###########################
    Global $hell = 168 ;Helligkeit des Bildes
    Global $Tiefe__ = 15 ;Tiefenwert
    Global $Seed = 9 ;Nummer des Bildes
    Global $F1 = 0xFF6060FF ;Farbe 1
    Global $F2 = 0xFFFFFFFF ;Farbe 2
    Global $Size = Int(@DesktopHeight*0.92) ; Welche Breite und Höhe soll das Bild haben ?
    Global $Stretch = 1 ;Um welchen Faktor wird das Bild vergrößert ?
    ;#######################################################################

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Global Const $Size = 200
    ;~ Global Const $Stretch = 2
    Global Const $BreiteMulti = 1
    Global Const $Breite = $Size
    Global Const $Hoehe = $Size
    Global Const $Titel = 'Perlin'

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $WM_NCHITTEST = 0x0084 ; Fenster "Anfassen"
    Global Const $HTCAPTION = 2 ; Fenster "Anfassen"
    Global Const $WS_EX_LAYERED = 0x00080000
    Global Const $WS_POPUP = 0x80000000
    Global Const $SRCCOPY = 0x00CC0020
    Global Const $BLACKNESS = 0x00000042
    Global Const $DIB_RGB_COLORS = 0 ;Eine Absolut sinnlose Variable die aber immer fehlt.

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $h_NTDLL_DLL = DllOpen('ntdll.dll')
    Global Const $h_MSIMG32_DLL = DllOpen('msimg32.dll')
    Global Const $h_GDI32_DLL = DllOpen('gdi32.dll')
    Global Const $h_OLE32_DLL = DllOpen('ole32.dll')
    Global Const $h_USER32_DLL = DllOpen('user32.dll')
    Global Const $h_KERNEL32_DLL = DllOpen('kernel32.dll')

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $h_AlphaStruct = _GDI_AlphaBlend_GetStruct()

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGUI = GUICreate($Titel, $Breite * $Stretch * $BreiteMulti, $Hoehe * $Stretch, _C($Breite * $Stretch * $BreiteMulti, 1), _C($Hoehe * $Stretch, 0), $WS_POPUP, $WS_EX_LAYERED)
    GUISetBkColor(0xFF0000, $hGUI)
    WinSetTrans($hGUI, '', 255)
    GUISetOnEvent(-3, '_Exit', $hGUI)
    GUISetState(@SW_SHOW, $hGUI)

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $hdc_GUI = _WinAPI_GetDC($hGUI)
    Global $ASM_Struct_Verpixelung = _AsmToStruct('0x8B4C24048B398B51048B4110A3ED7C62018B4114A3F17C62018B41088B590C5189C1515053E80D0000005B585983E90177F059895104C3B80000000089D9E81E00000083F8007509A1ED7C62018907EB07A1F17C6201890783C70483E90177DEC389D0BA0000000069C0E51B000005F5D5000031D2BB80F40300F7FB81FA40FA01007707B800000000EB05B801000000C3') ;Wird für den Perlingenerator gebraucht.

    [/autoit] [autoit][/autoit] [autoit]

    Global $Backbuffer = _CreateImage($Breite*$Stretch*$BreiteMulti, $Hoehe*$Stretch)
    Global $hDC_Backbuffer = DllStructGetData($Backbuffer, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ ;################## Hier Parameter bestimmen ###########################
    ;~ Global $hell = 120 ;Helligkeit des Bildes
    ;~ Global $Tiefe__ = 15 ;Tiefenwert
    ;~ Global $Seed = 9 ;Nummer des Bildes
    ;~ Global $F1 = 0xFF4040A0 ;Farbe 1
    ;~ Global $F2 = 0xFFFFFFFF ;Farbe 2
    ;~ ;#######################################################################

    [/autoit] [autoit][/autoit] [autoit]

    Global $Tiefe_ = 0
    Global $Timer = TimerInit()
    Global $Perlin = _CreatePerlin($Breite, $Hoehe, $Tiefe__, $Seed, $hell, $F1, $F2)
    Global $Diff = Int(TimerDiff($Timer))

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _SaveImage($Perlin)

    [/autoit] [autoit][/autoit] [autoit]

    Global $ImageSchrift_Zeit = _CreateImageSchrift('Size: ' & $Breite & 'x' & $Hoehe & ' px' & '|Helligkeit: ' & $hell & '|Tiefe: ' & $Tiefe_ & '|Benötigte Zeit: ' & $Diff & ' ms|Pixel pro ms: ' & Round($Breite*$Hoehe/$Diff, 2), 0xFF000000, 4) ; 4px große Schrift

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _AsmToStruct($ASM_Code)
    Local $CodeStruct = DllStructCreate('byte[' & StringLen($ASM_Code) / 2 - 1 & ']')
    DllStructSetData($CodeStruct, 1, $ASM_Code)
    Return $CodeStruct
    EndFunc ;==>_AsmToStruct

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ASM_Verpixelung($Ziel, ByRef $Nummer, $b, $h, $f1, $f2)
    ;~ Ziel = Bitmap wo der Spaß hinsoll
    ;~ Nummer = Startwert
    ;~ b = Breite
    ;~ h = Hoehe

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $f1 = 0xFF00FF00
    ;~ $f2 = 0xFFFf00FF

    [/autoit] [autoit][/autoit] [autoit]

    Local $struct = DllStructCreate('int[6]')
    DllStructSetData($struct, 1, $Ziel, 1)
    DllStructSetData($struct, 1, $Nummer, 2)
    DllStructSetData($struct, 1, $b, 3)
    DllStructSetData($struct, 1, $h, 4)
    DllStructSetData($struct, 1, $f1, 5)
    DllStructSetData($struct, 1, $f2, 6)
    ;~ _AssembleIt('ptr','_ASM_Verpixelung_','ptr', $Ziel, 'int', $Nummer, 'int', $b, 'int', $h) ;um den code zu erhalten. - Veraltet

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _AssembleIt('ptr','_ASM_Verpixelung_','ptr', DllStructGetPtr($struct)) - Neu. Mit Struct
    ;~ ToolTip('vorher: ' & $Nummer & @CRLF & _
    ;~ 'nachher: ' & DllStructGetData($struct, 1, 2))

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($h_USER32_DLL, 'ptr', 'CallWindowProcW', 'ptr', DllStructGetPtr($ASM_Struct_Verpixelung), 'ptr', DllStructGetPtr($struct), 'int', 0, 'int', 0, 'int', 0)

    [/autoit] [autoit][/autoit] [autoit]

    $Nummer = DllStructGetData($struct, 1, 2)
    $struct = 0

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_ASM_BitBlt

    [/autoit] [autoit][/autoit] [autoit]

    Func _ASM_Verpixelung_()
    _('use32')
    _('org '&FasmGetBasePtr($Fasm))
    _('mov ecx, [esp+4]') ;Pointer auf die Struct (Hier steckt alles an Daten drin.
    _('mov edi,dword[ecx]') ;Pointer fürs Bitmap = edi
    _('mov edx,dword[ecx+4]') ;Startnummer = edx
    _('mov eax, dword[ecx+16]') ; Farbe1 aus der Struct holen
    _('mov dword[farbe1], eax') ; Farbe 1 speichern
    _('mov eax, dword[ecx+20]') ; Farbe2 aus der Struct holen
    _('mov dword[farbe2], eax') ; Farbe 2 speichern
    _('mov eax,dword[ecx+8]') ;Breite = eax
    _('mov ebx,dword[ecx+12]') ;Höhe = ebx
    _('push ecx') ;Datenpointer sichern. (esp + 4)
    _('mov ecx, eax') ; Der Zähler enthält die breite.
    _('_x:') ;Schleife 1
    _('push ecx') ; Der Zähler wird gesichert.(esp + 4)
    _('push eax') ; Die Breite wird gesichert, weil eax in der Schleife2 gebraucht wird(esp + 4)
    _('push ebx') ; Auch die Höhe wird gesichert.(esp + 4)
    _('call Schleife2') ; Hier wird tüchtig gefärbt
    _('pop ebx') ;Höhe wieder herstlelen
    _('pop eax') ;Die Breite wird wieder hergestellt
    _('pop ecx') ;Zähler wieder herstellen
    _('sub ecx,1');Schleife 1
    _('ja _x');ende von Schleife 1
    _('pop ecx') ;Pointer auf die Daten wieder holen
    _('mov dword[ecx + 4], edx') ;Startummer abspeichern
    _('ret ') ; Ende

    [/autoit] [autoit][/autoit] [autoit]

    _('Schleife2:') ;Sprungstelle zu Schleife 2
    _('mov eax, 0') ;Speicherstelle leeren. Hier sitzt später die 0 oder 1
    _('mov ecx, ebx') ;Die breite wird geholt für die Anzahl Durchläufe
    _('_y:') ;Schleife 2
    _('call zufall') ;edx erhält die fortlaufende Nr, eax enthält 0 oder 1
    _('cmp eax, 0') ;Wenn die Zufallszahl 0 ist dann:
    _('jne ungleich')
    ;######## Wenn eax = 0 Dann
    _('mov eax,dword[farbe1]')
    _('mov dword[edi], eax') ;Färben
    ;#################################
    _('jmp weiter')
    _('ungleich:')
    ;######## Wenn eax <> 0 Dann
    _('mov eax,dword[farbe2]')
    _('mov dword[edi], eax') ;Färben
    ;#################################
    _('weiter:')
    _('add edi,4') ;Nächster Pixel
    _('sub ecx,1') ;Runterzählen
    _('ja _y');Schleife 2
    _('ret ') ;Rücksprung zum Aufruf

    [/autoit] [autoit][/autoit] [autoit]

    _('zufall:') ; edx hat die startnummer
    _('mov eax, edx') ;Die Startnummer wird ins eax kopiert
    _('mov edx, 0') ;edx leeren
    _('imul eax, 7141') ; Multiplikation mit 7141
    _('add eax, 54773') ; Addition von 54773
    _('xor edx, edx') ; edx leeren
    _('mov ebx, 259200') ; den Wert ins ebx packen
    _('idiv ebx') ; edx = mod(eax, ebx)
    _('cmp edx, 129600'); Vergleichen von edx
    _('ja edxgr') ; Wenn größer dann
    _('mov eax, 0') ; eax = 0 --> Farbe 1
    _('jmp zufallende'); Das setzen der 1 überspringen, da eax = 0
    _('edxgr:') ; Wenns größer ist wird hier weiter gemacht.
    _('mov eax, 1') ; eax = 1 --> Farbe 2
    _('zufallende:') ; um alles zu beenden.
    _('ret ') ; Weiter gehts. eax enthält 0 oder 1, edx enthält die zufallszahl

    [/autoit] [autoit][/autoit] [autoit]

    _('farbe1 dd ?') ; Speicher für Die Farben
    _('farbe2 dd ?') ; Speicher für Die Farben
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    OnAutoItExitRegister('_Exit')

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Global $3D_Profil = _Create3DProfil_from_PerlinImage($Perlin, $hGUI, $breite*$Stretch, 0, $breite*$Stretch, $hoehe*$Stretch)

    [/autoit] [autoit][/autoit] [autoit]

    #cs _Create3DProfil_from_PerlinImage
    Func _Create3DProfil_from_PerlinImage($img, $hGUI, $x, $y, $breite, $hoehe)

    [/autoit] [autoit][/autoit] [autoit]

    Local $b = DllStructGetData($img, 1, 2)
    Local $h = DllStructGetData($img, 1, 3)
    Local $ptr = DllStructGetData($img, 1, 4)
    Local $Struct = DllStructCreate('int['& $b * $h &']', $ptr)

    [/autoit] [autoit][/autoit] [autoit]

    _DrawImageStretch($hDC_Backbuffer, 0, 0, $img, $Stretch)
    _DrawImage($hdc_GUI, 0, 0, $Backbuffer)

    [/autoit] [autoit][/autoit] [autoit]

    EmbedGlWindow( $hGUI, $breite,$hoehe,$x,$y)
    SetClearColor(1,1,1)
    Local $oBalken = ObjectCreate()
    Local $col, $high
    Local $x1, $y1, $z1, $x2, $y2, $z2
    Local $X_Achse = 0, $Y_Achse = 0, $Z_Achse = 0
    Local $rot, $blau, $gruen

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    SetPrint($oBalken)
    SetCamera(0, 0, $b*1.3, 0, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To $b - 1 Step 1
    For $o = 0 To $h - 1 Step 1
    $col = DllStructGetData($struct, 1, $b * $i + $o + 1);pixelfarbe aus bitmap
    $high = Dec(Hex($col, 2)) ;höhe aus farbe
    ;~ ToolTip($high)
    ;~ Sleep(100)

    [/autoit] [autoit][/autoit] [autoit]

    Switch $high
    Case 0 To 70
    $rot = $high/255*2.5
    $blau = $high/255*5
    $gruen = $high/255*2.5
    Case 70 To 160
    $rot = $high/255*2
    $blau = $high/255*3
    $gruen = $high/255*5
    Case 160 To 255
    $rot = $high/255*5
    $blau = $high/255*5
    $gruen = $high/255*5
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _CreateCube($oBalken, $i-$b/2, $o-$h/2, 0,1+$i-$b/2, 1+$o-$h/2, $high^0.6, $rot, $gruen, $blau, 255)
    ;~ _CreateCube($oBalken, -$b + $i, $h, 0,-$b+1 + $i, $h+1, $high, 1, 0, 0, 255)
    ;~ SceneDraw()
    ;~ ObjectRotate($oBalken, $Y_Achse, $X_Achse, 0)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;~ $high = 100

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _CreateCube($oBalken, -$b, $h, 0,-$b+1, $h+1, $high, Random(0, 5), Random(0, 5), Random(0, 5), 255)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $high = 150
    ;~ _CreateCube($oBalken, -$b+1, $h, 0,-$b+2, $h+1, $high, Random(0, 5), Random(0, 5), Random(0, 5), 255)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _CreateCube( $ObjId, $OrX, $OrY, $OrZ, $DeX, $DeY, $DeZ ,$Red, $Green, $Blue, $Alpha, $Tex = "" )
    ;~ AddCube($oBalken, 1, 1, 100, 3, 6, 0, 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    while Sleep(10)
    SceneDraw()
    _DrawImageStretch($hDC_Backbuffer, 0, 0, $img, $Stretch)
    _DrawImage($hdc_GUI, 0, 0, $Backbuffer)
    ;~ $X_Achse += 0.1
    ;~ $Y_Achse += -0.1
    $Z_Achse += 0.1
    ;~ ToolTip($Y_Achse)
    If $Y_Achse < 0 Then $Y_Achse += 360
    If $Y_Achse > 360 Then $Y_Achse -= 360
    If $X_Achse < 0 Then $X_Achse += 360
    If $X_Achse > 360 Then $X_Achse -= 360
    If $z_Achse < 0 Then $z_Achse += 360
    If $z_Achse > 360 Then $z_Achse -= 360
    $Y_Achse = 300
    ObjectRotate($oBalken, $Y_Achse, $X_Achse, $Z_Achse)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Return _CreateImage($b, $h)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    #ce _Create3DProfil_from_PerlinImage

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    $Seed = Random(0, 50000, 1)
    _DrawImageStretch($hDC_Backbuffer, 0, 0, $Perlin, $Stretch)
    ;~ _DrawImageStretch($hDC_Backbuffer, $Breite * $Stretch, 0, $3D_Profil, $Stretch)
    _DrawImageTrans($hDC_Backbuffer, 2*$Stretch, ($Hoehe - DllStructGetData($ImageSchrift_Zeit, 1, 3) - 1)*$Stretch, $ImageSchrift_Zeit, $Stretch)
    _DrawImage($hdc_GUI, 0, 0, $Backbuffer)
    _DeleteImage($Perlin)
    _DeleteImage($ImageSchrift_Zeit)
    ;~ $hell += 1
    If $hell > 255 Then $hell = 0
    $Timer = TimerInit()
    $Perlin = _CreatePerlin($Breite, $Hoehe, $Tiefe__, $Seed, $hell, $F1, $F2)
    $Diff = Int(TimerDiff($Timer))
    $ImageSchrift_Zeit = _CreateImageSchrift('Size: ' & $Breite & 'x' & $Hoehe & ' px' & '|Helligkeit: ' & $hell & '|Tiefe: ' & $Tiefe_ & '|Benötigte Zeit: ' & $Diff & ' ms|Pixel pro ms: ' & Round($Breite*$Hoehe/$Diff, 2), 0xFF000000, 4) ; 4px große Schrift
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zufall(ByRef $Z) ; Eine Pseudo Zufallszahl wird generiert.
    $Z = Mod((7141 * $Z + 54773), 259200)
    If $Z < 129600 Then Return 1 ; Nur mit 0 und 1
    Return 0
    EndFunc ;==>_Zufall

    [/autoit] [autoit][/autoit] [autoit]

    Func _Zufall2(ByRef $Z) ; Eine Pseudo Zufallszahl wird generiert.
    $Z = Mod((7141 * $Z + 54773), 259200)
    Return $Z / 259200 ; Ein Kommawert zw 0 und 1
    EndFunc ;==>_Zufall

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreatePerlin($b, $h, $Tiefe = 15, $Nummer = 1, $Helligkeit = 100, $Farbe1 = 0xFF000000, $Farbe2 = 0xFFFFFFFF)
    If $Tiefe < 1 Then $Tiefe = 1
    If Int(_Log(_Min($b, $h),2)) - 1 <= Int($Tiefe) Then $Tiefe = Int(_Log(_Min($b, $h),2)) - 1 ;Überprüfung ob die Tiefe möglich ist bei der angegebenen Auflösung
    $Tiefe_ = $Tiefe
    Local $randx = Int($b/3) ; Ein Rand muss sein, da sonst unten und rechts alles dunkel ist
    Local $randy = Int($h/3) ; Und oben und links alles hell. Kommt durch das Vergrößern...
    $b += $randx
    $h += $randy
    Local $img = _CreateImage($b, $h) ;Bild erzeugen Hier liegen die ganzen Verpixelungen
    Local $hdc = DllStructGetData($img, 1, 1)
    Local $ptr = DllStructGetData($img, 1, 4)
    Local $hbmp = DllStructGetData($img, 1, 5)
    Local $struct = DllStructCreate('int['& $b * $h &']', $ptr)
    Local $ziel = _CreateImage($b, $h) ;Hier wird das Endergebnis zusammengebaut.
    Local $hdc_ziel = DllStructGetData($ziel, 1, 1)
    Local $tmpImg = _CreateImage($b, $h) ;Hier wird immer jeweils eine Ebene vergrößert.
    ;~ Local $Mode = 0
    $gr = _GDIPlus_GraphicsCreateFromHDC(DllStructGetData($tmpImg, 1, 1))
    _GDIPlus_GraphicsSetInterpolationMode($gr, 7)
    For $p = 0 To $Tiefe Step 1

    [/autoit] [autoit][/autoit] [autoit]

    _ASM_Verpixelung(DllStructGetPtr($struct), $Nummer, $b, $h, $Farbe1, $Farbe2)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ Die Asm Func macht folgendes:
    ;~ - Verpixelung der kompletten Bitmap (bisher wird nicht nur ein Teil verpixelt, sondern alles) - kommt wahrscheinlich auch nicht mehr, da die meiste Ausbremsung durch AutoIt kommt und nicht durch die paar Pixel die zuviel gefüllt werden. (vllt aber doch :P)
    ;~ - Die Fortlaufende Nummer wird aktualisiert
    ;~ - Farben werden nun auch beachtet

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _Zufall($Nummer)
    ;~ ToolTip($Nummer)
    ;~ Sleep(1000)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ For $i = 0 To $b / 2 ^ ($Tiefe - $p) - 1 Step 1
    ;~ For $o = 0 To $h / 2 ^ ($Tiefe - $p) - 1 Step 1
    ;~ Switch _Zufall($Nummer)
    ;~ Case 1
    ;~ DllStructSetData($struct, 1, $Farbe2, $b * $i + $o + 1)
    ;~ Case 0
    ;~ DllStructSetData($struct, 1, $Farbe1, $b * $i + $o + 1)
    ;~ EndSwitch
    ;~ Next
    ;~ Next

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $Mode = 1
    $bm = _GDIPlus_BitmapCreateFromHBITMAP($hbmp)
    _GDIPlus_GraphicsDrawImageRectRect($gr, $bm, 0, 0, $b / 2 ^ ($Tiefe - $p), $h / 2 ^ ($Tiefe - $p), 0, 0, $b, $h)
    _GDIPlus_BitmapDispose($bm)
    _GDI_AlphaBlend($hdc_ziel, 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, $b, $h, _GDI_AlphaBlend_GetStruct(255 / 2 ^ $p))
    Next
    $b -= $randx
    $h -= $randy
    Local $tmpImg2 = _CreateImage($b, $h) ; Dieses Bild enthält das Endbild.
    _WinAPI_BitBlt(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, $hdc_ziel, $randx/2,$randy/2, $SRCCOPY) ;Es wird der Mittelteil ins Endbild kopiert. Ränder werden so beschnitten.
    Switch $Helligkeit
    Case 0 To 255/2
    _GDIPlus_GraphicsClear($gr, 0xFF000000) ; TmpImg1 wird nicht mehr gebraucht
    _GDI_AlphaBlend(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, 10,10, _GDI_AlphaBlend_GetStruct(255-$Helligkeit*2))
    Case 255/2 To 255
    _GDIPlus_GraphicsClear($gr, 0xFFFFFFFF) ; TmpImg1 wird nicht mehr gebraucht
    _GDI_AlphaBlend(DllStructGetData($tmpImg2, 1, 1), 0, 0, $b, $h, DllStructGetData($tmpImg, 1, 1), 0, 0, 10,10, _GDI_AlphaBlend_GetStruct($Helligkeit*2 - 255))
    EndSwitch
    _GDIPlus_GraphicsDispose($gr)
    _DeleteImage($img)
    _DeleteImage($tmpImg)
    _DeleteImage($ziel)
    Return $tmpImg2
    EndFunc ;==>_PerlinNoise

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Return SetError(@error, @extended, False)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_SetStretchBltMode($hDC, $iMode)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Ret = DllCall($h_GDI32_DLL, 'int', 'SetStretchBltMode', 'hwnd', $hDC, 'int', $iMode)

    [/autoit] [autoit][/autoit] [autoit]

    If (@error) Or (Not $Ret[0]) Then
    Return SetError(1, 0, 0)
    EndIf
    Return 1
    EndFunc ;==>_WinAPI_SetStretchBltMode

    [/autoit] [autoit][/autoit] [autoit]

    #cs - Alte Perlin Noise Func

    [/autoit] [autoit][/autoit] [autoit]

    Func _PerlinNoise($b, $h, $Tiefe, $Helligkeit, $Nummer, $hGraphics, $hDC_Backbuffer)
    If $Tiefe < 1 Then $Tiefe = 1
    If Int(_Log(_Min($b, $h),2)) - 1 <= Int($Tiefe) Then $Tiefe = Int(_Log(_Min($b, $h),2)) - 1 ;Überprüfung ob die Tiefe möglich ist bei der angegebenen Auflösung
    $Tiefe_ = $Tiefe

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $b = Breite
    ;~ $h = Hoehe
    ;~ $Tiefe = Anzahl Bilder
    ;~ $Helligkeit = 0 - 255

    [/autoit] [autoit][/autoit] [autoit]

    Local $img = _CreateImage($b, $h) ;Bild erzeugen
    Local $hdc = DllStructGetData($img, 1, 1)
    Local $ptr = DllStructGetData($img, 1, 4)
    Local $struct = DllStructCreate('int['&$b * $h&']', $ptr)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $bmp = _GDIPlus_BitmapCreateFromGraphics($b, $h, $hGraphics)
    Local $hBu = _GDIPlus_ImageGetGraphicsContext($bmp)
    Local $col
    Local $bmp2 = _GDIPlus_BitmapCloneArea($bmp, 0, 0, $b, $h)
    Local $bbuffer = _GDIPlus_ImageGetGraphicsContext($bmp2)
    Local $hBuffer = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer)

    [/autoit] [autoit][/autoit] [autoit]

    Local $Erhellen = 1, $Verdunkeln = 1
    $Helligkeit = _Betrag($Helligkeit)
    While $Helligkeit > 2
    $Helligkeit -= 1
    WEnd
    If $Helligkeit < 1 Then
    $Verdunkeln = $Helligkeit
    $Erhellen = 1
    Else
    $Erhellen = 1 - ($Helligkeit - 1)
    $Verdunkeln = 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $px = 0
    Local $pxges = 0

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To $Tiefe Step 1 ;p = BildNummern
    For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
    For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
    $pxges += 1
    Next
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To $Tiefe Step 1 ;p = BildNummern
    For $x = 0 To $b / 2 ^ ($Tiefe - $p) Step 1
    For $y = 0 To $h / 2 ^ ($Tiefe - $p) Step 1
    Switch _Zufall($Nummer)
    Case 0
    $col = '0x' & Hex((255 / 2 ^ $p) * $Erhellen, 2) & '000000'
    Case 1
    $col = '0x' & Hex((255 / 2 ^ $p) * $Verdunkeln, 2) & 'FFFFFF'
    EndSwitch
    DllCall($ghGDIPDll, 'int', 'GdipBitmapSetPixel', 'hwnd', $bmp, 'int', $x, 'int', $y, 'dword', $col)
    Next
    Next
    _GDIPlus_GraphicsDrawImageRectRect($bbuffer, $bmp, 0, 0, $b / 2 ^ ($Tiefe - $p), $h / 2 ^ ($Tiefe - $p), 0, 0, $b, $h)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Local $_ptr, $_hbmp
    Local $_hdc = _CreateNewBmp32($b, $h, $_ptr, $_hbmp)
    Local $gra = _GDIPlus_GraphicsCreateFromHDC($_hdc)
    _GDIPlus_GraphicsDrawImage($gra, $bmp2, 0, 0)
    _GDIPlus_GraphicsDispose($gra)
    _GDIPlus_GraphicsDispose($hBu)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_GraphicsDispose($bbuffer)
    _GDIPlus_BitmapDispose($bmp)
    _GDIPlus_BitmapDispose($bmp2)
    Local $a[3] = [$_hdc, $_hbmp, $_ptr]
    Return $a
    EndFunc ;==>_PerlinNoise

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit]

    #Region - Image UDF (by Mars)

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImage($b, $h)
    Local $ptr, $hdc, $hbmp
    $hdc = _CreateNewBmp32($b, $h, $ptr, $hbmp)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImageRes($res)
    Local $ptr, $hdc, $hbmp, $b, $h
    $hdc = getDCfromRes32($res, $ptr, $hbmp, $b, $h)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImageRes

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateImageSchrift($String, $Farbe = 0xFFFFFFFF, $Size_ = 5, $abs = 1)
    Local $size = _GetSize($String, $Size_, $abs)
    Local $b = $size[0]
    Local $h = $size[1]
    Local $ptr, $hbmp
    Local $hdc = _CreateNewBmp32($b, $h, $ptr, $hbmp)
    Local $hgr = _GDIPlus_GraphicsCreateFromHDC($hdc)
    _GDIPlus_GraphicsClear($hgr, 0x00000000)
    _GDIPlus_GraphicsDispose($hgr)
    _DrawSchrift($hdc, $String, $Size_, $Farbe, $abs)
    Local $struct = DllStructCreate('int[5]')
    DllStructSetData($struct, 1, $hdc, 1)
    DllStructSetData($struct, 1, $b, 2)
    DllStructSetData($struct, 1, $h, 3)
    DllStructSetData($struct, 1, $ptr, 4)
    DllStructSetData($struct, 1, $hbmp, 5)
    Return $struct
    EndFunc ;==>_CreateImageSchrift

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImage($hdc, $x, $y, $struct, $yoffset = 0)
    _WinAPI_BitBlt($hdc, $x, $y + $yoffset, DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), DllStructGetData($struct, 1, 1), 0, 0, $SRCCOPY)
    EndFunc ;==>_DrawImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImageStretch($hdc, $x, $y, $struct, $Zoom = 1, $yoffset = 0)
    _WinAPI_StretchBlt($hdc, $x, $y, DllStructGetData($struct, 1, 2)*$Zoom, DllStructGetData($struct, 1, 3)*$Zoom, DllStructGetData($struct, 1, 1), 0, 0,DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), $SRCCOPY)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawImageTrans($hdc, $x, $y, $struct, $Zoom = 1, $yoffset = 0)
    _GDI_AlphaBlend($hdc, $x, $y + $yoffset, DllStructGetData($struct, 1, 2)*$Zoom, DllStructGetData($struct, 1, 3)*$Zoom, DllStructGetData($struct, 1, 1), 0, 0, DllStructGetData($struct, 1, 2), DllStructGetData($struct, 1, 3), $h_AlphaStruct)
    EndFunc ;==>_DrawImageTrans

    [/autoit] [autoit][/autoit] [autoit]

    Func _DeleteImage(ByRef $struct)
    _Delete_Bitmap32(DllStructGetData($struct, 1, 1), DllStructGetData($struct, 1, 5))
    $struct = 0
    EndFunc ;==>_DeleteImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _CopyImage($img)
    Local $hDC_img = DllStructGetData($img, 1, 1)
    Local $b_img = DllStructGetData($img, 1, 2)
    Local $h_img = DllStructGetData($img, 1, 3)
    Local $ret = _CreateImage($b_img, $h_img)
    _DrawImage(DllStructGetData($ret, 1, 1), 0, 0, $img, 0)
    Return $ret
    EndFunc ;==>_CopyImage

    [/autoit] [autoit][/autoit] [autoit]

    Func _SaveImage($img)
    Local $Pfad = FileSaveDialog('BildSpeichern', @ScriptDir, '(*,.png)', Default, Hex(Random(256, 16 ^ 3, 1), 3) & '.png')
    If Not StringRight($Pfad, 4) = '.png' Then $Pfad &= '.png'
    ;~ _GDIPlus_Startup()
    Local $bm = _GDIPlus_BitmapCreateFromHBITMAP(DllStructGetData($img, 1, 5))
    _GDIPlus_ImageSaveToFile($bm, $Pfad)
    _GDIPlus_BitmapDispose($bm)
    ;~ _GDIPlus_Shutdown()
    EndFunc ;==>_Save

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion - Image UDF (by Mars)
    ;EndRegion - Image UDF (by Mars)

    [/autoit] [autoit][/autoit] [autoit]

    #Region

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_Shutdown()
    _WinAPI_ReleaseDC($hGUI, $hdc_GUI)
    _DeleteImage($Backbuffer)
    _DeleteImage($Perlin)
    _DeleteImage($ImageSchrift_Zeit)
    ;~ _DeleteImage($3D_Profil)
    DllClose($h_NTDLL_DLL)
    DllClose($h_MSIMG32_DLL)
    DllClose($h_GDI32_DLL)
    DllClose($h_OLE32_DLL)
    DllClose($h_USER32_DLL)
    DllClose($h_KERNEL32_DLL)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Log($x, $y) ; Logarithmus zur Basis y
    Return Log($x) / Log($y)
    EndFunc ;==>Log2

    [/autoit] [autoit][/autoit] [autoit]

    Func _Betrag($a)
    If $a > 0 Then Return $a
    Return -$a
    EndFunc ;==>_Betrag

    [/autoit] [autoit][/autoit] [autoit]

    Func _Min($a, $b)
    If $a > $b Then Return $b
    Return $a
    EndFunc ;==>_Min

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
    EndFunc ;==>WM_NCHITTEST

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawSchrift($hdc, $String, $px, $Farbe = 0xFFFF0000, $abs = 1)
    Local $FontPng = _SchriftRes($px)
    Local $Font
    Local $ptr, $hbmp, $imgBreite, $imgHoehe
    Local $hDC_Font = getDCfromRes32($FontPng, $ptr, $hbmp, $imgBreite, $imgHoehe)
    _Farbe($ptr, $Farbe, $imgBreite * $imgHoehe)
    Local $l = StringLen($String)
    Local $s = ''
    Local $x = 0, $y = 0, $nr = 0
    For $i = 1 To $l Step 1
    $s = StringMid($String, $i, 1)
    If $s = '|' Then
    $y += $px + $abs
    $x = 0
    Else
    $nr = _GetNr($s)
    If $nr <> 36 Then _WinAPI_StretchBlt($hdc, $x, $y, $px, $px, $hDC_Font, $nr * $px, 0, $px, $px, $SRCCOPY)
    $x += $px + $abs
    EndIf
    Next
    _Delete_Bitmap32($hDC_Font, $hbmp)
    EndFunc ;==>_DrawSchrift

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetSize($a, $px, $abs = 1)
    Local $l = StringLen($a)
    Local $s = ''
    Local $c = 0, $c2 = 0, $c3 = 0
    For $i = 1 To $l Step 1
    $c += 1
    If $c >= $c2 Then $c2 = $c
    $s = StringMid($a, $i, 1)
    If $s = '|' Then
    $c = 0
    $c3 += 1
    EndIf
    Next
    Local $ret[2] = [$c2 * ($px + $abs), ($c3 + 1) * ($px + $abs)] ;5px für den Buchstaben und einer für den Abstand, $c3 wird erhöht, da Zeile 0 sonst nicht mitgezählt wird.
    Return $ret
    EndFunc ;==>_GetSize

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetNr($a) ;Gibt die Nummer des Zeichens aus
    Local $b[36 + 23] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_', '.', ';', 'ä', 'ö', 'ü', '-', '§', '$', '%', '&', '#', '>', '<', '[', ']', '(', ')', '"', "'", '=', '+', ':']
    For $i = 0 To 35 + 23 Step 1
    If $a = $b[$i] Then Return $i
    Next
    Return 36 + 23
    EndFunc ;==>_GetNr

    [/autoit] [autoit][/autoit] [autoit]

    Func _Farbe($ptr, $col, $px)
    Local $_Struct = DllStructCreate('int[' & $px & ']', $ptr)
    For $i = 0 To $px Step 1
    If DllStructGetData($_Struct, 1, $i) = 0xFFFFFFFF Then
    DllStructSetData($_Struct, 1, $col, $i)
    Else
    DllStructSetData($_Struct, 1, 0x00000000, $i)
    EndIf
    Next
    EndFunc ;==>_Farbe

    [/autoit] [autoit][/autoit] [autoit]

    Func _SchriftRes($px) ;Enthält die png Bilder der Schriften als Ressourcen.
    Switch $px
    Case 4
    Return '0x89504E470D0A1A0A0000000D49484452000000EC000000040100000000A5BFEE56000000874944415468DE017C0083FF00FEFEFFF9FF98FDFFFFFF99999FEFF8F8FFFF0006660BF996C3BD7EA4F000009989888921A8BD9999C299B693231ACF999B000FF90BF42F3CC3A5A4044000FA89EEBF21E8BB9FAE3296B6FC2C7F393FFD004F996B024F3CC3A5000E00009FFEF8F9F69F9BF8D9F2F6F92FFFF2FF1F1FF449FF0BF996C3BD7E00F440068A47638487EBE40000000049454E44AE426082'
    Case 5
    Return '0x89504E470D0A1A0A0000000D49484452000001270000000501000000002F321765000000C94944415478DA01BE0041FF00FFFFEFFFF1FFE30DC7FFFFFFF8C6318FFDFFC3F0FFFFF0000A52815FC92AC0EFD7F9440000008C6118423120630AE6318C6048C6B1884410C21F8C6330001FFC4150265F21303A1544F908008DA11F7A1F207D0AD6318FFE48C6AEFFC5F7D3F10FE35000118C5D5F908A1E303A1400038000FC6118427120630ACE3F948248AAB1240500FC311C7F90009F8C4150493F21303A1400F908008FFFEFC3F1FBE3F8C7F0EC7E4F93F127FFFF93FF0FC3FF9091FFC15FA64AC0EFD7F80000002DA25C98C2B780160000000049454E44AE426082'
    EndSwitch
    EndFunc ;==>_SchriftRes

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalAlloc($iBytes, $iFlags = 0)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'handle', 'GlobalAlloc', 'uint', $iFlags, 'ulong_ptr', $iBytes)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalAlloc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalLock($hMem)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'ptr', 'GlobalLock', 'handle', $hMem)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalLock

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemGlobalUnlock($hMem)
    Local $aResult = DllCall($h_KERNEL32_DLL, 'bool', 'GlobalUnlock', 'handle', $hMem)
    Return $aResult[0]
    EndFunc ;==>_MemGlobalUnlock

    [/autoit] [autoit][/autoit] [autoit]

    Func _IsPressed($a)
    Local $b = DllCall($h_USER32_DLL, "short", "GetAsyncKeyState", "int", '0x' & $a)
    Return BitAND($b[0], 0x8000) <> 0
    EndFunc ;==>_IsPressed

    [/autoit] [autoit][/autoit] [autoit]

    Func _Delete_Bitmap32($hdc, $hbmp)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteDC($hdc)
    EndFunc ;==>_Delete_Bitmap32

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe DC und ptr und handle auf die Bitmapdaten
    ;by Andy
    Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
    Local $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", -$iHeight) ;minus =standard = bottomup
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
    Local $adib = DllCall($h_GDI32_DLL, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
    $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
    _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
    Return $hcdc ;DC der Bitmap zurückgeben
    EndFunc ;==>_CreateNewBmp32

    [/autoit] [autoit][/autoit] [autoit]

    Func getDCfromRes32($res, ByRef $ptr, ByRef $hbmp, ByRef $iwidth_file32, ByRef $iheight_file32);Erstellt eine 32-Bit Bitmap von Ressource Daten. + Breite und Höhe werden ermittelt
    _GDIPlus_Startup()
    Local $hBitmap = Load_BMP_From_Mem($res)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $iwidth_file32 = _GDIPlus_ImageGetWidth($hBitmap)
    $iheight_file32 = _GDIPlus_ImageGetHeight($hBitmap)
    ;by Andy
    Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
    Local $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
    DllStructSetData($tBMI, "Width", $iwidth_file32)
    DllStructSetData($tBMI, "Height", -$iheight_file32) ;minus =standard = bottomup
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
    Local $adib = DllCall($h_GDI32_DLL, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    _WinAPI_SelectObject($hcdc, $adib[0])
    ; copy the content of the bitmap into the buffer ...
    _WinAPI_GetDIBits($hcdc, $hbmp, 0, $iheight_file32, $adib[4], DllStructGetPtr($tBMI), $DIB_RGB_COLORS)
    $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
    $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
    ;_arraydisplay($adib)
    _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
    Return $hcdc ;DC der Bitmap zurückgeben
    EndFunc ;==>getDCfromRes32

    [/autoit] [autoit][/autoit] [autoit]

    Func Load_BMP_From_Mem($pic)
    Local $memBitmap, $len, $tMem, $hImage, $hData, $pData, $hStream, $hBitmapFromStream
    $memBitmap = Binary($pic)
    $len = BinaryLen($memBitmap)
    $hData = _MemGlobalAlloc($len, 0x0002)
    $pData = _MemGlobalLock($hData)
    $tMem = DllStructCreate("byte[" & $len & "]", $pData)
    DllStructSetData($tMem, 1, $memBitmap)
    _MemGlobalUnlock($hData)
    $hStream = _WinAPI_CreateStreamOnHGlobal($pData)
    $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream)
    $tMem = ""
    Return $hBitmapFromStream
    EndFunc ;==>Load_BMP_From_Mem

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
    DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
    EndFunc ;==>_WinAPI_StretchBlt

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDI_AlphaBlend_GetStruct($Alpha = 255)
    Local $struct = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($struct, 1, 0) ; 0 = AC_SRC_OVER
    DllStructSetData($struct, 2, 0) ; 0 "Must be Zero"
    DllStructSetData($struct, 3, $Alpha) ; Alpha fürs ganze Bild
    DllStructSetData($struct, 4, 1) ; 1 = Bild enthält einen Alphakanal
    Local $data = DllStructCreate("dword", DllStructGetPtr($struct))
    $data = DllStructGetData($data, 1)
    Return $data
    EndFunc ;==>_GDI_AlphaBlend_GetStruct

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDI_AlphaBlend($hDCDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hDCSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $blendFunction)
    DllCall($h_MSIMG32_DLL, 'int', 'AlphaBlend', _
    'ptr', $hDCDest, _ ; // handle to destination DC
    'int', $nXOriginDest, _ ; // x-coord of upper-left corner
    'int', $nYOriginDest, _ ; // y-coord of upper-left corner
    'int', $nWidthDest, _ ; // destination width
    'int', $nHeightDest, _ ; // destination height
    'ptr', $hDCSrc, _ ; // handle to source DC
    'int', $nXOriginSrc, _ ; // x-coord of upper-left corner
    'int', $nYOriginSrc, _ ; // y-coord of upper-left corner
    'int', $nWidthSrc, _ ; // source width
    'int', $nHeightSrc, _ ; // source height
    'dword', $blendFunction);$blendFunction) ; // alpha-blending function
    EndFunc ;==>_GDI_AlphaBlend

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True)
    Local $aResult = DllCall($h_OLE32_DLL, "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0)
    Return $aResult[3]
    EndFunc ;==>_WinAPI_CreateStreamOnHGlobal

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateFromStream($pStream)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    Return $aResult[2]
    EndFunc ;==>_GDIPlus_BitmapCreateFromStream

    [/autoit] [autoit][/autoit] [autoit]

    Func _C($a, $b = 0) ;Gibt x/y Koords für ein Fenster damit es zentriert ist.
    If $b Then Return @DesktopWidth / 2 - $a / 2 ; Wenn b dann x
    Return @DesktopHeight / 2 - $a / 2 ; Sonst y
    EndFunc ;==>_C

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion

    [/autoit]