@@ 3,12 3,11 @@ from migen.genlib.fsm import *
import compress_ref
-MAX_Y_OFFSET = 4
-# From -MAX_OFFSET to +MAX_OFFSET
-OFFSET_COUNT = (MAX_Y_OFFSET * 2) + 1
# In theory could have max y & x offset different, but the code doesn't fully
# support it currently
-MAX_X_OFFSET = MAX_Y_OFFSET
+MAX_OFFSET = 4
+# From -MAX_OFFSET to +MAX_OFFSET
+OFFSET_COUNT = (MAX_OFFSET * 2) + 1
# Apply fn pairwise recursively until there is a single result
# e.g. reduce_pairwise(lambda x, y, _: (x + y, []), a, b, c)
@@ 164,15 163,15 @@ class CompressFrames(Module):
ref_read_pointer = Signal(max = mem.depth)
self.ctl.act('READ_COMP_LINE_WAIT',
NextState('READ_COMP_LINE'),
- If(line_within_frame < MAX_Y_OFFSET,
+ If(line_within_frame < MAX_OFFSET,
NextValue(ref_read_pointer, read_pointer - line_within_frame - frame_height),
- NextValue(ref_offset, MAX_Y_OFFSET - line_within_frame)
+ NextValue(ref_offset, MAX_OFFSET - line_within_frame)
).Else(
- NextValue(ref_read_pointer, read_pointer - frame_height - MAX_Y_OFFSET),
+ NextValue(ref_read_pointer, read_pointer - frame_height - MAX_OFFSET),
NextValue(ref_offset, 0)
),
- If(line_within_frame >= frame_height - MAX_Y_OFFSET,
- NextValue(ref_offset_last, MAX_Y_OFFSET + frame_height - 1 - line_within_frame)
+ If(line_within_frame >= frame_height - MAX_OFFSET,
+ NextValue(ref_offset_last, MAX_OFFSET + frame_height - 1 - line_within_frame)
).Else(
NextValue(ref_offset_last, OFFSET_COUNT - 1)
)
@@ 209,7 208,7 @@ class CompressFrames(Module):
NextState('COMP_LINES'))
comparisons = []
- for i, offset in enumerate(range(-MAX_X_OFFSET, MAX_X_OFFSET + 1)):
+ for i, offset in enumerate(range(-MAX_OFFSET, MAX_OFFSET + 1)):
c, comp_logic = byte_compare(comp_line, read_port.dat_r, 2*offset)
cmp_popcount, count_logic = popcount(c)
self.comb += comp_logic
@@ 305,15 304,15 @@ class CompressFrames(Module):
)
).Else(
If(last_line,
- # Been keeping around MAX_Y_OFFSET extra lines from the previous
+ # Been keeping around MAX_OFFSET extra lines from the previous
# frame but now it's the last line of the frame so can drop them
If(write_port.we,
- NextValue(full_lines, full_lines - MAX_Y_OFFSET)
+ NextValue(full_lines, full_lines - MAX_OFFSET)
).Else(
- NextValue(full_lines, full_lines - MAX_Y_OFFSET - 1)
+ NextValue(full_lines, full_lines - MAX_OFFSET - 1)
)
- ).Elif(line_within_frame >= MAX_Y_OFFSET,
- # Keep MAX_Y_OFFSET extra lines from the previous frame for
+ ).Elif(line_within_frame >= MAX_OFFSET,
+ # Keep MAX_OFFSET extra lines from the previous frame for
# prediction
If(~write_port.we,
NextValue(full_lines, full_lines - 1))
@@ 340,11 339,11 @@ if __name__ == '__main__':
best_match_count = 0
best = None
idx_within_frame = idx % frame_height
- for off_y in range(-MAX_Y_OFFSET, MAX_Y_OFFSET+1):
+ for off_y in range(-MAX_OFFSET, MAX_OFFSET+1):
if idx_within_frame + off_y < 0 or idx_within_frame + off_y >= frame_height:
continue
ref = lines[idx - frame_height + off_y]
- for off_x in range(-MAX_X_OFFSET, MAX_X_OFFSET+1):
+ for off_x in range(-MAX_OFFSET, MAX_OFFSET+1):
if off_x < 0:
ref_shifted = ref << abs(off_x)
else:
@@ 379,7 378,7 @@ if __name__ == '__main__':
for _ in range(rng.randint(1, 5)):
v |= (rng.randint(0,255) << rng.randint(0,line_bits-8))
if rng.random() > 0.5:
- s = rng.randint(-MAX_X_OFFSET, MAX_X_OFFSET)
+ s = rng.randint(-MAX_OFFSET, MAX_OFFSET)
if s > 0:
v >>= s
else:
@@ 405,7 404,7 @@ if __name__ == '__main__':
yield
yield
- codec = compress_ref.CODEC(line_px, frame_height, MAX_Y_OFFSET)
+ codec = compress_ref.CODEC(line_px, frame_height, MAX_OFFSET)
def lines_out(dut, expected_lines):
# TODO test stalling output