#!/usr/bin/python

# make_16_arrows.py
#       --copyright--                   Copyright 2010 (C) Tranzoa, Co. All rights reserved.    Warranty: You're free and on your own here. This code is not necessarily up-to-date or of public quality.
#       --url--                         http://www.tranzoa.net/tzpython/
#       --email--                       pycode is the name to send to. tranzoa.com is the place to send to.
#       --bodstamps--
#       May 16, 2010            bar
#       May 25, 2010            bar     tz_os_priority
#       November 29, 2011       bar     pyflake cleanup
#       May 27, 2012            bar     doxygen namespace
#       --eodstamps--
##      \file
#       \namespace              tzpython.make_16_arrows
#
#
#       Make 16 arrow images using ImageMagick's 'convert' program from a zero degree, up-arrow image we have here, hard-coded.
#
#
#

import  multiprocessing
import  os

import  tzlib
import  tz_os_priority

SIZE            = 32


a000_512_png    = (   ""
                   +  """\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x02\x00\x00\x00\x02\x00\x08\x06"""
                   +  """\x00\x00\x00\xf4x\xd4\xfa\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00"""
                   +  """\x00\x06bKGD\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00\x00\tpHYs\x00"""
                   +  """\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x07tIME\x07"""
                   +  """\xda\x05\x11\x00*\x16\xc4\x8bS\x1a\x00\x00\x08\x8fIDATx\xda\xed\xd7\x81\x91"""
                   +  """\x840\x10\x03A\x99"\xff\x94q\x1c\xd4t\x87poV\xf3\x1bP\xf4\xf9\t\xa0\xed\xf8"""
                   +  """\t =\xfen\x00\x08\x00 \xfa\x9f\xbf;\x00\x02\x00\x88\x8d\xbf[\x00\x02\x00\x88"""
                   +  """\x8e\xbf{\x00\x02\x00\x88\x8e\xbf\x9b\x00\x02\x00\x88\x8e\xbf\xbb\x00\x02\x00"""
                   +  """\x88\x8e\xbf\xdb\x00\x02\x00\x88\x8e\xbf\xfb\x00\x02\x00\x88\x8e\xbf\x1b\x01"""
                   +  """\x02\x00\x88\x8e\xbf;\x01\x02\x00\x88\x8e\xbf[\x01\x02\x00\x88\x8e\xbf{\x01"""
                   +  """\x02\x00\x88\x8e\xbf\x9b\x01\x02\x00\x88\x8e\xbf\xbb\x01\x02\x00\x88\x8e\xbf"""
                   +  """\xdb\x01\x02\x00\x88\x8e\xbf\xfb\x01\x02\x00\x88\x8e\xbf\x1b\x02\x02\x00\x88"""
                   +  """\x8e\xbf;\x02\x02\x00\x88\x8e\xbf[\x02\x02\x00\x88\x8e\xbf{\x02\x02\x00\x88"""
                   +  """\x8e\xbf\x9b\x02\x02\x00\x88\x8e\xbf\xbb\x02>T :\xfen\x0b\xf8H\x81\xe8\xf8"""
                   +  """\xbb/\xe0\x03\x05\xa2\xe3\xef\xc6\x80\x8f\x13\x88\x8e\xbf;\x03>L :\xfen\r"""
                   +  """\xf8(\x81\xe8\xf8\xbb7\xe0\x83\x04\xa2\xe3\xef\xe6\x80\x8f\x11\x88\x8e\xbf"""
                   +  """\xbb\x03>D :\xfen\x0f\xf8\x08\xc1\xf8\xbb?\x80\x0f\x10\x8c\xbf\x1b\x04\xf8"""
                   +  """\xf8\xc0\xf8\xbbC\x80\x0f\x0f\x8c\xbf[\x04\xf8\xe8\xc0\xf8\xbbG\x80\x0f\x0e"""
                   +  """\x8c\xbf\x9b\x04\xf8\xd8\xc0\xf8\xbbK\x80\x0f\r\x8c\xbf\xdb\x04\xf8\xc8\xc0"""
                   +  """\xf8\xbbO\x80\x0f\x0c\x8c\xbf\x1b\x05>.\xc0\xf8\xbbS\xe0\xc3\x02\x8c\xbf["""
                   +  """\x05>*\xc0\xf8\xbbW\xe0\x83\x02\x8c\xbf\x9b\x05>&0\xfe\xb8[\xe0C\x02\xe3"""
                   +  """\x8f\xdb\x05>"0\xfe\xb8_\xe0\x03\x02\xe3\x8f\x1b\x06>\x1e0\xfe\xb8c\xe0\xc3"""
                   +  """\x01\xe3\x8f[\x06>\x1a0\xfe\xb8g\xe0\x83\x01\xe3\x8f\x9b\x06>\x160\xfe\xb8k"""
                   +  """\xe0C\x01\xe3\x8f\xdb\x06>\x120\xfe\xee\x1b\xe0\x03\x01\xe3\xef\xc6\x01>"""
                   +  """\x0e0\xfe\xee\x1c\xf80\xc0\xf8\xe3\xd6\x81\x8f\x02\x8c?\xee\x1d\xf8 \xc0"""
                   +  """\xf8\xe3\xe6\x81\x8f\x01\x8c?\xee\x1e\xf8\x10\xc0\xf8\xe3\xf6\x81\x8f\x00"""
                   +  """\x8c?\xee\x1f\xf8\x00\xc0\xf8\xe3\x06\x82\xc7\x0f\xc6\x1fw\x10<|0\xfe\xb8"""
                   +  """\x85\xe0\xd1\x83\xf1\xc7=\x04\x0f\x1e\x8c?n"x\xec`\xfcq\x17\xc1C\x07\xe3"""
                   +  """\x8f\xdb\x08\x1e9\x18\x7f\xdcG\xf0\xc01\xfe\xe0F\x82\xc7\x8d\xf1\x07w"""
                   +  """\x12<l\x8c?\xb8\x95x\xd4`\xfc\xc1\xbd\xc4\x83\x06\xe3\x0fn&\x1e3\x18\x7fp7"""
                   +  """\xf1\x90\xc1\xf8\xe3v\x82G\x0c\xc6\x1f\xf7\x13<`0\xfe\xb8\xa1\xe0\xf1\x82"""
                   +  """\xf1\xc7\x1d\x05\x0f\x17\x8c?n)x\xb4`\xfcqO\xc1\x83\x05\xe3\x8f\x9b\n\x1e+"""
                   +  """\x18\x7f\xdcU\xf0P1\xfe\xe0\xb6\x82G\x8a\xf1\x07\xf7\x15<P\x8c?\xb8\xb1"""
                   +  """\xe0qb\xfc\xc1\x9d\x05\x0f\x13\xe3\x0fn-x\x94\x18\x7fpo\xf1 \xc1\xf8\x83"""
                   +  """\x9b\x8b\xc7\x08\xc6\x1f\xdc]<D0\xfe\xe0\xf6\xe2\x11\x82\xf1\x07\xf7\x17"""
                   +  """\x0f\x10\x8c?\xb8\xc1x|`\xfc\xc1\x1d\xc6\xc3\x03\xe3\x0fn1\x1e\x1d\xc6"""
                   +  """\x1fp\x8f\xf1\xe00\xfe\x80\x9b\x8c\xc7\x86\xf1\x07\xdce<4\x8c?\xb8\xcd"""
                   +  """\xe0\x91a\xfc\xc1}\x06\x0f\x0c\xe3\x0fn4x\\\x18\x7fp\xa7\xc1\xc3\xc2\xf8"""
                   +  """\x83[\r\x1e\x15\xc6\x1f\xdck\xf0\xa00\xfe\xe0f\xe31\x81\xf1\x07w\x1b\x0f"""
                   +  """\t\x8c?\xb8\xddxD`\xfc\xc1\xfd\xc6\x03\x02\xe3\x0fn8\x1e\x0f\xc6\x1fp"""
                   +  """\xc7\xf1p0\xfe\x80[\x8eG\x83\xf1\x07\xdcs<\x18\x8c?\xe0\xa6\xe3\xb1`\xfc"""
                   +  """\x01w\x1d\x0f\x05\xe3\x0f\xb8\xedx$\x18\x7f\xc0}\xc7\x03\xc1\xf8\x03n<\x1e"""
                   +  """\x07\xc6\x1fp\xe7\xf100\xfe\x80[\x8fG\x81\xf1\x07\xdc{<\x08\x8c?\xe0\xe6"""
                   +  """\xe31`\xfc\xc1\xdd\x07\x0f\xc1\xf8\x03n?\x1e\x01\xc6\x1fp\xff\xf1\x000"""
                   +  """\xfe\x80\r\xc0\x1f\x1f\xe3\x0f\xd8\x01\xfc\xe11\xfe\x80-\xc0\x1f\x1d\x10e"""
                   +  """\xd8\x03\xfe\xe2\xf5\x13\x00F\x06z\x1e?\x01\x00\x08\x00\x00@\x00\x00\x00"""
                   +  """\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01"""
                   +  """\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00"""
                   +  """\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00\x10\x00\x00\x80\x00\x00"""
                   +  """\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00"""
                   +  """\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00"""
                   +  """\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10"""
                   +  """\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00@\x00\x00\x00\x02\x00\x00"""
                   +  """\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00"""
                   +  """\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x80\x00\x00\x00\x04"""
                   +  """\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00"""
                   +  """\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x01\xe0"""
                   +  """\'\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00"""
                   +  """\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00"""
                   +  """\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00"""
                   +  """\x00\x01\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00"""
                   +  """\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00"""
                   +  """\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00"""
                   +  """\x00\x00\x02\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00"""
                   +  """\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00"""
                   +  """\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00"""
                   +  """\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00\x08\x00\x00@\x00\x00\x00"""
                   +  """\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00"""
                   +  """\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80"""
                   +  """\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00\x10"""
                   +  """\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04"""
                   +  """\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00"""
                   +  """\x00\x10\x00\x00 \x00\xfc\x04\x00 \x00\x00\x00\x01\x00\x00\x08\x00"""
                   +  """\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00"""
                   +  """\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00"""
                   +  """\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00@\x00\x00\x00\x02"""
                   +  """\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01"""
                   +  """\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00"""
                   +  """\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00"""
                   +  """\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00"""
                   +  """\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00"""
                   +  """\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80"""
                   +  """\x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10"""
                   +  """\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00"""
                   +  """\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00"""
                   +  """\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x02\x00\x00\x10\x00"""
                   +  """\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00"""
                   +  """\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00"""
                   +  """\x02\x00\x00\x04\x80\x9f\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00"""
                   +  """\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00"""
                   +  """\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00"""
                   +  """\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00\x08\x00\x00@\x00"""
                   +  """\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00"""
                   +  """\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10"""
                   +  """\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00"""
                   +  """\x08\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00"""
                   +  """\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00"""
                   +  """\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08"""
                   +  """\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00 \x00\x00\x00\x01"""
                   +  """\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00"""
                   +  """\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00"""
                   +  """\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00@"""
                   +  """\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00"""
                   +  """\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00"""
                   +  """\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00"""
                   +  """\x00\x08\x00\x00@\x00\x00\x80\x00\xf0\x13\x00\x80\x00\x00\x00\x04"""
                   +  """\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00"""
                   +  """\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00"""
                   +  """\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x01"""
                   +  """\x00\x00\x08\x00\x00@\x00\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00"""
                   +  """\x00\x00\x04\x00\x00 \x00\x00\x00\x01\x00\x00\x08\x00\x00@\x00"""
                   +  """\x00\x00\x02\x00\x00\x10\x00\x00\x80\x00\x00\x00\x04\x00\x00 \x00"""
                   +  """\x00\x80m\xdb\x05KH\x88}\xc1\xc03\xc2\x00\x00\x00\x00IEND\xaeB`\x82"""
                  )


