def run(infile, outfile, options): if options.binary or options.org is not None: snapshot = read_bin_file(infile, 49152) if options.org is None: org = 65536 - len(snapshot) else: org = options.org snapshot = [0] * org + list(snapshot) + [0] * (65536 - org - len(snapshot)) elif infile[-4:].lower() == '.scr': scr = read_bin_file(infile, 6912) snapshot = [0] * 65536 snapshot[16384:16384 + len(scr)] = scr elif infile[-4:].lower() in ('.sna', '.szx', '.z80'): snapshot = get_snapshot(infile) else: try: snapshot = BinWriter(infile, fix_mode=options.fix_mode).snapshot except SkoolKitError: raise except: raise SkoolKitError( 'Unable to parse {} as a skool file'.format(infile)) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) if options.macro is not None: match = re.match('(#?)(FONT|SCR|UDG|UDGARRAY)([^A-Z]|$)', options.macro) if match: macro = match.group(2) try: frame = MACROS[macro](snapshot, options.macro[match.end(2):]) except skoolmacro.MacroParsingError as e: raise SkoolKitError('Invalid #{} macro: {}'.format( macro, e.args[0])) else: raise SkoolKitError('Macro must be #FONT, #SCR, #UDG or #UDGARRAY') else: (x, y), (w, h) = options.origin, options.size frame = Frame(scr_udgs(snapshot, x, y, w, h), options.scale) if options.invert: for row in frame.udgs: for udg in row: if udg.attr & 128: udg.data = [b ^ 255 for b in udg.data] udg.attr &= 127 flip_udgs(frame.udgs, options.flip) rotate_udgs(frame.udgs, options.rotate) _write_image(frame, outfile, options.animated)
def run(infile, outfile, options): if options.binary or options.org is not None or infile[-4:].lower() in ('.sna', '.szx', '.z80'): snapshot = make_snapshot(infile, options.org)[0] elif infile[-4:].lower() == '.scr': snapshot = make_snapshot(infile, 16384)[0] else: try: snapshot = BinWriter(infile, fix_mode=options.fix_mode).snapshot except SkoolKitError: raise except: raise SkoolKitError('Unable to parse {} as a skool file'.format(infile)) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) if options.macro is not None: match = re.match('(#?)(FONT|SCR|UDG|UDGARRAY)([^A-Z]|$)', options.macro) if match: macro = match.group(2) try: frame = MACROS[macro](snapshot, options.macro[match.end(2):]) except skoolmacro.MacroParsingError as e: raise SkoolKitError('Invalid #{} macro: {}'.format(macro, e.args[0])) else: raise SkoolKitError('Macro must be #FONT, #SCR, #UDG or #UDGARRAY') else: (x, y), (w, h) = options.origin, options.size frame = Frame(scr_udgs(snapshot, x, y, w, h), options.scale) if options.invert: for row in frame.udgs: for udg in row: if udg.attr & 128: udg.data = [b^255 for b in udg.data] udg.attr &= 127 flip_udgs(frame.udgs, options.flip) rotate_udgs(frame.udgs, options.rotate) _write_image(frame, outfile, options.animated)
def _parse_scr(snapshot, param_str): end, crop_rect, fname, frame, alt, params = skoolmacro.parse_scr(param_str) scale, x, y, w, h, df, af, tindex, alpha = params udgs = scr_udgs(snapshot, x, y, w, h, df, af) return Frame(udgs, scale, 0, *crop_rect, tindex=tindex, alpha=alpha)
def _parse_scr(snapshot, param_str): end, crop_rect, fname, frame, alt, params = skoolmacro.parse_scr(param_str) scale, x, y, w, h, df, af = params udgs = scr_udgs(snapshot, x, y, w, h, df, af) return Frame(udgs, scale, 0, *crop_rect)