Пример #1
0
def test_write_2bpp_graphic_to_block_offset_xy():
    source = [[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]]
    target = Block()
    target.from_list([0xff] * 18)
    assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=1, x=2, y=1, bit_offset=0))
    assert_list_equal(target.to_list(),
                      [0xff,
                       0b01010101,
                       0b10111010,
                       0b01100100,
                       0b11001111,
                       0b10100000,
                       0b10111101,
                       0b11100001,
                       0b01101011,
                       0b10110111,
                       0b00000111,
                       0b11111010,
                       0b01111101,
                       0b00110010,
                       0b11101100,
                       0b00110110,
                       0b10111100,
                       0xff])
Пример #2
0
def test_write_2bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([0] * 16)
    assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
    assert_list_equal(target.to_list(),
                      [0b01010101,
                       0b10111010,
                       0b01100100,
                       0b11001111,
                       0b10100000,
                       0b10111101,
                       0b11100001,
                       0b01101011,
                       0b10110111,
                       0b00000111,
                       0b11111010,
                       0b01111101,
                       0b00110010,
                       0b11101100,
                       0b00110110,
                       0b10111100])
Пример #3
0
    def to_block(self, block, offset=0, bpp=2):
        """Writes this tileset to 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 write image data of width[{}], height[{}], and bpp[{}]"
                .format(self.tile_width, self.tile_height, bpp))

        for tile in self.tiles:
            if bpp == 2:
                offset += write_2bpp_graphic_to_block(source=tile,
                                                      target=block,
                                                      offset=offset)
            elif bpp == 4:
                offset += write_4bpp_graphic_to_block(source=tile,
                                                      target=block,
                                                      offset=offset)
            elif bpp == 8:
                offset += write_8bpp_graphic_to_block(source=tile,
                                                      target=block,
                                                      offset=offset)
            else:  # bpp == 1
                for x in range(0, self.tile_width, 8):
                    offset += write_1bpp_graphic_to_block(
                        source=tile,
                        target=block,
                        offset=offset,
                        x=x,
                        height=self.tile_height)
Пример #4
0
def test_write_2bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([0] * 16)
    assert_equal(
        16,
        write_2bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=0,
                                    x=0,
                                    y=0,
                                    bit_offset=0))
    assert_list_equal(target.to_list(), [
        0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000, 0b10111101,
        0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010, 0b01111101,
        0b00110010, 0b11101100, 0b00110110, 0b10111100
    ])
Пример #5
0
    def to_block(self, block, offset=0, bpp=2):
        """Writes this tileset to 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 write image data of width[{}], height[{}], and bpp[{}]"
                                      .format(self.tile_width, self.tile_height, bpp))

        for tile in self.tiles:
            if bpp == 2:
                offset += write_2bpp_graphic_to_block(source=tile, target=block, offset=offset)
            elif bpp == 4:
                offset += write_4bpp_graphic_to_block(source=tile, target=block, offset=offset)
            elif bpp == 8:
                offset += write_8bpp_graphic_to_block(source=tile, target=block, offset=offset)
            else:  # bpp == 1
                for x in range(0, self.tile_width, 8):
                    offset += write_1bpp_graphic_to_block(source=tile, target=block, offset=offset,
                                                          x=x, height=self.tile_height)
Пример #6
0
def test_write_2bpp_graphic_to_block_offset_xy():
    source = [[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]]
    target = Block()
    target.from_list([0xff] * 18)
    assert_equal(
        16,
        write_2bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=1,
                                    x=2,
                                    y=1,
                                    bit_offset=0))
    assert_list_equal(target.to_list(), [
        0xff, 0b01010101, 0b10111010, 0b01100100, 0b11001111, 0b10100000,
        0b10111101, 0b11100001, 0b01101011, 0b10110111, 0b00000111, 0b11111010,
        0b01111101, 0b00110010, 0b11101100, 0b00110110, 0b10111100, 0xff
    ])