pfnc 0.1.0__cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataspree/pfnc/__about__.py +3 -0
- dataspree/pfnc/__init__.py +122 -0
- dataspree/pfnc/_internal/__init__.py +0 -0
- dataspree/pfnc/_internal/registry.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/_internal/registry.pyi +43 -0
- dataspree/pfnc/_internal/utils.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/_internal/utils.pyi +8 -0
- dataspree/pfnc/decoder_registry.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/decoder_registry.pyi +84 -0
- dataspree/pfnc/exceptions.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/exceptions.pyi +30 -0
- dataspree/pfnc/genicam/__init__.py +1 -0
- dataspree/pfnc/genicam/components.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/components.pyi +1077 -0
- dataspree/pfnc/genicam/data_types.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/data_types.pyi +115 -0
- dataspree/pfnc/genicam/interface_specifics.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/interface_specifics.pyi +102 -0
- dataspree/pfnc/genicam/number_of_bits.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/number_of_bits.pyi +53 -0
- dataspree/pfnc/genicam/packing_types.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/packing_types.pyi +81 -0
- dataspree/pfnc/genicam/pixel_format.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/genicam/pixel_format.pyi +95 -0
- dataspree/pfnc/pixel_format.cpython-311-x86_64-linux-gnu.so +0 -0
- dataspree/pfnc/pixel_format.pyi +40 -0
- dataspree/pfnc/py.typed +0 -0
- pfnc-0.1.0.dist-info/METADATA +134 -0
- pfnc-0.1.0.dist-info/RECORD +31 -0
- pfnc-0.1.0.dist-info/WHEEL +6 -0
- pfnc-0.1.0.dist-info/licenses/LICENSE.txt +21 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Parse and model GenICam PFNC pixel format designations and decode image buffers via extensible decoders."""
|
|
2
|
+
|
|
3
|
+
from dataspree.pfnc.decoder_registry import PixelFormatDecoder, DecoderRegistry
|
|
4
|
+
from dataspree.pfnc.exceptions import (
|
|
5
|
+
PixelFormatDecodeNotSupportedError,
|
|
6
|
+
NotRegisteredError,
|
|
7
|
+
DuplicateRegistrationError,
|
|
8
|
+
InvalidRegistrationError,
|
|
9
|
+
PixelFormatDecodeAmbiguousError,
|
|
10
|
+
PixelFormatDecodeError,
|
|
11
|
+
PixelFormatError,
|
|
12
|
+
PixelFormatValueReject,
|
|
13
|
+
PixelFormatNotImplementedError,
|
|
14
|
+
PixelFormatImplementationError,
|
|
15
|
+
ParseReject,
|
|
16
|
+
PixelFormatNotSupportedError,
|
|
17
|
+
PixelFormatParseError,
|
|
18
|
+
PixelFormatRegistryError,
|
|
19
|
+
RegistryError,
|
|
20
|
+
)
|
|
21
|
+
from dataspree.pfnc.genicam.components import (
|
|
22
|
+
CHANNEL_REGISTRY,
|
|
23
|
+
Channels,
|
|
24
|
+
CompoundChannels,
|
|
25
|
+
CompoundChannel,
|
|
26
|
+
CoordinateChannel,
|
|
27
|
+
ChannelProperty,
|
|
28
|
+
ChannelRegistry,
|
|
29
|
+
Coord3D,
|
|
30
|
+
ColorSpaceStandard,
|
|
31
|
+
ItuRBt601,
|
|
32
|
+
ItuRBt709,
|
|
33
|
+
Bt601,
|
|
34
|
+
Bt709,
|
|
35
|
+
Location,
|
|
36
|
+
MonoLocation,
|
|
37
|
+
LMNLocation,
|
|
38
|
+
BayerLocation,
|
|
39
|
+
BiColor,
|
|
40
|
+
ColorFilterArray,
|
|
41
|
+
SquarePattern,
|
|
42
|
+
SparseColorFilterLocation,
|
|
43
|
+
Components,
|
|
44
|
+
GenicamComponents,
|
|
45
|
+
CustomComponents,
|
|
46
|
+
SizedColorSpaceStandard,
|
|
47
|
+
RGB10V1,
|
|
48
|
+
RGB12V1,
|
|
49
|
+
)
|
|
50
|
+
from dataspree.pfnc.genicam.data_types import DATA_TYPE_REGISTRY, DataTypes, CompoundDataTypes
|
|
51
|
+
from dataspree.pfnc.genicam.interface_specifics import InterfaceSpecific, Planar, SemiPlanar, ComponentsSequencing
|
|
52
|
+
from dataspree.pfnc.genicam.number_of_bits import Size
|
|
53
|
+
from dataspree.pfnc.genicam.packing_types import PADDING_TYPE_NAME_REGISTRY, Packing, PaddingType
|
|
54
|
+
from dataspree.pfnc.genicam.pixel_format import GenicamPixelFormat
|
|
55
|
+
from dataspree.pfnc.pixel_format import PixelFormat
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
# decoder / registry
|
|
59
|
+
'PixelFormatDecoder',
|
|
60
|
+
'DecoderRegistry',
|
|
61
|
+
# exceptions
|
|
62
|
+
'PixelFormatDecodeNotSupportedError',
|
|
63
|
+
'NotRegisteredError',
|
|
64
|
+
'DuplicateRegistrationError',
|
|
65
|
+
'InvalidRegistrationError',
|
|
66
|
+
'PixelFormatDecodeAmbiguousError',
|
|
67
|
+
'PixelFormatDecodeError',
|
|
68
|
+
'PixelFormatError',
|
|
69
|
+
'PixelFormatValueReject',
|
|
70
|
+
'PixelFormatNotImplementedError',
|
|
71
|
+
'PixelFormatImplementationError',
|
|
72
|
+
'ParseReject',
|
|
73
|
+
'PixelFormatNotSupportedError',
|
|
74
|
+
'PixelFormatParseError',
|
|
75
|
+
'PixelFormatRegistryError',
|
|
76
|
+
'RegistryError',
|
|
77
|
+
# components / channels
|
|
78
|
+
'CHANNEL_REGISTRY',
|
|
79
|
+
'Channels',
|
|
80
|
+
'CompoundChannels',
|
|
81
|
+
'CompoundChannel',
|
|
82
|
+
'CoordinateChannel',
|
|
83
|
+
'ChannelProperty',
|
|
84
|
+
'ChannelRegistry',
|
|
85
|
+
'Coord3D',
|
|
86
|
+
'ColorSpaceStandard',
|
|
87
|
+
'ItuRBt601',
|
|
88
|
+
'ItuRBt709',
|
|
89
|
+
'Bt601',
|
|
90
|
+
'Bt709',
|
|
91
|
+
'Location',
|
|
92
|
+
'MonoLocation',
|
|
93
|
+
'LMNLocation',
|
|
94
|
+
'BayerLocation',
|
|
95
|
+
'BiColor',
|
|
96
|
+
'ColorFilterArray',
|
|
97
|
+
'SquarePattern',
|
|
98
|
+
'SparseColorFilterLocation',
|
|
99
|
+
'Components',
|
|
100
|
+
'GenicamComponents',
|
|
101
|
+
'CustomComponents',
|
|
102
|
+
'SizedColorSpaceStandard',
|
|
103
|
+
'RGB10V1',
|
|
104
|
+
'RGB12V1',
|
|
105
|
+
# data types
|
|
106
|
+
'DATA_TYPE_REGISTRY',
|
|
107
|
+
'DataTypes',
|
|
108
|
+
'CompoundDataTypes',
|
|
109
|
+
# interface specifics
|
|
110
|
+
'InterfaceSpecific',
|
|
111
|
+
'Planar',
|
|
112
|
+
'SemiPlanar',
|
|
113
|
+
'ComponentsSequencing',
|
|
114
|
+
# sizes / packing
|
|
115
|
+
'Size',
|
|
116
|
+
'PADDING_TYPE_NAME_REGISTRY',
|
|
117
|
+
'Packing',
|
|
118
|
+
'PaddingType',
|
|
119
|
+
# pixel formats
|
|
120
|
+
'PixelFormat',
|
|
121
|
+
'GenicamPixelFormat',
|
|
122
|
+
]
|
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Generic, TypeVar
|
|
4
|
+
|
|
5
|
+
T = TypeVar('T')
|
|
6
|
+
K = TypeVar('K')
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class MappingSnapshot(Generic[K, T]):
|
|
10
|
+
"""Snapshot for a single mapping-based registry."""
|
|
11
|
+
mapping: dict[K, T]
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class Registry(Generic[K, T]):
|
|
15
|
+
"""Registry."""
|
|
16
|
+
def register(self, name: K, value: T) -> None:
|
|
17
|
+
"""Register.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
name: Alias string uniquely identifying the value
|
|
21
|
+
value: The registered value type.
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
DuplicateRegistrationError: If already registered.
|
|
25
|
+
"""
|
|
26
|
+
def snapshot(self) -> MappingSnapshot[K, T]:
|
|
27
|
+
"""Snapshot current state."""
|
|
28
|
+
def restore(self, snap: MappingSnapshot[K, T]) -> None:
|
|
29
|
+
"""Restore a snapshot."""
|
|
30
|
+
def resolve(self, name: K) -> T:
|
|
31
|
+
"""Resolve alias to type."""
|
|
32
|
+
def get(self, key: K, default_value: T | None = None) -> T | None:
|
|
33
|
+
"""Return the value for key if key is registered, else default_value.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
key: Name to look up.
|
|
37
|
+
default_value: Value to return if key is not registered.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The registered value or default_value if key is missing.
|
|
41
|
+
"""
|
|
42
|
+
def __iter__(self) -> Iterator[K]:
|
|
43
|
+
"""Iterate over registered names."""
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from typing import TypeVar
|
|
2
|
+
|
|
3
|
+
def join_designators(a: str, b: str) -> str:
|
|
4
|
+
"""Join two pixel format designators according to the genicam naming conventions."""
|
|
5
|
+
T = TypeVar('T', bound=object)
|
|
6
|
+
|
|
7
|
+
def all_implementations(cls, allow_parent: bool = True) -> list[type[T]]:
|
|
8
|
+
"""Yield all implementations of a subclass."""
|
|
Binary file
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from _typeshed import Incomplete
|
|
3
|
+
from abc import ABCMeta, abstractmethod
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from dataspree.pfnc.pixel_format import PixelFormat as PixelFormat
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
logger: Incomplete
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class PixelFormatDecoder(metaclass=ABCMeta):
|
|
12
|
+
"""Base class for decoder backends.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
name (str) name of the decoder.
|
|
16
|
+
"""
|
|
17
|
+
name: str
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def is_applicable(self, pixel_format: PixelFormat) -> bool:
|
|
20
|
+
"""Return True if this decoder can handle the given pixel format."""
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def decode(self, pixel_format: PixelFormat, buffer: bytes, *, width: int, height: int, stride: int, copy: bool = False) -> np.ndarray[Any, Any]:
|
|
23
|
+
"""Decode a frame buffer into a numpy array."""
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class DecoderRegistration:
|
|
27
|
+
"""Single decoder registration entry.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
priority (int) priority. The higher, the more priority.
|
|
31
|
+
|
|
32
|
+
decoder (PixelFormatDecoder) The decoder.
|
|
33
|
+
"""
|
|
34
|
+
decoder: PixelFormatDecoder
|
|
35
|
+
priority: int
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True)
|
|
38
|
+
class DecoderRegistrySnapshot:
|
|
39
|
+
"""Snapshot of registry state for test isolation."""
|
|
40
|
+
registrations: tuple[DecoderRegistration, ...]
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class DecoderRegistry:
|
|
44
|
+
"""Registry that resolves a decoder for a given GenICam pixel format."""
|
|
45
|
+
def register(self, priority: int, decoder: PixelFormatDecoder) -> None:
|
|
46
|
+
"""Register a decoder backend.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
priority (int): priority. The higher, the more priority.
|
|
50
|
+
|
|
51
|
+
decoder (PixelFormatDecoder): The decoder.
|
|
52
|
+
"""
|
|
53
|
+
def snapshot(self) -> DecoderRegistrySnapshot:
|
|
54
|
+
"""Create a snapshot of the registry state."""
|
|
55
|
+
def restore(self, snap: DecoderRegistrySnapshot) -> None:
|
|
56
|
+
"""Restore the registry state from a snapshot."""
|
|
57
|
+
def resolve(self, pixel_format: PixelFormat) -> PixelFormatDecoder:
|
|
58
|
+
"""Resolve the best decoder for a pixel format.
|
|
59
|
+
|
|
60
|
+
If multiple decoders exist that have got the same priority, take the first one registered.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
pixel_format: Parsed GenICam pixel format instance.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
PixelFormatDecoder: The selected decoder.
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
PixelFormatDecodeNotSupportedError: If no decoder matches.
|
|
70
|
+
"""
|
|
71
|
+
def decode(self, pixel_format: PixelFormat, buffer: bytes, *, width: int, height: int, stride: int, copy: bool = False) -> np.ndarray[Any, Any]:
|
|
72
|
+
"""Decode using the resolved decoder.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
pixel_format: Parsed GenICam pixel format instance.
|
|
76
|
+
buffer: Raw frame bytes (one image).
|
|
77
|
+
width: Image width in pixels.
|
|
78
|
+
height: Image height in pixels.
|
|
79
|
+
stride: Bytes per line (can be > width * bytes_per_pixel).
|
|
80
|
+
copy: If True, return a contiguous copy without line padding.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
np.ndarray: Decoded array.
|
|
84
|
+
"""
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class PixelFormatError(Exception):
|
|
2
|
+
"""Base error for pixel format handling."""
|
|
3
|
+
class PixelFormatParseError(PixelFormatError):
|
|
4
|
+
"""Raised when a designation cannot be parsed."""
|
|
5
|
+
class PixelFormatNotSupportedError(PixelFormatError):
|
|
6
|
+
"""Raised when the format is valid but not supported by a feature."""
|
|
7
|
+
class PixelFormatNotImplementedError(PixelFormatNotSupportedError):
|
|
8
|
+
"""Raised when the format is not implemented / supported."""
|
|
9
|
+
class PixelFormatRegistryError(PixelFormatError):
|
|
10
|
+
"""Raised on invalid or conflicting registrations."""
|
|
11
|
+
class PixelFormatValueReject(PixelFormatError):
|
|
12
|
+
"""Pixel format was parsed but values were rejected."""
|
|
13
|
+
class PixelFormatImplementationError(PixelFormatError):
|
|
14
|
+
"""Internal implementation error."""
|
|
15
|
+
class ParseReject(ValueError):
|
|
16
|
+
"""Internal: implementation does not match this input."""
|
|
17
|
+
class PixelFormatDecodeError(PixelFormatError):
|
|
18
|
+
"""Base class for pixel format decoding errors."""
|
|
19
|
+
class PixelFormatDecodeNotSupportedError(PixelFormatDecodeError):
|
|
20
|
+
"""Raised when no decoder supports a pixel format."""
|
|
21
|
+
class PixelFormatDecodeAmbiguousError(PixelFormatDecodeError):
|
|
22
|
+
"""Raised when multiple decoders match the same pixel format."""
|
|
23
|
+
class RegistryError(Exception):
|
|
24
|
+
"""Base class for registry errors."""
|
|
25
|
+
class DuplicateRegistrationError(RegistryError):
|
|
26
|
+
"""Raised when a key is registered more than once."""
|
|
27
|
+
class InvalidRegistrationError(RegistryError):
|
|
28
|
+
"""Raised when registration input is invalid."""
|
|
29
|
+
class NotRegisteredError(RegistryError):
|
|
30
|
+
"""Raised when a key is registered more than once."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Genicam module."""
|
|
Binary file
|