Code archives/File Utilities/SaveTGA

This code has been declared by its author to be Public Domain code.

Download source code

SaveTGA by skidracer2001
This function saves a Blitz3D texture in TGA format, writing both rgb and alpha components of the texture.
Function SaveTGA(name$,texture)
    Local f,width,height,tbuffer,x,y
    width=TextureWidth(texture)
    height=TextureHeight(texture)
    f=WriteFile(name$)
    WriteByte(f,0) ;idlength
    WriteByte(f,0) ;colormaptype
    WriteByte(f,2) ;imagetype 2=rgb
    WriteShort(f,0) ;colormapindex
    WriteShort(f,0) ;colormapnumentries
    WriteByte(f,0) ;colormapsize 
    WriteShort(f,0) ;xorigin
    WriteShort(f,0) ;yorigin
    WriteShort(f,width) ;width
    WriteShort(f,height) ;height
    WriteByte(f,32) ;pixsize
    WriteByte(f,8) ;attributes
    tbuffer=TextureBuffer(texture)
    For y=height-1 To 0 Step -1
        For x=0 To width-1
            WriteInt f,ReadPixel(x,y,tbuffer)
        Next
    Next
    CloseFile f
End Function

Comments

simonh2004
Great work Skid!!


Code Archives Forum