Skip to content

Commit

Permalink
Separate MetaFormats
Browse files Browse the repository at this point in the history
  • Loading branch information
tomba committed Aug 23, 2024
1 parent 95b2063 commit ffbbeeb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
1 change: 1 addition & 0 deletions pixutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations

from .pixelformats import *
from .metaformats import *
42 changes: 1 addition & 41 deletions pixutils/pixelformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit ffbbeeb

Please sign in to comment.