diff options
| author | Fuwn <[email protected]> | 2024-09-12 23:10:03 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-09-12 23:10:03 -0700 |
| commit | f6f43b6911b903a47403db44dcc0a22e07840499 (patch) | |
| tree | 62f24a62c05b5744b9b0fdb5c28a632b22b41f70 | |
| parent | fb10fa1b146b4daf87a97f3ac6a3b295ff80481e (diff) | |
| download | pywal.nix-f6f43b6911b903a47403db44dcc0a22e07840499.tar.xz pywal.nix-f6f43b6911b903a47403db44dcc0a22e07840499.zip | |
feat: add remaining backends (full support)
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | flake.nix | 51 | ||||
| -rw-r--r-- | pywal/backends/fast_colorthief.py | 69 | ||||
| -rw-r--r-- | pywal/backends/haishoku.py | 56 | ||||
| -rw-r--r-- | pywal/backends/schemer2.py | 54 | ||||
| -rw-r--r-- | wrap.py | 10 |
6 files changed, 242 insertions, 5 deletions
@@ -52,7 +52,9 @@ the `pywal-nix` attribute. pywal-nix = { wallpaper = /path/to/wallpaper.png; # Required light = false; # Defaults to false - backend = "wal"; # One of "wal", "colorz", or "colorthief"; Defaults to "wal" + backend = "wal"; # One of "colorthief", "colorz", + # "fast_colorthief", "haishoku", + # "schemer2", "wal"; Default to "wal" }; # Example usage to print out few colours @@ -100,6 +102,9 @@ licensed under the [MIT License](./pywal/LICENSE.md). - [`pywal/backends/colorthief.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/colorthief.py) - [`pywal/backends/colorz.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/colorz.py) +- [`pywal/backends/fast_colorthief.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/fast_colorthief.py) +- [`pywal/backends/haishoku.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/haishoku.py) +- [`pywal/backends/schemer2.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/schemer2.py) - [`pywal/backends/wal.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/backends/wal.py) - [`pywal/colors.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/colors.py) - [`pywal/theme.py`](https://github.com/dylanaraps/pywal/blob/master/pywal/theme.py) @@ -27,6 +27,52 @@ jq python312Packages.colorthief colorz + python312Packages.pillow + python312Packages.numpy + (pkgs.python3.withPackages (ps: [ + (ps.buildPythonPackage rec { + pname = "haishoku"; + version = "1.1.8"; + doCheck = false; + + src = ps.fetchPypi { + inherit pname version; + hash = "sha256-5LmhTANYYIGxirzwS0MgFo/qk/9hHoGyvM1dUmn/y9Q="; + }; + }) + (ps.buildPythonPackage { + pname = "fast_colorthief"; + version = "0.0.5"; + doCheck = false; + dontUseCmakeConfigure = true; + + nativeBuildInputs = [ + pkgs.cmake + ps.setuptools + ps.setuptools_scm + ps.scikit-build + ]; + + src = pkgs.fetchgit { + url = "https://github.com/bedapisl/fast-colorthief"; + rev = "92eda78157bed309ef9c12e85708ae21241e11d0"; + hash = "sha256-0S8YI2DlEMx75vuAxcWzTBCcerLvULdh4nY2k3zdsqg="; + fetchSubmodules = true; + }; + }) + ])) + (pkgs.buildGoModule { + pname = "schemer2"; + version = "5dc8b0208efce6990c7dd0bf7fe3f044d11c65de"; + vendorHash = null; + + src = pkgs.fetchFromGitHub { + owner = "Fuwn"; + repo = "schemer2"; + rev = "5dc8b0208efce6990c7dd0bf7fe3f044d11c65de"; + hash = "sha256-/49TRM4B/EVJlj96RQ1RRsGdK2xP95FLkfwngKXL2ZI="; + }; + }) ]; } '' @@ -35,7 +81,7 @@ cp ${./wrap.py} $out/wrapper/wrap.py cp -r ${./pywal} $out/wrapper/pywal - ${pkgs.python3}/bin/python3 $out/wrapper/wrap.py ${config.pywal-nix.backend} ${config.pywal-nix.wallpaper} ${ + python3 $out/wrapper/wrap.py ${config.pywal-nix.backend} ${config.pywal-nix.wallpaper} ${ if config.pywal-nix.light then "1" else "0" } | \ sed "s/'/\"/g" | \ @@ -55,6 +101,9 @@ type = lib.types.enum [ "colorthief" "colorz" + "fast_colorthief" + "haishoku" + "schemer2" "wal" ]; diff --git a/pywal/backends/fast_colorthief.py b/pywal/backends/fast_colorthief.py new file mode 100644 index 0000000..82c2d02 --- /dev/null +++ b/pywal/backends/fast_colorthief.py @@ -0,0 +1,69 @@ +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +""" +Generate a colorscheme using fast_colorthief. +""" + +import logging +import sys + +try: + import fast_colorthief + +except ImportError: + logging.error("fast_colorthief wasn't found on your system.") + logging.error("Try another backend. (wal --backend)") + sys.exit(1) + +from .. import util + + +def gen_colors(img): + """Ask backend to generate 16 colors.""" + raw_colors = fast_colorthief.get_palette(img, 16) + + return [util.rgb_to_hex(color) for color in raw_colors] + + +def adjust(cols, light): + """Create palette.""" + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols, *cols] + + if light: + raw_colors[0] = util.lighten_color(cols[0], 0.90) + raw_colors[7] = util.darken_color(cols[0], 0.75) + + else: + for color in raw_colors: + color = util.lighten_color(color, 0.40) + + raw_colors[0] = util.darken_color(cols[0], 0.80) + raw_colors[7] = util.lighten_color(cols[0], 0.60) + + raw_colors[8] = util.lighten_color(cols[0], 0.20) + raw_colors[15] = raw_colors[7] + + return raw_colors + + +def get(img, light=False): + """Get colorscheme.""" + cols = gen_colors(img) + return adjust(cols, light) diff --git a/pywal/backends/haishoku.py b/pywal/backends/haishoku.py new file mode 100644 index 0000000..1369869 --- /dev/null +++ b/pywal/backends/haishoku.py @@ -0,0 +1,56 @@ +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +""" +Generate a colorscheme using Haishoku. +""" + +import logging +import sys + +try: + from haishoku.haishoku import Haishoku + +except ImportError: + logging.error("Haishoku wasn't found on your system.") + logging.error("Try another backend. (wal --backend)") + sys.exit(1) + +from .. import colors +from .. import util + + +def gen_colors(img): + """Generate a colorscheme using Colorz.""" + palette = Haishoku.getPalette(img) + return [util.rgb_to_hex(col[1]) for col in palette] + + +def adjust(cols, light): + """Create palette.""" + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols, *cols] + raw_colors[0] = util.lighten_color(cols[0], 0.40) + + return colors.generic_adjust(raw_colors, light) + + +def get(img, light=False): + """Get colorscheme.""" + cols = gen_colors(img) + return adjust(cols, light) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py new file mode 100644 index 0000000..44e531f --- /dev/null +++ b/pywal/backends/schemer2.py @@ -0,0 +1,54 @@ +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +""" +Generate a colorscheme using Schemer2. +""" + +import logging +import shutil +import subprocess +import sys + +from .. import colors +from .. import util + + +def gen_colors(img): + """Generate a colorscheme using Colorz.""" + cmd = ["schemer2", "-format", "img::colors", "-minBright", "75", "-in"] + return subprocess.check_output([*cmd, img]).splitlines() + + +def adjust(cols, light): + """Create palette.""" + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols[8:], *cols[8:]] + + return colors.generic_adjust(raw_colors, light) + + +def get(img, light=False): + """Get colorscheme.""" + if not shutil.which("schemer2"): + logging.error("Schemer2 wasn't found on your system.") + logging.error("Try another backend. (wal --backend)") + sys.exit(1) + + cols = [col.decode("UTF-8") for col in gen_colors(img)] + return adjust(cols, light) @@ -3,6 +3,9 @@ import sys from pywal.backends import ( colorthief, colorz, + fast_colorthief, + haishoku, + schemer2, wal, ) @@ -11,8 +14,9 @@ if __name__ == "__main__" and len(sys.argv) > 1: { "colorthief": colorthief.get, "colorz": colorz.get, + "fast_colorthief": fast_colorthief.get, + "haishoku": haishoku.get, + "schemer2": schemer2.get, "wal": wal.get, - }[ - sys.argv[1] - ](sys.argv[2], sys.argv[3] == "1" if len(sys.argv) > 3 else False) + }[sys.argv[1]](sys.argv[2], sys.argv[3] == "1" if len(sys.argv) > 3 else False) ) |