summaryrefslogtreecommitdiff
path: root/src/caelestia/utils/material/__init__.py
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-24 00:11:20 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-24 00:11:20 +1000
commit82f98a4f6a38c3a9ad2702ffb5207be9fc08e822 (patch)
treefc7291afaba1dfe46c913248e15280524ecee063 /src/caelestia/utils/material/__init__.py
parentscore: fix for low contrast wallpapers (diff)
downloadcaelestia-cli-82f98a4f6a38c3a9ad2702ffb5207be9fc08e822.tar.gz
caelestia-cli-82f98a4f6a38c3a9ad2702ffb5207be9fc08e822.tar.bz2
caelestia-cli-82f98a4f6a38c3a9ad2702ffb5207be9fc08e822.zip
[!B] colours: better colours
Also remove multiple dynamic flavours Add extended material (success colours)
Diffstat (limited to 'src/caelestia/utils/material/__init__.py')
-rw-r--r--src/caelestia/utils/material/__init__.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/caelestia/utils/material/__init__.py b/src/caelestia/utils/material/__init__.py
index 447a952..b96849f 100644
--- a/src/caelestia/utils/material/__init__.py
+++ b/src/caelestia/utils/material/__init__.py
@@ -8,20 +8,18 @@ from caelestia.utils.material.score import score
from caelestia.utils.paths import compute_hash, scheme_cache_dir, wallpaper_thumbnail_path
-def get_score_for_image(image: Path | str, cache_base: Path) -> tuple[list[Hct], list[Hct]]:
+def get_score_for_image(image: Path | str, cache_base: Path) -> Hct:
cache = cache_base / "score.json"
try:
- with cache.open("r") as f:
- return [[Hct.from_int(c) for c in li] for li in json.load(f)]
- except (IOError, json.JSONDecodeError):
+ return Hct.from_int(cache.read_text())
+ except (IOError, TypeError):
pass
s = score(str(image))
cache.parent.mkdir(parents=True, exist_ok=True)
- with cache.open("w") as f:
- json.dump([[c.to_int() for c in li] for li in s], f)
+ cache.write_text(str(s.to_int()))
return s
@@ -32,10 +30,8 @@ def get_colours_for_image(image: Path | str = wallpaper_thumbnail_path, scheme=N
scheme = get_scheme()
- flavour = scheme.flavour if scheme.flavour in ("default", "alt1", "alt2") else "default"
-
cache_base = scheme_cache_dir / compute_hash(image)
- cache = (cache_base / scheme.variant / flavour / scheme.mode).with_suffix(".json")
+ cache = (cache_base / scheme.variant / scheme.mode).with_suffix(".json")
try:
with cache.open("r") as f:
@@ -43,9 +39,8 @@ def get_colours_for_image(image: Path | str = wallpaper_thumbnail_path, scheme=N
except (IOError, json.JSONDecodeError):
pass
- primaries, colours = get_score_for_image(image, cache_base)
- i = ["default", "alt1", "alt2"].index(flavour)
- scheme = gen_scheme(scheme, primaries[i], colours)
+ primary = get_score_for_image(image, cache_base)
+ scheme = gen_scheme(scheme, primary)
cache.parent.mkdir(parents=True, exist_ok=True)
with cache.open("w") as f: