Minor code cleanups

This commit is contained in:
kris 2019-06-21 22:08:22 +01:00
parent b0e83d2faf
commit b2c00784b0
6 changed files with 20 additions and 28 deletions

View File

@ -116,12 +116,13 @@ class FileFrameGrabber(FrameGrabber):
def worker():
"""Invoke bmp2dhr to encode input image frames and push to queue."""
decode = (
_dhgr_decode if self.video_mode == VideoMode.DHGR else
_hgr_decode
)
for _idx, _frame in enumerate(self._frame_grabber()):
if self.video_mode == VideoMode.DHGR:
res = _dhgr_decode(_idx, _frame)
else:
res = _hgr_decode(_idx, _frame)
q.put(res)
q.put(decode(_idx, _frame))
q.put((None, None))

View File

@ -2,24 +2,12 @@
from typing import Iterator
import numpy as np
import screen
class Machine:
"""Represents Apple II and player virtual machine state."""
def __init__(
self,
memmap: screen.MemoryMap,
update_priority: np.array
):
def __init__(self):
self.page = 0x20 # type: int
self.content = 0x7f # type: int
self.memmap = memmap # type: screen.MemoryMap
self.update_priority = update_priority # type: np.array
def emit(self, opcode: "Opcode") -> Iterator[int]:
"""

View File

@ -1,12 +1,11 @@
import bz2
import functools
import pickle
from typing import Dict, List, Iterable, Type
from typing import Iterable, Type
import colormath.color_conversions
import colormath.color_diff
import colormath.color_objects
import numpy as np
import weighted_levenshtein

View File

@ -38,15 +38,16 @@ class Movie:
palette=self.palette
) # type: video.Video
# Byte offset within TCP stream
self.stream_pos = 0 # type: int
# Current audio tick opcode count within movie stream.
self.ticks = 0 # type: int
self.state = machine.Machine(
self.video.memory_map,
self.video.update_priority
)
# Tracks internal state of player virtual machine
self.state = machine.Machine()
# Currently operating on AUX memory bank?
self.aux_memory_bank = False
def encode(self) -> Iterator[opcodes.Opcode]:

View File

@ -22,15 +22,16 @@ class Video:
def __init__(
self,
frame_grabber: FrameGrabber,
ticks_per_second: int,
ticks_per_second: float,
mode: VideoMode = VideoMode.HGR,
palette: Palette = Palette.NTSC
):
self.mode = mode # type: VideoMode
self.frame_grabber = frame_grabber # type: FrameGrabber
self.ticks_per_second = float(ticks_per_second) # type: float
self.ticks_per_second = ticks_per_second # type: float
self.ticks_per_frame = (
self.ticks_per_second / frame_grabber.input_frame_rate) # type: float
self.ticks_per_second / frame_grabber.input_frame_rate
) # type: float
self.frame_number = 0 # type: int
self.palette = palette # type: Palette

View File

@ -12,7 +12,9 @@ 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)
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