ZoomSprite(#sprite, zoomfaktor) - Funktion

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Lebostein
Beiträge: 674
Registriert: 13.09.2004 11:31
Wohnort: Erzgebirge

ZoomSprite(#sprite, zoomfaktor) - Funktion

Beitrag von Lebostein »

Hi, hab für mein Projekt eine (ganzzahlige) Zoomfunktion für Sprites gebastelt:

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
Ist schon sehr schnell. Hat man hier noch die Möglichkeit, den Code zu optimieren? Was würdet ihr anders machen?

Was meint ihr?
pjanfred
Beiträge: 130
Registriert: 01.03.2006 15:41
Wohnort: Dortmund
Kontaktdaten:

Beitrag von pjanfred »

Ich dachte das Zoomen geht nur mit Images aber das hir hat mich anderseitig überzeugt.
Antworten