def test_read_4bpp_graphic_from_block():
    source = Block()
    source.from_list([0b01010110,
                      0b00001011,

                      0b11001110,
                      0b10010110,

                      0b01110001,
                      0b00111011,

                      0b00001011,
                      0b10011110,

                      0b00011000,
                      0b00000011,

                      0b10000001,
                      0b11101011,

                      0b00000100,
                      0b01000101,

                      0b01010110,
                      0b10001111,

                      0b00101100,
                      0b10110000,

                      0b01010110,
                      0b10110010,

                      0b01010000,
                      0b11000000,

                      0b00111000,
                      0b10010111,

                      0b00101101,
                      0b11111100,

                      0b01111101,
                      0b11101010,

                      0b10101111,
                      0b10110111,

                      0b01100000,
                      0b11101110])
    target = [[0 for x in range(8)] for y in range(8)]
    assert_equal(32, read_4bpp_graphic_from_block(target=target, source=source, offset=0, x=0, y=0, bit_offset=0))
    assert_list_equal(target,
                      [[8, 1, 12, 9, 6, 5, 3, 2],
                       [11, 5, 8, 14, 1, 7, 15, 0],
                       [8, 13, 3, 7, 2, 0, 2, 3],
                       [10, 0, 4, 14, 7, 10, 11, 9],
                       [8, 8, 12, 9, 13, 12, 2, 6],
                       [11, 14, 14, 4, 14, 4, 10, 7],
                       [12, 2, 12, 8, 4, 15, 12, 14],
                       [10, 13, 12, 1, 10, 11, 11, 2]])
Beispiel #2
0
def test_read_4bpp_graphic_from_block():
    source = Block()
    source.from_list([
        0b01010110, 0b00001011, 0b11001110, 0b10010110, 0b01110001, 0b00111011,
        0b00001011, 0b10011110, 0b00011000, 0b00000011, 0b10000001, 0b11101011,
        0b00000100, 0b01000101, 0b01010110, 0b10001111, 0b00101100, 0b10110000,
        0b01010110, 0b10110010, 0b01010000, 0b11000000, 0b00111000, 0b10010111,
        0b00101101, 0b11111100, 0b01111101, 0b11101010, 0b10101111, 0b10110111,
        0b01100000, 0b11101110
    ])
    target = [[0 for x in range(8)] for y in range(8)]
    assert_equal(
        32,
        read_4bpp_graphic_from_block(target=target,
                                     source=source,
                                     offset=0,
                                     x=0,
                                     y=0,
                                     bit_offset=0))
    assert_list_equal(
        target,
        [[8, 1, 12, 9, 6, 5, 3, 2], [11, 5, 8, 14, 1, 7, 15, 0],
         [8, 13, 3, 7, 2, 0, 2, 3], [10, 0, 4, 14, 7, 10, 11, 9],
         [8, 8, 12, 9, 13, 12, 2, 6], [11, 14, 14, 4, 14, 4, 10, 7],
         [12, 2, 12, 8, 4, 15, 12, 14], [10, 13, 12, 1, 10, 11, 11, 2]])
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
 def from_block(self, block, width, height, offset=0):
     self.width = width
     self.height = height
     self.data = [array('B', [0] * self.width) for i in range(self.height)]
     for i in range(self.height / 8):
         for j in range(self.width / 8):
             offset += read_4bpp_graphic_from_block(target=self.data, source=block, offset=offset, x=j*8, y=i*8)
Beispiel #6
0
    def from_block(self, block, offset=0, size=0):
        width, height = BATTLE_SPRITE_SIZES[size]
        if (self.width != width) or (self.height != height):
            self.width = width
            self.height = height
            self.sprite = [array('B', [0] * self.width) for y in range(self.height)]

        for q in range(0, height / 32):
            for r in range(0, width / 32):
                for a in range(0, 4):
                    for j in range(0, 4):
                        offset += read_4bpp_graphic_from_block(
                            target=self.sprite,
                            source=block,
                            offset=offset,
                            x=(j + r * 4) * 8,
                            y=(a + q * 4) * 8
                        )