Skip to content

Automatic detection of appropriate filter #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dann-merlin opened this issue Feb 13, 2025 · 2 comments
Open

Automatic detection of appropriate filter #399

dann-merlin opened this issue Feb 13, 2025 · 2 comments

Comments

@dann-merlin
Copy link

dann-merlin commented Feb 13, 2025

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!

@LGFae
Copy link
Owner

LGFae commented Feb 13, 2025

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.

@dann-merlin
Copy link
Author

dann-merlin commented Feb 19, 2025

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?

Edit: Oh, this is the project btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants