aboutsummaryrefslogtreecommitdiff
path: root/encoder.py
diff options
context:
space:
mode:
authorAnthony Wang2024-04-21 11:47:36 -0400
committerAnthony Wang2024-04-21 11:47:36 -0400
commit959f31d58548d8d1e932dba7de591a07b7258672 (patch)
tree7226885313a0d82ff9ae3de05adb0f678934ab9c /encoder.py
parentcef9bab49ad9f303978858b2824ab0862c0df689 (diff)
XOR frames with arange, implement color to 8-bit in decoder, add camera device index flag
Diffstat (limited to 'encoder.py')
-rw-r--r--encoder.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/encoder.py b/encoder.py
index 6fe05c4..cc4d7cb 100644
--- a/encoder.py
+++ b/encoder.py
@@ -21,6 +21,7 @@ cheight = args.height // 10
cwidth = args.width // 10
midwidth = args.width - 2 * cwidth
frame_size = args.height * args.width - 4 * cheight * cwidth
+frame_xor = np.arange(frame_size, dtype=np.uint8)
# reedsolo breaks message into 255-byte chunks
# raptorq can add up to 4 extra bytes
rs_size = frame_size - int((frame_size + 254) / 255) * int(args.level * 255) - 4
@@ -52,15 +53,15 @@ class EncoderWidget(QWidget):
def update(self):
frame_data = np.array(rsc.encode(packets[self.idx]))
# Pad frame to fit frame_size since raptorq might not add 4 bytes
- frame_data = np.pad(frame_data, (0, frame_size - len(frame_data)))
+ frame_data = np.pad(frame_data, (0, frame_size - len(frame_data))) ^ frame_xor
self.idx = (self.idx + 1) % len(packets)
frame = np.concatenate(
(
np.concatenate(
(
- np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
+ np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
frame_data[: cheight * midwidth].reshape((cheight, midwidth)),
- np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
+ np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
),
axis=1,
),
@@ -69,18 +70,18 @@ class EncoderWidget(QWidget):
].reshape((args.height - 2 * cheight, args.width)),
np.concatenate(
(
- np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
+ np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
frame_data[frame_size - cheight * midwidth :].reshape(
(cheight, midwidth)
),
- np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
+ np.zeros((cheight, cwidth), dtype=np.uint8), # TODO
),
axis=1,
),
)
)
color_frame = np.stack(
- ((frame & 0x03) << 6, (frame >> 2 & 0x07) << 5, (frame >> 5 & 0x7) << 5),
+ (frame << 5 & 0b11100000, frame << 2 & 0b11100000, frame & 0b11000000),
axis=-1,
)
img = Image.fromarray(color_frame)