Cache coefficients that are used for different size layouts

This commit is contained in:
Nick Mowen 2023-07-04 09:42:47 -06:00
parent 08412a444d
commit 81f47222ae

View File

@ -56,10 +56,17 @@ class Canvas:
) )
self.width = canvas_width self.width = canvas_width
self.height = (self.width * self.aspect[1]) / self.aspect[0] self.height = (self.width * self.aspect[1]) / self.aspect[0]
self.coefficient_cache: dict[int, int] = {}
def get_aspect(self, coefficient: int) -> tuple[int, int]: def get_aspect(self, coefficient: int) -> tuple[int, int]:
return (self.aspect[0] * coefficient, self.aspect[1] * coefficient) return (self.aspect[0] * coefficient, self.aspect[1] * coefficient)
def get_coefficient(self, camera_count: int) -> int:
return self.coefficient_cache.get(camera_count, 2)
def set_coefficient(self, camera_count: int, coefficient: int) -> None:
self.coefficient_cache[camera_count] = coefficient
class FFMpegConverter: class FFMpegConverter:
def __init__( def __init__(
@ -376,7 +383,7 @@ class BirdsEyeFrameManager:
] ]
else: else:
# calculate optimal layout # calculate optimal layout
coefficient = 2 coefficient = self.canvas.get_coefficient(len(active_cameras))
calculating = True calculating = True
# decrease scaling coefficient until height of all cameras can fit into the birdseye canvas # decrease scaling coefficient until height of all cameras can fit into the birdseye canvas
@ -398,6 +405,7 @@ class BirdsEyeFrameManager:
return return
calculating = False calculating = False
self.canvas.set_coefficient(len(active_cameras), coefficient)
self.camera_layout = layout_candidate self.camera_layout = layout_candidate