ii-vision/transcoder/video_test.py
kris 5c550d8524 Separate the details of the bitmap packing from operations on the
packed representation (diff, apply etc).  This allows the (D)HGRBitmap
classes to focus on the bitmap packing and share common logic.

Numpy has unfortunate long-standing bugs to do with type coercion of
np.uint64, which leads to spurious "incompatible type" warnings when
e.g. operating on a np.uint64 and some other integer type.  To work
around this we cast explicitly to np.uint64 everywhere.

Get tests working again - for now HGR tests in screen_test.py are
disabled until I finish implementing new packing.

HGRBitmap is still incomplete although closer.
2019-07-04 15:21:20 +01:00

84 lines
2.4 KiB
Python

"""Tests for the video module."""
import unittest
import frame_grabber
import palette
import screen
import video
import video_mode
class TestVideo(unittest.TestCase):
def test_diff_weights(self):
fs = frame_grabber.FrameGrabber(mode=video_mode.VideoMode.DHGR)
v = video.Video(
fs, ticks_per_second=10000.,
mode=video_mode.VideoMode.DHGR)
frame = screen.MemoryMap(screen_page=1)
frame.page_offset[0, 0] = 0b1111111
frame.page_offset[0, 1] = 0b1010101
target_pixelmap = screen.DHGRBitmap(
palette=palette.Palette.NTSC,
main_memory=v.memory_map,
aux_memory=frame
)
self.assertEqual(
0b0000000000101010100000001111111000,
target_pixelmap.packed[0, 0])
pal = palette.NTSCPalette
diff = target_pixelmap.diff_weights(v.pixelmap, is_aux=True)
# Expect byte 0 to map to 0b0001111111000
expect0 = target_pixelmap.edit_distances(pal.ID)[0][0b0001111111000]
# Expect byte 2 to map to 0b0001010101000
expect2 = target_pixelmap.edit_distances(pal.ID)[2][0b0001010101000]
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(
0b0000000000101010100000001111111000,
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,
aux_memory=frame,
palette=pal.ID
)
self.assertEqual(
0b0000000000011011000000001101101000,
target_pixelmap.packed[0, 0]
)
diff = target_pixelmap.diff_weights(v.pixelmap, is_aux=True)
# Expect byte 0 to map to 0b01111111 01101101 XXX
expect0 = target_pixelmap.edit_distances(pal.ID)[0][
0b00011111110000001101101000]
# Expect byte 2 to map to 0b000101010100 000011011000
expect2 = target_pixelmap.edit_distances(pal.ID)[2][
0b00010101010000000110110000]
self.assertEqual(expect0, diff[0, 0])
self.assertEqual(expect2, diff[0, 1])
if __name__ == '__main__':
unittest.main()