Swift package · v0.1.0

KLAdaptiveSurface

Normalize image-derived colors before they become muddy surfaces.

A synchronous color policy that keeps a source hue when possible, raises dark or overly saturated colors into a readable range, and selects a foreground color for the resulting surface.

Platforms
iOS 17+ · macOS 14+
Toolchain
Swift 6.0+
License
MIT
Dependencies
None

Functions

  • Configurable brightness and saturation bounds
  • Dirtiness threshold to leave clean colors untouched
  • Preserve-hue, neutral, cool, and warm preferences
  • Automatic, dark, or light foreground strategy

Not included

It normalizes a CGColor. Image loading, pixel sampling, recomputation timing, caching, and SwiftUI or UIKit presentation remain the integrating application's responsibility.

Install with SwiftPM

Package.swiftSwift
.package(url: "https://github.com/KoenLee1023/KLAdaptiveSurface.git", from: "0.1.0")

Usage

Integration exampleSwift
let surface = KLAdaptiveSurface.normalize(
    sampledColor,
    using: .reading
)
apply(surface.background, foreground: surface.foreground)
KLAdaptiveSurface.normalize(_:using:)

Normalizes one CGColor with a value-type configuration.

KLAdaptiveSurface.Configuration

Defines thresholds, strength, color preference, and foreground strategy.

KLAdaptiveSurface.Result

Returns the background, foreground, contrast direction, and normalization state.

Demo apps