def blit_tile_into(self, dst, dst_has_alpha, tx, ty, mipmap_level=0): # used mainly for saving (transparent PNG) #assert dst_has_alpha is True if self.mipmap_level < mipmap_level: return self.mipmap.blit_tile_into(dst, dst_has_alpha, tx, ty, mipmap_level) assert dst.shape[2] == 4 if dst.dtype not in ('uint16', 'uint8'): raise ValueError('Unsupported destination buffer type %r', dst.dtype) dst_is_uint16 = (dst.dtype == 'uint16') with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: #dst[:] = 0 # <-- notably slower than memset() if dst_is_uint16: mypaintlib.tile_clear_rgba16(dst) else: mypaintlib.tile_clear_rgba8(dst) else: if dst_is_uint16: # this will do memcpy, not worth to bother skipping the u channel mypaintlib.tile_copy_rgba16_into_rgba16(src, dst) else: if dst_has_alpha: mypaintlib.tile_convert_rgba16_to_rgba8(src, dst) else: mypaintlib.tile_convert_rgbu16_to_rgbu8(src, dst)
def composite_tile(self, dst, dst_has_alpha, tx, ty, mipmap_level=0, opacity=1.0, mode=mypaintlib.CombineNormal, *args, **kwargs): """Composite one tile of this surface over a NumPy array. See lib.surface.TileCompositable for the parameters. This implementation adds two further ones: :param float opacity: opacity multiplier :param int mode: mode to use when compositing """ if opacity == 0: if mode == mypaintlib.CombineDestinationIn or mode == mypaintlib.CombineDestinationAtop: if dst_has_alpha: mypaintlib.tile_clear_rgba16(dst) return else: return if self.mipmap_level < mipmap_level: self.mipmap.composite_tile(dst, dst_has_alpha, tx, ty, mipmap_level, opacity, mode) return with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: if mode == mypaintlib.CombineDestinationIn or mode == mypaintlib.CombineDestinationAtop: if dst_has_alpha: mypaintlib.tile_clear_rgba16(dst) return else: return mypaintlib.tile_combine(mode, src, dst, dst_has_alpha, opacity)
def composite_tile(self, dst, dst_has_alpha, tx, ty, mipmap_level=0, opacity=1.0, mode=mypaintlib.CombineNormal, *args, **kwargs): """Composite one tile of this surface over a NumPy array. See lib.surface.TileCompositable for the parameters. This implementation adds two further ones: :param float opacity: opacity multiplier :param int mode: mode to use when compositing """ # Apply zero-alpha-source optimizations if possible. # Sometimes this can be done without issuing a tile request. if opacity == 0: if dst_has_alpha: if mode in lib.modes.MODES_CLEARING_BACKDROP_AT_ZERO_ALPHA: mypaintlib.tile_clear_rgba16(dst) return if mode not in lib.modes.MODES_EFFECTIVE_AT_ZERO_ALPHA: return # Tile request needed, but may need to satisfy it from a deeper # mipmap level. if self.mipmap_level < mipmap_level: self.mipmap.composite_tile(dst, dst_has_alpha, tx, ty, mipmap_level, opacity, mode) return # Tile request at the required level. # Try optimizations again if we got the special marker tile with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: if dst_has_alpha: if mode in lib.modes.MODES_CLEARING_BACKDROP_AT_ZERO_ALPHA: mypaintlib.tile_clear_rgba16(dst) return if mode not in lib.modes.MODES_EFFECTIVE_AT_ZERO_ALPHA: return mypaintlib.tile_combine(mode, src, dst, dst_has_alpha, opacity)
def blit_tile_into(self, dst, dst_has_alpha, tx, ty, mipmap_level=0, *args, **kwargs): """Copy one tile from this object into a destination array See lib.surface.TileBlittable for the parameters. This implementation adds an extra param: :param int mipmap_level: layer mipmap level to use Used mainly for saving (transparent PNG). """ # assert dst_has_alpha is True if self.mipmap_level < mipmap_level: return self.mipmap.blit_tile_into(dst, dst_has_alpha, tx, ty, mipmap_level) assert dst.shape[2] == 4 if dst.dtype not in ('uint16', 'uint8'): raise ValueError('Unsupported destination buffer type %r', dst.dtype) dst_is_uint16 = (dst.dtype == 'uint16') with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: # dst[:] = 0 # <-- notably slower than memset() if dst_is_uint16: mypaintlib.tile_clear_rgba16(dst) else: mypaintlib.tile_clear_rgba8(dst) else: if dst_is_uint16: # this will do memcpy, not worth to bother skipping # the u channel mypaintlib.tile_copy_rgba16_into_rgba16(src, dst) else: if dst_has_alpha: mypaintlib.tile_convert_rgba16_to_rgba8(src, dst) else: mypaintlib.tile_convert_rgbu16_to_rgbu8(src, dst)
def composite_tile(self, dst, dst_has_alpha, tx, ty, mipmap_level=0, opacity=1.0, mode=mypaintlib.CombineNormal): """Composite one tile of this surface over a NumPy array. :param dst: target tile array (uint16, NxNx4, 15-bit scaled int) :param dst_has_alpha: alpha channel in dst should be preserved :param tx: tile X coordinate, in model tile space :param ty: tile Y coordinate, in model tile space :param mipmap_level: layer mipmap level to use :param opacity: opacity multiplier :param mode: mode to use when compositing Composite one tile of this surface over the array dst, modifying only dst. """ if opacity == 0: if mode == mypaintlib.CombineDestinationIn: if dst_has_alpha: mypaintlib.tile_clear_rgba16(dst) return else: return if self.mipmap_level < mipmap_level: self.mipmap.composite_tile(dst, dst_has_alpha, tx, ty, mipmap_level, opacity, mode) return with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: if mode == mypaintlib.CombineDestinationIn: if dst_has_alpha: mypaintlib.tile_clear_rgba16(dst) return else: return mypaintlib.tile_combine(mode, src, dst, dst_has_alpha, opacity)
def blit_tile_into(self, dst, dst_has_alpha, tx, ty, mipmap_level=0, *args, **kwargs): """Copy one tile from this object into a destination array See lib.surface.TileBlittable for the parameters. This implementation adds an extra param: :param int mipmap_level: layer mipmap level to use """ # used mainly for saving (transparent PNG) #assert dst_has_alpha is True if self.mipmap_level < mipmap_level: return self.mipmap.blit_tile_into(dst, dst_has_alpha, tx, ty, mipmap_level) assert dst.shape[2] == 4 if dst.dtype not in ('uint16', 'uint8'): raise ValueError('Unsupported destination buffer type %r', dst.dtype) dst_is_uint16 = (dst.dtype == 'uint16') with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: #dst[:] = 0 # <-- notably slower than memset() if dst_is_uint16: mypaintlib.tile_clear_rgba16(dst) else: mypaintlib.tile_clear_rgba8(dst) else: if dst_is_uint16: # this will do memcpy, not worth to bother skipping the u channel mypaintlib.tile_copy_rgba16_into_rgba16(src, dst) else: if dst_has_alpha: mypaintlib.tile_convert_rgba16_to_rgba8(src, dst) else: mypaintlib.tile_convert_rgbu16_to_rgbu8(src, dst)