From ffbbeeb8d27bc449062c47467c0416c4c53bd9fd Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 23 Aug 2024 09:35:54 +0300 Subject: [PATCH] Separate MetaFormats --- pixutils/__init__.py | 1 + pixutils/pixelformats.py | 42 +--------------------------------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/pixutils/__init__.py b/pixutils/__init__.py index ce53813..916f2e8 100644 --- a/pixutils/__init__.py +++ b/pixutils/__init__.py @@ -1,3 +1,4 @@ from __future__ import annotations from .pixelformats import * +from .metaformats import * diff --git a/pixutils/pixelformats.py b/pixutils/pixelformats.py index b5fc2b6..f814ace 100644 --- a/pixutils/pixelformats.py +++ b/pixutils/pixelformats.py @@ -5,7 +5,7 @@ from .fourcc_str import str_to_fourcc, fourcc_to_str -__all__ = [ 'PixelColorEncoding', 'PixelFormat', 'PixelFormats', 'MetaFormat', 'MetaFormats' ] +__all__ = [ 'PixelColorEncoding', 'PixelFormat', 'PixelFormats' ] class PixelColorEncoding(Enum): RGB = 0 @@ -410,43 +410,3 @@ def find_by_name(name): 1, ( ( 1, 1 ), ), ) - - -class MetaFormat: - def __init__(self, name: str, v4l2_fourcc: str, pixelspergroup: int, bytespergroup: int) -> None: - self.name = name - self.v4l2_fourcc = str_to_fourcc(v4l2_fourcc) - self.pixelspergroup = pixelspergroup - self.bytespergroup = bytespergroup - - def stride(self, width: int, align: int = 1): - # ceil(width / pixelsPerGroup) * bytesPerGroup - stride = (width + self.pixelspergroup - 1) // self.pixelspergroup * self.bytespergroup - - # ceil(stride / align) * align - return (stride + align - 1) // align * align - - -class MetaFormats: - @staticmethod - def find_v4l2_fourcc(fourcc): - return next(v for v in MetaFormats.__dict__.values() if isinstance(v, MetaFormat) and v.v4l2_fourcc == fourcc) - - @staticmethod - def find_v4l2_fourcc_unsupported(fourcc): - try: - return MetaFormats.find_v4l2_fourcc(fourcc) - except StopIteration: - s = fourcc_to_str(fourcc) - return MetaFormat(f'Unsupported<{s}>', s, 0, 0) - - @staticmethod - def find_by_name(name): - return next(v for v in MetaFormats.__dict__.values() if isinstance(v, MetaFormat) and v.name == name) - - GENERIC_8 = MetaFormat('GENERIC_8', 'MET8', 2, 2) - GENERIC_CSI2_10 = MetaFormat('GENERIC_CSI2_10', 'MC1A', 4, 5) - GENERIC_CSI2_12 = MetaFormat('GENERIC_CSI2_12', 'MC1C', 2, 3) - - RPI_FE_CFG = MetaFormat('RPI_FE_CFG', 'RPFC', 1, 1) - RPI_FE_STATS = MetaFormat('RPI_FE_STATS', 'RPFS', 1, 1)