bitmap

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderSize = 28

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

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 EncodeReferenced

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

EncodeReferenced writes the bitmap to a byte array and returns it. If the bitmap is a compressed one, the compression takes the pixels of the reference bitmap as a basis.

Types

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, reference *Bitmap) (*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.

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

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 [256]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.

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

Jump to

Keyboard shortcuts

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