aboutsummaryrefslogtreecommitdiff
path: root/decoder.py
diff options
context:
space:
mode:
authorAnthony Wang2024-04-28 15:52:52 -0400
committerAnthony Wang2024-04-28 15:52:52 -0400
commit4f9cdeedb7d6a4ee20e503f9c2b20b5b2de1bf51 (patch)
tree46ab8b3c6c793a4a77b77d1cdf815e7dee9a5ddc /decoder.py
parenta03cefbbc5e3452e86e2725380d37fae2e15e0dd (diff)
3-bit color
Diffstat (limited to 'decoder.py')
-rw-r--r--decoder.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/decoder.py b/decoder.py
index 2b09081..efa9a81 100644
--- a/decoder.py
+++ b/decoder.py
@@ -20,11 +20,12 @@ args = parser.parse_args()
cheight = cwidth = max(args.height // 10, args.width // 10)
frame_size = args.height * args.width - 4 * cheight * cwidth
-frame_xor = np.arange(frame_size // 2, dtype=np.uint8)
-rs_size = frame_size // 2 - (frame_size // 2 + 254) // 255 * int(args.level * 255) - 4
+frame_bytes = frame_size * 3 // 8
+frame_xor = np.arange(frame_bytes, dtype=np.uint8)
+rs_bytes = frame_bytes - (frame_size // 2 + 254) // 255 * int(args.level * 255) - 4
rsc = RSCodec(int(args.level * 255))
-decoder = Decoder.with_defaults(args.size, rs_size)
+decoder = Decoder.with_defaults(args.size, rs_bytes)
def find_corner(A, f):
@@ -38,8 +39,8 @@ def find_corner(A, f):
np.empty(0),
tuple(reversed(guess)),
0,
- (50, 50, 50),
- (50, 50, 50),
+ (100, 100, 100),
+ (100, 100, 100),
cv2.FLOODFILL_MASK_ONLY + cv2.FLOODFILL_FIXED_RANGE,
)[2][1:-1, 1:-1].astype(bool)
return np.average(np.where(mask), axis=1), np.average(A[mask], axis=0).astype(np.float64)
@@ -113,8 +114,7 @@ while data is None:
frame = raw_frame[
np.clip(np.round(xp).astype(np.int64), 0, X - 1), np.clip(np.round(yp).astype(np.int64), 0, Y - 1), :
]
- frame = np.clip(np.squeeze(F @ (frame - origin)[..., np.newaxis]), 0, 255).astype(np.uint8)
- frame = (frame[:, :, 0] >> 7) + (frame[:, :, 1] >> 5 & 0b0110) + (frame[:, :, 2] >> 4 & 0b1000)
+ frame = (np.squeeze(F @ (frame - origin)[..., np.newaxis]) >= 128).astype(np.uint8)
frame = np.concatenate(
(
frame[:cheight, cwidth : args.width - cwidth].flatten(),
@@ -122,11 +122,8 @@ while data is None:
frame[args.height - cheight :, cwidth : args.width - cwidth].flatten(),
)
)
- frame = (frame[::2] << 4) + frame[1::2]
- # frame = np.pad(frame, (0, (len(frame) + 254) // 255 * 255 - len(frame)))
- # frame = np.ravel(frame.reshape(255, len(frame) // 255), "F")[: frame_size // 2]
- erase_pos = bytearray(np.where(frame == 0)[0]) if args.erasure else bytearray()
- data = decoder.decode(bytes(rsc.decode(bytearray(frame ^ frame_xor), erase_pos=erase_pos)[0]))
+ # erase_pos = bytearray(np.where(frame == 0)[0]) if args.erasure else bytearray()
+ data = decoder.decode(bytes(rsc.decode(bytearray(np.packbits(frame) ^ frame_xor))[0]))
print("Decoded frame")
except KeyboardInterrupt:
sys.exit()