def _make_params(angle, size = None, background_rgb = None, scale = None, arrow_rgb = None) :
    size                = int(round(size  or SIZE))
    background_rgb      = background_rgb  or []
    scale               = scale           or 1.0
    arrow_rgb           = arrow_rgb       or [ 0, 0, 0 ]

    a10                 = int(round(angle * 10))

    if  not background_rgb :
        bgs = "transparent"
    else    :
        bgs = "rgb(%u,%u,%u)" % ( background_rgb[0], background_rgb[1], background_rgb[2] )

    acs     = "rgb(%u,%u,%u)" % ( arrow_rgb[0], arrow_rgb[1], arrow_rgb[2] )

    shva    = int(round(((450 - abs(450 - (a10 % 900))) / 450.0) * 160))

    if  not scale :
        sc      = size
        sco     = 0
    else        :
        sc      = int(round(size * scale))
        sco     = (size - sc) / 2

    return(angle, size, background_rgb, scale, arrow_rgb, a10, bgs, acs, shva, sc, sco)


def make_arrow_file_name(output_file_name_template, angle, size = None, background_rgb = None, scale = None, arrow_rgb = None) :
    ( angle, size, background_rgb, scale, arrow_rgb, a10, bgs, acs, shva, sc, sco ) = _make_params(angle, size, background_rgb, scale, arrow_rgb)

    ( n, ext )  = os.path.splitext(output_file_name_template)
    ext         = ext or ".png"
    if  ext    == "." :
        ext     = ".png"

    crc         = tzlib.blkcrc32(tzlib.INITIAL_CRC32_VALUE, str(bgs) + str(acs) + str(angle) + str(shva) + str(sc) + str(sco) + str(size))

    return("%s_%08x%s" % ( n, crc, ext ))



