#!/usr/bin/python2

import sys
from optparse import OptionParser

from light_compositing import light_compositing


def parse_opts():
    usage = "usage: %prog [options] [directory]"
    parser = OptionParser(usage=usage)
    parser.add_option("-c", "--count", dest="count",  default=-1,
                      metavar="COUNT", help="The number of images to use.")
    parser.add_option("-m", "--mask", dest="mask", type="string", default="mask.png",
                      metavar="MASK", help="The mask image that defines the object of interest.")
    parser.add_option("-f", "--fill", dest="fill", type="float", default=1,
                      metavar="FILL", help="The weight of the fill light.")
    parser.add_option("-e", "--edge", dest="edge", type="float", default=1,
                      metavar="EDGE", help="The weight of the edge light.")
    parser.add_option("-d", "--diffuse", dest="diffuse", type="float", default=1,
                      metavar="DIFFUSE", help="The weight of the diffuse color light.")
    parser.add_option("-o", "--output", dest="output", type="string", default="per_object_light.png",
                      metavar="OUTPUT", help="The output file name.")
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
                  metavar="VERBOSE", help="Print debug information.")

    (options, arguments) = parser.parse_args()
    return (options, arguments)


def main():
    (options, arguments) = parse_opts()
    default_args = ["fill_light.png", "edge_light.png",
                    "diffuse_color_light.png"]
    args = []

    for argument in arguments:
        args.append(argument)

    for i in range(len(arguments), 3):
        args.append(default_args[i])

    light_compositing.object_modifier(args[0], args[1], args[2], options.output,
                                      options.mask, options.fill, options.edge,
                                      options.diffuse, count=options.count,
                                      verbose=options.verbose)

main()
