Skip to content

Commit 8759acb

Browse files
Expand color space conversions and enhance test coverage (#5)
* Expand color space conversions and enhance test coverage - Generate all 10 possible color space conversion pairs (rgb↔hsl, rgb↔hsv, rgb↔xyy, rgb↔cct, hsl↔hsv, hsl↔xyy, hsl↔cct, hsv↔xyy, hsv↔cct, xyy↔cct) - Add comprehensive documentation with color space standards and algorithms - Upgrade tests from basic non-nil checks to meaningful validation (types, ranges, format handling) - Fix format handling bugs in CCT conversions (remove double-conversion) - Regenerate all convert modules and test specs with proper bidirectional conversions * Fix luacheck warnings in generator scripts - Remove empty lines containing only whitespace - Break long comment lines (>120 characters) for better readability - Split long assertion statements across multiple lines - Maintain code functionality while improving style compliance * Regenerate conversion modules and tests with improved formatting - Update generated code to reflect luacheck style improvements - Break long comment lines and split long assertions in generated files - Maintain all functionality while improving code readability - All 836 tests still pass after regeneration
1 parent 0c85539 commit 8759acb

25 files changed

+7847
-998
lines changed

color/convert/cct_hsl.lua

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--- Cct ↔ Hsl conversion module
2+
--- Contains all format variants for this conversion pair
3+
---
4+
--- This module provides industry-standard color space conversions following
5+
--- established algorithms and best practices for computer graphics.
6+
---
7+
--- CCT ↔ HSL conversions chain through RGB intermediate representation
8+
--- using optimized lookup table interpolation for CCT and standard
9+
--- lightness calculations for HSL.
10+
---
11+
--- Standards: CIE 1931 color space, correlated color temperature,
12+
--- CSS Color Module Level 4
13+
--- Algorithm: Lookup table interpolation + golden section search →
14+
--- Lightness = (max + min)/2
15+
--- Accuracy: < 10K error for CCT, standard HSL precision
16+
17+
local cctk_to_rgb = require 'color.core.cctk_to_rgb'
18+
local rgb_to_hsl = require 'color.core.rgb_to_hsl'
19+
local hsl_to_hsl360 = require 'color.format.hsl'.hsl_to_hsl360
20+
local cctk_to_cctm = require 'color.format.cct'.cctk_to_cctm
21+
local hsl_to_rgb = require 'color.core.hsl_to_rgb'
22+
local rgb_to_cctk = require 'color.core.rgb_to_cctk'
23+
local cctm_to_cctk = require 'color.format.cct'.cctm_to_cctk
24+
local hsl360_to_hsl = require 'color.format.hsl'.hsl360_to_hsl
25+
26+
local M = {}
27+
28+
-- cctk to hsl
29+
function M.cctk_to_hsl(
30+
kelvin
31+
)
32+
return rgb_to_hsl(cctk_to_rgb(kelvin))
33+
end
34+
35+
-- cctk to hsl360
36+
function M.cctk_to_hsl360(
37+
kelvin
38+
)
39+
return hsl_to_hsl360(rgb_to_hsl(cctk_to_rgb(kelvin)))
40+
end
41+
42+
-- cctm to hsl
43+
function M.cctm_to_hsl(
44+
mired
45+
)
46+
return rgb_to_hsl(cctk_to_rgb(cctk_to_cctm(mired)))
47+
end
48+
49+
-- cctm to hsl360
50+
function M.cctm_to_hsl360(
51+
mired
52+
)
53+
return hsl_to_hsl360(rgb_to_hsl(cctk_to_rgb(cctk_to_cctm(mired))))
54+
end
55+
56+
-- hsl to cctk
57+
function M.hsl_to_cctk(
58+
hue, saturation, lightness
59+
)
60+
return rgb_to_cctk(hsl_to_rgb(hue, saturation, lightness))
61+
end
62+
63+
-- hsl to cctm
64+
function M.hsl_to_cctm(
65+
hue, saturation, lightness
66+
)
67+
return cctm_to_cctk(rgb_to_cctk(hsl_to_rgb(hue, saturation, lightness)))
68+
end
69+
70+
-- hsl360 to cctk
71+
function M.hsl360_to_cctk(
72+
hue_degrees, saturation, lightness
73+
)
74+
return rgb_to_cctk(hsl_to_rgb(hsl360_to_hsl(hue_degrees, saturation, lightness)))
75+
end
76+
77+
-- hsl360 to cctm
78+
function M.hsl360_to_cctm(
79+
hue_degrees, saturation, lightness
80+
)
81+
return cctm_to_cctk(rgb_to_cctk(hsl_to_rgb(hsl360_to_hsl(hue_degrees, saturation, lightness))))
82+
end
83+
84+
return M

color/convert/cct_hsv.lua

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--- Cct ↔ Hsv conversion module
2+
--- Contains all format variants for this conversion pair
3+
---
4+
--- This module provides industry-standard color space conversions following
5+
--- established algorithms and best practices for computer graphics.
6+
---
7+
--- CCT ↔ HSV conversions chain through RGB intermediate representation
8+
--- using optimized lookup table interpolation for CCT and standard
9+
--- computer graphics algorithms for HSV.
10+
---
11+
--- Standards: CIE 1931 color space, correlated color temperature,
12+
--- computer graphics (Foley et al.)
13+
--- Algorithm: Lookup table interpolation + golden section search →
14+
--- component-wise max/min
15+
--- Accuracy: < 10K error for CCT, standard HSV precision
16+
17+
local cctk_to_rgb = require 'color.core.cctk_to_rgb'
18+
local rgb_to_hsv = require 'color.core.rgb_to_hsv'
19+
local hsv_to_hsv360 = require 'color.format.hsv'.hsv_to_hsv360
20+
local cctk_to_cctm = require 'color.format.cct'.cctk_to_cctm
21+
local hsv_to_rgb = require 'color.core.hsv_to_rgb'
22+
local rgb_to_cctk = require 'color.core.rgb_to_cctk'
23+
local cctm_to_cctk = require 'color.format.cct'.cctm_to_cctk
24+
local hsv360_to_hsv = require 'color.format.hsv'.hsv360_to_hsv
25+
26+
local M = {}
27+
28+
-- cctk to hsv
29+
function M.cctk_to_hsv(
30+
kelvin
31+
)
32+
return rgb_to_hsv(cctk_to_rgb(kelvin))
33+
end
34+
35+
-- cctk to hsv360
36+
function M.cctk_to_hsv360(
37+
kelvin
38+
)
39+
return hsv_to_hsv360(rgb_to_hsv(cctk_to_rgb(kelvin)))
40+
end
41+
42+
-- cctm to hsv
43+
function M.cctm_to_hsv(
44+
mired
45+
)
46+
return rgb_to_hsv(cctk_to_rgb(cctk_to_cctm(mired)))
47+
end
48+
49+
-- cctm to hsv360
50+
function M.cctm_to_hsv360(
51+
mired
52+
)
53+
return hsv_to_hsv360(rgb_to_hsv(cctk_to_rgb(cctk_to_cctm(mired))))
54+
end
55+
56+
-- hsv to cctk
57+
function M.hsv_to_cctk(
58+
hue, saturation, value
59+
)
60+
return rgb_to_cctk(hsv_to_rgb(hue, saturation, value))
61+
end
62+
63+
-- hsv to cctm
64+
function M.hsv_to_cctm(
65+
hue, saturation, value
66+
)
67+
return cctm_to_cctk(rgb_to_cctk(hsv_to_rgb(hue, saturation, value)))
68+
end
69+
70+
-- hsv360 to cctk
71+
function M.hsv360_to_cctk(
72+
hue_degrees, saturation, value
73+
)
74+
return rgb_to_cctk(hsv_to_rgb(hsv360_to_hsv(hue_degrees, saturation, value)))
75+
end
76+
77+
-- hsv360 to cctm
78+
function M.hsv360_to_cctm(
79+
hue_degrees, saturation, value
80+
)
81+
return cctm_to_cctk(rgb_to_cctk(hsv_to_rgb(hsv360_to_hsv(hue_degrees, saturation, value))))
82+
end
83+
84+
return M
Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,41 @@
1-
--- RgbCct conversion module
1+
--- CctRgb conversion module
22
--- Contains all format variants for this conversion pair
33
---
44
--- This module provides industry-standard color space conversions following
55
--- established algorithms and best practices for computer graphics.
6-
---
7-
--- RGB ↔ CCT conversions use optimized lookup table interpolation
8-
--- with golden section search for accurate color temperature calculation.
9-
--- Provides high accuracy across the full 1000K-30000K range.
10-
---
11-
--- Standards: CIE 1931 color space, correlated color temperature
12-
--- Algorithm: Lookup table interpolation + golden section search
13-
--- Accuracy: < 10K error across standard illuminant range
146

15-
local rgb_to_cctk = require 'color.core.rgb_to_cctk'
167
local cctk_to_rgb = require 'color.core.cctk_to_rgb'
17-
local rgb8_to_rgb = require 'color.format.rgb'.rgb8_to_rgb
8+
local rgb_to_cctk = require 'color.core.rgb_to_cctk'
9+
local rgb_to_rgb8 = require 'color.format.rgb'.rgb_to_rgb8
10+
local rgb_to_hex24 = require 'color.format.rgb'.rgb_to_hex24
11+
local rgb_to_rgb100 = require 'color.format.rgb'.rgb_to_rgb100
1812
local cctk_to_cctm = require 'color.format.cct'.cctk_to_cctm
13+
local rgb8_to_rgb = require 'color.format.rgb'.rgb8_to_rgb
1914
local cctm_to_cctk = require 'color.format.cct'.cctm_to_cctk
2015
local hex24_to_rgb = require 'color.format.rgb'.hex24_to_rgb
2116
local rgb100_to_rgb = require 'color.format.rgb'.rgb100_to_rgb
22-
local rgb_to_rgb8 = require 'color.format.rgb'.rgb_to_rgb8
23-
local rgb_to_hex24 = require 'color.format.rgb'.rgb_to_hex24
24-
local rgb_to_rgb100 = require 'color.format.rgb'.rgb_to_rgb100
2517

2618
local M = {}
2719

28-
-- rgb8 to cctk
29-
function M.rgb8_to_cctk(
30-
red, green, blue
31-
)
32-
return cctk_to_cctm(rgb_to_cctk(rgb8_to_rgb(red, green, blue)))
33-
end
34-
35-
-- rgb8 to cctm
36-
function M.rgb8_to_cctm(
37-
red, green, blue
38-
)
39-
return cctm_to_cctk(rgb_to_cctk(rgb8_to_rgb(red, green, blue)))
40-
end
41-
42-
-- hex24 to cctk
43-
function M.hex24_to_cctk(
44-
hex
45-
)
46-
return cctk_to_cctm(rgb_to_cctk(hex24_to_rgb(hex)))
47-
end
48-
49-
-- hex24 to cctm
50-
function M.hex24_to_cctm(
51-
hex
52-
)
53-
return cctm_to_cctk(rgb_to_cctk(hex24_to_rgb(hex)))
54-
end
55-
56-
-- rgb100 to cctk
57-
function M.rgb100_to_cctk(
58-
red, green, blue
59-
)
60-
return cctk_to_cctm(rgb_to_cctk(rgb100_to_rgb(red, green, blue)))
61-
end
62-
63-
-- rgb100 to cctm
64-
function M.rgb100_to_cctm(
65-
red, green, blue
66-
)
67-
return cctm_to_cctk(rgb_to_cctk(rgb100_to_rgb(red, green, blue)))
68-
end
69-
7020
-- cctk to rgb8
7121
function M.cctk_to_rgb8(
7222
kelvin
7323
)
74-
return rgb_to_rgb8(cctk_to_rgb(cctm_to_cctk(kelvin)))
24+
return rgb_to_rgb8(cctk_to_rgb(kelvin))
7525
end
7626

7727
-- cctk to hex24
7828
function M.cctk_to_hex24(
7929
kelvin
8030
)
81-
return rgb_to_hex24(cctk_to_rgb(cctm_to_cctk(kelvin)))
31+
return rgb_to_hex24(cctk_to_rgb(kelvin))
8232
end
8333

8434
-- cctk to rgb100
8535
function M.cctk_to_rgb100(
8636
kelvin
8737
)
88-
return rgb_to_rgb100(cctk_to_rgb(cctm_to_cctk(kelvin)))
38+
return rgb_to_rgb100(cctk_to_rgb(kelvin))
8939
end
9040

9141
-- cctm to rgb8
@@ -109,11 +59,46 @@ function M.cctm_to_rgb100(
10959
return rgb_to_rgb100(cctk_to_rgb(cctk_to_cctm(mired)))
11060
end
11161

112-
-- rgb to cctk (normalized pass-through)
113-
function M.rgb_to_cctk(
62+
-- rgb8 to cctk
63+
function M.rgb8_to_cctk(
11464
red, green, blue
11565
)
116-
return rgb_to_cctk(red, green, blue)
66+
return rgb_to_cctk(rgb8_to_rgb(red, green, blue))
67+
end
68+
69+
-- rgb8 to cctm
70+
function M.rgb8_to_cctm(
71+
red, green, blue
72+
)
73+
return cctm_to_cctk(rgb_to_cctk(rgb8_to_rgb(red, green, blue)))
74+
end
75+
76+
-- hex24 to cctk
77+
function M.hex24_to_cctk(
78+
hex
79+
)
80+
return rgb_to_cctk(hex24_to_rgb(hex))
81+
end
82+
83+
-- hex24 to cctm
84+
function M.hex24_to_cctm(
85+
hex
86+
)
87+
return cctm_to_cctk(rgb_to_cctk(hex24_to_rgb(hex)))
88+
end
89+
90+
-- rgb100 to cctk
91+
function M.rgb100_to_cctk(
92+
red, green, blue
93+
)
94+
return rgb_to_cctk(rgb100_to_rgb(red, green, blue))
95+
end
96+
97+
-- rgb100 to cctm
98+
function M.rgb100_to_cctm(
99+
red, green, blue
100+
)
101+
return cctm_to_cctk(rgb_to_cctk(rgb100_to_rgb(red, green, blue)))
117102
end
118103

119104
-- cctk to rgb (normalized pass-through)
@@ -123,4 +108,11 @@ function M.cctk_to_rgb(
123108
return cctk_to_rgb(kelvin)
124109
end
125110

111+
-- rgb to cctk (normalized pass-through)
112+
function M.rgb_to_cctk(
113+
red, green, blue
114+
)
115+
return rgb_to_cctk(red, green, blue)
116+
end
117+
126118
return M

color/convert/cct_xyy.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212

1313
local cctk_to_rgb = require 'color.core.cctk_to_rgb'
1414
local rgb_to_xyy = require 'color.core.rgb_to_xyy'
15-
local cctm_to_cctk = require 'color.format.cct'.cctm_to_cctk
1615
local cctk_to_cctm = require 'color.format.cct'.cctk_to_cctm
1716
local xyy_to_rgb = require 'color.core.xyy_to_rgb'
1817
local rgb_to_cctk = require 'color.core.rgb_to_cctk'
18+
local cctm_to_cctk = require 'color.format.cct'.cctm_to_cctk
1919

2020
local M = {}
2121

2222
-- cctk to xyy
2323
function M.cctk_to_xyy(
2424
kelvin
2525
)
26-
return rgb_to_xyy(cctk_to_rgb(cctm_to_cctk(kelvin)))
26+
return rgb_to_xyy(cctk_to_rgb(kelvin))
2727
end
2828

2929
-- cctm to xyy
@@ -37,7 +37,7 @@ end
3737
function M.xyy_to_cctk(
3838
x, y, Y
3939
)
40-
return cctk_to_cctm(rgb_to_cctk(xyy_to_rgb(x, y, Y)))
40+
return rgb_to_cctk(xyy_to_rgb(x, y, Y))
4141
end
4242

4343
-- xyy to cctm

0 commit comments

Comments
 (0)