python/image2h.py
def image_data_to_str(image_data,invert=False, has_alpha=False, primary=[255, 255, 255],
                      secondary=[], verbose=False):
   """
   Converts a PIL.Image object to a data string that is then added to the
   header file. String is hex values, lines terminated by "0x0a,\n"

   :param image_data PIL.Image: 
   :param invert bool: Invert the on/off colors in the returned data string.
   :param has_alpha bool: True of the image uses an alpha channel.
   :param primary list: RGB of primary color
   :param secondary list: RGB of secondary color 
   :param verbose bool: Enable additional debug output.
   :return: A string of hex values.
   :rtype str:
   """
   on = C2 if invert else C1
   off = C1 if invert else C2

   if has_alpha:
      primary = primary + [255]

      if secondary:
         secondary = secondary + [255]

   primary = tuple(primary)
   secondary = tuple(secondary)

   line = []
   data = ""
   for i, d in enumerate(image_data.getdata()):
         if verbose:
            print(i, d)

         if d == primary:
            line.append(on)
         elif secondary and d == secondary:
            line.append(C3)
         else:
            line.append(off)

         col = i + 1 
         if col % float(image_data.width) == 0:
            data = "".join([data, ','.join(line), ',', EOL, ',\n'])
            line = []

   data = "{}{}".format(data, EOF)

   return data

   Converts a PIL.Image object to a data string that is then added to the
   header file. String is hex values, lines terminated by "0x0a,\n"

   :param image_data PIL.Image: 
   :param invert bool: Invert the on/off colors in the returned data string.
   :param has_alpha bool: True of the image uses an alpha channel.
   :param primary list: RGB of primary color
   :param secondary list: RGB of secondary color 
   :param verbose bool: Enable additional debug output.
   :return: A string of hex values.
   :rtype str:
   
Converts a PIL.Image object to a data string that is then added to the
header file. String is hex values, lines terminated by "0x0a,\n"
Converts a PIL . Image object to a data string that is then added to the header file . String is hex values lines terminated by " 0x0a \ n "
def image_data_to_str(image_data,invert=False, has_alpha=False, primary=[255, 255, 255],
                      secondary=[], verbose=False):
   on = C2 if invert else C1
   off = C1 if invert else C2
   if has_alpha:
      primary = primary + [255]
      if secondary:
         secondary = secondary + [255]
   primary = tuple(primary)
   secondary = tuple(secondary)
   line = []
   data = ""
   for i, d in enumerate(image_data.getdata()):
         if verbose:
            print(i, d)
         if d == primary:
            line.append(on)
         elif secondary and d == secondary:
            line.append(C3)
         else:
            line.append(off)
         col = i + 1 
         if col % float(image_data.width) == 0:
            data = "".join([data, ','.join(line), ',', EOL, ',\n'])
            line = []
   data = "{}{}".format(data, EOF)
   return data
def image_data_to_str ( image_data , invert = False , has_alpha = False , primary = [ 255 , 255 , 255 ] , secondary = [ ] , verbose = False ) : on = C2 if invert else C1 off = C1 if invert else C2 if has_alpha : primary = primary + [ 255 ] if secondary : secondary = secondary + [ 255 ] primary = tuple ( primary ) secondary = tuple ( secondary ) line = [ ] data = "" for i , d in enumerate ( image_data . getdata ( ) ) : if verbose : print ( i , d ) if d == primary : line . append ( on ) elif secondary and d == secondary : line . append ( C3 ) else : line . append ( off ) col = i + 1 if col % float ( image_data . width ) == 0 : data = "" . join ( [ data , ',' . join ( line ) , ',' , EOL , ',\n' ] ) line = [ ] data = "{}{}" . format ( data , EOF ) return data
Converts a PIL.Image object to a data string that is then added to the
header file.
Converts a PIL . Image object to a data string that is then added to the header file .
"""
   Converts a PIL.Image object to a data string that is then added to the
   header file. String is hex values, lines terminated by "0x0a,\n"

   :param image_data PIL.Image: 
   :param invert bool: Invert the on/off colors in the returned data string.
   :param has_alpha bool: True of the image uses an alpha channel.
   :param primary list: RGB of primary color
   :param secondary list: RGB of secondary color 
   :param verbose bool: Enable additional debug output.
   :return: A string of hex values.
   :rtype str:
   """
A string of hex values.
A string of hex values .
image_data
invert
has_alpha
primary
secondary
verbose
PIL.Image
None
bool
Enable additional debug output.
Enable additional debug output .
list
RGB of secondary color
RGB of secondary color