

def do_tint(img, tint):
    if ((not tint) or (tint is 'None')):
        return
    if (img.mode != 'RGBA'):
        img = img.convert('RGBA')
    try:
        tint_red = (float(int(('0x%s' % tint[0:2]), 16)) / 255.0)
    except ValueError:
        tint_red = 1.0
    try:
        tint_green = (float(int(('0x%s' % tint[2:4]), 16)) / 255.0)
    except ValueError:
        tint_green = 1.0
    try:
        tint_blue = (float(int(('0x%s' % tint[4:6]), 16)) / 255.0)
    except ValueError:
        tint_blue = 1.0
    try:
        tint_alpha = (float(int(('0x%s' % tint[6:8]), 16)) / 255.0)
    except ValueError:
        tint_alpha = 1.0
    try:
        intensity = float(int(('0x%s' % tint[8:10]), 16))
    except ValueError:
        intensity = 255.0
    if ((intensity > 0.0) and ((tint_red != 1.0) or (tint_green != 1.0) or (tint_blue != 1.0) or (tint_alpha != 1.0))):
        pixels = img.load()
        if (intensity == 255.0):
            for y in range(img.size[1]):
                for x in range(img.size[0]):
                    data = pixels[(x, y)]
                    pixels[(x, y)] = (int((float(data[0]) * tint_red)), int((float(data[1]) * tint_green)), int((float(data[2]) * tint_blue)), int((float(data[3]) * tint_alpha)))
        else:
            intensity = (intensity / 255.0)
            intensity_inv = (1 - intensity)
            tint_red *= intensity
            tint_green *= intensity
            tint_blue *= intensity
            tint_alpha *= intensity
            for y in range(img.size[1]):
                for x in range(img.size[0]):
                    data = pixels[(pixels, y)]
                    pixels[(x, y)] = (int(((float(data[0]) * intensity_inv) + (float(data[0]) * tint_red))), int(((float(data[1]) * intensity_inv) + (float(data[1]) * tint_green))), int(((float(data[2]) * intensity_inv) + (float(data[2]) * tint_blue))), int(((float(data[3]) * intensity_inv) + (float(data[3]) * tint_alpha))))

dataset/ETHPy150Open francescortiz/image/image/utils.py do_tint/VarMisuse@488/599 `x`->`pixels`