def get_run_convert_cmd(ifile_name, output_file_name, angle, size = None, background_rgb = None, scale = None, arrow_rgb = None) :
    ( angle, size, background_rgb, scale, arrow_rgb, a10, bgs, acs, shva, sc, sco ) = _make_params(angle, size, background_rgb, scale, arrow_rgb)

    #
    #           Note: I did the original arrow-up picture and fight-convert-cmd-line-param logic before realizing it would be been better to go mathematical rather than aviation degrees.
    #           So this little dance converts math degrees 0..360 in to aviation degrees where 0 is north and 90 is east.
    #
    angle   = angle % 360.0
    angle   = 360.0 - angle
    angle  += 90.0
    angle   = angle % 360.0

    return("""convert "%s" -background "%s" +level-colors "%s" -rotate %.1f -shave %ux%u -resize %ux%u -repage %ux%u+%u+%u -flatten "%s" """ % ( ifile_name, bgs, acs, angle, shva, shva, sc, size, size, size, sco, sco, output_file_name ))



def run_it(cl) :
    tz_os_priority.set_proc_to_idle_priority(1)

    if  os.system(cl) :
        sys.exit(1)
    pass

def run_cmd(cl) :
    if  multiprocessing :
        p           = multiprocessing.Process(target = run_it, args = ( cl, ))
        p.daemon    = True
        p.start()

        return(p)

    run_it(cl)

    return(None)


