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 GetLastFolderName(path string) string
- func GetOpaqueBounds(img image.Image, tolerance uint8) image.Rectangle
- func ListFilePaths(dirPath string) ([]string, error)
- 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 SafeCreate(outputPath string) (*os.File, error)
- func SaveImgAutoExt(pathNoneExt string, img image.Image, format ImageFormat, ...) error
- func SaveImgByExt(outputPath 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) 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 SameDetectInfo
- 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 GetLastFolderName ¶
GetLastFolderName
Parameters:
- path: the path
Returns:
- string: the last folder name
Example:
folderName := GetLastFolderName("./sprites/atlas/a.png")
// folderName = "atlas"
func GetOpaqueBounds ¶
GetOpaqueBounds returns the bounds of the opaque area of the image. The image is assumed to be in RGBA format.
func ListFilePaths ¶
ListFilePaths
Parameters:
- dirPath: the directory path
Returns:
- []string: the file paths
- error: the error
Example:
filePaths, err := ListFilePaths("./sprites")
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 SaveImgAutoExt ¶
func SaveImgByExt ¶
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
Example:
spriteAtlas, atlasImages, err := packer.PackSprites("./input")
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 SameDetectInfo ¶
func FindDuplicateFiles ¶
func FindDuplicateFiles(filePaths []string) ([]string, SameDetectInfo, error)
FindDuplicateFiles finds duplicate files in the given file paths.
Parameters:
- filePaths: the paths of the files to be checked
Returns:
- []string: the paths of the unique files
- map[string]string: the map of duplicate file names and their corresponding base names
- map[string][]string: the map of base file names to their duplicate file names
- error
type Size ¶
Size represents a size with width and height. The width and height must be positive.
func (Size) PowerOfTwo ¶
type Sprite ¶
type SpriteAtlas ¶
type UnpackOpts ¶
type UnpackOpts func(*unpackedOpts)
func WithImg ¶
func WithImg(atlasImgPath string) UnpackOpts
func WithOutput ¶
func WithOutput(outputPath string) UnpackOpts