DDS Loader

Blitz3D Forums/Blitz3D Programming/DDS Loader

JoshK(Posted 2005) [#1]
This works on all the images I have tested. It can be easily modified to return a bank with an alpha channel. This also loads tga, pcx, png, bmp, jpg, without modifying the code:

a=filoadimage("rockbase.dds")
SaveImage a,"test.bmp"
ExecFile "test.bmp"

Function FILoadImage(file$)
ftype=FIGetType(file,0)
If ftype=-1
	ftype=FIGuessType(file)
	If ftype=-1 Return
	EndIf
fibitmap%=FILoad(ftype,file,0)
If Not fibitmap Return
pixels=figetbits(fibitmap)
i=CreateImage(FIGetWidth(fibitmap),FIGetHeight(fibitmap))
SetBuffer ImageBuffer(i)
LockBuffer ImageBuffer(i)
width=FIGetWidth(fibitmap)
height=FIGetHeight(fibitmap)
depth=FIGetDepth(fibitmap)
For y=0 To height-1
	For x=0 To width-1
		b=PeekB(pixels+(y*width+x)*(depth/8)+0)
		g=PeekB(pixels+(y*width+x)*(depth/8)+1)
		r=PeekB(pixels+(y*width+x)*(depth/8)+2)		
		If depth=32 a=PeekB(pixels+(y*width+x)*(depth/8)+3)
		WritePixelFast x,height-1-y,RGB(r,g,b)
		Next
	Next
UnlockBuffer ImageBuffer(i)
FIUnload fibitmap
Return i
End Function


You need FreeImage.dll:



Mustang(Posted 2005) [#2]
One of my first posts after buying Blitz3D years ago was a kind request to have DXTC and Block commenting (/* - */) because they are so useful. I'm still waiting.


AdrianT(Posted 2005) [#3]
yeah same here, it's one of those features that you get frustrated not having once youve used them.


JoshK(Posted 2005) [#4]
Someone wrote a loader. I am just asking them to write it in bb.