Last active
August 9, 2024 11:03
-
-
Save heisvoid/c92955fded020cfc5f1c0a809dc5097a to your computer and use it in GitHub Desktop.
Check a .rpl file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import argparse | |
import struct | |
import os | |
parser = argparse.ArgumentParser(description='Check .rpl file.') | |
parser.add_argument('-f', required=True, help='rpl file', dest='file') | |
args = parser.parse_args() | |
with open(args.file, 'rb') as f: | |
f.seek(0, os.SEEK_END) | |
file_len = f.tell() | |
f.seek(0, os.SEEK_SET) | |
buf = f.read(4) | |
buf = struct.unpack('<HH', buf) # little-endian, unsigned short * 2 | |
i = buf[0] # palette index, maybe | |
j = buf[1] # palette index, maybe | |
assert 256 > i | |
assert 256 > j | |
while i < j: | |
# r, g, b of palette | |
buf = f.read(3) | |
buf = struct.unpack('<BBB', buf) # little-endian, unsigned char * 3 | |
i = i + 1 | |
assert f.tell() == file_len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment