Documentation
¶
Overview ¶
Package pack provides texture packing utilities, including support for rotation, transparent pixel trimming, automatic resizing and so on.
Supported input image formats include PNG, JPEG, TIFF, BMP, and WEBP. Supported output formats are PNG, JPEG, TIFF, and BMP.
Index ¶
- Constants
- func DecImg(r io.Reader) (image.Image, error)
- func EncImg(w io.Writer, img image.Image, format ImageFormat, compressionLevel ...SetClv) error
- func GetFilesInDirectory(dirPath string) ([]string, error)
- func GetLastFolderName(path string) string
- func GetOpaqueBounds(img image.Image, tolerance uint8) image.Rectangle
- func LoadImg(pathName string) (image.Image, error)
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func NaturalLess(a, b string) bool
- func NaturalSort(items []string)
- func NextPowerOfTwo(n int) int
- func Parallel(start, stop int, fn func(<-chan int))
- func Rotate90(img image.Image) *image.NRGBA
- func Rotate180(img image.Image) *image.NRGBA
- func Rotate270(img image.Image) *image.NRGBA
- func SaveImg(pathName string, img image.Image, format ImageFormat, ...) error
- func SaveImgExt(fileName string, img image.Image, compressionLevel ...SetClv) error
- func UnpackSprites(jsonPath string, fn ...UnpackOpts) error
- type Algorithm
- type Atlas
- type Bin
- type Heuristic
- type ImageFormat
- type Meta
- type Options
- func (b *Options) Algorithm(algo Algorithm) *Options
- func (b *Options) AllowRotate(enable bool) *Options
- func (b *Options) AutoSize(enable bool) *Options
- func (b *Options) Heuristic(heuristic Heuristic) *Options
- func (b *Options) MaxSize(w, h int) *Options
- func (b *Options) Name(name string) *Options
- func (b *Options) Padding(padding int) *Options
- func (b *Options) PmAlpha(enable bool) *Options
- func (b *Options) PowerOfTwo(enable bool) *Options
- func (b *Options) SameDetect(enable bool) *Options
- func (b *Options) Sort(enable bool) *Options
- func (b *Options) Tolerance(tolerance int) *Options
- func (b *Options) Trim(enable bool) *Options
- func (b *Options) Validate() (*Options, error)
- type Packer
- type Point
- type Rect
- type SetClv
- type Size
- type Sprite
- type SpriteAtlas
- type UnpackOpts
Constants ¶
const ( Version = "0.0.1" Repo = "https://github.com/91xusir/spritepacker" Format = "RGBA8888" )
const ( NoCompression clv = 0 // No compression BestSpeed clv = 1 // Best speed DefaultCompression clv = 2 // Default compression BestCompression clv = 3 // Best compression )
Variables ¶
This section is empty.
Functions ¶
func EncImg ¶
EncImg encodes the image to the specified format and writes it to the writer. Parameters:
- w: the writer to write the encoded image
- img: the image to encode
- format: the image format to encode
- compressionLevel: the compression level to use, default is NoCompression
Returns:
- error: an error if the format is unsupported or if encoding fails
Supported formats:
- JPEG
- PNG
- TIFF
- BMP
func GetFilesInDirectory ¶ added in v1.0.0
GetFilesInDirectory reads files in specified directory and returns file names slice
func GetLastFolderName ¶
GetLastFolderName 获取路径中的最后一个文件夹名称
func GetOpaqueBounds ¶
GetOpaqueBounds returns the bounds of the opaque area of the image. The image is assumed to be in RGBA format.
func NaturalLess ¶
func NextPowerOfTwo ¶
NextPowerOfTwo returns the next power of two of n.
func Rotate90 ¶
Rotate90 rotates the image 90 degrees counter-clockwise and returns the transformed image.
func Rotate180 ¶
Rotate180 rotates the image 180 degrees counter-clockwise and returns the transformed image.
func Rotate270 ¶
Rotate270 rotates the image 270 degrees counter-clockwise and returns the transformed image.
func SaveImgExt ¶ added in v1.0.0
func UnpackSprites ¶
func UnpackSprites(jsonPath string, fn ...UnpackOpts) error
Types ¶
type Bin ¶
Bin represents a Bin with a width, height,and a list of rectangles have been packed.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func NewOptions ¶
func NewOptions() *Options
func (*Options) Algorithm ¶
Algorithm sets the packing algorithm of the atlas. If the algorithm is not valid, it will be set to AlgoBasic.
func (*Options) AllowRotate ¶
AllowRotate allow sprites to Rotate to optimizeAtlasSize
func (*Options) Heuristic ¶
Heuristic sets the heuristic of the atlas. If the heuristic is not valid, it will be set to BestShortSideFit. It is valid only when the algorithm is AlgoMaxRects.
func (*Options) MaxSize ¶
MaxSize sets the maximum size of the atlas. If the width or height is less than or equal to 0, it will be set to 512.
func (*Options) Name ¶
Name sets the name of the atlas. If the name is empty, the default name is "atlas".
func (*Options) Padding ¶
Padding sets the padding of the atlas. If the padding is less than 0, it will be set to 0.
func (*Options) PowerOfTwo ¶
PowerOfTwo sets the power of two of the atlas. The atlas pixels are fixed to a power of 2.
func (*Options) SameDetect ¶
SameDetect sets the same detection of the atlas.
type Packer ¶
type Packer struct {
// contains filtered or unexported fields
}
func (*Packer) PackSprites ¶
PackSprites packs the given sprite images
Parameters:
- spritePaths: the paths of the sprite images
Returns:
- *SpriteAtlas: the sprite atlas info
- []image.Image: the atlas images
- error
type Rect ¶
Rect represents an immutable rectangle using value semantics.
func NewRectByPosAndSize ¶
func NewRectBySize ¶
func NewRectBySizeAndId ¶
func (Rect) CloneWithPos ¶
func (Rect) CloneWithSize ¶
func (Rect) ToImageRect ¶
type Size ¶
Size represents a size with width and height. The width and height must be positive.
func (Size) PowerOfTwo ¶
type SpriteAtlas ¶
type UnpackOpts ¶
type UnpackOpts func(*unpackedOpts)
func WithAtlasImgPath ¶ added in v1.0.0
func WithAtlasImgPath(atlasImgPath string) UnpackOpts
func WithOutputPath ¶ added in v1.0.0
func WithOutputPath(outputPath string) UnpackOpts