Automatic detection of appropriate filter
Hey there,
I use a mix of pixel art and non-pixel art in my wallpaper collection. As you know, this requires changing the filter depending on whether it is pixel art or not, as pixel art images would look blurry when not using Nearest and other images would likely also look bad when using Nearest Neighbor filtering on them.
Because of this, I started renaming all my pixel art images to start with "pixel-" and wrote a small script that selects the correct filter accordingly:
#!/bin/sh
WALLPAPER_CHANGE_TIME_SECS=$((60*10))
WALLPAPER_DIR="$(xdg-user-dir PICTURES)/livewallpapers/gifs"
while pgrep swww >/dev/null; do killall swww-daemon; sleep 1 ; done
swww init
select_filter() {
filename="$(basename $1)"
if echo "${filename}" | grep -q '^pixel-' ; then
echo Nearest
else
echo Lanczos3
fi
}
while true; do
for image in $(find "${WALLPAPER_DIR}" -iname '*.gif' -type f | shuf) ; do
swww img --transition-type random --filter "$(select_filter "$image")" "${image}"
sleep "${WALLPAPER_CHANGE_TIME_SECS}"
done
done
While this does work well, it means I need to manually go through (new) gifs to name them correctly.
I thought it would be cool to automatically detect whether the image file is pixel-art and then select the filter according to that.
I have some ideas how this detection can be accomplished, but with this issue, I mostly want to check if there's interest in adding this to swww.
I thought a --filter auto option would be nice. It would detect if an image is pixel art and would use Nearest in that case and Lanczos3 otherwise.
Let me know what you think!
Interesting. Generally speaking, I want the daemon to remain as simple as possible because it is a long-running program that can hog resources for a very long time. But, I do not mind more complexity in the client program. Since the client is the one who reads the images, I guess we could try integrating this in swww if you manage to make it work.
Hey, so I've managed to write something that works for pretty much all wallpapers I currently have.
So I was able to change the script to use it instead:
#!/bin/sh
WALLPAPER_CHANGE_TIME_SECS=$((60*10))
WALLPAPER_DIR="$(xdg-user-dir PICTURES)/livewallpapers/gifs"
while pgrep swww >/dev/null; do killall swww-daemon; sleep 1 ; done
swww-daemon -q &
select_filter() {
filename="$(basename $1)"
if [ "$(pyxelart-detector "${filename}")" -eq "True" ]; then
echo Nearest
else
echo Lanczos3
fi
}
while true; do
for image in $(find "${WALLPAPER_DIR}" -iname '*.gif' -type f | shuf) ; do
swww img --transition-type random --filter Nearest "${image}"
sleep "${WALLPAPER_CHANGE_TIME_SECS}"
done
done
The thing is: It's written in python, because I felt it was easier while developing a good algorithm for the detection.
Do you think it would be fine to call the python script in swww client code?