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 with self.tile_request(tx, ty, readonly=True) as src: if src is transparent_tile.rgba: #dst[:] = 0 # <-- notably slower than memset() mypaintlib.tile_clear(dst) else: if dst.dtype == 'uint16': # this will do memcpy, not worth to bother skipping the u channel mypaintlib.tile_copy_rgba16_into_rgba16(src, dst) elif dst.dtype == 'uint8': if dst_has_alpha: mypaintlib.tile_convert_rgba16_to_rgba8(src, dst) else: mypaintlib.tile_convert_rgbu16_to_rgbu8(src, dst) else: raise ValueError, 'Unsupported destination buffer type'
def convert_to_normal_mode(self, get_bg): """ Given a background, this layer is updated such that it can be composited over the background in normal blending mode. The result will look as if it were composited with the current blending mode. """ if self.compositeop == "svg:src-over" and self.effective_opacity == 1.0: return # optimization for merging layers N = tiledsurface.N tmp = empty((N, N, 4), dtype='uint16') for tx, ty in self._surface.get_tiles(): bg = get_bg(tx, ty) # tmp = bg + layer (composited with its mode) mypaintlib.tile_copy_rgba16_into_rgba16(bg, tmp) self.composite_tile(tmp, False, tx, ty) # overwrite layer data with composited result with self._surface.tile_request(tx, ty, readonly=False) as dst: mypaintlib.tile_copy_rgba16_into_rgba16(tmp, dst) dst[:,:,3] = 0 # minimize alpha (throw away the original alpha) # recalculate layer in normal mode mypaintlib.tile_flat2rgba(dst, bg)
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 convert_to_normal_mode(self, get_bg): """ Given a background, this layer is updated such that it can be composited over the background in normal blending mode. The result will look as if it were composited with the current blending mode. """ if self.compositeop == "svg:src-over" and self.effective_opacity == 1.0: return # optimization for merging layers N = tiledsurface.N tmp = empty((N, N, 4), dtype='uint16') for tx, ty in self._surface.get_tiles(): bg = get_bg(tx, ty) # tmp = bg + layer (composited with its mode) mypaintlib.tile_copy_rgba16_into_rgba16(bg, tmp) self.composite_tile(tmp, False, tx, ty) # overwrite layer data with composited result with self._surface.tile_request(tx, ty, readonly=False) as dst: mypaintlib.tile_copy_rgba16_into_rgba16(tmp, dst) dst[:, :, 3] = 0 # minimize alpha (throw away the original alpha) # recalculate layer in normal mode mypaintlib.tile_flat2rgba(dst, bg)
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 blit_tile_into(self, dst, dst_has_alpha, tx, ty, mipmap_level=0): assert dst_has_alpha is False if self.mipmap_level < mipmap_level: return self.mipmap.blit_tile_into(dst, dst_has_alpha, tx, ty, mipmap_level) rgbu = self.get_tile_memory(tx, ty) # render solid or tiled background #dst[:] = rgb # 13 times slower than below, with some bursts having the same speed as below (huh?) # note: optimization for solid colors is not worth it, it gives only 2x speedup (at best) if dst.dtype == 'uint16': # this will do memcpy, not worth to bother skipping the u channel mypaintlib.tile_copy_rgba16_into_rgba16(rgbu, dst) else: # this case is for saving the background assert dst.dtype == 'uint8' # note: when saving the background layer we usually # convert here the same tile over and over again. But it # does help much to cache this conversion result. The # save_ora speedup when doing this is below 1%, even for a # single-layer ora. mypaintlib.tile_convert_rgbu16_to_rgbu8(rgbu, dst)
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)