interlace video output
This commit is contained in:
31
common.py
31
common.py
@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Packet:
|
||||
class StdPacket:
|
||||
def __init__(self, x: int, y: int, array: np.ndarray):
|
||||
self.x = x
|
||||
self.y = y
|
||||
@ -14,9 +14,34 @@ class Packet:
|
||||
bytestr += self.array.tobytes()
|
||||
return bytestr
|
||||
|
||||
def from_bytes(b: bytes) -> Packet:
|
||||
def from_bytes_std(b: bytes) -> StdPacket:
|
||||
x = int.from_bytes(b[0:4], signed = False)
|
||||
y = int.from_bytes(b[4:8], signed = False)
|
||||
array = np.frombuffer(b[8:], np.uint8).reshape(16, 16, 3)
|
||||
|
||||
return Packet(x, y, array)
|
||||
return StdPacket(x, y, array)
|
||||
|
||||
|
||||
class InterlacedPacket:
|
||||
def __init__(self, x: int, y: int, even: bool, array: np.ndarray):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.even = even
|
||||
self.array = array
|
||||
|
||||
def to_bytestr(self) -> bytes:
|
||||
bytestr = b""
|
||||
bytestr += self.x.to_bytes(length=4, signed=False)
|
||||
bytestr += self.y.to_bytes(length=4, signed=False)
|
||||
bytestr += self.even.to_bytes(length=4)
|
||||
bytestr += self.array.tobytes()
|
||||
return bytestr
|
||||
|
||||
|
||||
def from_bytes_int(b: bytes) -> InterlacedPacket:
|
||||
x = int.from_bytes(b[0:4], signed=False)
|
||||
y = int.from_bytes(b[4:8], signed=False)
|
||||
even = bool.from_bytes(b[8:12])
|
||||
array = np.frombuffer(b[12:], np.uint8).reshape(16, 16, 3)
|
||||
|
||||
return InterlacedPacket(x, y, even, array)
|
Reference in New Issue
Block a user