bitmap

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderSize = 28

HeaderSize is the size of the Header structure, in bytes.

View Source
const PaletteSize = 256

PaletteSize indicates how many colors a palette can hold with a byte index.

Variables

This section is empty.

Functions

func Encode

func Encode(bmp *Bitmap, offsetBase int) []byte

Encode writes the bitmap to a byte array and returns it. Compressed bitmaps will be compressed with a reference image with pixel data all 0x00.

func WriteAnimation added in v1.2.0

func WriteAnimation(writer io.Writer, anim Animation) error

WriteAnimation serializes an animation to a writer.

Types

type Animation added in v1.2.0

type Animation struct {
	Width      int16
	Height     int16
	ResourceID resource.ID
	IntroFlag  uint16
	Entries    []AnimationEntry
}

Animation describes a sequence of bitmaps to form a small movie.

func ReadAnimation added in v1.2.0

func ReadAnimation(reader io.Reader) (anim Animation, err error)

ReadAnimation extracts an animation from a serialized stream.

type AnimationCache added in v1.2.0

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

AnimationCache retrieves animations from a localizer and keeps them decoded until they are invalidated.

func NewAnimationCache added in v1.2.0

func NewAnimationCache(localizer resource.Localizer) *AnimationCache

NewAnimationCache returns a new instance.

func (*AnimationCache) Animation added in v1.2.0

func (cache *AnimationCache) Animation(key resource.Key) (anim Animation, err error)

Animation tries to look up given animation.

func (*AnimationCache) InvalidateResources added in v1.2.0

func (cache *AnimationCache) InvalidateResources(ids []resource.ID)

InvalidateResources lets the cache remove any animations from resources that are specified in the given slice.

type AnimationEntry added in v1.2.0

type AnimationEntry struct {
	FirstFrame byte
	LastFrame  byte
	FrameTime  int16
}

AnimationEntry describes one part of an animation with common frame time.

type Area

type Area [4]int16

Area is a placeholder for either a rectangle, or an anchoring point (first two entries).

type Bitmap

type Bitmap struct {
	Header  Header
	Pixels  []byte
	Palette *Palette
}

Bitmap describes a palette based image.

func Decode

func Decode(reader io.Reader) (*Bitmap, error)

Decode tries to read a bitmap from given reader. Should the bitmap be a compressed bitmap, then a reference image with pixel data all 0x00 is assumed.

func DecodeReferenced

func DecodeReferenced(reader io.Reader, provider func(width, height int16) ([]byte, error)) (*Bitmap, error)

DecodeReferenced tries to read a bitmap from given reader. If the serialized bitmap describes a compressed bitmap, then the pixels from the reference are used as a basis for the result. The returned byte array from the provider will be used as pixel buffer for the new bitmap.

type Bitmapper added in v0.6.0

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

Bitmapper creates bitmap images from generic images.

func NewBitmapper added in v0.6.0

func NewBitmapper(palette *Palette) *Bitmapper

NewBitmapper returns a new bitmapper instance based on the given palette.

func (*Bitmapper) Map added in v0.6.0

func (bitmapper *Bitmapper) Map(img image.Image) Bitmap

Map maps the provided image to a bitmap based on the internal palette.

func (*Bitmapper) MapColor added in v0.6.0

func (bitmapper *Bitmapper) MapColor(clr color.Color) (palIndex byte)

MapColor maps the provided color to the nearest index in the palette.

type Flag

type Flag uint16

Flag adds further properties.

const (
	// FlagTransparent is set for bitmaps that shall treat palette index 0x00 as fully transparent.
	FlagTransparent Flag = 0x0001
)

Flag constants are listed below.

type Header struct {
	Type Type

	Flags         Flag
	Width         int16
	Height        int16
	Stride        uint16
	WidthFactor   byte
	HeightFactor  byte
	Area          Area
	PaletteOffset int32
	// contains filtered or unexported fields
}

Header contains the meta information for a bitmap.

type Palette

type Palette [PaletteSize]RGB

Palette describes a list of colors to be used by bitmaps. It is an array of 256 RGB values.

func (Palette) ColorPalette added in v0.6.0

func (pal Palette) ColorPalette(firstIndexTransparent bool) color.Palette

ColorPalette returns a palette usable for the image packages.

func (Palette) IndexClosestTo added in v1.4.0

func (pal Palette) IndexClosestTo(rgb RGB, excluding []byte) byte

IndexClosestTo returns the index into this palette that matches the given color the closest. This search excludes the provided indices.

type PaletteCache

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

PaletteCache retrieves palettes from a localizer and keeps them decoded until they are invalidated.

func NewPaletteCache

func NewPaletteCache(localizer resource.Localizer) *PaletteCache

NewPaletteCache returns a new instance.

func (*PaletteCache) InvalidateResources

func (cache *PaletteCache) InvalidateResources(ids []resource.ID)

InvalidateResources lets the cache remove any palettes from resources that are specified in the given slice.

func (*PaletteCache) Palette

func (cache *PaletteCache) Palette(key resource.Key) (pal Palette, err error)

Palette tries to look up given palette.

type RGB

type RGB struct {
	Red   uint8
	Green uint8
	Blue  uint8
}

RGB is describing Red, Green, and Blue intensities with 8-bit resolution.

func (RGB) Color added in v0.6.0

func (col RGB) Color(alpha byte) color.Color

Color returns the RGB data as a regular Color entry.

type Type

type Type byte

Type describes the data layout of a bitmap.

const (
	// TypeFlat8Bit bitmaps are 8-bit paletted bitmaps that have their pixel stored in a flat layout.
	TypeFlat8Bit Type = 2
	// TypeCompressed8Bit bitmaps are 8-bit paletted bitmaps that have their pixel compressed in storage.
	// Compression is using run-length-encoding (RLE); See package rle.
	TypeCompressed8Bit Type = 4
)

Type constants are listed below.

Jump to

Keyboard shortcuts

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