How to include Piglet image area in PIL image?
My app reads frames from the video (using pyglet), extracts the "strip" (ie the area is 1 to 6 lines full width of video), then inserts each strip (appends it) into the image, which can then be written out to a file * .png.
The problem is that Pyglet GL images are stored in graphics memory, so their size is very limited. My current klunky workaround creates the current png image as small chunks (i.e. within the GL size limit of the piglet), when the tile is full, write it out to a * png file, read this as a PIL image file, then insert / add the image tiles into the final PIL Image * png file.
I believe it should be possible to convert the pyglet-GL bar to an image-compatible PIL format and insert / add that directly into the final PIL image, thus not having the need for the tile business, which greatly complicates things and has a performance impact.
But I can't seem to find how to get the strip data into a form that I can insert into a PIL image. I've seen a lot of requests change in a different way, but I've never run with a herd.
I know this is a bad form to answer one question of my own, but I have devised an answer that may be useful to others, so here it goes ...
nextframe = source.get_next_video_frame () # get the first video
snippet and nextframe! = None: # returns None in EOF
#
### extract strip data, conver to PIL Image-friendly form, paste itn into travo Image
#
strip = nextframe.get_region(0, (vid_frame_h//2)-(strip_h//2), strip_w, strip_h) # Extract strip from this frame
strip_image_data = strip.get_image_data()
strip_data = strip_image_data.get_data(strip_image_data.format, strip_image_data.pitch)
strip_Image = Image.frombuffer("RGB", (strip_w, strip_h), strip_data)
travo_image.paste(strip_Image, (0, travo_filled_to, strip_w, travo_filled_to + strip_h)) # paste strip image into travo_image
travo_filled_to = travo_filled_to + strip_h # update travo_filled pointer
nextframe = source.get_next_video_frame() # get next video frame (EOF returns None)