texture

package
v0.0.0-...-912d621 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MemSize = 4096

MemSize is the maximum size in memory of a texture.

Variables

This section is empty.

Functions

func AutoScale

func AutoScale(im *image.RGBA64, maxbytes, bits int, mipmap bool) (*image.RGBA64, error)

AutoScale scales the image to fit within the given number of bytes. The number of bits per pixel is given in 'bits'.

func CreateMipMaps

func CreateMipMaps(im *image.RGBA64) ([]*image.RGBA64, error)

CreateMipMaps creates the mipmap levels for an image.

func IsEmpty

func IsEmpty(im *image.RGBA) bool

IsEmpty returns true if the image contains no pixels with non-zero alpha.

func Pack

func Pack(im *image.RGBA, f SizedFormat, layout Layout) ([]byte, error)

Pack packs a texture into binary data.

func ReadPNG

func ReadPNG(filename string) (image.Image, error)

ReadPNG reads an image file.

func Scale

func Scale(im *image.RGBA64, xbits, ybits int) (*image.RGBA64, error)

Scale returns an image scaled down by the given number of factors of two in the X and Y directions.

func TileSize

func TileSize(xsize, ysize, bits int) int

TileSize returns the number of bytes used by a tile with the given dimensions.

func ToRGBA

func ToRGBA(im image.Image) *image.RGBA

ToRGBA converts an image to RGBA format.

func ToRGBA16

func ToRGBA16(im *image.RGBA, gamma float64) *image.RGBA64

ToRGBA16 converts an RGBA image to a linear RGBA64 format.

func ToRGBA8

func ToRGBA8(im *image.RGBA64) *image.RGBA

ToRGBA8 converts an RGBA64 image to RGBA format.

func ToSizedFormat

func ToSizedFormat(f SizedFormat, im *image.RGBA, dithering Dithering) error

ToSizedFormat changes the values in an image to be within range for a texture format and rescales them to 0-255. For I and IA formats, the red channel is used for intensity, and it is copied to the green and blue channels. For the I format, it is also copied to alpha. CI formats are not supported.

func Trim

func Trim(im *image.RGBA) *image.RGBA

Trim returns the smallest subimage of the image containing all pixels with nonzero alpha. May return an empty image.

Types

type Dithering

type Dithering uint32

A Dithering is a dithering technique.

const (
	// NoDither performs no dithering.
	NoDither Dithering = iota

	// FloydSteinberg performs Floyd-Steinberg error diffusion dithering.
	FloydSteinberg

	// Bayer performs Bayer ordered dithering.
	Bayer
)

func ParseDithering

func ParseDithering(s string) (d Dithering, err error)

ParseDithering parses a dithering algorithm name.

func (Dithering) String

func (d Dithering) String() (s string)

type Format

type Format uint32

A Format is an unsized pixel format.

const (
	// UnknownFormat is an unknown or missing format.
	UnknownFormat Format = iota
	// RGBA is RGB color with alpha.
	RGBA
	// CI is indexed color.
	CI
	// IA is intensity (grayscale) with alpha.
	IA
	// I is intensity only (grayscale) without alpha.
	I
)

func (Format) Enum

func (f Format) Enum() uint32

Enum returns the N64 enum value for this pixel format.

func (*Format) Set

func (f *Format) Set(s string) error

Set sets the format to a string value.

func (Format) String

func (f Format) String() (s string)

String returns the name of the format.

type Layout

type Layout uint32

A Layout describes the texture layout.

const (
	// Linear is the ordinary linear texture layout, with rows of pixels packed
	// after each other.
	Linear Layout = iota

	// Native is the texture layout that the texture unit on the RDP uses. The
	// exact layout depends on the size, and is described in section 13.8 of the
	// programming manual. In general, texels are reordered so that any 2x2
	// block of texels can be fetched in a single cycle.
	Native
)

type PixelSize

type PixelSize uint32

PixelSize is a texture pixel size.

const (
	// UnknownSize is an unknown or invalid size.
	UnknownSize PixelSize = iota
	// Size32 is 32 bits per pixel.
	Size32
	// Size16 is 32 bits per pixel.
	Size16
	// Size8 is 32 bits per pixel.
	Size8
	// Size4 is 32 bits per pixel.
	Size4
)

func (PixelSize) Enum

func (s PixelSize) Enum() uint32

Enum returns the N64 enum value for this pixel size.

func (*PixelSize) Set

func (s *PixelSize) Set(st string) error

Set sets the pixel size to a string value.

func (PixelSize) Size

func (s PixelSize) Size() int

Size returns the size of the pixel format in bits.

func (PixelSize) String

func (s PixelSize) String() (st string)

String returns the name of the pixel size.

type SizedFormat

type SizedFormat struct {
	Format Format
	Size   PixelSize
}

A SizedFormat is a combination pixel format and size.

func (SizedFormat) ChannelBits

func (f SizedFormat) ChannelBits() (bits [4]int, err error)

ChannelBits returns the number of bits in each channel. Four channels are always returned. For I and IA textures, the red channel is used as the intensity channel, and the blue and green channels are given zero bits.

func (*SizedFormat) Set

func (f *SizedFormat) Set(s string) error

Set sets the sized format to a string value.

func (*SizedFormat) String

func (f *SizedFormat) String() (s string)

String converts the sized format to a string.

Jump to

Keyboard shortcuts

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