コード例 #1
0
 def _setstate_old(self, state):
     self._random = state[0]
     self.noise_c = ffi.new('struct TCOD_Noise*')
     self.noise_c.ndim = state[3]
     ffi.buffer(self.noise_c.map)[:] = state[4]
     ffi.buffer(self.noise_c.buffer)[:] = state[5]
     self.noise_c.H = state[6]
     self.noise_c.lacunarity = state[7]
     ffi.buffer(self.noise_c.exponent)[:] = state[8]
     if state[9]:
         # high change of this being prematurely garbage collected!
         self.__waveletTileData = ffi.new('float[]', 32 * 32 * 32)
         ffi.buffer(self.__waveletTileData)[:] = state[9]
     self.noise_c.noise_type = state[10]
     self._tdl_noise_c = ffi.new(
         'TDLNoise*', (self.noise_c, self.noise_c.ndim, state[1], state[2]))
コード例 #2
0
ファイル: image.py プロジェクト: quuxtastic/python-tcod
 def __new__(cls, image):
     size = image.height * image.width
     self = np.frombuffer(ffi.buffer(lib.TCOD_image_get_colors()[size]),
                          np.uint8)
     self = self.reshape((image.height, image.width, 3)).view(cls)
     self._image_c = image.cdata
     return self
コード例 #3
0
    def _init_setup_console_data(self, order="C"):
        """Setup numpy arrays over libtcod data buffers."""
        global _root_console
        self._key_color = None
        if self.console_c == ffi.NULL:
            _root_console = self
            self._console_data = lib.TCOD_ctx.root
        else:
            self._console_data = ffi.cast(
                "struct TCOD_Console*", self.console_c
            )

        def unpack_color(color_data):
            """return a (height, width, 3) shaped array from an image struct"""
            color_buffer = ffi.buffer(color_data[0 : self.width * self.height])
            array = np.frombuffer(color_buffer, np.uint8)
            return array.reshape((self.height, self.width, 3))

        self._fg = unpack_color(self._console_data.fg_array)
        self._bg = unpack_color(self._console_data.bg_array)

        buf = self._console_data.ch_array
        buf = ffi.buffer(buf[0 : self.width * self.height])
        self._ch = np.frombuffer(buf, np.intc).reshape(
            (self.height, self.width)
        )

        self._order = tcod._internal.verify_order(order)
コード例 #4
0
    def _init_setup_console_data(self, order='C'):
        """Setup numpy arrays over libtcod data buffers."""
        self._key_color = None
        if self.console_c == ffi.NULL:
            self._console_data = lib.TCOD_ctx.root
        else:
            self._console_data = ffi.cast('TCOD_console_data_t *',
                                          self.console_c)

        def unpack_color(color_data):
            """return a (height, width, 3) shaped array from an image struct"""
            color_buffer = ffi.buffer(color_data[0:self.width * self.height])
            array = np.frombuffer(color_buffer, np.uint8)
            return array.reshape((self.height, self.width, 3))

        self._fg = unpack_color(self._console_data.fg_array)
        self._bg = unpack_color(self._console_data.bg_array)

        buf = self._console_data.ch_array
        buf = ffi.buffer(buf[0:self.width * self.height])
        self._ch = np.frombuffer(buf, np.intc).reshape(
            (self.height, self.width))

        order = tcod._internal.verify_order(order)
        if order == 'F':
            self._fg = self._fg.transpose(1, 0, 2)
            self._bg = self._bg.transpose(1, 0, 2)
            self._ch = self._ch.transpose()
コード例 #5
0
ファイル: image.py プロジェクト: mkdir-not-war/mapgen
 def __new__(cls, image: Any) -> "_ImageBufferArray":
     size = image.height * image.width
     self = np.frombuffer(ffi.buffer(lib.TCOD_image_get_colors()[size]),
                          np.uint8)
     self = self.reshape((image.height, image.width, 3)).view(cls)
     self._image_c = image.cdata
     return self  # type: ignore
コード例 #6
0
ファイル: console.py プロジェクト: mkdir-not-war/mapgen
    def _init_setup_console_data(self, order: str = "C") -> None:
        """Setup numpy arrays over libtcod data buffers."""
        global _root_console
        self._key_color = None
        if self.console_c == ffi.NULL:
            _root_console = self
            self._console_data = lib.TCOD_ctx.root
        else:
            self._console_data = ffi.cast("struct TCOD_Console*",
                                          self.console_c)

        self._tiles = np.frombuffer(
            ffi.buffer(self._console_data.tiles[0:self.width * self.height]),
            dtype=self.DTYPE,
        ).reshape((self.height, self.width))

        self._order = tcod._internal.verify_order(order)
コード例 #7
0
 def unpack_color(color_data):
     """return a (height, width, 3) shaped array from an image struct"""
     color_buffer = ffi.buffer(color_data[0:self.width * self.height])
     array = np.frombuffer(color_buffer, np.uint8)
     return array.reshape((self.height, self.width, 3))