utfextract

package
v1.110.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package utfextract provides parsing and image extraction for Microsoft Freelancer (2003) UTF binary files (.txm, .cmp, .3db, .mat, .dfm).

The UTF format is a tree of named nodes, each node holding either child nodes or raw binary data. Texture images (TGA or DDS) are stored inside a sub-tree called "Texture library".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompositeOverWhite

func CompositeOverWhite(img *image.NRGBA) *image.NRGBA

func ExtractFromDir

func ExtractFromDir(inputDir, outputDir string, recursive, preservePaths bool, shapes *Shapes) (err error)

ExtractFromDir walks inputDir for UTF files and extracts images into outputDir. When recursive is true it descends into sub-directories.

When preservePaths is true the sub-directory structure inside inputDir is mirrored under outputDir, so a file found at

inputDir/foo/bar/model.3db

produces images under

outputDir/foo/bar/model.3db/<imagefile>

rather than the flat

outputDir/model.3db/<imagefile>

Use preservePaths=true when validating output against a known-good reference tree extracted with the Perl tool.

func ExtractFromFile

func ExtractFromFile(inputPath, outputDir string, shapes *Shapes) error

ExtractFromFile reads one UTF file and writes all found images into

outputDir/<basename>/<imagefile>

Returns the number of images written.

func TransformToJpeg

func TransformToJpeg(img *Image) (*bytes.Buffer, error)

Types

type ExtractedImage

type ExtractedImage struct {
	// Filename is the output path relative to the UTF file's output directory.
	// May contain one sub-directory for multi-mip entries, e.g. "asterdust/MIP0.tga".
	Filename string
	Data     []byte
}

ExtractedImage holds one image found inside a UTF file.

func ExtractImages

func ExtractImages(raw []byte) ([]ExtractedImage, error)

ExtractImages parses a raw UTF file and returns all texture images found in its "Texture library" sub-tree.

type Image

type Image struct {
	Nickname  string
	Extension string
	Dest      string
	Data      []byte
}

type Node

type Node struct {
	Name     string
	Children []*Node // directory node
	Data     []byte  // leaf node
}

Node represents one entry in the UTF tree. Exactly one of Children or Data is non-nil.

func ParseUTF

func ParseUTF(raw []byte) (*Node, error)

ParseUTF reads raw UTF file bytes and returns the root node of the tree. The root node is a synthetic container whose Children are the top-level entries of the file (typically a single "\" directory node).

func (*Node) Child

func (n *Node) Child(name string) *Node

Child returns the first direct child whose name matches (case-insensitive).

type Shape

type Shape struct {
	Nickname  string
	Extension string
	Images    []*Image
}

type ShapeOption

type ShapeOption func(s *Shapes)

type Shapes

type Shapes struct {
	ShapesConfig
	ImageWritten int
	FilesRead    int
	ShapesByNick map[string]*Shape
}

func NewShapes

func NewShapes(opts ...ShapeOption) *Shapes

type ShapesConfig

type ShapesConfig struct {
	WriteToFile bool

	//optimization to use less for purpose of in memory faster dev run
	UsePermittedShapesWhitelist bool
	PermittedShapes             map[string]bool
}

Directories

Path Synopsis
Command utfextract extracts TGA/DDS textures from Freelancer UTF files.
Command utfextract extracts TGA/DDS textures from Freelancer UTF files.

Jump to

Keyboard shortcuts

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