packer

package module
v0.0.0-...-aebd349 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

packer

Golang 2d bin image packer

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownEncoding is an error that is thrown when the image is with unsupported encoding
	ErrUnknownEncoding = errors.New("Unknown image encoding provided")

	// ErrEmptyImage is an error thrown when the provided image is empty
	ErrEmptyImage = errors.New("Provided empty image")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	SortOrder         SortOrder
	TextureHeight     int
	TextureWidth      int
	Merge             bool
	Crop              bool
	Square            bool
	Rotate            bool
	Border            int
	Extrude           int
	AutoGrow          bool
	Autosize          bool
	CropThreshold     int
	AutoSizeThreshold int
	MinTextureSizeX   int
	MinTextureSizeY   int
	Heuristic         Heuristic
}

Config is the packer configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default config for the packer

type Heuristic

type Heuristic int

Heuristic defines the enum for the heuristic

const (
	HNone Heuristic = iota
	HTl
	HBaf
	HBssf
	HBlsf
	HMinw
	HMinh
)

type InputImage

type InputImage struct {
	Name string
	// contains filtered or unexported fields
}

InputImage is the image wrapper that defines the position of the

func (*InputImage) Bounds

func (i *InputImage) Bounds() image.Rectangle

Bounds get the bounds for the provided image

func (*InputImage) Hash

func (i *InputImage) Hash() uint64

Hash gets the image hash value

func (*InputImage) Image

func (i *InputImage) Image() draw.Image

Image returns the input image

func (*InputImage) PackedPosition

func (i *InputImage) PackedPosition() image.Point

PackedPosition gets the position of the image within the packed image

func (*InputImage) TextureID

func (i *InputImage) TextureID() int

TextureID gets the target image (output) texture id

type OutputImage

type OutputImage struct {
	draw.Image

	ID int
}

OutputImage is the packed image, result from the Packer Pack

type Packer

type Packer struct {
	Ltr         bool
	MinFillRate int

	Rotate Rotation

	OutputImages []*OutputImage
	// contains filtered or unexported fields
}

Packer is the image 2d bin packer

func New

func New(cfg *Config) *Packer

New creates the new Packer

func NewCtx

func NewCtx(ctx context.Context, cfg *Config) *Packer

NewCtx creates the new Packer with the provided context

func (*Packer) AddImage

func (p *Packer) AddImage(img image.Image, hash ...uint64) (*InputImage, error)

AddImage adds the image with the hash provided

func (*Packer) AddImageBytes

func (p *Packer) AddImageBytes(data []byte) (*InputImage, error)

AddImageBytes add the image in the form of raw bytes

func (*Packer) AddImageReader

func (p *Packer) AddImageReader(r io.Reader) (*InputImage, error)

AddImageReader adds the image from the reader

func (*Packer) Pack

func (p *Packer) Pack() (err error)

Pack packs the images with respect to the provided config parameters throws an error when the context provided in the Packer Creator is Done.

func (*Packer) Reset

func (p *Packer) Reset()

Reset resets the packer data

type Rotation

type Rotation int

Rotation defines the enums for the rotation

const (
	RNever Rotation = iota
	ROnlyWhenNeeded
	RH2WidthH
	RWidthGreaterHeight
	RWidthGreater2Height
	RW2HeightW
	RHeightGreaterWidth
	RHeightGreater2Width
)

type SortOrder

type SortOrder int

SortOrder is the enum that defines sorting order for the packer

const (
	OrderNone SortOrder = iota
	OrderByWidth
	OrderByHeight
	OrderByArea
	OrderByMax
)

Jump to

Keyboard shortcuts

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