mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-27 12:08:49 +02:00
wallpaper: add options to modify scoring
This commit is contained in:
parent
c8bd6f35a4
commit
fd5bfda5f3
1 changed files with 39 additions and 14 deletions
|
@ -20,6 +20,7 @@ import collections
|
|||
import itertools
|
||||
import logging
|
||||
import logging.handlers
|
||||
import inspect
|
||||
|
||||
from Xlib import display
|
||||
from Xlib.ext import randr
|
||||
|
@ -136,7 +137,7 @@ def get_random_images(directory, number):
|
|||
return images
|
||||
|
||||
|
||||
def get_best_parts(groups, images):
|
||||
def get_best_parts(groups, images, ratio_score=100, scale_score=60, wallpaper_score=2):
|
||||
"""Find optimal association for images for the groups of covering rectangles.
|
||||
|
||||
>>> gbp = get_best_parts
|
||||
|
@ -201,15 +202,15 @@ def get_best_parts(groups, images):
|
|||
r = iratio / oratio
|
||||
if r > 1:
|
||||
r = 1 / r
|
||||
score += r * 100
|
||||
score += r * ratio_score
|
||||
# Similar scale (when cropped)
|
||||
opixels = assoc.rectangle.width * assoc.rectangle.height
|
||||
ipixels = assoc.image.width * assoc.image.height * r
|
||||
r = ipixels / opixels
|
||||
if r >= 1:
|
||||
r = 1
|
||||
score += r * 60
|
||||
score /= len(group) * len(group)
|
||||
score += r * scale_score
|
||||
score /= pow(len(group), wallpaper_score)
|
||||
logger.debug("association: %s, score %.2f", association, score)
|
||||
if score > best_score or best_association is None:
|
||||
best_association = association
|
||||
|
@ -259,25 +260,43 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="enable debugging",
|
||||
)
|
||||
parser.add_argument(
|
||||
group = parser.add_argument_group("image selection")
|
||||
group.add_argument(
|
||||
"-d",
|
||||
"--directory",
|
||||
default=".",
|
||||
help="search for images in DIRECTORY",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--target",
|
||||
default="background.png",
|
||||
help="write background to FILE",
|
||||
)
|
||||
parser.add_argument(
|
||||
group.add_argument(
|
||||
"--extra-images",
|
||||
default=3,
|
||||
metavar="N",
|
||||
help="consider N additional images to choose the best combination",
|
||||
)
|
||||
parser.add_argument(
|
||||
params = inspect.signature(get_best_parts).parameters
|
||||
group.add_argument(
|
||||
"--ratio-score",
|
||||
default=params["ratio_score"].default,
|
||||
help="multiplicative weight applied to ratio matching for score",
|
||||
)
|
||||
group.add_argument(
|
||||
"--scale-score",
|
||||
default=params["scale_score"].default,
|
||||
help="multiplicative weight applied to pixel matching for score",
|
||||
)
|
||||
group.add_argument(
|
||||
"--wallpaper-score",
|
||||
default=params["wallpaper_score"].default,
|
||||
help="invert power weight applied to the number of wallpapers used",
|
||||
)
|
||||
group = parser.add_argument_group("image output")
|
||||
group.add_argument(
|
||||
"-t",
|
||||
"--target",
|
||||
default="background.png",
|
||||
help="write background to FILE",
|
||||
)
|
||||
group.add_argument(
|
||||
"--compression", default=0, type=int, help="compression level when saving"
|
||||
)
|
||||
options = parser.parse_args()
|
||||
|
@ -299,7 +318,13 @@ if __name__ == "__main__":
|
|||
images = get_random_images(
|
||||
options.directory, len(outputs) + options.extra_images
|
||||
)
|
||||
wallpaper_parts = get_best_parts(candidates, images)
|
||||
wallpaper_parts = get_best_parts(
|
||||
candidates,
|
||||
images,
|
||||
ratio_score=options.ratio_score,
|
||||
scale_score=options.scale_score,
|
||||
wallpaper_score=options.wallpaper_score,
|
||||
)
|
||||
for part in wallpaper_parts:
|
||||
logger.info(
|
||||
"wallpaper: {} ({}×{})".format(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue