resources

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Code generated by go generate; DO NOT EDIT. This file was generated automatically based on resource_files.csv

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedTABOffset is thrown if the offset is not 2 or 4
	ErrUnsupportedTABOffset = errors.New("unsupported offset size for TAB file")
	// ErrNotEnoughSprites is thrown if no (or not enough) images are found in ImageCollection.
	ErrNotEnoughSprites = errors.New("could not load sprites from file")
	// ErrNotEnoughTabs is thrown if not enough offsets are found to load PCK file.
	ErrNotEnoughTabs = errors.New("could not load offsets from tab file")
)
View Source
var (
	// ErrImageNotFound is thrown if path is not found in meta data map
	ErrImageNotFound = errors.New("image not found in meta data")
	// ErrNotImplemented is thrown if image type is not supported
	ErrNotImplemented = errors.New("not implemented yet")
	// ErrPaletteNotFound is thrown if specified colour pallete is not found
	ErrPaletteNotFound = errors.New("color pallete not found")
)
View Source
var Images = map[string]ImageEntry{}/* 195 elements not displayed */

Functions

func LoadTAB

func LoadTAB(path string, offsetSize int) ([]int, error)

LoadTAB loads TAB file from path.

The TAB file is a list of file offsets saying where each image begins in the related PCK archive. Some offsets are encoded in 2 bytes while others are encoded in 4. It depends on how many images are in the PCK archive.

Types

type ImageCollection

type ImageCollection struct {
	Sprites     []*ImageResource
	SpriteWidth int
}

ImageCollection is a list of ImageResources. These will typically be turned into a gallery or an animated image.

func LoadImageCollectionFromPCK

func LoadImageCollectionFromPCK(path string, width int, offsets []int) (*ImageCollection, error)

LoadImageCollectionFromPCK loads a collection of images from a PCK file.

func (*ImageCollection) Animated

func (c *ImageCollection) Animated(delay int, height int, palette *Palette) *gif.GIF

Animated converts ImageCollection into a single GIF.

func (*ImageCollection) Gallery

func (c *ImageCollection) Gallery(numberPerRow int, rowHeight int, palette *Palette) (image.Image, error)

Gallery creates a collection of all images on a grid with numberPerRow images in each row. The final size will depend on the number of Sprites in the collection (making up the grid), the size of the single SpriteWidth and the rowHeight.

type ImageEntry

type ImageEntry struct {
	Format    ImageFormat
	PaletteNr int
	Width     int
	Height    int
	TabFile   string
	TabOffset int
}

ImageEntry is a resource file for images in formats

type ImageFormat added in v0.1.3

type ImageFormat int
const (
	ImageFormatUnknown ImageFormat = iota
	ImageFormatSPK
	ImageFormatPCK
	ImageFormatSCR
)

type ImageResource

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

ImageResource is a list of pixels (colors) that will create an image of width.

func LoadPCK

func LoadPCK(path string, width int, offset int) (*ImageResource, error)

LoadPCK loads PCK image from path.

func LoadSCR

func LoadSCR(path string, width int) (*ImageResource, error)

LoadSCR loads an SCR image from path.

These ones are easy, every byte is an uncompressed index into the game's palette. Typically SCR files are used for 320x200 background images (and often stored in greyscale so they can be re-colored on the fly). DAT files that contain images use the same format, though the line width tends to vary depending on the specific use to which they are to be put.

func LoadSPK

func LoadSPK(path string) (*ImageResource, error)

LoadSPK loads SPK image from path.

Another 320 pixels wide x 200 pixels high image format but using compression, primarily used by UFO for background images (eg inventory screens).

https://www.ufopaedia.org/index.php/Image_Formats

func (*ImageResource) Height

func (i *ImageResource) Height() int

Height calculates the image's height in pixels.

func (*ImageResource) Image

func (i *ImageResource) Image(palette *Palette) image.Image

Image will create an Image object with colors from palette.

func (*ImageResource) Paletted

func (i *ImageResource) Paletted(palette *Palette) *image.Paletted

Paletted returns an image with a limited palette (used for GIFs).

func (*ImageResource) Width

func (i *ImageResource) Width() int

Width returns the image's width in pixels.

type Palette

type Palette struct {
	Colors [256]color.Color `struct:"[768]byte"`
	Buffer []byte           `struct:"[6]byte"`
}

Palette stores colours used for game images.

Back in the days of low video memory, storing each pixel as a multi-byte color value (such as in today's "High Color" and "True Color" modes common under MS Windows) was not practical. Instead, a common method for was to create a palette of 256 different colors (usually of 3 bytes each), and then use single byte values to index into that. The ability of a video card to use such a palette was known as "VGA compatibility".

This dramatically decreased the memory requirements of a given image, though it lowered the amount of colors that could be used in any single moment.

func LoadPalettes

func LoadPalettes(path string) ([]*Palette, error)

LoadPalettes loads Palettes from path. (see https://www.ufopaedia.org/index.php/PALETTES.DAT)

func (*Palette) Palette

func (p *Palette) Palette() *color.Palette

Palette returns the colors as color.Palette object.

func (Palette) SizeOf

func (p Palette) SizeOf() int

SizeOf implements the restruct.Sizer interface

func (*Palette) Unpack

func (p *Palette) Unpack(buf []byte, order binary.ByteOrder) ([]byte, error)

Unpack implements the restruct.Unpacker interface

type ResourceLoader

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

ResourceLoader will load resources from game directory.

func NewResourceLoader

func NewResourceLoader(root string) (*ResourceLoader, error)

NewResourceLoader will return a new instance of ResourceLoader.

func (*ResourceLoader) LoadImage

func (rs *ResourceLoader) LoadImage(pth string) (image.Image, error)

LoadImage loads an image from pth with the palette as defined in resource list meta data. If pth is not found in meta data, an error is returned.

func (*ResourceLoader) LoadImageWithPalette

func (rs *ResourceLoader) LoadImageWithPalette(pth string, paletteNr int) (image.Image, error)

LoadImageWithPalette loads an image with a specific colour palette.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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