Working on a YUV-viewer in python using pygame
.
The code below displays one frame of YUV 4:2:0
#!/usr/bin/env python
import pygame
W = 352
H = 288
WH = (W, H)
pygame.init()
screen = pygame.display.set_mode(WH)
overlay = pygame.Overlay(pygame.YV12_OVERLAY, WH)
fd = open('foreman.yuv', 'rb')
y = fd.read(W * H)
u = fd.read(W * H / 4)
v = fd.read(W * H / 4)
overlay = pygame.Overlay(pygame.YV12_OVERLAY, WH)
overlay.display((y, u, v))
This code displays a 16x16 semi-transparent rectangle in position (0,0)
pygame.init()
screen = pygame.display.set_mode(WH)
s = pygame.Surface((16,16))
s.set_alpha(128)
s.fill((255,255,255))
screen.blit(s, (0,0))
pygame.display.flip()
But, how do I combine them? I.e. how do I display a semi-transparent rectangle in position (0,0) on top of the YUV-data so that the YUV-data can be seen through the rectangle?