Swift package · v0.1.2
KLAdaptivePalette
Derive a palette from the image region visible in a host container.
A Core Graphics palette analyzer that accounts for the host container, content mode, and crop anchor. It returns colors, ranked candidates, contrast-aware foregrounds, and a deterministic cache key.
Functions
- Aspect-fill and aspect-fit visible-region analysis
- Ranked perceptual color candidates
- Foreground selection from actual background luminance
- Per-instance in-memory palette cache
Not included
It analyzes CGImage pixels. Image loading, task scheduling, persistence, and host view composition remain the integrating application's responsibility.
Install with SwiftPM
.package(url: "https://github.com/KoenLee1023/KLAdaptivePalette.git", from: "0.1.2")Usage
let request = KLPaletteRequest(
image: image,
cacheID: mediaID,
containerSize: size
)
let palette = KLPaletteAnalyzer().analyze(request)API documentation
Open the complete API documentation.KLPaletteAnalyzerAnalyzes a KLPaletteRequest and produces a deterministic cache key for equal pixels and display geometry.
KLPaletteRequestCarries a CGImage, cache ID, container size, content mode, and normalized crop anchor.
KLAdaptivePaletteReturns source, candidate, tint, background, and foreground colors for the visible region.
Demo apps
PaletteInspector
Inspects the visible crop, candidates, confidence, and cache key while changing display geometry.
AdaptiveSurface
Shows light and dark surfaces using foregrounds selected from the returned background colors.