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
#include <GDIPlus.au3>
#include <AssembleIt.au3>
;~ #include 'GlPluginUtils.au3'
Opt('GUICloseOnESC', 0)
Opt('GUIOnEventMode', 0)
;~ Opt('MustDeclareVars', 1)
_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 ?
;#######################################################################
;~ Global Const $Size = 200
;~ Global Const $Stretch = 2
Global Const $BreiteMulti = 1
Global Const $Breite = $Size
Global Const $Hoehe = $Size
Global Const $Titel = 'Perlin'
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.
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')
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)
Global Const $hdc_GUI = _WinAPI_GetDC($hGUI)
Global $ASM_Struct_Verpixelung = _AsmToStruct('0x8B4C24048B398B51048B4110A3ED7C62018B4114A3F17C62018B41088B590C5189C1515053E80D0000005B585983E90177F059895104C3B80000000089D9E81E00000083F8007509A1ED7C62018907EB07A1F17C6201890783C70483E90177DEC389D0BA0000000069C0E51B000005F5D5000031D2BB80F40300F7FB81FA40FA01007707B800000000EB05B801000000C3') ;Wird für den Perlingenerator gebraucht.
Global $Backbuffer = _CreateImage($Breite*$Stretch*$BreiteMulti, $Hoehe*$Stretch)
Global $hDC_Backbuffer = DllStructGetData($Backbuffer, 1, 1)
;~ ;################## 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 $Tiefe_ = 0
Global $Timer = TimerInit()
Global $Perlin = _CreatePerlin($Breite, $Hoehe, $Tiefe__, $Seed, $hell, $F1, $F2)
Global $Diff = Int(TimerDiff($Timer))
;~ _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
Func _ASM_Verpixelung($Ziel, ByRef $Nummer, $b, $h, $f1, $f2)
;~ Ziel = Bitmap wo der Spaß hinsoll
;~ Nummer = Startwert
;~ b = Breite
;~ h = Hoehe
;~ $f1 = 0xFF00FF00
;~ $f2 = 0xFFFf00FF
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
;~ _AssembleIt('ptr','_ASM_Verpixelung_','ptr', DllStructGetPtr($struct)) - Neu. Mit Struct
;~ ToolTip('vorher: ' & $Nummer & @CRLF & _
;~ 'nachher: ' & DllStructGetData($struct, 1, 2))
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
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
_('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
_('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
_('farbe1 dd ?') ; Speicher für Die Farben
_('farbe2 dd ?') ; Speicher für Die Farben
EndFunc
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
OnAutoItExitRegister('_Exit')
;~ 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)
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)
_DrawImageStretch($hDC_Backbuffer, 0, 0, $img, $Stretch)
_DrawImage($hdc_GUI, 0, 0, $Backbuffer)
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
SetPrint($oBalken)
SetCamera(0, 0, $b*1.3, 0, 0, 0)
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)
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
_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
;~ $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)
;~ _CreateCube( $ObjId, $OrX, $OrY, $OrZ, $DeX, $DeY, $DeZ ,$Red, $Green, $Blue, $Alpha, $Tex = "" )
;~ AddCube($oBalken, 1, 1, 100, 3, 6, 0, 1)
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
Return _CreateImage($b, $h)
EndFunc
#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
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
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
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
_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
;~ _Zufall($Nummer)
;~ ToolTip($Nummer)
;~ Sleep(1000)
;~ 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
Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)
If @error Then Return SetError(@error, @extended, False)
$GDIP_STATUS = $aResult[0]
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode
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
#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
;~ $b = Breite
;~ $h = Hoehe
;~ $Tiefe = Anzahl Bilder
;~ $Helligkeit = 0 - 255
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)
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)
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
Local $px = 0
Local $pxges = 0
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
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
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
#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
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
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
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
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
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
Func _DeleteImage(ByRef $struct)
_Delete_Bitmap32(DllStructGetData($struct, 1, 1), DllStructGetData($struct, 1, 5))
$struct = 0
EndFunc ;==>_DeleteImage
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
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
#EndRegion - Image UDF (by Mars)
;EndRegion - Image UDF (by Mars)
#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
Func _Log($x, $y) ; Logarithmus zur Basis y
Return Log($x) / Log($y)
EndFunc ;==>Log2
Func _Betrag($a)
If $a > 0 Then Return $a
Return -$a
EndFunc ;==>_Betrag
Func _Min($a, $b)
If $a > $b Then Return $b
Return $a
EndFunc ;==>_Min
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST
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
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
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
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
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
Func _MemGlobalAlloc($iBytes, $iFlags = 0)
Local $aResult = DllCall($h_KERNEL32_DLL, 'handle', 'GlobalAlloc', 'uint', $iFlags, 'ulong_ptr', $iBytes)
Return $aResult[0]
EndFunc ;==>_MemGlobalAlloc
Func _MemGlobalLock($hMem)
Local $aResult = DllCall($h_KERNEL32_DLL, 'ptr', 'GlobalLock', 'handle', $hMem)
Return $aResult[0]
EndFunc ;==>_MemGlobalLock
Func _MemGlobalUnlock($hMem)
Local $aResult = DllCall($h_KERNEL32_DLL, 'bool', 'GlobalUnlock', 'handle', $hMem)
Return $aResult[0]
EndFunc ;==>_MemGlobalUnlock
Func _IsPressed($a)
Local $b = DllCall($h_USER32_DLL, "short", "GetAsyncKeyState", "int", '0x' & $a)
Return BitAND($b[0], 0x8000) <> 0
EndFunc ;==>_IsPressed
Func _Delete_Bitmap32($hdc, $hbmp)
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdc)
EndFunc ;==>_Delete_Bitmap32
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
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
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
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
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
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
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
Func _GDIPlus_BitmapCreateFromStream($pStream)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
Return $aResult[2]
EndFunc ;==>_GDIPlus_BitmapCreateFromStream
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
#EndRegion
[/autoit]