kitty/tools/utils
Jökull Sólberg 64abd87a9e Add wide gamut color support with OKLCH and LAB formats
Implements modern wide gamut color formats with CSS Color Module Level 4
gamut mapping, addressing PR feedback with Go implementation, performance
benchmarks, and reorganized documentation.

Features:
- OKLCH (perceptually uniform color space)
- CIE LAB (device-independent color space)
- CSS Color 4 compliant gamut mapping algorithm
- Inline comment support in color config parsing

Addressing PR Feedback:

1. Go Implementation (tools/utils/style/):
   - Complete OKLCH and LAB parsing with gamut mapping
   - Matches Python implementation structure
   - Comprehensive test suite (all tests passing)
   - Performance benchmarks showing acceptable overhead

2. Performance Benchmarks:
   - OKLCH: ~4.6 µs/op
   - LAB: ~1.5 µs/op
   - 10 mixed colors: ~13 µs total
   - Typical config (50 colors): <0.5ms startup impact

3. Documentation Reorganization:
   - Moved detailed color docs to docs/wide-gamut-colors.rst
   - Configuration docs now link to separate documentation
   - Reduces size of main configuration documentation

Gamut Mapping:
- Binary search chroma reduction from CSS Color Module Level 4
- Preserves lightness and hue while reducing chroma for out-of-gamut colors
- Uses deltaE OK (JND threshold: 0.02) for perceptual difference
- Ensures graceful degradation on sRGB displays

Python Implementation:
- parse_oklch(): OKLCH color parsing with gamut mapping
- parse_lab(): CIE LAB parsing with gamut mapping via OKLCH conversion
- lab_to_oklch(): LAB to OKLCH conversion for consistent gamut mapping
- oklch_to_srgb_gamut_map(): CSS Color 4 gamut mapping algorithm
- srgb_to_oklab(): Reverse conversion for deltaE calculations
- deltaE_ok(): Perceptual color difference in OKLab space

Go Implementation:
- colorspaces.go: All color space conversions and gamut mapping
- wrapper.go: ParseColor() updated to support OKLCH and LAB
- Comprehensive test coverage with benchmarks
- Matches Python implementation behavior

Robustness:
- NaN and infinity validation in all color parsing functions
- Defense-in-depth with validation at parsing and gamut mapping levels
- Returns None/error for invalid input (consistent error handling)
- Validates before clamping operations to prevent NaN propagation

Files changed:
- Python: kitty/rgb.py, kitty_tests/datatypes.py (+250 lines)
- Go: tools/utils/style/colorspaces.go, wrapper.go (+350 lines, tests)
- Docs: docs/wide-gamut-colors.rst (moved from inline)
- Config: kitty/options/definition.py (simplified, links to docs)

References:
- CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/
- OKLCH Color Space: https://bottosson.github.io/posts/oklab/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 14:34:34 +00:00
..
base85 run modernize 2025-11-11 17:09:37 +05:30
humanize run modernize 2025-11-11 17:09:37 +05:30
images Resize method should not use bounds 2025-11-17 12:59:04 +05:30
paths Rename go module from kitty -> github.com/kovidgoyal/kitty 2025-05-16 08:43:39 +05:30
random
secrets
shlex Rename go module from kitty -> github.com/kovidgoyal/kitty 2025-05-16 08:43:39 +05:30
style Add wide gamut color support with OKLCH and LAB formats 2025-12-27 14:34:34 +00:00
atexit.go Add integration test for go atexit implementation 2025-09-30 12:37:25 +05:30
atomic-write.go Dont ignore err in close on atomicwrite 2024-09-10 21:53:49 +05:30
cache.go diff kitten: Automatically change colors on terminal color scheme change 2025-01-05 06:00:24 +05:30
cached_values.go
clock_with_raw.go
clock_without_raw.go
colors.go hints kitten: Workaround for some broken light color themes that make the hints text color too low contrast to read 2025-01-17 20:22:10 +05:30
download_file.go
embed.go
filelock.go
filelock_test.go
hostname.go
io.go
iso8601.go More CodeQL fixes 2025-04-20 23:08:14 +05:30
iso8601_test.go
levenshtein.go
longest-common.go run modernize 2025-11-11 17:09:37 +05:30
longest-common_test.go
mimetypes.go
misc.go Move error handling code into its own library 2025-10-12 13:51:16 +05:30
passwd.go
passwd_test.go
paths.go choose files: Add a few more output formats 2025-11-26 21:13:57 +05:30
regexp.go
ring.go
ring_test.go
select.go
select_posix.go
select_without_pselect.go
set.go Convenience method to access any member of a set 2025-05-15 21:40:06 +05:30
shell.go
short-uuid.go run modernize 2025-11-11 17:09:37 +05:30
short-uuid_test.go
sockets.go
sockets_test.go Fix #8220 2025-01-16 13:21:31 +05:30
stream_decompressor.go
stream_decompressor_test.go
strings.go
strings_test.go Use SIMD to replace C0 control codes in Go code 2025-07-21 08:54:22 +05:30
tar.go ... 2025-04-21 09:50:30 +05:30
tar_test.go Add test for tarfile extractall 2025-04-21 09:32:56 +05:30
tmpfile_linux.go Allow specifying permissions when creating anonymous temp files 2024-07-23 07:28:10 +05:30
tmpfile_others.go Allow specifying permissions when creating anonymous temp files 2024-07-23 07:28:10 +05:30
tpmfile_test.go
types.go
unsafe.go
utf-8.go
which.go