Skip to content
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

Add a new default filter that dithers a wallpaper image to the web safe color palette #679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/config/filters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ False|Soft blur|-scale 20% -blur 0x2 -resize 500%
False|Oil painting|-paint 8
False|Pointilism|-spread 10 -noise 3
False|Pixellate|-scale 3% -scale 3333%
False|Web safe|\( -size 1x1 xc:#000000 xc:#000033 xc:#000066 xc:#000099 xc:#0000CC xc:#0000FF xc:#003300 xc:#003333 xc:#003366 xc:#003399 xc:#0033CC xc:#0033FF xc:#006600 xc:#006633 xc:#006666 xc:#006699 xc:#0066CC xc:#0066FF xc:#009900 xc:#009933 xc:#009966 xc:#009999 xc:#0099CC xc:#0099FF xc:#00CC00 xc:#00CC33 xc:#00CC66 xc:#00CC99 xc:#00CCCC xc:#00CCFF xc:#00FF00 xc:#00FF33 xc:#00FF66 xc:#00FF99 xc:#00FFCC xc:#00FFFF xc:#330000 xc:#330033 xc:#330066 xc:#330099 xc:#3300CC xc:#3300FF xc:#333300 xc:#333333 xc:#333366 xc:#333399 xc:#3333CC xc:#3333FF xc:#336600 xc:#336633 xc:#336666 xc:#336699 xc:#3366CC xc:#3366FF xc:#339900 xc:#339933 xc:#339966 xc:#339999 xc:#3399CC xc:#3399FF xc:#33CC00 xc:#33CC33 xc:#33CC66 xc:#33CC99 xc:#33CCCC xc:#33CCFF xc:#33FF00 xc:#33FF33 xc:#33FF66 xc:#33FF99 xc:#33FFCC xc:#33FFFF xc:#660000 xc:#660033 xc:#660066 xc:#660099 xc:#6600CC xc:#6600FF xc:#663300 xc:#663333 xc:#663366 xc:#663399 xc:#6633CC xc:#6633FF xc:#666600 xc:#666633 xc:#666666 xc:#666699 xc:#6666CC xc:#6666FF xc:#669900 xc:#669933 xc:#669966 xc:#669999 xc:#6699CC xc:#6699FF xc:#66CC00 xc:#66CC33 xc:#66CC66 xc:#66CC99 xc:#66CCCC xc:#66CCFF xc:#66FF00 xc:#66FF33 xc:#66FF66 xc:#66FF99 xc:#66FFCC xc:#66FFFF xc:#990000 xc:#990033 xc:#990066 xc:#990099 xc:#9900CC xc:#9900FF xc:#993300 xc:#993333 xc:#993366 xc:#993399 xc:#9933CC xc:#9933FF xc:#996600 xc:#996633 xc:#996666 xc:#996699 xc:#9966CC xc:#9966FF xc:#999900 xc:#999933 xc:#999966 xc:#999999 xc:#9999CC xc:#9999FF xc:#99CC00 xc:#99CC33 xc:#99CC66 xc:#99CC99 xc:#99CCCC xc:#99CCFF xc:#99FF00 xc:#99FF33 xc:#99FF66 xc:#99FF99 xc:#99FFCC xc:#99FFFF xc:#CC0000 xc:#CC0033 xc:#CC0066 xc:#CC0099 xc:#CC00CC xc:#CC00FF xc:#CC3300 xc:#CC3333 xc:#CC3366 xc:#CC3399 xc:#CC33CC xc:#CC33FF xc:#CC6600 xc:#CC6633 xc:#CC6666 xc:#CC6699 xc:#CC66CC xc:#CC66FF xc:#CC9900 xc:#CC9933 xc:#CC9966 xc:#CC9999 xc:#CC99CC xc:#CC99FF xc:#CCCC00 xc:#CCCC33 xc:#CCCC66 xc:#CCCC99 xc:#CCCCCC xc:#CCCCFF xc:#CCFF00 xc:#CCFF33 xc:#CCFF66 xc:#CCFF99 xc:#CCFFCC xc:#CCFFFF xc:#FF0000 xc:#FF0033 xc:#FF0066 xc:#FF0099 xc:#FF00CC xc:#FF00FF xc:#FF3300 xc:#FF3333 xc:#FF3366 xc:#FF3399 xc:#FF33CC xc:#FF33FF xc:#FF6600 xc:#FF6633 xc:#FF6666 xc:#FF6699 xc:#FF66CC xc:#FF66FF xc:#FF9900 xc:#FF9933 xc:#FF9966 xc:#FF9999 xc:#FF99CC xc:#FF99FF xc:#FFCC00 xc:#FFCC33 xc:#FFCC66 xc:#FFCC99 xc:#FFCCCC xc:#FFCCFF xc:#FFFF00 xc:#FFFF33 xc:#FFFF66 xc:#FFFF99 xc:#FFFFCC xc:#FFFFFF +append -write mpr:z +delete \) -dither FloydSteinberg -remap mpr:z
2 changes: 1 addition & 1 deletion variety/VarietyWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ def apply_filters(self, to_set, refresh_level):
):
self.post_filter_filename = to_set
target_file = os.path.join(
self.wallpaper_folder, "wallpaper-filter-%s.jpg" % Util.random_hash()
self.wallpaper_folder, "wallpaper-filter-%s.png" % Util.random_hash()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reluctant to accept this change. JPGs are lossy, yes, but the majority of wallpapers and photos are still served in this format, and converting things to PNG will easily bloat file sizes from ~3MB (for a UHD image) to almost 10x that size. That's a lot of additional I/O if Variety is configured to change the wallpaper often.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my limited testing, at least in the case of the Web safe filter in this pull request, the PNG version of the filtered image does not have a significantly higher file size than the JPG version, and in many cases can have an even smaller file size. For example, a 4160x3120 JPG image of about 3.9 MiB is converted to a 4.5 MiB filtered PNG under the Web safe filter — so not even close to a 10× blowup. I suppose this is because the Web safe filter uses the ImageMagick remap command so that the PNG is saved as an 8-bit per pixel indexed color format, rather than in a 24-bit per pixel format.

However, I see the point that the PNG format might not make sense for all filters, especially for the existing default filters. Thus, I suggest a filter-by-filter option for the output image format (which defaults to .JPG), or to use the PNG format only when the unfiltered image file is "small enough".

)
cmd = self.build_imagemagick_filter_cmd(to_set, target_file)
if cmd:
Expand Down