Изменён алгоритм для подбора ближайшего разрешения для fb

master-3.5 3.5.8.11
Mike Hiretsky 6 years ago
parent fdb7eb6b59
commit d35d1d082c

@ -607,16 +607,22 @@ class Brokenable(object):
def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False): def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False):
""" """
Получить наилучшее ближайшее к preferred_res разрешенение из support_res. Получить наилучшее ближайшее к preferred_res разрешенение из support_res.
Разрешение берётся ближайшее по размеру диагонали, с применением "штрафного"
коэфициента по разнице аспектов
""" """
width, height = map(int, preferred_res.split('x')) width, height = map(int, preferred_res.split('x'))
gep = sqrt(height ** 2 + width ** 2) gep = sqrt(height ** 2 + width ** 2)
k = float(width) / float(height) k = float(width) / float(height)
s = float(width) * float(height)
support_res_int = (tuple(map(int, x.split("x"))) for x in support_res) support_res_int = (tuple(map(int, x.split("x"))) for x in support_res)
support_res_int = ((x, y, sqrt(y*y + x*x), abs(x/float(y)-k))
for x, y in support_res_int)
if not aspect_only: if not aspect_only:
support_res_int = [(x,y) for x,y in support_res_int if x <= width and y <= height] support_res_int = [(x,y,g,dasp)
for x,y,g,dasp in support_res_int if x <= width and y <= height]
if not support_res_int: if not support_res_int:
return None return None
bestRes = min(support_res_int, keyfunc = lambda x,y,g, dasp: g -g * dasp
key=lambda x: (abs(x[0] / float(x[1]) - k), bestRes = max(support_res_int, key=lambda x:keyfunc(*x) )
abs(gep - sqrt(x[0] ** 2 + x[1] ** 2)))) return "%sx%s" % bestRes[0:2]
return "%sx%s" % bestRes

Loading…
Cancel
Save