No-BS FI

BlitzPlus Forums/BlitzPlus Beginners Area/No-BS FI

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

This works on all the images I have tested. It can be easily modified to return a bank with an alpha channel:

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:
.lib "FreeImage.dll"

FIAllocate%( Width%,Height%,BPP%,RedMask%,GreenMask%,BlueMask% ) : "_FreeImage_Allocate@24"
FILoad%( ImageType%,File$,Mode% ) : "_FreeImage_Load@12"
FISave%( ImapeType%,FIBITMAP%,File$,Flags% ) : "_FreeImage_Save@16"
FIUnload%( FIBITMAP% ) : "_FreeImage_Unload@4"
FIGetDescription$( FREE_IMAGE_FORMAT% ) : "_FreeImage_GetFIFDescription@4"
FIGetType%( File$,Default% ) : "_FreeImage_GetFileType@8"
FIToBank( Bank*,FIBITMAP%,Pitch%,Depth%,Red_Mask%,Green_Mask%,Blue_Mask%,TopDown% ) : "_FreeImage_ConvertToRawBits@32"
FIGuessType%( File$ ) : "_FreeImage_GetFIFFromFilename@4"
FIGetClrUsed%( FIBITMAP% ) : "_FreeImage_GetColorsUsed@4"
FIGetBitStart%( FIBITMAP% ) : "_FreeImage_GetBits@4"
FIGetScanLine%( FIBITMAP%,ScanLine% ) : "_FreeImage_Get@8"
FIGetDepth%( FIBITMAP% ) : "_FreeImage_GetBPP@4"
FIGetWidth%( FIBITMAP% ) : "_FreeImage_GetWidth@4"
FIGetBits%( FIBITMAP% ) : "_FreeImage_GetBits@4"
FIGetHeight%( FIBITMAP% ) : "_FreeImage_GetHeight@4"
FIGetLine%( FIBITMAP% ) : "_FreeImage_GetLine@4"
FIGetPitch%( FIBITMAP% ) : "_FreeImage_GetPitch@4"
FIGetSize%( FIBITMAP% ) : "_FreeImage_GetDIBSize@4"
FIGetPalette%( FIBITMAP% ) : "_FreeImage_GetPalette@4"
FIGetDPMX%( FIBITMAP% ) : "_FreeImage_GetDotsPerMeterX@4"
FIGetDPMY%( FIBITMAP% ) : "_FreeImage_GetDotsPerMeterY@4"
FIGetHeader%( FIBITMAP% ) : "_FreeImage_GetInfoHeader@4"
FIGetInfo%( FIBITMAP% ) : "_FreeImage_GetInfo@4"
FIGetColorType%( FIBITMAP% ) : "_FreeImage_GetColorType@4"
FIGetRedMask%( FIBITMAP% ) : "_FreeImage_GetRedMask@4"
FIGetGreenMask%( FIBITMAP% ) : "_FreeImage_GetGreenMask@4"
FIGetBlueMask%( FIBITMAP% ) : "_FreeImage_GetBlueMask@4"
FIGetTranCount%( FIBITMAP% ) : "_FreeImage_GetTransparencyCount@4"
FIGetTranTable%( FIBITMAP% ) : "_FreeImage_GetTransparencyTable@4"
FISetTran( FIBITMAP%,Flag% ) : "_FreeImage_SetTransparent@8"
FIIsTran%( FIBITMAP% ) : "_FreeImage_IsTransparent@4"
FIConvert8Bits%( FIBITMAP% ) : "_FreeImage_ConvertTo8Bits@4"
FIConvert555%( FIBITMAP% ) : "_FreeImage_ConvertTo16Bits555@4"
FIConvert565%( FIBITMAP% ) : "_FreeImage_ConvertTo16Bits565@4"
FIConvert24Bits%( FIBITMAP% ) : "_FreeImage_ConvertTo24Bits@4"
FIConvert32Bits%( FIBITMAP% ) : "_FreeImage_ConvertTo32Bits@4"
FIColorQuantize%( FIBITMAP%,Flag% ) : "_FreeImage_ColorQuantize@8"
FIThreshold%( FIBITMAP%,Flag% ) : "_FreeImage_Threshold@8"
FIDither%( FIBITMAP%,Algo% ) : "_FreeImage_Dither@8"
FIFromBank%( Bank*,Width%,Height%,Pitch%,Depth%,RedMask%,GreenMask%,BlueMask%,TopDown% ) : "_FreeImage_ConvertFromRawBits@36"
FIClone%(DIB%) : "_FreeImage_Clone@4"