class   a_file_angle(object) :
    def __init__(me, fn, a, s) :
        me.file_name    = fn
        me.angle        = a or 0.0
        me.scale        = s or 1.0
    #   a_file_angle


def make_source_file(output_file_name_template) :
    tfn     = os.path.join(os.path.dirname(output_file_name_template), "make_16_arrows_%u_tmp.png" % os.getpid())
    tzlib.write_whole_binary_file(tfn, a000_512_png)

    return(tfn)


def do_convert(output_file_name_template, size = None, background_rgb = None, arrow_rgb = None) :
    tfn     = make_source_file(output_file_name_template)

    ofns    = []
    pa      = []
    for a in range(0, 3600, 225) :
        a   = a / 10.0
        for scale in [ 1.0, 0.75, 0.5 ] :
            ofn = make_arrow_file_name(    output_file_name_template, a, size = size, background_rgb = background_rgb, scale = scale, arrow_rgb = arrow_rgb)
            cmd = get_run_convert_cmd(tfn, ofn,                       a, size = size, background_rgb = background_rgb, scale = scale, arrow_rgb = arrow_rgb)
            ofns.append(a_file_angle(ofn, a, scale))
            # print cmd
            pa.append(run_cmd(cmd))
        pass

    for p in pa :
        if  p != None :
            p.join()
        pass

    os.remove(tfn)

    return(ofns)


