@@ -518,10 +518,9 @@ def downgrade(self, system: ColorSystem) -> "Color":
518518 # Convert to 8-bit color from truecolor color
519519 if system == ColorSystem .EIGHT_BIT and self .system == ColorSystem .TRUECOLOR :
520520 assert self .triplet is not None
521- red , green , blue = self .triplet .normalized
522- _h , l , s = rgb_to_hls (red , green , blue )
523- # If saturation is under 10% assume it is grayscale
524- if s < 0.1 :
521+ _h , l , s = rgb_to_hls (* self .triplet .normalized )
522+ # If saturation is under 15% assume it is grayscale
523+ if s < 0.15 :
525524 gray = round (l * 25.0 )
526525 if gray == 0 :
527526 color_number = 16
@@ -531,8 +530,13 @@ def downgrade(self, system: ColorSystem) -> "Color":
531530 color_number = 231 + gray
532531 return Color (self .name , ColorType .EIGHT_BIT , number = color_number )
533532
533+ red , green , blue = self .triplet
534+ six_red = red / 95 if red < 95 else 1 + (red - 95 ) / 40
535+ six_green = green / 95 if green < 95 else 1 + (green - 95 ) / 40
536+ six_blue = blue / 95 if blue < 95 else 1 + (blue - 95 ) / 40
537+
534538 color_number = (
535- 16 + 36 * round (red * 5.0 ) + 6 * round (green * 5.0 ) + round (blue * 5.0 )
539+ 16 + 36 * round (six_red ) + 6 * round (six_green ) + round (six_blue )
536540 )
537541 return Color (self .name , ColorType .EIGHT_BIT , number = color_number )
538542
0 commit comments