Esempio n. 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)
Esempio n. 2
0
 def to_block(self, block, offset=0):
     for i in range(self.height // 8):
         for j in range(self.width // 8):
             offset += write_4bpp_graphic_to_block(source=self.data,
                                                   target=block,
                                                   offset=offset,
                                                   x=j * 8,
                                                   y=i * 8)
Esempio n. 3
0
 def to_block(self, block, offset=0):
     for q in range(0, self.height // 32):
         for r in range(0, self.width // 32):
             for a in range(0, 4):
                 for j in range(0, 4):
                     offset += write_4bpp_graphic_to_block(
                         source=self.sprite,
                         target=block,
                         offset=offset,
                         x=(j + r * 4) * 8,
                         y=(a + q * 4) * 8)
Esempio n. 4
0
 def to_block(self, block, offset=0):
     for q in range(0, self.height / 32):
         for r in range(0, self.width / 32):
             for a in range(0, 4):
                 for j in range(0, 4):
                     offset += write_4bpp_graphic_to_block(
                         source=self.sprite,
                         target=block,
                         offset=offset,
                         x=(j + r * 4) * 8,
                         y=(a + q * 4) * 8
                     )
Esempio n. 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)
Esempio n. 6
0
def test_write_4bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([0] * 32)
    assert_equal(
        32,
        write_4bpp_graphic_to_block(source=source,
                                    target=target,
                                    offset=0,
                                    x=0,
                                    y=0,
                                    bit_offset=0))
    assert_list_equal(target.to_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
    ])
Esempio n. 7
0
def test_write_4bpp_graphic_to_block():
    source = [[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]]
    target = Block()
    target.from_list([0] * 32)
    assert_equal(32, write_4bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
    assert_list_equal(target.to_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
                      ])
Esempio n. 8
0
 def to_block(self, block, offset=0):
     for i in range(self.height / 8):
         for j in range(self.width / 8):
             offset += write_4bpp_graphic_to_block(source=self.data, target=block, offset=offset, x=j*8, y=i*8)