@@ -13,17 +13,39 @@ defmodule Color.Palette.Visualizer.GamutView do
1313 { :ProPhoto , "ProPhoto RGB" , "#f43f5e" , false }
1414 ]
1515
16+ # Palette-gamut dropdown options — mirrors TonalView so the
17+ # gamut view can reproduce the same tonal palette the Tonal tab
18+ # would generate.
19+ @ palette_gamut_options [
20+ { :SRGB , "sRGB" } ,
21+ { :P3_D65 , "P3 (D65)" } ,
22+ { :Rec2020 , "Rec2020" } ,
23+ { :Adobe , "Adobe RGB" } ,
24+ { :ProPhoto , "ProPhoto" }
25+ ]
26+
1627 def render ( params , base ) do
1728 projection = Map . get ( params , :projection , :uv )
1829 enabled = Map . get ( params , :gamuts , default_gamuts ( ) )
1930 show_planck = Map . get ( params , :planckian , true )
2031 overlay_seed = Map . get ( params , :overlay_seed , true )
2132 overlay_palette = Map . get ( params , :overlay_palette , false )
33+ palette_gamut = Map . get ( params , :palette_gamut , :SRGB )
34+ palette_chroma_ceiling = Map . get ( params , :palette_chroma_ceiling , 1.0 )
2235 seed = Map . get ( params , :seed , "#3b82f6" )
2336
2437 body =
2538 try do
26- success_body ( projection , enabled , show_planck , overlay_seed , overlay_palette , seed )
39+ success_body (
40+ projection ,
41+ enabled ,
42+ show_planck ,
43+ overlay_seed ,
44+ overlay_palette ,
45+ seed ,
46+ palette_gamut ,
47+ palette_chroma_ceiling
48+ )
2749 rescue
2850 e ->
2951 [ "<div class=\" vz-error\" >" , Render . escape ( Exception . message ( e ) ) , "</div>" ]
@@ -35,15 +57,38 @@ defmodule Color.Palette.Visualizer.GamutView do
3557 seed: seed ,
3658 body: body ,
3759 base: base ,
38- extra_fields: extra_fields ( projection , enabled , show_planck , overlay_seed , overlay_palette )
60+ extra_fields:
61+ extra_fields (
62+ projection ,
63+ enabled ,
64+ show_planck ,
65+ overlay_seed ,
66+ overlay_palette ,
67+ palette_gamut ,
68+ palette_chroma_ceiling
69+ ) ,
70+ tab_params: % {
71+ "tonal" => % {
72+ "gamut" => Atom . to_string ( palette_gamut ) ,
73+ "chroma_ceiling" => format_ceiling ( palette_chroma_ceiling )
74+ }
75+ }
3976 )
4077 end
4178
4279 defp default_gamuts do
4380 for { atom , _label , _colour , default? } <- @ working_spaces , default? , do: atom
4481 end
4582
46- defp extra_fields ( projection , enabled , show_planck , overlay_seed , overlay_palette ) do
83+ defp extra_fields (
84+ projection ,
85+ enabled ,
86+ show_planck ,
87+ overlay_seed ,
88+ overlay_palette ,
89+ palette_gamut ,
90+ palette_chroma_ceiling
91+ ) do
4792 [
4893 "<label>proj <select name=\" projection\" >" ,
4994 option ( "uv" , "u′v′ (CIE 1976)" , projection == :uv ) ,
@@ -73,10 +118,24 @@ defmodule Color.Palette.Visualizer.GamutView do
73118 "<label><input type=\" checkbox\" name=\" overlay_palette\" value=\" 1\" " ,
74119 if ( overlay_palette , do: " checked" , else: "" ) ,
75120 "> Plot tonal palette</label>" ,
121+ "<label>palette gamut <select name=\" palette_gamut\" >" ,
122+ Enum . map ( @ palette_gamut_options , fn { atom , label } ->
123+ selected = if atom == palette_gamut , do: " selected" , else: ""
124+ [ "<option value=\" " , Atom . to_string ( atom ) , "\" " , selected , ">" , label , "</option>" ]
125+ end ) ,
126+ "</select></label>" ,
127+ "<label>palette ceiling <input type=\" number\" name=\" palette_chroma_ceiling\" " ,
128+ " min=\" 0.1\" max=\" 1.0\" step=\" 0.05\" value=\" " ,
129+ format_ceiling ( palette_chroma_ceiling ) ,
130+ "\" ></label>" ,
76131 "<input type=\" hidden\" name=\" submitted\" value=\" 1\" >"
77132 ]
78133 end
79134
135+ defp format_ceiling ( value ) when is_float ( value ) , do: :erlang . float_to_binary ( value , decimals: 2 )
136+ defp format_ceiling ( value ) when is_integer ( value ) , do: Integer . to_string ( value )
137+ defp format_ceiling ( value ) , do: to_string ( value )
138+
80139 defp option ( value , label , selected? ) do
81140 [
82141 "<option value=\" " ,
@@ -89,8 +148,20 @@ defmodule Color.Palette.Visualizer.GamutView do
89148 ]
90149 end
91150
92- defp success_body ( projection , enabled , show_planck , overlay_seed , overlay_palette , seed ) do
93- palette = if overlay_palette , do: safe_tonal ( seed ) , else: nil
151+ defp success_body (
152+ projection ,
153+ enabled ,
154+ show_planck ,
155+ overlay_seed ,
156+ overlay_palette ,
157+ seed ,
158+ palette_gamut ,
159+ palette_chroma_ceiling
160+ ) do
161+ palette =
162+ if overlay_palette ,
163+ do: safe_tonal ( seed , palette_gamut , palette_chroma_ceiling ) ,
164+ else: nil
94165
95166 svg_binary =
96167 Color.Gamut.SVG . render (
@@ -120,8 +191,8 @@ defmodule Color.Palette.Visualizer.GamutView do
120191 ]
121192 end
122193
123- defp safe_tonal ( seed ) do
124- Color.Palette.Tonal . new ( seed )
194+ defp safe_tonal ( seed , gamut , chroma_ceiling ) do
195+ Color.Palette.Tonal . new ( seed , gamut: gamut , chroma_ceiling: chroma_ceiling )
125196 rescue
126197 _ -> nil
127198 end
0 commit comments