Code-Beispiel
Blur-Effekt
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
k. A. | Eternal_Pain | 18.08.2011 |
Blur (verwischen/unschärfe)
Ein Beispiel für den von mir in Grafikprogrammen oft genutzen Blur Filter zum 'Weichzeichnen'
SUB Blur (byref Buffer as any ptr)
If Buffer=0 then Exit Sub
Dim BlurBuffer as any ptr
Dim BlurP as UInteger ptr
''Hoehe, Breite und Version des Buffers ermitteln
Dim BufferP as UInteger Ptr = Buffer
Dim BVersion as UInteger = BufferP[0]
If BVersion<>&h7 Then Exit Sub
Dim BSizeX as UInteger = BufferP[2]
Dim BSizeY as UInteger = BufferP[3]
Dim BPitch as UInteger = BufferP[4]/4
BufferP=Buffer+32
Dim OldColor as UInteger ptr
OldColor=Callocate(8*Len(Uinteger))
Dim BlurColor as UInteger=0
Dim Blurred as Integer
Dim Blurgreen as Integer
Dim Blurblue as Integer
Dim Calcptr as ubyte ptr
BlurBuffer=IMAGECreate(BSizeX,BSizeY)
BlurP=BlurBuffer+32
Dim posx as Integer
Dim posy as Integer
for y as Short=0 to BSizeY-1
for x as Short=0 to BSizeX-1
posx=x : posy=y
if posy>BSizeY-2 then posy=BSizeY-2
if posx>BSizeX-2 then posx=BSizeX-2
OldColor[0]=BufferP[(posx+1)+((posy )*BPitch)]
OldColor[1]=BufferP[(posx )+((posy+1)*BPitch)]
OldColor[2]=BufferP[(posx+1)+((posy+1)*BPitch)]
if posy<1 then posy=1
if posx<1 then posx=1
OldColor[3]=BufferP[(posx-1)+((posy-1)*BPitch)]
OldColor[4]=BufferP[(posx )+((posy-1)*BPitch)]
OldColor[5]=BufferP[(posx-1)+((posy )*BPitch)]
If posx+1 > BSizeX-1 Then posx-=1
If posy-1 < 0 Then posy+=1
OldColor[6]=BufferP[(posx+1)+((posy-1)*BPitch)]
If posx-1 < 0 Then posx+=1
If posy+1 > BSizeY-1 Then posy-=1
OldColor[7]=BufferP[(posx-1)+((posy+1)*BPitch)]
Blurred = 0
Blurgreen = 0
Blurblue = 0
for l as ubyte=0 to 7
Calcptr=CPTR(ubyte ptr, @OldColor[l])
Blurred += calcptr[2]
Blurgreen += calcptr[1]
Blurblue += calcptr[0]
next l
BlurColor = ((Blurred/8) SHL 16) + ((Blurgreen/8) SHL 8) + (Blurblue/8)
BlurP[x+(y*BPitch)]=BlurColor
BlurColor=0
next x
next y
Deallocate OldColor
DeAllocate (Buffer)
Buffer=BlurBuffer
End Sub
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|
|