Skip to content

Commit

Permalink
Use p3 for gamut checks (#108)
Browse files Browse the repository at this point in the history
* Use p3 for gamut checks, appears to be more accurate

* doh
  • Loading branch information
mcnuttandrew authored Sep 13, 2024
1 parent 90048c7 commit f5f5ad2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/palette/src/Color.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,26 @@ test("All color spaces do round trip to each other correctly", () => {
);
});
});

test("In gamut tests", () => {
const colors = [
"#f00",
"#ff0",
"#0f0",
"#0ff",
"#00f",
"#f0f",
"#fff",
"#888",
"#000",
];
const spaces = ["lab"];
colors.forEach((color) => {
spaces.forEach((space) => {
const colorObj = Color.colorFromHex(color, space as any);
expect(colorObj.inGamut(), `${color} from ${space} to be in gamut`).toBe(
true
);
});
});
});
2 changes: 1 addition & 1 deletion packages/palette/src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Color {
if (InGamutCache.has(key)) {
return InGamutCache.get(key)!;
}
const result = this.toColorIO().inGamut("srgb");
const result = this.toColorIO().to("p3", { inGamut: false }).inGamut();
InGamutCache.set(key, result);
return result;
}
Expand Down

0 comments on commit f5f5ad2

Please sign in to comment.