vtf

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2018 License: Unlicense Imports: 7 Imported by: 3

README

GoDoc Go report card

vtf

Parse Valves own .vtf format (literally Valve Texture Format) for Source Engine texture.

Features
  • Supports versions 7.1-7.5
  • Full header data
  • Low resolution thumbnail loading
  • Complete mipmap + high-resolution texture loading
Usage
import (  
	"github.com/galaco/vtf"
	"log"
	"os"
)

func main() {
  file,_ := os.LoadFile("foo.vtf")
  texture,err := vtf.ReadFromStream(file)
	if err != nil {
		log.Println(err)
	} else {
    log.Println(texture.GetHeader().Width)
  }
}

Whats missing
  • Resource data is ignored (besides mipmaps) in 7.3+
  • Texture with depth > 1 are unsupported. This is very rare
  • Textures with zslices > 1 are unsupported. This is very rare
  • Modify/export functionality
What won't this ever do?
  • Colour format transformation. Header properties LowResImageFormat and HighResImageFormat will provide the format.
  • (Probably) support depths or zslices > 1
Contributing

No where near all the possible texture configurations have been tested. It's possible some could cause issues. Any issues (including offending file) are greatly appreciated.

Documentation

Index

Constants

View Source
const FlagAlphaTestMipmapGeneration = 0x400000
View Source
const FlagAnisotropicFiltering = 0x0010
View Source
const FlagBorder = 0x20000000
View Source
const FlagClampS = 0x0004
View Source
const FlagClampT = 0x0008
View Source
const FlagClampU = 0x2000000
View Source
const FlagDepthRenderTarget = 0x10000
View Source
const FlagEightBitAlpha = 0x2000
View Source
const FlagEnvironmentMap = 0x4000
View Source
const FlagHintDXT5 = 0x0020
View Source
const FlagNiceFiltered = 0x1000000
View Source
const FlagNoCompress = 0x0040
View Source
const FlagNoDebugOverride = 0x20000
View Source
const FlagNoDepthBuffer = 0x800000
View Source
const FlagNoLevelOfDetail = 0x0200
View Source
const FlagNoMinimumMipmap = 0x0400
View Source
const FlagNoMipmaps = 0x0100
View Source
const FlagNormalMap = 0x0080
View Source
const FlagNormalToDuDv = 0x200000
View Source
const FlagOneBitAlpha = 0x1000
View Source
const FlagOneOverMipmapLevelInAlpha = 0x80000
View Source
const FlagPWLCorrected = 0x0040
View Source
const FlagPointSampling = 0x0001
View Source
const FlagPreMultiplyColorByOneOverMipmapLevel = 0x100000
View Source
const FlagPreSRGB = 0x80000
View Source
const FlagProcedural = 0x0800
View Source
const FlagRenderTarget = 0x8000
View Source
const FlagSRGB = 0xFFFF // n/a
View Source
const FlagSSBump = 0x8000000
View Source
const FlagSingleCopy = 0x40000
View Source
const FlagTrilinearSampling = 0x0002
View Source
const FlagVertexTexture = 0x4000000

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	HeaderCommon
	Header72
	Header73
}

Header: VTF Header format Contents includes information for all versions Its up to the implementee to decide what properties they need based on the version

type Header72

type Header72 struct {
	Depth uint16 //Depth of the largest mipmap in pixels (^2) ushort
}

Header72: v7.2+ includes these properties

type Header73

type Header73 struct {
	NumResource uint32 // Number of resources this vtf has
	// contains filtered or unexported fields
}

Header73: v7.3+ includes these properties

type HeaderCommon

type HeaderCommon struct {
	Signature  [4]byte   //File signature char
	Version    [2]uint32 //Version[0].version[1] e.g. 7.2 uint
	HeaderSize uint32    //Size of Header (16 byte aligned, currently 80bytes) uint
	Width      uint16    //Width of largest mipmap (^2) ushort
	Height     uint16    //Height of largest mipmap (^2) ushort
	Flags      uint32    //VTF Flags uint
	Frames     uint16    //Number of frames (if animated) default: 1 ushort
	FirstFrame uint16    //First frame in animation (0 based) ushort

	Reflectivity [3]float32 //reflectivity vector float

	BumpmapScale       float32 //Bumpmap scale float
	HighResImageFormat uint32  //High resolution image format uint (probably 4?)
	MipmapCount        uint8   //Number of mipmaps uchar
	LowResImageFormat  uint32  //Low resolution image format (always DXT1 [=14]) uint
	LowResImageWidth   uint8   //Low resolution image width uchar
	LowResImageHeight  uint8   //Low resolution image height uchar
	// contains filtered or unexported fields
}

HeaderCommon: All VTF versions start with these properties

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader: Vtf Reader

func (*Reader) Read

func (reader *Reader) Read() (*Vtf, error)

Read: Reads the vtf image from stream into a usable structure The only error to expect would be if mipmap data size overflows the total file size; normally due to tampered Header data.

type Vtf

type Vtf struct {
	// contains filtered or unexported fields
}

Vtf: Exported vtf format Contains a Header, resources (v7.3+), low res thumbnail & high-res mipmaps

func ReadFromFile

func ReadFromFile(filepath string) (*Vtf, error)

ReadFromFile: ReadFromStream wrapper to load directly from filesystem. Exists for convenience

func ReadFromStream

func ReadFromStream(stream io.Reader) (*Vtf, error)

ReadFromStream: Load vtf from standard io.Reader stream,

func (*Vtf) GetHeader

func (vtf *Vtf) GetHeader() Header

GetHeader: Get vtf Header

func (*Vtf) GetHighResImageData

func (vtf *Vtf) GetHighResImageData() [][][][][]byte

GetHighResImageData: Get all data for all mipmaps

func (*Vtf) GetHighestResolutionImageForFrame

func (vtf *Vtf) GetHighestResolutionImageForFrame(frame int) []byte

GetHighestResolutionImageForFrame: Get the best possible resolution for a single frame in the vtf

func (*Vtf) GetLowResImageData

func (vtf *Vtf) GetLowResImageData() []uint8

GetLowResImageData: Get raw data of low-resolution thumbnail

func (*Vtf) GetMipmapsForFrame

func (vtf *Vtf) GetMipmapsForFrame(frame int) [][]byte

GetMipmapsForFrame: Get all mipmap sizes for a single frame

Directories

Path Synopsis
samples
read command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL