|
|
|
@ -27,7 +27,7 @@ from os import path
|
|
|
|
|
import time
|
|
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
from types import GeneratorType
|
|
|
|
|
|
|
|
|
|
from math import sqrt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -602,3 +602,21 @@ class Brokenable(object):
|
|
|
|
|
return f(self, *args, **kw)
|
|
|
|
|
return wrapper
|
|
|
|
|
return decor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_best_nearest_resolution(preferred_res, support_res, aspect_only=False):
|
|
|
|
|
"""
|
|
|
|
|
Получить наилучшее ближайшее к preferred_res разрешенение из support_res.
|
|
|
|
|
"""
|
|
|
|
|
width, height = map(int, preferred_res.split('x'))
|
|
|
|
|
gep = sqrt(height ** 2 + width ** 2)
|
|
|
|
|
k = float(width) / float(height)
|
|
|
|
|
support_res_int = (tuple(map(int, x.split("x"))) for x in support_res)
|
|
|
|
|
if not aspect_only:
|
|
|
|
|
support_res_int = [(x,y) for x,y in support_res_int if x <= width and y <= height]
|
|
|
|
|
if not support_res_int:
|
|
|
|
|
return None
|
|
|
|
|
bestRes = min(support_res_int,
|
|
|
|
|
key=lambda x: (abs(x[0] / float(x[1]) - k),
|
|
|
|
|
abs(gep - sqrt(x[0] ** 2 + x[1] ** 2))))
|
|
|
|
|
return "%sx%s" % bestRes
|
|
|
|
|