فهرست منبع

fix de-/saturate of colors with no hue

Alexander Rose 1 سال پیش
والد
کامیت
d5a47e617a
2فایلهای تغییر یافته به همراه9 افزوده شده و 0 حذف شده
  1. 1 0
      CHANGELOG.md
  2. 8 0
      src/mol-util/color/color.ts

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@ Note that since we don't clearly distinguish between a public and private interf
 ## [Unreleased]
 
 - Fix handling of PDB files with insertion codes (#945)
+- Fix de-/saturate of colors with no hue
 
 ## [v3.41.0] - 2023-10-15
 

+ 8 - 0
src/mol-util/color/color.ts

@@ -111,8 +111,16 @@ export namespace Color {
         return ((r << 16) | (g << 8) | b) as Color;
     }
 
+    export function hasHue(c: Color): boolean {
+        const r = c >> 16 & 255;
+        const g = c >> 8 & 255;
+        const b = c & 255;
+        return r !== g || r !== b;
+    }
+
     const tmpSaturateHcl = [0, 0, 0] as unknown as Hcl;
     export function saturate(c: Color, amount: number): Color {
+        if (!hasHue(c)) return c;
         Hcl.fromColor(tmpSaturateHcl, c);
         return Hcl.toColor(Hcl.saturate(tmpSaturateHcl, tmpSaturateHcl, amount));
     }