#
#
#
if __name__ == '__main__' :

    import  sys

    import  TZCommandLineAtFile


    program_name    = sys.argv.pop(0)
    TZCommandLineAtFile.expand_at_sign_command_line_files(sys.argv)


    help_str    = """%s (options)   output_file_name_template

Create output_file_name_template_a0000.ext
       output_file_name_template_a0225.ext
       output_file_name_template_a0450.ext
       output_file_name_template_a0675.ext
       output_file_name_template_a0900.ext
       ...
       output_file_name_template_a3375.ext

where "ext" is the extension of output_file_name_template.

--size              n                       Set size in pixels of the square images. (default: %u)

--arrow             0xRRGGBB                Set arrow color.                         (default: black)
--arrow_red         n                       Set arrow red   value (0..255)
--arrow_green       n                       Set arrow green value (0..255)
--arrow_blue        n                       Set arrow blue  value (0..255)

--background        0xRRGGBB                Set background color.                    (default: transparent)
--background_red    n                       Set background red   value (0..255)
--background_green  n                       Set background green value (0..255)
--background_blue   n                       Set background blue  value (0..255)

""" % ( os.path.basename(program_name), SIZE )



    if  tzlib.array_find(sys.argv, [ "--help", "-h", "/?", "-?", ] ) >= 0 :
        print help_str
        sys.exit(254)


    bgrnd       = None
    red         = 255
    green       = 255
    blue        = 255

    acol        = None
    ared        = 0
    agreen      = 0
    ablue       = 0

    size        = SIZE

    a           = 0
    while a < len(sys.argv) :
        arg = sys.argv[a]

        if  (arg == "--size") or (arg == "-s") :
            del(sys.argv[a])
            size    = int(sys.argv.pop(a), 0)

        elif (arg == "--background") or (arg == "-b") :
            del(sys.argv[a])
            bg          = sys.argv.pop(a)
            if  bg.lower().startswith('t') :
                bgrnd   = None
            else        :
                bg      = int(bg, 0)
                red     = (bg >> 16) & 0xff
                green   = (bg >>  8) & 0xff
                blue    =  bg        & 0xff
                bgrnd   = True
            pass

        elif (arg == "--background_red") or (arg == "-br") :
            del(sys.argv[a])
            red     = int(sys.argv.pop(a), 0)
            bgrnd   = True

        elif (arg == "--background_green") or (arg == "-bg") :
            del(sys.argv[a])
            green   = int(sys.argv.pop(a), 0)
            bgrnd   = True

        elif (arg == "--background_blue") or (arg == "-bb") :
            del(sys.argv[a])
            blue    = int(sys.argv.pop(a), 0)
            bgrnd   = True

        elif (arg == "--arrow") or (arg == "-a") :
            del(sys.argv[a])
            ac          = sys.argv.pop(a)
            if  ac.lower().startswith('t') :
                acol    = None
            else        :
                ac      = int(ac, 0)
                ared    = (ac >> 16) & 0xff
                agreen  = (ac >>  8) & 0xff
                ablue   =  ac        & 0xff
                acol    = True
            pass

        elif (arg == "--arrow_red") or (arg == "-ar") :
            del(sys.argv[a])
            ared        = int(sys.argv.pop(a), 0)
            acol        = True

        elif (arg == "--arrow_green") or (arg == "-ag") :
            del(sys.argv[a])
            agreen      = int(sys.argv.pop(a), 0)
            acol        = True

        elif (arg == "--arrow_blue") or (arg == "-ab") :
            del(sys.argv[a])
            ablue       = int(sys.argv.pop(a), 0)
            acol        = True

        else :
            a          += 1

        pass


    if  len(sys.argv) != 1 :
        print "Please tell me the output file name template!"
        sys.exit(254)


    output_file_name_template   = sys.argv[0]

    bg                          = (bgrnd and [ red,  green,  blue  ]) or []
    ac                          = (acol  and [ ared, agreen, ablue ]) or []
    do_convert(output_file_name_template, size = size, background_rgb = bg, arrow_rgb = ac)

#
#
#
# eof
