Skip to content

Add CCT ramp mode for D4K-3ch with colorimetric accuracy#147

Open
GlassOnTin wants to merge 2 commits intoToyKeeper:trunkfrom
GlassOnTin:d4k-3ch-cct-mode
Open

Add CCT ramp mode for D4K-3ch with colorimetric accuracy#147
GlassOnTin wants to merge 2 commits intoToyKeeper:trunkfrom
GlassOnTin:d4k-3ch-cct-mode

Conversation

@GlassOnTin
Copy link

Summary

Adds a correlated color temperature (CCT) channel mode for the Emisar D4K-3ch that produces accurate white tones along the Planckian locus (blackbody curve).

  • New CM_CCT mode: Smoothly transitions from 2700K (warm incandescent) to 6500K (D65 daylight)
  • Colorimetric accuracy: RGB values computed using CIE 1931 color matching functions
  • LED colorimetry tooling: Python tool to generate optimal mixing coefficients for any LED configuration
  • Documentation: Color science fundamentals and derivation methodology

Channel Modes

The D4K-3ch now has 9 channel modes enabled by default:

Mode Name Description
0 CM_MAIN2 Green LEDs only
1 CM_LED3 Red LED only
2 CM_LED4 Blue LED only
3 CM_ALL All channels (D65 white)
4 CM_BLEND34A R+B manual blend (3H adjusts)
5 CM_BLEND34B R+G manual blend (3H adjusts)
6 CM_HSV Hue wheel (3H rotates color)
7 CM_AUTO3 Cyan auto-blend
8 CM_CCT NEW - CCT ramp (3H adjusts warm↔cool)

Implementation Details

  • 16-entry lookup table with bilinear interpolation
  • Pre-scaled for RGBG configuration (dual green LEDs at 41% for balanced white)
  • Optional extended range: 1800K-10000K via CCT_TABLE_EXTENDED define
  • Gradual tick support for smooth transitions

Tooling

tools/led_colorimetry.py computes optimal RGB values from:

  • LED spectral power distributions
  • CIE 1931 2° standard observer color matching functions
  • Planckian locus coordinates for target CCT values

Test Plan

  • Firmware builds successfully (14218 bytes)
  • CCT mode transitions smoothly from warm to cool
  • 3H gesture adjusts color temperature
  • All 9 channel modes cycle correctly with 3C
  • Verify color accuracy with spectrometer (optional)

Adds tooling and documentation for achieving accurate color reproduction
on multi-channel LED flashlights like the D4K-3ch.

tools/led_colorimetry.py:
- Compute optimal RGB mixing coefficients from LED spectral data
- Calculate Planckian locus (blackbody) color coordinates
- Generate lookup tables for CCT-to-RGB conversion
- Support for arbitrary LED combinations and color temperatures

docs/color-science.md:
- Color science fundamentals (CIE 1931, chromaticity)
- LED spectral characteristics and mixing theory
- Derivation of PWM scaling factors for balanced color
- Planckian locus mathematics for CCT mode
- Visual diagrams: chromaticity, LED SPDs, color mixing

tools/generate_color_figures.py:
- Generates all documentation figures from source data
- Chromaticity diagrams, spectral plots, mixing visualizations
Adds a correlated color temperature (CCT) mode that smoothly transitions
along the Planckian locus (blackbody curve) from warm to cool white.

New channel mode CM_CCT:
- Default range: 2700K (warm incandescent) to 6500K (D65 daylight)
- Extended range option: 1800K to 10000K (define CCT_TABLE_EXTENDED)
- 3H gesture adjusts color temperature
- Lookup table interpolation for smooth transitions

Implementation:
- 16-entry RGB lookup table computed from CIE 1931 colorimetry
- Values pre-scaled for RGBG LED configuration (dual green LEDs)
- Bilinear interpolation between table entries
- Gradual tick support for smooth ramping

The LUT was generated using tools/led_colorimetry.py which computes
optimal RGB values to match points along the Planckian locus, accounting
for the specific LED spectral characteristics of the D4K-3ch.

Also enables all 9 channel modes by default:
- CM_MAIN2, CM_LED3, CM_LED4, CM_ALL (single/combined channels)
- CM_BLEND34A, CM_BLEND34B (manual R+B, R+G blends)
- CM_HSV (hue wheel), CM_AUTO3 (cyan auto-blend), CM_CCT (new)
@GlassOnTin
Copy link
Author

GlassOnTin commented Dec 12, 2025

Video with the camera white balance locked at 6500K.

Then varying the torch colour temperature:
6500K -> 3H -> 2700K -> 3H -> 6500K

VID_20251212_152253_431.mp4

@GlassOnTin
Copy link
Author

VID_20251212_152834_152.mp4

@GlassOnTin
Copy link
Author

Screenshot_20251212-153151.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant