Another example that adds a little more to the previous one by showing how the Python Imaging Library (PIL) can be used.
Code:
from ctypes import *
import numpy
from PIL import Image
class DisplayInfo(Structure):
_fields_ = [("Width", c_uint),
("Height", c_uint),
("PixelFormat", c_uint),
("Name", c_char * 32),
("UName", c_char * 16),
("Handle", c_uint),
("Version", c_uint)]
USBD480_GetNumberOfDisplays = windll.USBD480_lib.USBD480_GetNumberOfDisplays
USBD480_GetNumberOfDisplays.restype = c_uint
USBD480_GetDisplayConfiguration = windll.USBD480_lib.USBD480_GetDisplayConfiguration
USBD480_GetDisplayConfiguration.restype = c_uint
USBD480_GetDisplayConfiguration.argtypes = [c_uint, POINTER(DisplayInfo)]
USBD480_Open = windll.USBD480_lib.USBD480_Open
USBD480_Open.restype = c_uint
USBD480_Open.argtypes = [POINTER(DisplayInfo), c_uint]
USBD480_Close = windll.USBD480_lib.USBD480_Close
USBD480_Close.restype = c_uint
USBD480_Close.argtypes = [POINTER(DisplayInfo)]
USBD480_DrawFullScreen = windll.USBD480_lib.USBD480_DrawFullScreen
USBD480_DrawFullScreen.restype = c_uint
USBD480_DrawFullScreen.argtypes = [POINTER(DisplayInfo), POINTER(c_char)]
USBD480_DrawFullScreenRGB32 = windll.USBD480_lib.USBD480_DrawFullScreenRGB32
USBD480_DrawFullScreenRGB32.restype = c_uint
USBD480_DrawFullScreenRGB32.argtypes = [POINTER(DisplayInfo), POINTER(c_uint)]
USBD480_SetBrightness = windll.USBD480_lib.USBD480_SetBrightness
USBD480_SetBrightness.restype = c_uint
USBD480_SetBrightness.argtypes = [POINTER(DisplayInfo), c_uint]
width = 480
height = 272
# define some basic colors, format is 0xAABBGGRR
RED = 0xFF0000FF
GREEN = 0xFF00FF00
BLUE = 0xFFFF0000
img = numpy.empty((width,height),numpy.uint32) # 480x272 image array
img.shape=height,width
img[10, 10] = BLUE # plot one point to the image
img[12, 10] = BLUE # plot one point to the image
img[12, 11] = BLUE # plot one point to the image
img[10:21,112:224] = GREEN # draw a green rectangle
#pilimg = Image.new('RGBA', (480,272))
pilImage = Image.fromarray(img,'RGBA') # load the numpy array as a PIL image
pilImage.save('my.png') # save to disk
pilImage.putpixel((100,100), (255,255,255,255)) # set a white pixel to 100, 100
image2 = Image.open('rgba.png') # load image from disk
pilImage.paste(image2, (190,110)) # paste this image to the buffer
arr = numpy.asarray(pilImage) # get a numpy array from the PIL image buffer
disp = DisplayInfo()
print USBD480_GetNumberOfDisplays()
print USBD480_GetDisplayConfiguration(0, disp)
print disp.Width
print disp.Height
print USBD480_Open(disp, 0)
#print USBD480_DrawFullScreenRGB32(disp, img.ctypes.data_as(POINTER(c_uint)))
print USBD480_DrawFullScreenRGB32(disp, arr.ctypes.data_as(POINTER(c_uint)))
#print USBD480_SetBrightness(disp, 255)
print USBD480_Close(disp)