def test_read_2bpp_graphic_from_block_offset_xy(): source = Block() source.from_list([0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 5]) target = [[0 for x in range(10)] for y in range(10)] assert_equal(16, read_2bpp_graphic_from_block(target=target, source=source, offset=0, x=2, y=1, bit_offset=0)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 2, 3, 2, 1, 2, 1], [0, 0, 2, 3, 1, 0, 2, 3, 2, 2], [0, 0, 3, 0, 3, 2, 2, 2, 0, 2], [0, 0, 1, 3, 3, 0, 2, 0, 2, 3], [0, 0, 1, 0, 1, 1, 0, 3, 3, 3], [0, 0, 1, 3, 3, 3, 3, 2, 1, 2], [0, 0, 2, 2, 3, 1, 2, 2, 1, 0], [0, 0, 2, 0, 3, 3, 2, 3, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
def from_block(self, block, offset=0, bpp=2): """Reads in a tileset from the specified offset in the block. :param bpp: The number of bits used to represent each pixel by the block representation.""" if bpp not in _EB_GRAPHIC_TILESET_SUPPORTED_BPP_FORMATS: raise NotImplementedError("Don't know how to read graphical tile data of bpp[{}]".format(bpp)) elif (bpp != 1) and (self.tile_height != 8): raise NotImplementedError(("Don't know how to read graphical tile data of width[{}], height[{}], " "and bpp[{}]").format(self.tile_width, self.tile_height, bpp)) self._num_tiles_used = 0 self._used_tiles = dict() self.tiles = [[[0 for x in range(self.tile_width)] for y in range(self.tile_height)] for n in range(self.num_tiles_maximum)] for tile in self.tiles: try: if bpp == 2: offset += read_2bpp_graphic_from_block(source=block, target=tile, offset=offset) elif bpp == 4: offset += read_4bpp_graphic_from_block(source=block, target=tile, offset=offset) elif bpp == 8: offset += read_8bpp_graphic_from_block(source=block, target=tile, offset=offset) else: # bpp == 1 for x in range(0, self.tile_width, 8): offset += read_1bpp_graphic_from_block(source=block, target=tile, offset=offset, x=x, height=self.tile_height) self._num_tiles_used += 1 except OutOfBoundsError: break # Stop if we begin to read past the end of the block
def test_read_2bpp_graphic_from_block(): source = Block() source.from_list([ 1, 2, 3, 0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100 ]) target = [[0 for x in range(8)] for y in range(8)] assert_equal( 16, read_2bpp_graphic_from_block(target=target, source=source, offset=3, x=0, y=0, bit_offset=0)) assert_list_equal(target, [[2, 1, 2, 3, 2, 1, 2, 1], [2, 3, 1, 0, 2, 3, 2, 2], [3, 0, 3, 2, 2, 2, 0, 2], [1, 3, 3, 0, 2, 0, 2, 3], [1, 0, 1, 1, 0, 3, 3, 3], [1, 3, 3, 3, 3, 2, 1, 2], [2, 2, 3, 1, 2, 2, 1, 0], [2, 0, 3, 3, 2, 3, 1, 0]])