#!/usr/bin/env python

import sys
import Image

MASQUE_GAUCHE = (255, 0, 32)
MASQUE_DROITE = (0, 200, 213)

def apply_masque(pix, masque):
    return [
        pix[i] * masque[i] / 255
        for i in range(3)
    ]
def sum_pix(pix1, pix2):
    return [
        pix1[i] + pix2[i]
        for i in range(3)
    ]

img_gauche = Image.open(open(sys.argv[1], 'r'))
img_droite = Image.open(open(sys.argv[2], 'r'))
img_result = Image.new('RGB', img_gauche.size)

pix_gauche = img_gauche.getdata()
pix_droite = img_droite.getdata()
pix_result = []
for i in range(len(pix_gauche)):
    new_pix = sum_pix(
        apply_masque(pix_gauche[i], MASQUE_GAUCHE),
        apply_masque(pix_droite[i], MASQUE_DROITE)
    )
    pix_result.append(tuple(new_pix))

img_result.putdata(pix_result)
img_result.save(sys.argv[3])