image

package
v1.3.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ColorsPerPixel = 256

ColorsPerPixel is the constant 256, specifying how many colors are available for one pixel.

Variables

This section is empty.

Functions

func FromBitmap

func FromBitmap(bitmap Bitmap, palette color.Palette) image.PalettedImage

FromBitmap returns a paletted image instance based on the provided bitmap. If the bitmap does not contain a private palette, the provided one is used.

func LoadPalette

func LoadPalette(reader io.Reader) (pal color.Palette, err error)

LoadPalette reads the raw serialized palette from the given reader and returns the extracted palette. The first color has an alpha value of 0x00.

func SavePalette

func SavePalette(writer io.Writer, pal color.Palette) (err error)

SavePalette encodes the provided palette into the given writer. Alpha information is lost, the colors are converted to NRGBA and only their Red, Green and Blue values are used.

func Write

func Write(writer io.Writer, bmp Bitmap, bmpType BitmapType, forceTransparency bool, startOffset int)

Write serializes given bitmap. The provided type specifies whether the pixel data shall be compressed. The start offset is used for images with a private palette. The start offset specifies the byte length of the blocks before the current one. Force transparency indicates that palette index 0x00 is meant to be treated as transparent. Some usages of bitmaps imply transparency and don't require this flag to be set.

Types

type Bitmap

type Bitmap interface {
	// ImageWidth returns the width of the bitmap in pixel.
	ImageWidth() uint16
	// ImageHeight returns the height of the bitmap in pixel.
	ImageHeight() uint16

	// Row returns a slice of the pixel data for given row index.
	Row(index int) []byte

	// Palette returns the private palette of the bitmap. If none is set, this method returns nil.
	Palette() color.Palette

	// Hotspot returns a rectangle within the image bounds. May be 0,0,0,0.
	Hotspot() image.Rectangle
}

Bitmap wraps the access to a bitmap into abstract functions.

func NullBitmap added in v1.0.0

func NullBitmap() Bitmap

NullBitmap returns a bitmap of zero size without a palette.

func Read

func Read(source io.ReadSeeker) (bmp Bitmap, err error)

Read tries to extract a bitmap from the given source

type BitmapHeader

type BitmapHeader struct {
	Unknown0000      [4]byte
	Type             BitmapType
	TransparencyFlag int16

	Width        uint16
	Height       uint16
	Stride       uint16
	WidthFactor  byte
	HeightFactor byte
	HotspotBox   [4]uint16

	PaletteOffset int32
}

BitmapHeader describes the header of an encoded bitmap

func (*BitmapHeader) String

func (header *BitmapHeader) String() (result string)

type BitmapType

type BitmapType int16
const (
	UncompressedBitmap BitmapType = 0x0002
	CompressedBitmap   BitmapType = 0x0004
)

func (BitmapType) String

func (bmpType BitmapType) String() (result string)

type MemoryBitmap

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

MemoryBitmap is a bitmap held in memory.

func NewMemoryBitmap

func NewMemoryBitmap(header *BitmapHeader, data []byte, palette color.Palette) *MemoryBitmap

NewMemoryBitmap returns a MemoryBitmap instance based on the provided data.

func ToBitmap

func ToBitmap(img image.PalettedImage, palette color.Palette) *MemoryBitmap

ToBitmap creates a MemoryBitmap out of a paletted image. If a palette is provided, this will be used as the private palette of the resulting bitmap.

func (*MemoryBitmap) Compressed

func (bmp *MemoryBitmap) Compressed() bool

Compressed returns whether the bitmap data is stored in compressed form

func (*MemoryBitmap) Hotspot

func (bmp *MemoryBitmap) Hotspot() image.Rectangle

Hotspot returns a rectangle within the image bounds. May be 0,0,0,0.

func (*MemoryBitmap) ImageHeight

func (bmp *MemoryBitmap) ImageHeight() uint16

ImageHeight returns the height of the bitmap in pixel.

func (*MemoryBitmap) ImageWidth

func (bmp *MemoryBitmap) ImageWidth() uint16

ImageWidth returns the width of the bitmap in pixel.

func (*MemoryBitmap) Palette

func (bmp *MemoryBitmap) Palette() color.Palette

Palette returns the private palette of the bitmap. If none is set, this method returns nil.

func (*MemoryBitmap) Row

func (bmp *MemoryBitmap) Row(index int) []byte

Row returns a slice of the pixel data for given row index.

Jump to

Keyboard shortcuts

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