ich habe ein grafik Display(132x65) und muss RGB-Werte, die mir die
Funktion image.load als Tupel liefert in einen INT im ARGB Format umwandeln.
Folgendes funktioniert zwar ist aber sicherlich von der Geschwindigkeit
her nicht optimal.
Kann mir jemand einen Tip geben was ich besser/schneller machen kann?
Code: Alles auswählen
from __future__ import division
import ctypes , sys, time, re
from PIL import Image, ImageColor, ImageDraw
color_map = { '10':'A', '11':'B', '12':'C', '13':'D', '14':'E', '15':'F' }
def get_parts(number):
parts = re.match("^([0-9]+)\.([0-9]+)", str(number))
return (parts.group(1), parts.group(2))
def get_hex(rgb_tuple):
hex_string = ''
for color in rgb_tuple:
quotient = str(color / 16)
first_a, first_b = get_parts(quotient)
second_a, second_b = get_parts(float("0." + first_b) * 16)
if color_map.has_key(first_a):
hex_string += color_map[first_a]
else:
hex_string += first_a
if color_map.has_key(second_a):
hex_string += color_map[second_a]
else:
hex_string += second_a
return hex_string
def load_pic(filename,x,y):
image = Image.open(filename)
pix = image.load()
for row in xrange(image.size[1]):
for column in xrange(image.size[0]):
pcol = int("FF" + get_hex(pix[column,row]),16)
libc.serdisp_setcolour(dd,column+x,row+y,pcol)
return 1