Commit Graph

93 Commits

Author SHA1 Message Date
kris
20a6f03482 Default to DHGR and NTSC palette 2019-06-15 21:32:56 +01:00
kris
44f8ab39e4 Vectorizing does not help, the array is not big enough to amortize the
python overheads.
2019-06-15 21:30:25 +01:00
kris
bf2057cbb9 random.getrandbits() is much faster than random.randint() 2019-06-15 21:23:36 +01:00
kris
ca817999f6 Parametrize the RGB palette to encode with, and support both NTSC and
IIGS palettes.

Move the palette diff_matrix generation into make_data_tables.py since
that is the only place it is used.

Demand-load the edit distance matrices when transcoding.
2019-06-15 21:02:00 +01:00
kris
824154fd39 Compress the precomputed edit_distance arrays 2019-06-14 22:08:34 +01:00
kris
c2c57b47d5 Add type annotations 2019-06-14 22:03:37 +01:00
kris
549752e112 Rename FrameSequencer to FrameGrabber and break out into separate file.
Add a test case that the bmp2dhr output of input filenames containing
'.'  are handled correctly.

Break out video.Mode into video_mode.VideoMode to resolve circular
dependency.
2019-06-14 21:59:39 +01:00
kris
d5f2482a0a Add tests for _diff_weights 2019-06-14 00:13:28 +01:00
kris
b781bf3a10 No longer used 2019-06-14 00:13:14 +01:00
kris
ec65684221 FrameSequencer:
- Extract out a (File)FrameSequencer class from Video to encapsulate
the generation of still frames.  This also makes Video easier to test.

- Fix FileFrameSequencer.frames() to correctly handle filenames
  containing '.'

