| From: WRKSYS::WOODS "Richard Woods DTN 223-1392" 11-JUL-1990 17:39:11.88
To: GOLDBERG
CC:
Subj: this is the Ultrix X server program that illustrates the possible bug
Richard,
Here is a small test program which behaves differently on a colour
VAXstation running the DECwindows server supplied with the version of
Ultrix 4.0 we are using to any other servers we have tried.
What the program does is to allocate colours in a similar fashion to
SoftPC and to then draw some colour bars using the XPutImage() call. This
program, along with SoftPC itself, ensures that the planes which are masked
out by the graphics context being used actually have the correct values
anyway, since this was found to be necessary on earlier versions of the
VAXstation colour DECwindows server; the behaviour noticed now seems to be
due to a different problem for which I cannot at this time see an easy
work-around for.
When the program starts up it outputs some information to stdout -
this has the following meaning:
depth = 8 - Depth of the display.
using 16 colours - The number of colours being used
plane_masks[0]=00000001 - The planes allocated to us by the server
plane_masks[1]=00000002
plane_masks[2]=00000004
plane_masks[3]=00000008
plane_mask = 0000000f - Previous values ORed together
pixels[0]=00000080 - Base pixel value allocated to us
pixels[1]=00000000
pixels[2]=00000000
pixels[3]=00000000
pixels[4]=00000000
pixels[5]=00000000
pixels[6]=00000000
pixels[7]=00000000
pixels[8]=00000000
pixels[9]=00000000
pixels[10]=00000000
pixels[11]=00000000
pixels[12]=00000000
pixels[13]=00000000
pixels[14]=00000000
pixels[15]=00000000
Colour cell 80 = (0000, 0000, 0000) Confirmation of what the program
Colour cell 81 = (0000, 0000, d600) has set the colour cell values to
Colour cell 82 = (0000, d600, 0000)
Colour cell 83 = (0000, d600, d600)
Colour cell 84 = (d600, 0000, 0000)
Colour cell 85 = (d600, 0000, d600)
Colour cell 86 = (d600, d600, 0000)
Colour cell 87 = (d600, d600, d600)
Colour cell 88 = (4e00, 4e00, 4e00)
Colour cell 89 = (0000, 0000, ff00)
Colour cell 8a = (0000, ff00, 0000)
Colour cell 8b = (0000, ff00, ff00)
Colour cell 8c = (ff00, 0000, 0000)
Colour cell 8d = (ff00, 0000, ff00)
Colour cell 8e = (ff00, ff00, 0000)
Colour cell 8f = (ff00, ff00, ff00)
col 0 : 10000000 Confirmation of the information in
col 1 : 10000001 the image buffer being passed to
col 2 : 10000010 the server for each column of the
col 3 : 10000011 colour bar - the binary values are
col 4 : 10000100 those of the colour cells selected
col 5 : 10000101 above
col 6 : 10000110
col 7 : 10000111
col 8 : 10001000
col 9 : 10001001
col 10 : 10001010
col 11 : 10001011
col 12 : 10001100
col 13 : 10001101
col 14 : 10001110
col 15 : 10001111
After printing this information, the program opens a window with sixteen
vertical colour bars, each 16 pixels wide. The colour sequence is:
L L L L L L L L H H H H H H H H
O O O O O O O O I I I I I I I I
B B G C R M Y W B B G C R M Y W
L L R Y E A E H L L R Y E A E H
A U E A D G L I A U E A D G L I
C E E N E L T C E E N E L T
K N N O E K N N O E
T W T W
A A
On the server that fails, you actually see:
H H H H L L L L H H H H L L L L
I I I I O O O O I I I I O O O O
W M C B W M C B W M C B W M C B
H A Y L H A Y L H A Y L H A Y L
I G A U I G A U I G A U I G A U
T E N E T E N E T E N E T E N E
E N E N E N E N
T T T T
A A A A
The actual source of the test program is at the bottom of this message.
Hope you are keeping well - see you,
Wayne Plummer
Insignia Solutions.
========================= C U T H E R E =====================================
/*
* Simple Test Program to observe the behaviour of XPutImage with XYPixmaps
*
* The program creates a window wide enough for sixteen colour bars, each BAR_WIDTH
* wide, and with a height of WIN_HEIGHT.
*
* It allocates four planes worth of colours use XAllocColorCells and sets the
* apropriate cells to the colours used by SoftPC.
*
* Upon the receipt of Expose events, the program clears the window to the first
* of the colours allocated and then makes a call to XPutImage to display the
* colour bars which have been set up in an image buffer pointed to by the
* variable "image_buffer"
*
* Wayne Plummer - July 1990
*/
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#define TRUE (0==0)
#define FALSE (0==1)
#define WIN_HEIGHT 200
#define BAR_WIDTH 16
/*
* Red, Green and Blue components for SoftPC palette...
*/
static unsigned r[] = { 0, 0, 0, 0, 55000, 55000, 55000, 55000,
20000, 0, 0, 0, 65535, 65535, 65535, 65535},
g[] = { 0, 0, 55000, 55000, 0, 0, 55000, 55000,
20000, 0, 65535, 65535, 0, 0, 65535, 65535},
b[] = { 0, 55000, 0, 55000, 0, 55000, 0, 55000,
20000, 65535, 0, 65535, 0, 65535, 0, 65535};
/*
* Various variables - apologies for lack of comments
*/
Display *dp; /* Pointer to display struct */
int scrn; /* Screen Pointer */
XSetWindowAttributes wa; /* Window Attributes */
Window win; /* Window ID */
Visual *vis; /* Pointer to Default Visual */
Colormap cmap; /* Our Color Map ID */
XColor col, col2; /* Colours */
char buff[80];
int i;
int depth;
int ncolours;
int nplanes;
int plane_masks[256];
int plane_mask;
int pixels[256];
GC mygc;
XEvent myevent;
XImage *image;
unsigned char *image_buffer;
/*
* The main function - note that no command line arguments are used
*/
main()
{
/* Open the display */
if ((dp = XOpenDisplay(NULL)) == NULL){
fprintf(stderr, "xtest: couldn't open display\n");
exit(1);
}
/* Get Default Screen Number */
scrn = DefaultScreen(dp);
/* Get Black pixel value */
wa.background_pixel = BlackPixel(dp, scrn);
/* Get default visual of the screen calculate depth (probably not the best way!) */
vis = XDefaultVisual(dp, scrn);
ncolours = vis->map_entries;
i = ncolours;
depth = 0;
while (i>1){
i>>=1;
depth++;
}
printf ("depth = %d\n", depth);
/* Decide how many colours we will use */
if (ncolours>16) ncolours = 16;
printf ("using %d colours\n", ncolours);
nplanes = depth;
if (nplanes>4) nplanes=4;
/* Create our window with a black background */
win = XCreateWindow(dp, DefaultRootWindow(dp), 0, 0, ncolours*BAR_WIDTH, WIN_HEIGHT,
0, CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel, &wa);
if (win == 0){
fprintf (stderr, "xtest: window painted shut!\n");
exit(1);
}
#ifdef OWN_MAP
/* Create Colour Map */
cmap = XCreateColormap(dp, win, vis, AllocNone);
if (cmap == 0){
fprintf(stderr, "xtest: couldn't get colour map\n");
exit(1);
}
#else
cmap = DefaultColormap (dp, 0);
#endif
/* Allocate the colours to ourselves */
i = XAllocColorCells(dp, cmap, TRUE, plane_masks, 4, pixels, 1);
if (i == 0){
fprintf(stderr, "xtest: couldn't allocate colours\n");
exit(1);
}
for (i=0; i<nplanes; i++){
printf ("\tplane_masks[%d]=%08x\n", i, plane_masks[i]);
plane_mask |= plane_masks[i];
}
printf ("plane_mask = %08x\n", plane_mask);
for (i=0; i<ncolours; i++){
printf ("\tpixels[%d]=%08x\n", i, pixels[i]);
}
/* Set Up Colours */
for (i=0; i<ncolours; i++){
col.pixel = pixels[0] | ((i&8) ? plane_masks[3] : 0) | ((i&4) ? plane_masks[2] : 0) |
((i&2) ? plane_masks[1] : 0) | ((i&1) ? plane_masks[0] : 0);
col.red = r[i];
col.green = g[i];
col.blue = b[i];
col.flags = (DoRed | DoGreen | DoBlue);
XStoreColor(dp, cmap, &col);
col2.pixel = col.pixel;
XQueryColor(dp, cmap, &col2);
printf ("Colour cell %02x = (%04x, %04x, %04x)\n", col.pixel, col2.red, col2.green, col2.blue);
pixels[i] = col.pixel;
}
#ifdef OWN_MAP
/* Associate the new color map with our window */
XSetWindowColorMap (dp, win, cmap);
#endif
/* Get the Image buffer */
image_buffer = (unsigned char *)malloc (depth * WIN_HEIGHT * ncolours * BAR_WIDTH / 8);
if (image_buffer == NULL){
printf ("No memory for image.\n");
exit (0);
}
/* Create the X Image structure */
image = XCreateImage (dp, vis, depth, XYPixmap, 0, image_buffer, ncolours*BAR_WIDTH, WIN_HEIGHT,
BitmapPad(dp), (ncolours*BAR_WIDTH+7)/8 );
if (image == NULL){
printf ("Failed to create X image.\n");
exit (0);
}
/* Now set up the image data */
{
int plane, row, col, byte;
int row_size = ncolours*(BAR_WIDTH/8);
int plane_size = row_size * WIN_HEIGHT;
int plane_select;
/* First set all planes to base pixel value... */
for (plane=0; plane<depth; plane++){
for (row=0; row<WIN_HEIGHT; row++){
for (col=0; col<ncolours; col++){
for (byte=0; byte<BAR_WIDTH/8; byte++){
image_buffer[(depth-plane-1)*plane_size + row*row_size + col*(BAR_WIDTH/8) + byte] =
((1<<plane) & pixels[0]) ? 0xFF : 0;
}
}
}
}
/* Now set up colour bar image in our planes */
plane_select = nplanes;
for (plane=0; plane<depth; plane++){
if ((1<<(depth-plane-1)) & plane_mask){
/* This plane is one of ours! */
plane_select--;
for (row=0; row<WIN_HEIGHT; row++){
for (col=0; col<ncolours; col++){
for (byte=0; byte<BAR_WIDTH/8; byte++){
image_buffer[plane*plane_size + row*row_size + col*(BAR_WIDTH/8) + byte] =
(col & (1<<plane_select)) ? 0xFF : 0;
}
}
}
}
}
/* Now output some values to check */
for (col=0; col<ncolours; col++){
printf ("col %d : ", col);
for (plane=0; plane<depth; plane++){
printf ("%01x", (image_buffer[plane*plane_size + col*(BAR_WIDTH/8)]) ? 1 : 0);
}
printf ("\n");
}
}
/* Draw the window on the display */
XMapRaised (dp, win);
/* Get Graphics Context */
mygc = XCreateGC (dp, win, 0, 0);
XSetState (dp, mygc, pixels[0], pixels[ncolours-1], GXcopy, AllPlanes);
XSelectInput (dp, win, ExposureMask);
/* Event Loop */
while(TRUE){
XNextEvent (dp, &myevent);
switch (myevent.type){
case Expose:
do_drawing();
break;
default:
printf (" Unexpected X event!\n");
break;
}
}
}
tidy_up()
{
/* Close the window */
XDestroyWindow(dp, win);
/* Close the display and exit */
XCloseDisplay(dp);
}
do_drawing()
{
XSetState (dp, mygc, pixels[0], pixels[ncolours-1], GXcopy, AllPlanes);
XSetForeground (dp, mygc, pixels[0]);
XFillRectangle (dp, win, mygc, 0, 0, ncolours*BAR_WIDTH, WIN_HEIGHT);
XSetState (dp, mygc, pixels[0], pixels[ncolours-1], GXcopy, plane_mask);
XPutImage (dp, win, mygc, image, 0, 0, 0, 0, ncolours*BAR_WIDTH, WIN_HEIGHT);
XFlush (dp);
XSync (dp, FALSE);
}
|