; Title: 640x480 full-screen fade
; Version: 4.01 (09/Sep/2004)
; Author: Leigh Bowers
;Graphics 640, 480, 16, 2
;img1% = LoadImage("Themes\Evolution\640x480\Images\Loading.bmp")
;img2% = LoadImage("Archon001.bmp") ; CreateImage(640, 480)
;WaitKey
;lngStart% = MilliSecs()
;ScreenFade img1
;WaitKey
;ScreenFade img2, 0.05
;ScreenFade 0, 0.1, $ff, $ff, $ff
;ScreenFade
;WaitKey
Function ScreenFade(pimgDestinationImage% = 0, pdblFadeSpeed# = 0.1, ColourR% = 0, ColourG% = 0, ColourB% = 0, pimgSourceImage% = 0)
If Prefs\Debug Then Return
lngBank% = CreateBank(2 * (307200 * 3))
; Take a copy of the front buffer and the destination screen
If pimgSourceImage = 0 Then
SetBuffer FrontBuffer()
Else
SetBuffer ImageBuffer(pimgSourceImage)
End If
lngBankPos% = 0
For bytLoop% = 0 To 1
If bytLoop = 1 Then
SetBuffer BackBuffer()
If pimgDestinationImage = 0 Then
ClsColor ColourR, ColourG, ColourB : Cls ; Fading to a blank screen (of specified colour)
Else
DrawBlock pimgDestinationImage, 0, 0 ; The image we're cross-fading in to
End If
End If
LockBuffer
bnkScreenFade% = LockedPixels()
intPitch% = LockedPitch()
bytFormat% = LockedFormat()
lngOffset% = 0
Select bytFormat
Case 1
intY% =0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
lngPixel% = PeekShort(bnkScreenFade, lngOffset)
PokeByte(lngBank, lngBankPos, ((lngPixel And $F800) Shr 11) Shl 3)
PokeByte(lngBank, lngBankPos + 1, ((lngPixel And $7E0) Shr 5) Shl 2)
PokeByte(lngBank, lngBankPos + 2, (lngPixel And $1F) Shl 3)
lngOffset = lngOffset + 2
lngBankPos = lngBankPos + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
Case 2
intY% =0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
lngPixel = PeekShort(bnkScreenFade, lngOffset)
PokeByte(lngBank, lngBankPos, ((lngPixel And $7C00) Shr 10) Shl 3)
PokeByte(lngBank, lngBankPos + 1, ((lngPixel And $3E0) Shr 5) Shl 2)
PokeByte(lngBank, lngBankPos + 2, (lngPixel And $1F) Shl 3)
lngOffset = lngOffset + 2
lngBankPos = lngBankPos + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
Case 3, 4
intY% =0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
lngPixel = PeekInt(bnkScreenFade, lngOffset)
PokeByte(lngBank, lngBankPos, (lngPixel And $FF0000) Shr 16) ; r
PokeByte(lngBank, lngBankPos + 1, (lngPixel And $FF00) Shr 8) ; g
PokeByte(lngBank, lngBankPos + 2, lngPixel And $FF) ; b
lngOffset = lngOffset + bytFormat
lngBankPos = lngBankPos + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
End Select
UnlockBuffer
Next
; Perform the fade using the appropriate "Poke"
SetBuffer BackBuffer()
dblAlpha# = 0.0
Repeat
dblAlpha = dblAlpha + pdblFadeSpeed
If dblAlpha > 1 Then dblAlpha = 1
LockBuffer
bnkScreenFade% = LockedPixels()
intPitch% = LockedPitch()
bytFormat% = LockedFormat()
lngBankPos1% = 0
lngBankPos2% = 921600
Select bytFormat
Case 1
intY% = 0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
bytCache1% = PeekByte(lngBank, lngBankPos1)
bytCache2% = PeekByte(lngBank, lngBankPos1 + 1)
bytCache3% = PeekByte(lngBank, lngBankPos1 + 2)
PokeInt bnkScreenFade, lngOffset, (((bytCache1 + (PeekByte(lngBank, lngBankPos2) - bytCache1) * dblAlpha) / 8) Shl 11) Or (((bytCache2 + (PeekByte(lngBank, lngBankPos2 + 1) - bytCache2) * dblAlpha) / 4) Shl 5) Or ((bytCache3 + (PeekByte(lngBank, lngBankPos2 + 2) - bytCache3) * dblAlpha) / 8)
lngOffset = lngOffset + 2
lngBankPos1 = lngBankPos1 + 3
lngBankPos2 = lngBankPos2 + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
Case 2
intY% = 0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
bytCache1% = PeekByte(lngBank, lngBankPos1)
bytCache2% = PeekByte(lngBank, lngBankPos1 + 1)
bytCache3% = PeekByte(lngBank, lngBankPos1 + 2)
PokeInt bnkScreenFade, lngOffset, (((bytCache1 + (PeekByte(lngBank, lngBankPos2) - bytCache1) * dblAlpha) / 8) Shl 10) Or (((bytCache2 + (PeekByte(lngBank, lngBankPos2 + 1) - bytCache2) * dblAlpha) / 4) Shl 5) Or ((bytCache3 + (PeekByte(lngBank, lngBankPos2 + 2) - bytCache3) * dblAlpha) / 8)
lngOffset = lngOffset + 2
lngBankPos1 = lngBankPos1 + 3
lngBankPos2 = lngBankPos2 + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
Case 3, 4
intY% = 0
Repeat
lngOffset% = (intY * intPitch)
intX% = 0
Repeat
bytCache1% = PeekByte(lngBank, lngBankPos1)
bytCache2% = PeekByte(lngBank, lngBankPos1 + 1)
bytCache3% = PeekByte(lngBank, lngBankPos1 + 2)
PokeInt bnkScreenFade, lngOffset, ((bytCache1 + (PeekByte(lngBank, lngBankPos2) - bytCache1) * dblAlpha) Shl 16) Or ((bytCache2 + (PeekByte(lngBank, lngBankPos2 + 1) - bytCache2) * dblAlpha) Shl 8) Or (bytCache3 + (PeekByte(lngBank, lngBankPos2 + 2) - bytCache3) * dblAlpha)
lngOffset = lngOffset + bytFormat
lngBankPos1 = lngBankPos1 + 3
lngBankPos2 = lngBankPos2 + 3
intX = intX + 1
Until intX = 640
intY = intY + 1
Until intY = 480
End Select
UnlockBuffer
VWait
Flip False
Until dblAlpha = 1
FreeBank lngBank
End Function