Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!bloom-beacon!MANATEE.CIS.UFL.EDU!kml From: kml@MANATEE.CIS.UFL.EDU (Kevin Lahey) Newsgroups: comp.windows.x Subject: Re: XPutImage monochrome image to color screen (sample program) Message-ID: <8904261720.AA00608@manatee.cis.ufl.edu> Date: 26 Apr 89 17:20:41 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 123 /* * A sample program to demonstrate my XPutImage problems. This program is * written using Xt, but I got the same sort of error when I used XPutImage * with just strictly X programming; i.e., I don't think it is a * toolkit problem. * * The problem: the program has no trouble displaying on a monochrome screen, * but on a color screen, I get strange results: the image is displayed * correctly, completely, but as soon as it is displayed, a vertical white * band is drawn on the image. This doesn't happen every time, but mostly * when I change the horizontal dimensions of the window, either with the * scroll bars or by changing the size of the window from the window manager. * * I'm running SunOS 4.0 on Sun3s and X11R3 with Purdue speedups. * I tried to make this example program minimalistic while still * retaining the same behavior as my program. With luck, I just missed * something subtle, and this isn't an X problem, although the program xim * hinted at this problem in the README and xviewsun contains a workaround, * but no comments. * * I appreciate mailed as well as posted responces: * Kevin Lahey UUCP: ...gatech!uflorida!beach.cis.ufl.edu!kml * University of Florida, CIS Internet: kml@beach.cis.ufl.edu */ #include #include #include #include #include void event_proc (); Display *display; Widget shell, view, canvas; XImage *image; main (argc, argv) int argc; char **argv; { int width = 400, height = 500; XWindowAttributes window_attributes; XtAppContext app_context; Arg arg_list [4]; XtSetArg(arg_list [0], XtNwidth, 200); XtSetArg(arg_list [1], XtNheight, 200); XtSetArg(arg_list [2], XtNallowVert, True); XtSetArg(arg_list [3], XtNallowHoriz, True); XtToolkitInitialize (); app_context = XtCreateApplicationContext (); display = XtOpenDisplay (app_context, NULL, "Sample", "xdemo", NULL, 0, &argc, argv); shell = XtAppCreateShell ("Sample", "xdemo", applicationShellWidgetClass, display, NULL, 0); view = XtCreateManagedWidget ("view", viewportWidgetClass, shell, arg_list, 4); XtSetArg(arg_list [0], XtNwidth, width); XtSetArg(arg_list [1], XtNheight, height); canvas = XtCreateManagedWidget ("canvas", widgetClass, view, arg_list, 2); XtAddEventHandler (canvas, ExposureMask, False, event_proc, 0); XtRealizeWidget (shell); create_image (width, height); XtAppMainLoop (app_context); } /* * Create a quick and dirty sample image for display. */ create_image (width, height) int width, height; { int i, bytes_wide; char *data; data = (char *) malloc (width * height); for (i = 0; i < width / 8; i++) data [i] = 204; for (i = 0; i < width / 8; i++) data [i + width / 8] = 51; for (i = 0; i < height / 2; i++) bcopy (data, data + i * width / 4, width / 4); image = XCreateImage (display, XDefaultVisualOfScreen(XtScreen(canvas)), 1, XYBitmap, 0, data, width, height, 8, width / 8); } /* * Handle the exposure event. */ void event_proc (w, client_data, event) Widget w; caddr_t client_data; XExposeEvent *event; { if (event->type == Expose) { printf ("At X = %d Y = %d width = %d height = %d\n", event->x, event->y, event->width, event->height); XPutImage (display, XtWindow(w), XDefaultGCOfScreen (XtScreen(canvas)), image, event->x, event->y, event->x, event->y, event->width, event->height); } }