~shiny/gbcap

4e2c65323891bdfaedfaee50d7dd743c1884713c — Thomas Spurden 2 years ago fb6b413
Delete some now unused code in compress.py
1 files changed, 1 insertions(+), 44 deletions(-)

M compress.py
M compress.py => compress.py +1 -44
@@ 332,43 332,6 @@ if __name__ == '__main__':
    line_bytes = line_bits // 8
    assert (line_bytes % 8) == 0

    def find_best_encoding(lines, idx):
        if idx < frame_height:
            return (0, 0, 0)
        else:
            best_match_count = 0
            best = None
            idx_within_frame = idx % frame_height
            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_OFFSET, MAX_OFFSET+1):
                    if off_x < 0:
                        ref_shifted = ref << abs(off_x)
                    else:
                        ref_shifted = ref >> off_x

                    ref_shifted &= (2**line_bits) - 1

                    if ref_shifted == lines[idx]:
                        return (off_x, off_y, (2**line_bytes) - 1)
                    match_mask = 0
                    for i in range(line_bytes):
                        byte_mask = 0xFF << (8 * i)
                        if (ref_shifted & byte_mask) == (lines[idx] & byte_mask):
                            match_mask |= (1 << i)
                    match_count = bin(match_mask).count('1')

                    if match_count >= best_match_count:
                        best = (off_x, off_y, match_mask)
                        best_match_count = match_count

            if best_match_count >= (line_bytes // 8):
                return best
            else:
                return (0, 0, 0)

    def lines_for(seed, unique_count, line_count):
        rng = random.Random(seed)
        lines = [rng.getrandbits(line_bits) for i in range(unique_count)]


@@ 385,10 348,6 @@ if __name__ == '__main__':
                    v <<= abs(s)
            yield v & ((2**line_bits) - 1)

    #test_lines = [
        #sum(((0xDEAD0000 + (i % 145)) << (32 * x)) for x in range(10))
        #for i in range(frame_height * 2)
    #]
    if sys.argv[1] == 'test':
        def wait(valid, v):
            while (yield valid) != v:


@@ 425,12 384,10 @@ if __name__ == '__main__':
        test_lines = list(lines_for(423, 2, 64))

        decomp = list(codec.decompress(codec.compress(test_lines)))
        #for i, (comp, expected) in enumerate(zip(decomp, test_lines)):
            #print('{:02d} {:x} {:x} {:x}'.format(i, comp, expected, comp ^ expected))
        assert decomp == test_lines

        for i, l in enumerate(test_lines):
            print('{:02d} {:080x}'.format(i, l))
            print('{:02d} {:016x}'.format(i, l))
        run_simulation(dut, [lines_in(dut, test_lines), lines_out(dut, test_lines)], vcd_name='out.vcd')
    else:
        raise ValueError(sys.argv[1])