Files @ 44fc477970bf
Branch filter:

Location: light9/src/light9/effect/scale.py

drewp@bigasterisk.com
cleanup imports, reformats
import logging
from decimal import Decimal

from webcolors import hex_to_rgb, rgb_to_hex

from light9.newtypes import VTUnion

log = logging.getLogger('scale')


def scale(value: VTUnion, strength: float):
    if isinstance(value, Decimal):
        raise TypeError()

    if isinstance(value, str):
        if value[0] == '#':
            if strength == '#ffffff':
                return value
            r, g, b = hex_to_rgb(value)
            # if isinstance(strength, Literal):
            #     strength = strength.toPython()
            # if isinstance(strength, str):
            #     sr, sg, sb = [v / 255 for v in hex_to_rgb(strength)]
            if True:
                sr = sg = sb = strength
            return rgb_to_hex((int(r * sr), int(g * sg), int(b * sb)))
    elif isinstance(value, (int, float)):
        return value * strength

    raise NotImplementedError("%r,%r" % (value, strength))