Remote File Engine

Miscellaneous Forums/Blitz Showcase/Remote File Engine

An example how to load TGA files directly from internet:
Include "transporter.bb"

file% = OpenRemoteFile("http://www.oat.ee/andres/oval.tga")
If Not file% Then RuntimeError "Unable to open the file!"

Graphics 800, 600, 32, 2
SetBuffer BackBuffer()

; Read TGA header
IDLenght% = ReadRemoteByte(file%)
ColorMapType% = ReadRemoteByte(file%)
ImageType% = ReadRemoteByte(file%)
ColorMapIndex% = ReadRemoteShort(file%)
ColorMapEntries% = ReadRemoteShort(file%)
ColorMapSize% = ReadRemoteByte(file%)
Xhandle% = ReadRemoteShort(file%)
YHandle% = ReadRemoteShort(file%)
Width% = ReadRemoteShort(file%)
Height% = ReadRemoteShort(file%)
BPP% = ReadRemoteByte(file%)
Attributes% = ReadRemoteByte(file%)

ImageID$ = ""
For i = 1 To IDLenght
	ImageID$ = ImageID$ + Chr(ReadRemoteByte(file%))
Next

; Read TGA body
image% = CreateImage(Width%, Height%)
LockBuffer ImageBuffer(image%)
For y = 0 To Height% - 1
	For x = 0 To Width% - 1
		b% = ReadRemoteByte(file%)
		g% = ReadRemoteByte(file%)
		r% = ReadRemoteByte(file%)
		a% = ReadRemoteByte(file%)
		WritePixelFast x, height% - y - 1, (b% Or (g% Shl 8) Or (r% Shl 16) Or ($FF000000)), ImageBuffer(image%)
	Next
Next
UnlockBuffer ImageBuffer(image%)

CloseRemoteFile(file%)

; Display the received image
While Not KeyHit(1)
	Cls
	DrawImage image%, MouseX(), MouseY()
	Flip
Wend