Revert to numpy

This commit is contained in:
iabdalkader 2015-07-31 15:18:41 +02:00
parent 856938fea5
commit ccc4de8488
2 changed files with 16 additions and 18 deletions

View File

@ -483,8 +483,8 @@ class OMVGtk:
return True return True
if fb: if fb:
# create pixbuf from RGB888 # create pixbuf from np array
self.pixbuf =gtk.gdk.pixbuf_new_from_data(fb[2], gtk.gdk.COLORSPACE_RGB, False, 8, fb[0], fb[1], fb[0]*3) self.pixbuf = gtk.gdk.pixbuf_new_from_array(fb[2], gtk.gdk.COLORSPACE_RGB, 8)
self.pixbuf = self.pixbuf.scale_simple(fb[0]*SCALE, fb[1]*SCALE, gtk.gdk.INTERP_BILINEAR) self.pixbuf = self.pixbuf.scale_simple(fb[0]*SCALE, fb[1]*SCALE, gtk.gdk.INTERP_BILINEAR)
self.drawingarea.realize(); self.drawingarea.realize();
@ -677,7 +677,6 @@ class OMVGtk:
pass pass
self.save_config() self.save_config()
# exit # exit
sys.exit(0) sys.exit(0)

View File

@ -9,7 +9,7 @@ import struct
import sys,time import sys,time
import serial import serial
import platform import platform
from array import array import numpy as np
from PIL import Image from PIL import Image
#import pydfu on Linux #import pydfu on Linux
@ -48,9 +48,6 @@ def init(serial):
global __serial global __serial
__serial = serial __serial = serial
def _rgb(rgb):
return struct.pack("BBB", ((rgb & 0xF800)>>11)*255/31, ((rgb & 0x07E0)>>5)*255/63, (rgb & 0x001F)*255/31)
def fb_size(): def fb_size():
# read fb header # read fb header
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_SIZE, __FB_HDR_SIZE)) __serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_SIZE, __FB_HDR_SIZE))
@ -77,23 +74,25 @@ def fb_dump():
buff = __serial.read(num_bytes) buff = __serial.read(num_bytes)
if size[2] == 1: # Grayscale if size[2] == 1: # Grayscale
s = buff y = np.fromstring(buff, dtype=np.uint8)
buff = ''.join([y for yyy in zip(s, s, s) for y in yyy]) buff = np.column_stack((y, y, y))
elif size[2] == 2: #RGB565 elif size[2] == 2: # RGB565
arr = array('H', buff) arr = np.fromstring(buff, dtype=np.uint16).newbyteorder('S')
arr.byteswap() r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8)
buff = ''.join(map(_rgb, arr)) g = (((arr & 0x07E0) >>5) *255.0/63.0).astype(np.uint8)
b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8)
buff = np.column_stack((r,g,b))
else: # JPEG else: # JPEG
try: try:
buff = Image.frombuffer("RGB", (size[0], size[1]), buff, "jpeg", "RGB", "").tostring() buff = np.asarray(Image.frombuffer("RGB", size[0:2], buff, "jpeg", "RGB", ""))
except Exception as e: except Exception as e:
#print ("JPEG decode error (%s)"%(e)) print ("JPEG decode error (%s)"%(e))
return None return None
if (len(buff) != (size[0]*size[1]*3)): if (buff.size != (size[0]*size[1]*3)):
return None return None
return (size[0], size[1], buff) return (size[0], size[1], buff.reshape((size[1], size[0], 3)))
def fb_update(): def fb_update():
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_UPDATE, 0)) __serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_UPDATE, 0))