{"modulePath":"github.com/nsgo-dev/game","version":"v0.4.0-rc.3","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package spriteframes\n\nPackage spriteframes is experimental: its API and documented formats may change in a minor release; see [https://nsgo.games/docs/stability/](https://nsgo.games/docs/stability/).\n\nPackage spriteframes turns a run of raster frames from a renderer, a video model or a capture into atlas-ready frames: chroma key with despill, loop seam selection, a shared anchor and nearest-neighbor scaling. Every function is pure and deterministic and returns new images, leaving its input untouched.\n\n## Functions\n\n```go\nfunc Anchor(frames []*image.NRGBA, mode AnchorMode) ([]*image.NRGBA, error)\n```\nAnchor crops each frame to its non-transparent bounding box and places it in a cell as large as the largest box, at the same anchor in every frame, so a subject that drifts inside its canvas stays put. The cell's pivot is (0.5, 1) for AnchorBottomCenter and (0.5, 0.5) for AnchorCenter. A fully transparent frame is refused.\n\n```go\nfunc ChromaKey(frames []*image.NRGBA, opts KeyOptions) ([]*image.NRGBA, error)\n```\nChromaKey returns copies of frames with the key colour made transparent. Each pixel is keyed on its own, so key-coloured holes enclosed by the subject (between an arm and the body, say) are cleared as well as the background around it.\n\n```go\nfunc LoopSeam(frames []*image.NRGBA, opts SeamOptions) (start, end int, loop []*image.NRGBA, err error)\n```\nLoopSeam finds the start and end frames that are most alike, so playing frames\\[start:end] in a loop jumps from end-1 back to start as smoothly as the source moved from end-1 to end. It compares the frames as alpha-weighted luminance thumbnails at most 96 pixels on a side. The end frame itself is dropped, which removes a final frame that duplicates the first. Ties keep the longer loop, then the earlier start. All frames must be the same size.\n\n```go\nfunc ResizeNearest(frames []*image.NRGBA, width, height int) ([]*image.NRGBA, error)\n```\nResizeNearest scales each frame to width by height with nearest-neighbor sampling, which keeps hard pixel edges when reducing a render to a pixel-art grid.\n\n## Types\n\n```go\ntype AnchorMode string\n```\nAnchorMode is where Anchor places each frame's subject in the shared cell.\n\n```go\nconst (\n\t// AnchorBottomCenter puts the bottom edge of each subject on the cell's bottom edge, centered horizontally: feet stay planted.\n\tAnchorBottomCenter AnchorMode = \"bottom-center\"\n\t// AnchorCenter centers each subject in the cell.\n\tAnchorCenter AnchorMode = \"center\"\n)\n```\n\n```go\ntype KeyOptions struct {\n\t// Color is the background colour to remove; its alpha is ignored.\n\tColor color.NRGBA\n\t// Tolerance is the RGB Euclidean distance from Color at or below which a pixel becomes fully transparent.\n\tTolerance uint8\n\t// Softness is the width of the linear alpha ramp above Tolerance, so pixels between Tolerance and Tolerance+Softness keep part of their alpha.\n\tSoftness uint8\n\t// Despill is the strength, from 0 (off) to 1, with which the key's dominant channel is pulled down to the larger of the other two channels on edge pixels: pixels left partly transparent and opaque pixels next to a removed one.\n\tDespill float64\n}\n```\nKeyOptions controls ChromaKey.\n\n```go\ntype SeamOptions struct {\n\t// MinFrames is the fewest frames the loop keeps (2 when below 2).\n\tMinFrames int\n\t// MaxFrames is the most frames the loop keeps (no limit when 0).\n\tMaxFrames int\n}\n```\nSeamOptions bounds the loop LoopSeam picks.\n\n","path":"github.com/nsgo-dev/game/pkg/tooling/spriteframes","name":"spriteframes","synopsis":"Package spriteframes is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.","isRedistributable":true}
