I use the libGD function gdImagePng(gdImagePtr im, FILE* fs) to pipe PNG images to the image viewer program feh from my program. I would like to be able to display an image and have control return to the calling process so that further images may be displayed in the same feh window.
I open a pipe to feh with
FILE* fs = popen("feh -", "w");
(the "-" tells feh to read from stdin), and then call
gdImagePng(im, fs);
to view the image. The image is indeed displayed in feh, but control does not return to the calling process until feh is closed.
Is there any way to force return of control to the caller, while keeping the pipe to the feh process open for subsequent image display? I have tried setting the pipe to non-blocking but this has no effect. Attempting to open the pipe with the "wb" attribute fails. Specifying the feh process as "feh - &" does not work either (the feh process does not appear to recognise the data as an image).
I do have a workaround: feh may be configured to auto-reload images when they change on disk, so I can start feh with a system() call to display an image written to a temporary file (say /tmp/tmp.png or /dev/shm/tmp.png) and repeatedly write different images to that file. This works, but is rather slow and clunky.
[Edit: this thread suggests to me that the implementation of feh may simply not accommodate what I am trying to achieve.]