Function SaveTGA(name$,image)
; saves an image as .tga format
Local f,width,height,tbuffer,x,y
width=ImageWidth(image)
height=ImageHeight(image)
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
buffer=ImageBuffer(image)
For y=height-1 To 0 Step -1
For x=0 To width-1
WriteInt f,ReadPixel(x,y,buffer)
Next
Next
CloseFile f
End Function
Function LoadTGA(name$)
;loads an .tga image and returns image handle
Local f,width,height,tbuffer,x,y
f=ReadFile(name$)
ReadByte(f) ;idlength
ReadByte(f) ;colormaptype
ReadByte(f) ;imagetype 2=rgb
ReadShort(f) ;colormapindex
ReadShort(f) ;colormapnumentries
ReadByte(f) ;colormapsize
ReadShort(f) ;xorigin
ReadShort(f) ;yorigin
width=ReadShort(f) ;width
height=ReadShort(f) ;height
ReadByte(f) ;pixsize
ReadByte(f) ;attributes
image = CreateImage(width,height)
buffer=ImageBuffer(image)
For y=height-1 To 0 Step -1
For x=0 To width-1
col = ReadInt(f)
WritePixel(x,y,col,buffer)
Next
Next
CloseFile f
Return image
End Function
|