ZoomSprite(#sprite, zoomfaktor) - Funktion
Verfasst: 16.09.2004 13:32
Hi, hab für mein Projekt eine (ganzzahlige) Zoomfunktion für Sprites gebastelt:
Ist schon sehr schnell. Hat man hier noch die Möglichkeit, den Code zu optimieren? Was würdet ihr anders machen?
Was meint ihr?
Code: Alles auswählen
Procedure ZoomSprite(sprite1, zoom)
widx = SpriteWidth(sprite1)
widy = SpriteHeight(sprite1)
sprite2 = CopySprite(sprite1, #PB_Any)
CreateSprite(sprite1, widx * zoom, widy * zoom)
StartDrawing(ScreenOutput())
Select DrawingBufferPixelFormat()
Case #PB_PixelFormat_8Bits : bperpix = 1
Case #PB_PixelFormat_15Bits : bperpix = 2
Case #PB_PixelFormat_16Bits : bperpix = 2
Case #PB_PixelFormat_24Bits_RGB : bperpix = 3
Case #PB_PixelFormat_24Bits_BGR : bperpix = 3
Case #PB_PixelFormat_32Bits_RGB : bperpix = 4
Case #PB_PixelFormat_32Bits_BGR : bperpix = 4
EndSelect
StopDrawing()
StartDrawing(SpriteOutput(sprite1))
adress1 = DrawingBuffer()
breite1 = DrawingBufferPitch()
StopDrawing()
StartDrawing(SpriteOutput(sprite2))
adress2 = DrawingBuffer()
breite2 = DrawingBufferPitch()
StopDrawing()
For posy = 0 To widy - 1
For posx = 0 To widx - 1
source = adress2 + posy * breite2 + posx * bperpix
destin = adress1 + posy * breite1 * zoom + posx * bperpix * zoom
For lupe = 0 To zoom - 1: CopyMemory(source, destin + lupe * bperpix, bperpix): Next lupe
Next posx
destin = adress1 + posy * breite1 * zoom
For lupe = 1 To zoom - 1: CopyMemory(destin, destin + lupe * breite1, breite1): Next lupe
Next posy
FreeSprite(sprite2)
EndProcedure
Was meint ihr?