@@ -518,10 +518,9 @@ def downgrade(self, system: ColorSystem) -> "Color":
518
518
# Convert to 8-bit color from truecolor color
519
519
if system == ColorSystem .EIGHT_BIT and self .system == ColorSystem .TRUECOLOR :
520
520
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 :
525
524
gray = round (l * 25.0 )
526
525
if gray == 0 :
527
526
color_number = 16
@@ -531,8 +530,13 @@ def downgrade(self, system: ColorSystem) -> "Color":
531
530
color_number = 231 + gray
532
531
return Color (self .name , ColorType .EIGHT_BIT , number = color_number )
533
532
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
+
534
538
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 )
536
540
)
537
541
return Color (self .name , ColorType .EIGHT_BIT , number = color_number )
538
542
0 commit comments