#!python

from PIL import Image

from ratr0.util import tiles, png_util
import argparse
import math

DESCRIPTION = """ratr0-makeplanes - Amiga bitplane extractor

This tool converts an indexed color PNG image into C source code containing its bitplanes"""

if __name__ == '__main__':
    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
                                     description=DESCRIPTION)
    parser.add_argument('pngfile', help="input PNG file")
    parser.add_argument('outfile', help="output C file")
    parser.add_argument('-ni', '--non_interleaved', action='store_true',
                        help="store data in interleaved manner")
    parser.add_argument('-fd', '--force_depth', type=int, default=None,
                        help="set depth to a value greater or equal the input image's value")
    parser.add_argument('-v', '--verbose', action='store_true', help="run in verbose mode")

    args = parser.parse_args()
    im = Image.open(args.pngfile)
    colors = png_util.make_colors(im, args.force_depth, args.verbose)
    print(colors)
    tiles.write_planes_to_c(im, args.outfile, colors,
                            non_interleaved=args.non_interleaved,
                            verbose=args.verbose)

