x393_tiff_verilog.py 1.91 KB
Newer Older
1 2
#!/usr/bin/env python
# encoding: utf-8
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
from __future__ import division
from __future__ import print_function

'''
# Copyright (C) 2015, Elphel.inc.
# Class to export hardware definitions from Verilog parameters  
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http:#www.gnu.org/licenses/>.

@author:     Andrey Filippov
@copyright:  2015 Elphel, Inc.
@license:    GPLv3.0+
@contact:    andrey@elphel.com
@deffield    updated: Updated
'''
__author__ = "Andrey Filippov"
__copyright__ = "Copyright 2015, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__status__ = "Development"
 
from PIL import Image
import sys
import numpy as np

40 41 42 43
try:
  fname = sys.argv[1]
except IndexError:
  fname = "/data_ssd/nc393/elphel393/fpga-elphel/x393/attic/hor-pairs-12b-1044x36.tiff"
44

45 46 47 48 49 50 51
try:
  digits = int(sys.argv[2])
except:
  digits = 3
try:
  outname = sys.argv[3]
except IndexError:
52
  outname = fname.replace(".tiff",".dat")  
53

54
tif = Image.open(fname)
55

56
image_array = np.array(tif)
57

58 59 60 61 62 63 64 65 66 67
f="%%0%dx"%(digits)
with open(outname,"w") as outfile:
    print("//",file=outfile)
    print("// autogenerated from %s"%(fname),file=outfile)
    print("//",file=outfile)
    for image_line in image_array:
        for pixel in image_line:
            print(f%(pixel), file=outfile, end = " ")
        print(file=outfile)
tif.close()
68

69
print ("All done!")
70