Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to display an image at regular intervals in a window ?

34 views
Skip to first unread message

Eric DELAGE's Office

unread,
Jun 30, 1999, 3:00:00 AM6/30/99
to
Hi,

I am processing video streams and I would like to display the results of
the algorithms in a window under the X Windows environment.

The video stream is made of two vertical/horizontal synchronization
signals and three color signals R/G/B. I would like to open the window
at the beginning of the simulation, display each pixel of the video
stream as soon as it is available (from left to right, then top to
bottom) and close the window at the end of the simulation.

Well ... I have many problems :

1.
All the examples are made of a main event loop! In my problem, there is
no interaction with the user. I would like to update the contents of the
window even if I haven't generated any event. How can I do ?

2.
However, I would like take care of some particular situations : how do I
know that the window is minimized ? how do I know that the window is
partly covered by another window ? Can I draw in the window without
taking care of such situations ? Are the conflicts resolved by the
X-Windows ?

3.
Based on few examples found on internet (there are not so many which
correspond exactly to my problem ... I could say that I have found
none), I have written a piece of code which does not work ;o) Could you
help me ?

Firstly, the border of a window appears but the XFillRectangle has no
result at all.
Secondly, I do not understand why I must request for an event to make
the window visible.

Thanks for your help.
Eric


.....................................................................

state -> theDisplay = XOpenDisplay (NULL);
if (state -> theDisplay == NULL) {
tss_printf(
"The instance %s failed to open the display.\n",
state -> InstanceName
);
return(TSS_ERROR);
}

state -> theScreen = DefaultScreen (state ->
theDisplay);
state -> theColormap = DefaultColormap (state ->
theDisplay, state -> theScreen);
state -> theRootWindow = RootWindow (state ->
theDisplay, state -> theScreen);
state -> theGC = DefaultGC (state ->
theDisplay, state -> theScreen);

XSetForeground(
state -> theDisplay,
state -> theGC,
WhitePixel(
state -> theDisplay,
state -> theScreen
)
);

XSetBackground(
state -> theDisplay,
state -> theGC,
BlackPixel(
state -> theDisplay,
state -> theScreen
)
);

state -> theViewWindow = XCreateWindow(
state -> theDisplay,
state -> theRootWindow,
0,
0,
256,
256,
0,
0,
CopyFromParent,
CopyFromParent,
0,
NULL
);

XMapWindow(
state -> theDisplay,
state -> theViewWindow
);

XSelectInput(
state -> theDisplay,
state -> theViewWindow,
ExposureMask
);

while(1) {
XEvent event;
XNextEvent (state -> theDisplay, &event);
HandleEvent (state, &event);
}

.........................................................................
...................

static void HandleEvent(
VIDEO_VIEWER_state_handleT state,
XEvent * event
) {
switch (event -> type) {
case Expose:
{
XExposeEvent *exposeevent = (XExposeEvent *) event;
if (exposeevent -> window == state -> theViewWindow) {

XSetForeground(
state -> theDisplay,
state -> theGC,
WhitePixel(
state -> theDisplay,
state -> theScreen
)
);

XFillRectangle(
state -> theDisplay,
state -> theViewWindow,
state -> theGC,
0,
0,
200,
200
);
}
}
break;
default:
break;
}
}


Munish Kumar

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to Eric DELAGE's Office
Eric,

For both problems 1 and 3 you can forcefully update the display by
calling XmUpdateDisplay(); either as soon as you update any window by
drawing or adding some contents or periodically by using
XtAppAddTimeout.

Regarding problem 2, I am not sure whether there should be any problem
drawing something in the drawing widget(s) when the window is minimized
or partially exposed since I see you already handling the expose event.
Any suggestions/pointers to this particular issue ??

Hope this helps.

regards
Munish

Chuck Dillon

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to Eric DELAGE's Office

Hi,

If I may, let me suggest a general methodology assuming an
implementation
using only X11 (with or without Xt/Motif). Your problem is separable
into two parts:

a) Rendering - You can write a code that allocates an offscreen pixmap
and render into it without the need to concern yourself with
events.

b) Display - All you need is a way to display an offscreen pixmap with
a periodic refresh.

I think you have a good handle on how to do the rendering and how you
could do it in an offscreen pixmap.

The simplest methodology of doing the display part is to simply create
a window that uses the pixmap as its background pixmap. Then the server
will take care of the display for you and the server will take care of
exposure conditions for you. All you need is a way to periodically ask
the server to refresh the window. A periodic call to XClearWindow will
do that. HOWEVER, note that if the pixmap is small (depending on the
server) the pixmap might get cached on the server side. If this happens
the refreshes will not reflect the current state of your pixmap. If
your
images are fairly large you may not see this problem. If they are
small,
rather than using XClearWindow you will need to re-assert the background
pixmap (XSetWindowBackgroundPixmap) forcing the server to update the
cache.

So in theory you could...

a) open the display (from Xlib or Xt level)
b) create a single simple window the size of your image. in Xt
you only need the application shell.
c) create a pixmap on the same visual of the same size.
d) specify that the window should use your pixmap as its background
pixmap.
e) realize/map the window.
f) render into the pixmap pausing periodically to use XClearWindow
or XSetWindowBackgroundPixmap to force an update.

If you don't see the caching problem you could improve performance by
only forcing updates of the portion of the pixmap that has changed. You
can do this with XClearArea.

This should get you something running pretty easily. When you attain
more X/Xt experience you can get more sophisticated on the display side.

Hope this helps...

ced

--
Charles E. Dillon
Senior Software Engineer
Genetics Computer Group, a subsidiary of Oxford Molecular

David B. Lewis

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to Eric DELAGE's Office
|> I am processing video streams and I would like to display the results of
|> the algorithms in a window under the X Windows environment.

It is probably best to use a server extension to do so, rather than convert
video to X Images.

|> 1.
|> All the examples are made of a main event loop! In my problem, there is
|> no interaction with the user. I would like to update the contents of the
|> window even if I haven't generated any event. How can I do ?

You can use XtAppAddInput, if the data is coming in that way,
and in the handler for that input render the images. Alternatively, you
can use Xt timers.

|> know that the window is minimized ? how do I know that the window is

It turns out that checking XtNiconic on the top-level shell works.

|> partly covered by another window ? Can I draw in the window without

Track the events.

|> taking care of such situations ? Are the conflicts resolved by the

Sure. The server clips.

|> Secondly, I do not understand why I must request for an event to make
|> the window visible.

You don't need to; your code selects for expose in order to know when to
fill the rectangle.

--
David B. Lewis Editor, The Motif Developer: http://www.motifzone.com/tmd/
d...@motifzone.com WebWrangler, The Motif Zone: http://www.motifzone.com/

0 new messages