2019-06-13 23:13:28 +00:00
|
|
|
"""Tests for the video module."""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2019-06-14 20:59:39 +00:00
|
|
|
import frame_grabber
|
2019-06-15 20:02:00 +00:00
|
|
|
import palette
|
2019-06-13 23:13:28 +00:00
|
|
|
import screen
|
|
|
|
import video
|
2019-06-14 20:59:39 +00:00
|
|
|
import video_mode
|
2019-06-13 23:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestVideo(unittest.TestCase):
|
|
|
|
def test_diff_weights(self):
|
2019-06-14 20:59:39 +00:00
|
|
|
fs = frame_grabber.FrameGrabber(mode=video_mode.VideoMode.DHGR)
|
2019-06-21 21:08:22 +00:00
|
|
|
v = video.Video(
|
|
|
|
fs, ticks_per_second=10000.,
|
|
|
|
mode=video_mode.VideoMode.DHGR)
|
2019-06-13 23:13:28 +00:00
|
|
|
|
|
|
|
frame = screen.MemoryMap(screen_page=1)
|
|
|
|
frame.page_offset[0, 0] = 0b1111111
|
|
|
|
frame.page_offset[0, 1] = 0b1010101
|
|
|
|
|
|
|
|
target_pixelmap = screen.DHGRBitmap(
|
2019-07-04 14:21:20 +00:00
|
|
|
palette=palette.Palette.NTSC,
|
2019-06-13 23:13:28 +00:00
|
|
|
main_memory=v.memory_map,
|
|
|
|
aux_memory=frame
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
2019-07-04 14:21:20 +00:00
|
|
|
0b0000000000101010100000001111111000,
|
2019-06-13 23:13:28 +00:00
|
|
|
target_pixelmap.packed[0, 0])
|
|
|
|
|
2019-06-15 20:02:00 +00:00
|
|
|
pal = palette.NTSCPalette
|
|
|
|
|
2019-07-02 21:40:50 +00:00
|
|
|
diff = target_pixelmap.diff_weights(v.pixelmap, is_aux=True)
|
|
|
|
|
2019-07-04 14:21:20 +00:00
|
|
|
# Expect byte 0 to map to 0b0001111111000
|
|
|
|
expect0 = target_pixelmap.edit_distances(pal.ID)[0][0b0001111111000]
|
2019-06-13 23:13:28 +00:00
|
|
|
|
2019-07-04 14:21:20 +00:00
|
|
|
# Expect byte 2 to map to 0b0001010101000
|
|
|
|
expect2 = target_pixelmap.edit_distances(pal.ID)[2][0b0001010101000]
|
2019-06-13 23:13:28 +00:00
|
|
|
|
|
|
|
self.assertEqual(expect0, diff[0, 0])
|
|
|
|
self.assertEqual(expect2, diff[0, 1])
|
|
|
|
|
|
|
|
# Update aux frame
|
|
|
|
v.aux_memory_map.page_offset = frame.page_offset
|
|
|
|
v.pixelmap._pack()
|
|
|
|
self.assertEqual(
|
2019-07-04 14:21:20 +00:00
|
|
|
0b0000000000101010100000001111111000,
|
2019-06-13 23:13:28 +00:00
|
|
|
v.pixelmap.packed[0, 0]
|
|
|
|
)
|
|
|
|
|
|
|
|
# Encode new aux frame
|
|
|
|
frame = screen.MemoryMap(screen_page=1)
|
|
|
|
frame.page_offset[0, 0] = 0b1101101
|
|
|
|
frame.page_offset[0, 1] = 0b0110110
|
|
|
|
|
|
|
|
target_pixelmap = screen.DHGRBitmap(
|
|
|
|
main_memory=v.memory_map,
|
2019-07-04 14:21:20 +00:00
|
|
|
aux_memory=frame,
|
|
|
|
palette=pal.ID
|
2019-06-13 23:13:28 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2019-07-04 14:21:20 +00:00
|
|
|
0b0000000000011011000000001101101000,
|
2019-06-13 23:13:28 +00:00
|
|
|
target_pixelmap.packed[0, 0]
|
|
|
|
)
|
|
|
|
|
2019-07-02 21:40:50 +00:00
|
|
|
diff = target_pixelmap.diff_weights(v.pixelmap, is_aux=True)
|
2019-06-13 23:13:28 +00:00
|
|
|
|
2019-07-11 22:40:00 +00:00
|
|
|
# Masked offset 0 changes from 0001111111000 to 0001101101000
|
2019-07-04 14:21:20 +00:00
|
|
|
expect0 = target_pixelmap.edit_distances(pal.ID)[0][
|
|
|
|
0b00011111110000001101101000]
|
2019-06-13 23:13:28 +00:00
|
|
|
|
2019-07-11 22:40:00 +00:00
|
|
|
# Masked offset 2 changes from 0001010101000 to 0000110110000
|
2019-06-15 20:02:00 +00:00
|
|
|
expect2 = target_pixelmap.edit_distances(pal.ID)[2][
|
2019-07-04 14:21:20 +00:00
|
|
|
0b00010101010000000110110000]
|
2019-06-13 23:13:28 +00:00
|
|
|
|
|
|
|
self.assertEqual(expect0, diff[0, 0])
|
|
|
|
self.assertEqual(expect2, diff[0, 1])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|