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

        """

        # 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, eotf())
                    else:
                        mypaintlib.tile_convert_rgbu16_to_rgbu8(
                            src, dst, eotf())
 def blit_tile_into(self, dst, dst_has_alpha, tx, ty):
     # (used mainly for loading transparent PNGs)
     assert dst_has_alpha is True
     assert dst.dtype == 'uint16', '16 bit dst expected'
     src = self.tile_memory_dict[(tx, ty)]
     assert src.shape[2] == 4, 'alpha required'
     mypaintlib.tile_convert_rgba8_to_rgba16(src, dst, eotf())
Exemplo n.º 3
0
    def stroke_to(self, *args):
        """ Delegates to mypaintlib with information about color space

        Checks whether color transforms should be done in linear sRGB
        so that HSV/HSL adjustments can be handled correctly.
        """
        linear = eotf() != 1.0
        args += (linear, )
        return super(Brush, self).stroke_to(*args)
Exemplo n.º 4
0
    def _transform_brush_color(self):
        """ Apply eotf transform to the backend color.

        By only applying the transform here, the issue of
        strokemap and brush color consistency between new
        and old color rendering modes does not arise.
        """
        hsv_orig = (self.brushinfo.get_base_value(k) for k in self.HSV_CNAMES)
        h, s, v = helpers.transform_hsv(hsv_orig, eotf())
        settings_dict = brushsettings.settings_dict
        self.set_base_value(settings_dict['color_h'].index, h)
        self.set_base_value(settings_dict['color_s'].index, s)
        self.set_base_value(settings_dict['color_v'].index, v)
Exemplo n.º 5
0
    def _update_from_brushinfo(self, settings):
        """Updates changed low-level settings from the BrushInfo"""

        # When eotf != 1.0, store transformed hsv values in the backend.
        transform = eotf() != 1.0
        if transform and any(hsv in settings for hsv in self.HSV_CNAMES):
            self._transform_brush_color()
            # Clear affected settings so the transformation
            # is not undone in the next step.
            # Note: x = x - y is not equivalent to x -= y here.
            settings = settings - self.HSV_SET

        for cname in settings:
            self._update_setting_from_brushinfo(cname)
 def consume_buf():
     ty = state['ty'] - 1
     for i in xrange(state['buf'].shape[1] // N):
         tx = x // N + i
         src = state['buf'][:, i * N:(i + 1) * N, :]
         if src[:, :, 3].any():
             with self.tile_request(tx, ty, readonly=False) as dst:
                 mypaintlib.tile_convert_rgba8_to_rgba16(
                     src, dst, eotf())
     if state["progress"]:
         try:
             state["progress"].completed(ty - ty0)
         except Exception:
             logger.exception("Progress.completed() failed")
             state["progress"] = None