Beispiel #1
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)
Beispiel #2
0
def test_write_1bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([32] * 10)
    assert_equal(
        8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8))
    assert_list_equal(target.to_list(), [
        32, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000, 0b01110001, 0b00000001, 32
    ])
Beispiel #3
0
def test_write_1bpp_graphic_to_block_rectangular_short():
    source = [[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]]
    target = Block()
    target.from_list([0xeb] * 8)
    target[0] = 42
    assert_equal(
        6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6))
    assert_list_equal(target.to_list(), [
        42, 0xeb, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000
    ])
Beispiel #4
0
def test_write_1bpp_graphic_to_block_offset_source():
    source = [[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]]
    target = Block()
    target.from_list([0] * 8)
    assert_equal(
        8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8))
    assert_list_equal(target.to_list(), [
        0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010, 0b11001000,
        0b01110001, 0b00000001
    ])
def test_write_1bpp_graphic_to_block_rectangular_short():
    source = [[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]]
    target = Block()
    target.from_list([0xeb] * 8)
    target[0] = 42
    assert_equal(6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6))
    assert_list_equal(target.to_list(), [42, 0xeb,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000])
Beispiel #6
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)
def test_write_1bpp_graphic_to_block_offset_source():
    source = [[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]]
    target = Block()
    target.from_list([0] * 8)
    assert_equal(8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8))
    assert_list_equal(target.to_list(), [0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001])
def test_write_1bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([32] * 10)
    assert_equal(8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8))
    assert_list_equal(target.to_list(), [32,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001,
                                         32])
Beispiel #9
0
def test_read_1bpp_graphic_from_block_rectangular_tall():
    source = [[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]]
    target = Block()
    target.from_list([
        42, 11, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 112, 113, 114, 115, 116,
        12, 21
    ])
    assert_equal(
        16, write_1bpp_graphic_to_block(source, target, 3, x=0, y=0,
                                        height=16))
    assert_list_equal(target.to_list(), [
        42, 11, 99, 0b00000011, 0b01110000, 0b01001001, 0b11110000, 0b01001010,
        0b11001000, 0b01110001, 0b00000001, 0b00100000, 0b00110000, 0b00101000,
        0b00101000, 0b01100000, 0b11100000, 0b11000000, 0b00000001, 12, 21
    ])
Beispiel #10
0
def test_read_1bpp_graphic_from_block_rectangular_tall():
    source = [[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]]
    target = Block()
    target.from_list([42, 11, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 112, 113, 114, 115, 116, 12, 21])
    assert_equal(16, write_1bpp_graphic_to_block(source, target, 3, x=0, y=0, height=16))
    assert_list_equal(target.to_list(), [42, 11, 99,
                                         0b00000011,
                                         0b01110000,
                                         0b01001001,
                                         0b11110000,
                                         0b01001010,
                                         0b11001000,
                                         0b01110001,
                                         0b00000001,
                                         0b00100000,
                                         0b00110000,
                                         0b00101000,
                                         0b00101000,
                                         0b01100000,
                                         0b11100000,
                                         0b11000000,
                                         0b00000001,
                                         12, 21])