Beispiel #1
0
    def bake(self, shape, target=None, offset=(0, 0)):
        """Apply the transformation stack for each pixel in the given shape

        Args:
          - shape: Source shape object to be processed
          - target [Optional]: optional target where final pixels are blitted into.
                If target is not given, 'shape' is modified inplace. Defaults to None.
          - offset: pixel-offset to blit the data to. Most useful with the target
          option.

        Returns:
          the affected Shape object
        """
        from terminedia.image import FullShape

        if target:
            source = shape
        else:
            # Creates a copy of all data channels, sans sprites neither transformers:
            source = FullShape.promote(shape)
            target = shape

        # if target is shape, bad things will happen for some transformers - specially Kernel based transforms

        offset = V2(offset)
        for pos, pixel in source:
            target[pos + offset] = self.process(source, pos, pixel)
        return target
Beispiel #2
0
    def _check_and_promote(self):
        """called at initialization to try to promote any object that is not a Shape
        to a Shape.

        """
        from terminedia.image import shape, Shape, FullShape
        for index, item in enumerate(self.shapes):
            if not isinstance(item, Shape):
                item = shape(item)
            if not isinstance(item, FullShape):
                item = FullShape.promote(item)
                self.shapes[index] = shape(item)
Beispiel #3
0
    def _check_and_promote(self, shape_specs):
        """called at initialization to try to promote any object that is not a Shape
        to a Shape.

        """
        from terminedia.image import shape, Shape, FullShape
        if isinstance(
                shape_specs,
            (str, Path, Shape, V2)) or (isinstance(shape_specs, Sequence)
                                        and len(shape_specs) == 2
                                        and isinstance(shape_specs[0], Real)):
            shape_specs = [shape_specs]
        shapes = []
        for index, item in enumerate(shape_specs):
            if not isinstance(item, Shape):
                item = shape(item)
            if not isinstance(item, FullShape):
                item = FullShape.promote(item)
            shapes.append(item)
        return shapes