Skip to content

Commit

Permalink
naive clip to gamut
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 14, 2024
1 parent 0afc1a3 commit e149bdd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/content-modules/ActionArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import AddColor from "./contextual-tools/AddColor.svelte";
import Rotate from "./contextual-tools/Rotate.svelte";
import Deduplicate from "./contextual-tools/Deduplicate.svelte";
import ClipToGamut from "./contextual-tools/ClipToGamut.svelte";
</script>

<div
class="flex bg-slate-400 p-2 h-12 flex-none items-center overflow-x-scroll overflow-y-hidden"
>
<AddColor />
<AdjustColor />
<ClipToGamut />
<OpposingColor />

<CreateAverage />
Expand Down
29 changes: 29 additions & 0 deletions src/content-modules/contextual-tools/ClipToGamut.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
import colorStore from "../../stores/color-store";
import { buttonStyle } from "../../lib/styles";
$: colors = $colorStore.currentPal.colors;
function clipToGamut() {
const newColors = colors.map((x) => {
if (x.inGamut()) {
return x;
} else {
const newChannels = x
.toColorIO()
.to("srgb")
.toGamut()
.to(x.spaceName).coords;
return x.fromChannels(newChannels);
}
});
colorStore.setCurrentPalColors(newColors);
}
$: outOfGamutColors = colors.map((x) => x.inGamut());
</script>

{#if outOfGamutColors.length >= 1}
<button class={buttonStyle} on:click={clipToGamut}>Clip to gamut</button>
{/if}

0 comments on commit e149bdd

Please sign in to comment.