def __init__(self, image, cv2_image): self.image = image self.image_grayscale = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2GRAY) self.chunks_list = [] while True: chunk_type, chunk_data, chunk_crc = read_chunk(self.image) self.chunks_list.append((chunk_type, chunk_data, chunk_crc)) if chunk_type == b'IEND': break
def load_level_header(chunk_id=None, level_id=None, title=None): if chunk_id is None: if level_id is None: chunk_id = util.find_if(lambda (lchunk, ltitle): ltitle == title, level_info)[0] else: chunk_id = level_info[level_id][0] level_header = level.LevelHeader() level_header.load(compression.decompress_data(chunk.read_chunk(chunk_id))) return level_header
def assemble_palette(pal_list): # Initialize with neon pink pal = [(255, 0, 255)] * 256 for chunk_id, position in pal_list: loaded_pal = unpack_palette(decompress_data(chunk.read_chunk(chunk_id))) # Convert from 6-bit to 8-bit pal[position:position + len(loaded_pal)] = ((r << 2, g << 2, b << 2) for r,g,b in loaded_pal) # Zero entries of each sub-pal like the game does for i in xrange(16, 256, 16): pal[i] = (0, 0, 0) return pal
def assemble_palette(pal_list): # Initialize with neon pink pal = [(255, 0, 255)] * 256 for chunk_id, position in pal_list: loaded_pal = unpack_palette(decompress_data( chunk.read_chunk(chunk_id))) # Convert from 6-bit to 8-bit pal[position:position + len(loaded_pal)] = ((r << 2, g << 2, b << 2) for r, g, b in loaded_pal) # Zero entries of each sub-pal like the game does for i in xrange(16, 256, 16): pal[i] = (0, 0, 0) return pal