extract a process_event function
extract duplicate pixel_buf init code