def _remove_redundant_conversion(v: Variable):
    if isinstance(v.output_from, ConvertRtoRGBA):
        if all([isinstance(op, ConvertRGBAtoR) for op in v.input_to]):
            v2 = v.output_from.inputs["x0"]
            v.output_from.remove_all()
            v2.replace(v)

            for op in v.input_to:
                v2 = op.outputs["y"]
                op.remove_all()
                v2.replace(v)

            v.get_attribute(ChannelMode)[0].mode = ChannelModeEnum.R
            return True

    elif isinstance(v.output_from, ConvertRGBAtoR):
        if all([isinstance(op, ConvertRtoRGBA) for op in v.input_to]):
            v2 = v.output_from.inputs["x0"]
            v.output_from.remove_all()
            v2.replace(v)

            for op in v.input_to:
                v2 = op.outputs["y"]
                op.remove_all()
                v2.replace(v)

            v.get_attribute(ChannelMode)[0].mode = ChannelModeEnum.RGBA
            return True

    return False
def _remove_convert_with_input(x: Variable):
    requested_mode = None
    for op in x.input_to:
        if isinstance(op, ConvertRtoRGBA):
            if requested_mode is ChannelModeEnum.R:
                return False

            requested_mode = ChannelModeEnum.RGBA

        elif isinstance(op, ConvertRGBAtoR):
            if requested_mode is ChannelModeEnum.RGBA:
                return False

            requested_mode = ChannelModeEnum.R

        else:
            return False

    if requested_mode is None:
        return False

    x.get_attribute(ChannelMode)[0].mode = requested_mode
    for op in list(x.input_to):
        y = list(op.outputs.values())[0]
        op.remove_all()
        y.replace(x)

    return True
Beispiel #3
0
    def get(base: Variable):
        if not base.has_attribute(TextureShape):
            attribute = TextureShape(base)
            base.attributes.add(attribute)
        else:
            attribute = base.get_attribute(TextureShape)[0]

        return [attribute.height, attribute.width]
Beispiel #4
0
    def set(base: Variable, width: int, height: int):
        if not base.has_attribute(TextureShape):
            attribute = TextureShape(base)
            base.attributes.add(attribute)
        else:
            attribute = base.get_attribute(TextureShape)[0]

        attribute.width = width
        attribute.height = height
Beispiel #5
0
    def get(variable: Variable):
        if variable.has_attribute(TextureShape):
            attribute = variable.get_attribute(TextureShape)[0]

        else:
            attribute = TextureShape(variable)
            variable.attributes.add(attribute)

        return attribute.height, attribute.width
Beispiel #6
0
    def set(variable: Variable, width: int, height: int):
        if variable.has_attribute(TextureShape):
            attribute = variable.get_attribute(TextureShape)[0]
        else:
            attribute = TextureShape(variable)
            variable.attributes.add(attribute)

        attribute.width = width
        attribute.height = height
Beispiel #7
0
 def get(base: Variable):
     return base.get_attribute(ChannelMode)[0].mode if base.has_attribute(
         ChannelMode) else ChannelModeEnum.R
Beispiel #8
0
 def set(base: Variable, mode: ChannelModeEnum):
     if base.has_attribute(ChannelMode):
         base.get_attribute(ChannelMode)[0].mode = mode
     else:
         base.attributes.add(ChannelMode(base, mode=mode))