def test_read_1bpp_graphic_from_block_rectangular_tall(): source = Block() source.from_list([ 42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21 ]) target = [[0 for x in range(8)] for y in range(16)] assert_equal( 16, read_1bpp_graphic_from_block(source, target, 3, x=0, y=0, height=16)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]])
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_1bpp_graphic_from_block_rectangular_short(): source = Block() source.from_list([ 42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000 ]) target = [[0 for x in range(8)] for y in range(6)] assert_equal( 6, read_1bpp_graphic_from_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]])
def test_read_1bpp_graphic_from_block(): source = Block() source.from_list([ 42, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001 ]) target = [[0 for x in range(8)] for y in range(8)] assert_equal( 8, read_1bpp_graphic_from_block(source, target, 1, x=0, y=0, height=8)) assert_list_equal(target, [[0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]])
def test_read_1bpp_graphic_from_block_offset_target(): source = Block() source.from_list([ 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001 ]) target = [[0 for x in range(10)] for y in range(10)] assert_equal( 8, read_1bpp_graphic_from_block(source, target, 0, x=2, y=1, height=8)) assert_list_equal( target, [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
def test_read_1bpp_graphic_from_block_rectangular_short(): source = Block() source.from_list([42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000]) target = [[0 for x in range(8)] for y in range(6)] assert_equal(6, read_1bpp_graphic_from_block(source, target, 2, x=0, y=0, height=6)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0]])
def test_read_1bpp_graphic_from_block_rectangular_tall(): source = Block() source.from_list([42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000, 0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21]) target = [[0 for x in range(8)] for y in range(16)] assert_equal(16, read_1bpp_graphic_from_block(source, target, 3, x=0, y=0, height=16)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]])
def test_read_1bpp_graphic_from_block(): source = Block() source.from_list([42, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001]) target = [[0 for x in range(8)] for y in range(8)] assert_equal(8, read_1bpp_graphic_from_block(source, target, 1, x=0, y=0, height=8)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]])
def test_read_1bpp_graphic_from_block_offset_target(): source = Block() source.from_list([0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000, 0b01110001, 0b00000001]) target = [[0 for x in range(10)] for y in range(10)] assert_equal(8, read_1bpp_graphic_from_block(source, target, 0, x=2, y=1, height=8)) assert_list_equal(target, [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])