File size: 870 Bytes
77b49a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # SPDX-License-Identifier: Apache-2.0
"""Pack data/scroll.bin (little-endian int16) as byte planes + gzip: data/scroll.i16p.gz.
The page fetches the packed file first and unpacks it to the exact original bytes
(lib/formats.js unpackInt16), falling back to scroll.bin. Run after tools/build.py.
"""
import gzip, os, sys
import numpy as np
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
def pack(raw: bytes) -> bytes:
a = np.frombuffer(raw, np.uint8).reshape(-1, 2)
return gzip.compress(a.T.copy().tobytes(), 9, mtime=0)
if __name__ == '__main__':
src = sys.argv[1] if len(sys.argv) > 1 else f'{ROOT}/data/scroll.bin'
dst = sys.argv[2] if len(sys.argv) > 2 else f'{ROOT}/data/scroll.i16p.gz'
raw = open(src, 'rb').read(); out = pack(raw)
open(dst, 'wb').write(out)
print(f'{src}: {len(raw)} -> {dst}: {len(out)} bytes')
|