#! /usr/bin/python3

"""
This program allows one to simulate screenshots of eyes17 on a light
screen, when they are given on a dark screen.

Dark pixels are lightened, light pixels are darkened, colored pixels
are left untouched.
"""

import sys
from PIL import Image
import colorsys
import numpy as np

# wheat is the named color rgb(245, 222, 179)
WHEAT = (245, 222, 179)
BLACK = (0, 0, 0)

def invertBW(img):
    pix = np.array(img)
    h, w, channels = pix.shape
    for y in range(h):
        for x in range(w):
            rgb = pix[y][x]
            h,s,v = colorsys.rgb_to_hsv(*(rgb/255.999))
            # dark pixels
            if v < 0.1:
                rgb=np.uint8(np.array(WHEAT))
            # light pixels
            if v > 0.95:
                rgb=np.uint8(np.array(BLACK))
            pix[y][x] = rgb
    result=Image.fromarray(pix)
    return result


if __name__ == "__main__":
    img = Image.open(sys.argv[1])
    img2 = invertBW(img)
    img2.show()
    