- Temporarily switch to the BMP2DHR NTSC palette (#5) for evaluation.

Video:
- Temporarily hardcode DHGR decoding

- Optimize _heapify_priorities() by using numpy to vectorize the
  construction of the list of tuples.  This requires changing the
  random nonce to an int so the intermediate array has a uniform type.

- Use the efficient 28-bit representation of DHGR (aux, main, aux,
  main) tuples introduced in DHGRBitmap to evaluate diffs

- Switch to np.int type for accumulating diffs, and random.randint(0,
  10000) instead of float for nonce values.

- Fix/improve some of the error evaluation in _index_changes:
  - skip offsets whose diffs have already been cleared
  - hoist some stuff out of _compute_error into the parent

- Add some validation that when we run out of work to do with a frame,
  the source and target memory maps should be equal.  This isn't
  happening sometimes, i.e. there is a bug.
2019-06-14 00:12:26 +01:00
kris
4251c9938f Remove unused code.
Add a new DHGRBitmap class that efficiently represents the
DHGR interleaving of the (aux, main) MemoryMap as a sequence of
28-bit integers.

This allows for easily extracting the 8-bit and 12-bit subsequences
representing the DHGR pixels that are influenced when storing a byte
at offsets 0..3 within the interleaved (aux, main, aux, main)
sequence.

Since we have precomputed all of the pairwise differences between
these 8- and 12-bit values, this allows us to efficiently compute the
edit distances between pairs of screen bytes (and/or arrays)
2019-06-13 23:44:41 +01:00
kris
a172214f16 Fix warnings 2019-06-13 23:41:28 +01:00
kris
5387eae674 Fix warning about missing newline at EOF 2019-06-13 23:40:55 +01:00
kris
fb14a20380 Precompute the edit distance between the 8-bit (2-pixel) and 12-bit
(3-pixel) sequences that may be modified when storing bytes to the
DHGR display.

This relies on producing an efficient linear representation of the
DHGR framebuffer in terms of a packed 28-bit representation of (Aux,
Main, Aux, Main) screen bytes.
2019-06-13 23:27:30 +01:00
kris
9f950739f9 Map DHGR colours to RGB values (for now using the BMP2DHR default
NTSC palette), and compute the matrix of pairwise perceptual
differences between these colours, using CIE2000 delta values.
2019-06-12 22:14:11 +01:00
kris
bed29004c2 Add a DHGRColours enum mapping the DHGR logical colours to their
(memory-order) 4-bit values.
2019-06-12 22:12:26 +01:00
kris
2d7d4acef7 Fix test 2019-06-12 22:06:58 +01:00
kris
b84f40308b Add TODO about Opcode.apply being currently unused 2019-06-12 21:42:17 +01:00
kris
721eb3112d Fix bug with DHGR bank switching: we were emitting the last writes to
a bank after switching to the new one, which caused video corruption.
2019-06-12 21:37:30 +01:00
kris
782156967b Add --video_mode HGR|DHGR option to support both video modes uniformly. 2019-04-25 17:38:04 +01:00
kris
a188216f90 Add a video Mode enum. 2019-04-25 16:28:25 +01:00
kris
de8747ff37 Emit the video header and add an assertion to help make sure we don't
break the stream framing.
2019-04-25 16:28:06 +01:00
kris
2a76e3d48f Add a HEADER opcode that emits the 7-byte video header, used to
select the playback mode (HGR/DHGR).
2019-04-25 16:26:38 +01:00
kris
33ac880d29 Improve comment about stream padding 2019-03-28 23:47:38 +00:00
kris
10fa4bc72d Proof of concept DHGR encoding/playback
- Every time we process an ACK opcode, toggle page 1/page 2 soft
  switches to steer subsequent writes between MAIN and AUX memory
- while I'm here, squeeze out some unnecessary operations from the
  buffer management

On the player side, this is implemented by maintaining two screen
memory maps, and alternating between opcode streams for each of them.
This is using entirely the wrong colour model for errors, but
surprisingly it already works pretty well in practise (and the frame
rate is acceptable on test videos)

DHGR/HGR could be made runtime selectable by adding a header byte that
determines whether to set the DHGR soft switches before initiating
the decode loop.

While I'm in here, fix op_terminate to clear keyboard strobe before
waiting.
2019-03-27 21:37:06 +00:00
kris
21a4ac0186 Fix video termination logic 2019-03-24 00:14:41 +00:00
kris
dd422d1156 Fix tests 2019-03-23 22:05:36 +00:00
kris
13fb9c3125 Clean up module and abort import if we are unable to find the address
of an opcode.
2019-03-23 22:01:49 +00:00
kris
531a6ae345 Allow player to exit cleanly
- can't emit Terminate opcode in the middle of the bytestream
- pad the TCP stream to next 2k boundary when emitting terminate opcode,
  since the player will block until receiving this much data.
2019-03-23 21:46:35 +00:00
kris
8174d853f9 Downsize image using LANCZOS resampler. 2019-03-22 00:06:29 +00:00
kris
f37d07914d Print input frame rate, and default to every_n_video_frames=2 which
gives better quality without compromising frame rate too much.
2019-03-21 23:25:51 +00:00
kris
eebbccf711 Add some docstrings
Clean up naming in edit_distance

In video encoder, when we emit additional offsets as part of an opcode,
reinsert back into the priority heapq if the new edit distance is
nonzero, in case we get the chance to fix it up later in the frame.

Also make sure to zero out the diff_weights and content_deltas
so we don't consider the offset again as a side-effect of some other
opcode.

Instead of prioritizing side-effect offsets by their previous update
priority, prioritize by those with the lowest (error - edit) delta i.e.
not introducing too much error relative to their edit distance.
2019-03-21 22:56:45 +00:00
kris
fe10f98128 Support skipping frames from the input video to increase output
image quality at the expense of frame rate.
2019-03-21 22:43:02 +00:00
kris
8bdad22162 Stop ticking cycles as part of emitting the opcodes, we are counting
them externally in audio.py now.

Add some docstrings
2019-03-21 22:42:09 +00:00
kris
ce078f493f Start to flesh out function docstrings, add some more type annotations. 2019-03-21 22:41:05 +00:00
kris
da2e2476e7 Rename tests and clean up a bit. Still don't pass. 2019-03-21 17:21:43 +00:00
kris
5a5c761183 Remove _END from opcode.
Don't set cls in outer module scope
2019-03-21 17:15:44 +00:00
kris
84e14efc57 Fix 2019-03-21 16:51:33 +00:00
kris
5411793ea4 factor out State and CycleCounter to a new machine module and rename 2019-03-21 16:48:02 +00:00
kris
cf493e782c Add module docstrings 2019-03-21 16:42:47 +00:00
kris
5d4148daaf No need to store opcode _END any more 2019-03-21 16:35:42 +00:00
kris
fb47e48e4a Fix imports and point to player debug symbols 2019-03-21 16:24:40 +00:00
kris
bbfcacd674 Move transcoder to new location 2019-03-21 16:10:16 +00:00