66# reserved. See LICENSE.
77#
88# File: biw-term-hsi.sh
9- # Description: Compute HSL (Hue/Saturation/Light) color space.
9+ # Description: Compute HSL (Hue/Saturation/Light) color space in 216
10+ # color SGR mode.
1011# #
1112
1213# colorspace params
13- declare -ir HSL_HUE_SIZE =36
14- declare -ir HSL_HUE_SECTORS =6
15- declare -ir HSL_SAT_SIZE =6
16- declare -ir HSL_LIGHT_SIZE =6
14+ declare -ir HSL216_HUE_SIZE =36
15+ declare -ir HSL216_HUE_SECTORS =6
16+ declare -ir HSL216_SAT_SIZE =6
17+ declare -ir HSL216_LIGHT_SIZE =6
1718
1819# Hue colors
19- declare -ir HSL_HUE_RED =$(( 0 * HSL_HUE_SECTORS ))
20- declare -ir HSL_HUE_YELLOW =$(( 1 * HSL_HUE_SECTORS ))
21- declare -ir HSL_HUE_GREEN =$(( 2 * HSL_HUE_SECTORS ))
22- declare -ir HSL_HUE_CYAN =$(( 3 * HSL_HUE_SECTORS ))
23- declare -ir HSL_HUE_BLUE =$(( 4 * HSL_HUE_SECTORS ))
24- declare -ir HSL_HUE_MAGENTA =$(( 5 * HSL_HUE_SECTORS ))
20+ declare -ir HSL216_HUE_RED =$(( 0 * HSL 216 _HUE_SECTORS ))
21+ declare -ir HSL216_HUE_YELLOW =$(( 1 * HSL 216 _HUE_SECTORS ))
22+ declare -ir HSL216_HUE_GREEN =$(( 2 * HSL 216 _HUE_SECTORS ))
23+ declare -ir HSL216_HUE_CYAN =$(( 3 * HSL 216 _HUE_SECTORS ))
24+ declare -ir HSL216_HUE_BLUE =$(( 4 * HSL 216 _HUE_SECTORS ))
25+ declare -ir HSL216_HUE_MAGENTA =$(( 5 * HSL 216 _HUE_SECTORS ))
2526
2627# lookup table for HSV-RGB transformations
27- declare -a HSL_TABLE
28- declare -ir HSL_TABLE_SIZE =$(( HSL_HUE_SIZE * HSL_SAT_SIZE * HSL_LIGHT_SIZE ))
28+ declare -a HSL216_TABLE_DATA
29+ declare -ir HSL216_TABLE_SIZE =$(( HSL 216 _HUE_SIZE * HSL 216 _SAT_SIZE * HSL 216 _LIGHT_SIZE ))
2930
3031# Interpolate y coordinates
3132# Parameters)
@@ -57,11 +58,11 @@ function fn_hsl_interp_y()
5758
5859# Calculate HSL color space (36x6x6) for the lookup table.
5960# Normalization for S<0 or H>=36 # are handled after the table calculation
60- # in fn_hsl_set .
61+ # in fn_hsl216_set .
6162# This algorithm makes use of the fn_hsl_interp_y routine to simplify code at the
6263# cost of minor additional computations. It is adapted for integer
6364# calculations for a small set of colors.
64- function fn_hsl_calc ()
65+ function fn_hsl216_calc ()
6566{
6667 local -i _hue=$1
6768 local -i _sat=$2
@@ -103,25 +104,25 @@ function fn_hsl_calc()
103104}
104105
105106# Compute HSV table of 6*6*36=1296 values.
106- function fn_hsl_init ()
107+ function fn_hsl216_init ()
107108{
108- HSL_TABLE[HSL_TABLE_SIZE - 1]=0
109+ HSL216_TABLE_DATA[HSL216_TABLE_SIZE - 1]=0
109110
110111 local -i _hue _sat _light
111112 local -i _sgr_code
112113 local -i _lut_idx
113114
114- for(( _light = 0 ; _light < HSL_LIGHT_SIZE ; _light++ ))
115+ for(( _light = 0 ; _light < HSL 216 _LIGHT_SIZE ; _light++ ))
115116 do
116- for(( _sat = 0 ; _sat < HSL_SAT_SIZE ; _sat++ ))
117+ for(( _sat = 0 ; _sat < HSL 216 _SAT_SIZE ; _sat++ ))
117118 do
118- for(( _hue = 0 ; _hue < HSL_HUE_SIZE ; _hue++ ))
119+ for(( _hue = 0 ; _hue < HSL 216 _HUE_SIZE ; _hue++ ))
119120 do
120- fn_hsl_calc $_hue $_sat $_light
121+ fn_hsl216_calc $_hue $_sat $_light
121122 _sgr_code=$?
122123
123- _lut_idx=$(( _light* HSL_SAT_SIZE * HSL_HUE_SIZE + _sat* HSL_HUE_SIZE + _hue))
124- HSL_TABLE [_lut_idx]=$_sgr_code
124+ _lut_idx=$(( _light* HSL 216 _SAT_SIZE * HSL 216 _HUE_SIZE + _sat* HSL 216 _HUE_SIZE + _hue))
125+ HSL216_TABLE_DATA [_lut_idx]=$_sgr_code
125126 done
126127 done
127128 done
@@ -134,13 +135,13 @@ function fn_hsl_init()
134135# 3) Saturation [-5..5]: Indicates amount of color. Negative values will
135136# invert color.
136137# 4) Light [0..5]: Indicates luminosity.
137- function fn_hsl_get ()
138+ function fn_hsl216_get ()
138139{
139140 local -i _hue=$1
140141 local -i _sat=$2
141142 local -i _light=$3
142143
143- if(( _light >= HSL_LIGHT_SIZE ))
144+ if(( _light >= HSL 216 _LIGHT_SIZE ))
144145 then
145146 echo " Error: L value must be the range [0..5]: ${_light} "
146147 exit 1
@@ -150,27 +151,27 @@ function fn_hsl_get()
150151 if(( _sat < 0 ))
151152 then
152153 _sat=$(( _sat * - 1 ))
153- _hue=$(( _hue + HSL_HUE_SIZE / 2 - 1 ))
154+ _hue=$(( _hue + HSL 216 _HUE_SIZE / 2 - 1 ))
154155 fi
155156
156157 # handle cyclic hue
157- if(( _hue >= HSL_HUE_SIZE ))
158+ if(( _hue >= HSL 216 _HUE_SIZE ))
158159 then
159- _hue=$(( _hue % HSL_HUE_SIZE ))
160+ _hue=$(( _hue % HSL 216 _HUE_SIZE ))
160161 fi
161162
162163 # get value from lookup table
163- local -i _lut_size=${# HSL_TABLE [*]}
164+ local -i _lut_size=${# HSL216_TABLE_DATA [*]}
164165 local -i _sgr_code
165166
166167 if(( _lut_size > 0 ))
167168 then
168169 # get from table
169- _lut_idx=$(( _light* HSL_SAT_SIZE * HSL_HUE_SIZE + _sat* HSL_HUE_SIZE + _hue))
170- _sgr_code=${HSL_TABLE [_lut_idx]}
170+ _lut_idx=$(( _light* HSL 216 _SAT_SIZE * HSL 216 _HUE_SIZE + _sat* HSL 216 _HUE_SIZE + _hue))
171+ _sgr_code=${HSL216_TABLE_DATA [_lut_idx]}
171172
172173 else
173- fn_hsl_calc $_hue $_sat $_light
174+ fn_hsl216_calc $_hue $_sat $_light
174175 _sgr_code=$?
175176 fi
176177
@@ -185,15 +186,15 @@ function fn_hsl_get()
185186# 3) Saturation [-5..5]: Indicates amount of color. Negative values will
186187# invert color.
187188# 4) Light [0..5]: Indicates luminosity.
188- function fn_hsl_set ()
189+ function fn_hsl216_set ()
189190{
190191 local -i _mode=$1
191192 local -i _hue=$2
192193 local -i _sat=$3
193194 local -i _light=$4
194195
195196 local -i _sgr_code
196- fn_hsl_get $_hue $_sat $_light
197+ fn_hsl216_get $_hue $_sat $_light
197198 _sgr_code=$?
198199
199200 fn_sgr_color216_set $_mode $_sgr_code
0 commit comments