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'
Exemple #2
0
    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'
Exemple #3
0
    def render_tile_scanlines():
        feedback_counter = 0
        for ty in range(render_ty, render_ty + render_th):
            skip_rendering = False
            if single_tile_pattern:
                # optimization for simple background patterns
                # e.g. solid color
                if ty != first_row:
                    skip_rendering = True

            for tx_rel in xrange(render_tw):
                # render one tile
                dst = arr[:, tx_rel * N:(tx_rel + 1) * N, :]
                if not skip_rendering:
                    tx = render_tx + tx_rel
                    try:
                        surface.blit_tile_into(dst, alpha, tx, ty, **kwargs)
                    except Exception, ex:
                        logger.exception("Failed to blit tile %r of %r",
                                         (tx, ty), surface)
                        mypaintlib.tile_clear(dst)
                if feedback_cb and feedback_counter % TILES_PER_CALLBACK == 0:
                    feedback_cb()
                feedback_counter += 1

            # yield a numpy array of the scanline without padding
            res = arr_xcrop
            if ty == last_row:
                res = res[:y + h - ty * N, :, :]
            if ty == first_row:
                res = res[y - render_ty * N:, :, :]
            yield res
Exemple #4
0
    def render_tile_scanlines():
        feedback_counter = 0
        for ty in range(render_ty, render_ty+render_th):
            skip_rendering = False
            if single_tile_pattern:
                # optimization for simple background patterns
                # e.g. solid color
                if ty != first_row:
                    skip_rendering = True

            for tx_rel in xrange(render_tw):
                # render one tile
                dst = arr[:,tx_rel*N:(tx_rel+1)*N,:]
                if not skip_rendering:
                    tx = render_tx + tx_rel
                    try:
                        surface.blit_tile_into(dst, alpha, tx, ty, **kwargs)
                    except Exception, ex:
                        logger.exception("Failed to blit tile %r of %r",
                                         (tx, ty), surface)
                        mypaintlib.tile_clear(dst)
                if feedback_cb and feedback_counter % TILES_PER_CALLBACK == 0:
                    feedback_cb()
                feedback_counter += 1

            # yield a numpy array of the scanline without padding
            res = arr_xcrop
            if ty == last_row:
                res = res[:y+h-ty*N,:,:]
            if ty == first_row:
                res = res[y-render_ty*N:,:,:]
            yield res
Exemple #5
0
 def blit_tile_into(self, dst, tx, ty, mipmap_level=0):
     # used mainly for saving (transparent PNG)
     if self.mipmap_level < mipmap_level:
         return self.mipmap.blit_tile_into(dst, tx, ty, mipmap_level)
     assert dst.shape[2] == 4
     src = self.get_tile_memory(tx, ty, readonly=True)
     if src is transparent_tile.rgba:
         #dst[:] = 0 # <-- notably slower than memset()
         mypaintlib.tile_clear(dst)
     else:
         mypaintlib.tile_convert_rgba16_to_rgba8(src, dst)
 def blit_tile_into(self, dst, tx, ty, mipmap_level=0):
     # used mainly for saving (transparent PNG)
     if self.mipmap_level < mipmap_level:
         return self.mipmap.blit_tile_into(dst, tx, ty, mipmap_level)
     assert dst.shape[2] == 4
     src = self.get_tile_memory(tx, ty, readonly=True)
     if src is transparent_tile.rgba:
         #dst[:] = 0 # <-- notably slower than memset()
         mypaintlib.tile_clear(dst)
     else:
         mypaintlib.tile_convert_rgba16_to_rgba8(src, dst)