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:
|