1
/*===========================================================================
2
Copyright (C) 1990-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
30
Xtest.c K.Banse 901206 creation
32
execute via: Xtest.exe [visual]
33
with visual = P (PseudoColor)
40
another way of obtaining the X11 capabilities of the display is to use
53
unsigned int border = 2; /* pad border */
58
static char *display = "";
59
static char midas[6] = "MIDAS";
60
char cbuf[24], defbuf[24];
63
int redget[2], redput[2];
64
int option, dwidth, dheight, ddepth, reqclass;
65
int oldx, oldy, RGBord;
66
int xoff , yoff , status;
68
int nf, winfla, dplanes;
69
int colormapsize, sys_colors, plot_colors;
70
int kred, jalloc, ioff, revert_to, iend;
71
int visid[6], visex[6], visdepth[6], viscolsize[6];
72
int reqvis, redm, greenm, bluem, redsz, greensz, bluesz;
75
unsigned int xdim , ydim;
76
unsigned long int mywhite, myblack, pixels[256], plane_mask[2], maska;
77
unsigned long int valuemask;
78
long int backpixel, mypixel;
81
XColor wh1, wh2, bbl1, bbl2, bl1, bl2, red1, red2;
82
XColor green1, green2, yel1, yel2, blu1, blu2;
83
XColor mag1, mag2, cyan1, cyan2;
85
XMappingEvent *mapevent;
86
XVisualInfo *vlist, *vl;
90
static int visclass[6] = {TrueColor, DirectColor, PseudoColor,
91
StaticColor, GrayScale, StaticGray};
93
static char *red_col = "red", *bl_col = "black", *wh_col = "white";
94
static char *blu_col = "blue", *yel_col = "yellow", *green_col = "green";
95
static char *mag_col = "magenta", *cyan_col = "cyan";
97
unsigned short int XSWAP_SHORT();
98
unsigned int XSWAP_INT();
99
int getvisual(), build32(), build24(), build16(), build8();
100
int findendian(), test_swap(), curs_demo(), text_demo(), own_test();
114
char *disp_var, *kargv;
118
(void) printf("\n****** X Window test program of Midas ******\n");
122
/* Connect to X server */
125
mydisp[0] = XOpenDisplay("DECW$DISPLAY");
128
if (!(disp_var = getenv("DISPLAY")))
130
printf("\n<<<<< You have to set the variable DISPLAY first! >>>>>\n");
133
mydisp[0] = XOpenDisplay(display);
138
printf("we got an error in XOpenDisplay!\n");
148
myscreen = DefaultScreen(mydisp[0]);
149
mywhite = WhitePixel(mydisp[0],myscreen);
150
myblack = BlackPixel(mydisp[0],myscreen);
151
rw[0] = RootWindow(mydisp[0],myscreen);
153
dwidth = DisplayWidth(mydisp[0],myscreen);
154
dheight = DisplayHeight(mydisp[0],myscreen);
155
ddepth = DefaultDepth(mydisp[0],myscreen);
156
dplanes = DisplayPlanes(mydisp[0],myscreen);
157
printf ("\nOn screen %d we have:\n", myscreen);
158
printf("Display width, height, depth, no_planes = %d, %d, %d, %d \n",
159
dwidth,dheight,ddepth,dplanes);
162
myvis[0] = XDefaultVisual(mydisp[0],myscreen);
163
if (myvis[0]->class == GrayScale)
164
strcpy(defbuf,"GrayScale");
165
else if (myvis[0]->class == StaticGray)
166
strcpy(defbuf,"StaticGray");
167
else if (myvis[0]->class == PseudoColor)
168
strcpy(defbuf,"PseudoColor");
169
else if (myvis[0]->class == StaticColor)
170
strcpy(defbuf,"StaticColor");
171
else if (myvis[0]->class == TrueColor)
174
strcpy(defbuf,"TrueColor");
176
else if (myvis[0]->class == DirectColor)
179
strcpy(defbuf,"DirectColor");
183
printf("class looks exotic, value = %d\n",myvis[0]->class);
187
(void) printf("\nDefault Visual (id = 0x%x) is %s\n",(unsigned int) myvis[0]->visualid,defbuf);
191
/* get list of all possible Visuals */
193
vlist = XGetVisualInfo(mydisp[0],VisualNoMask,&vinfo,&nf);
196
(void) printf("\nNo Visuals available...\n");
202
for (vl=vlist; vl<vlist+nf; vl++)
204
if (vl->screen == myscreen) k++;
206
(void) printf("\nNo. of Visuals: %d\n",k);
208
for (n=0; n<6; n++) visex[n] = 0; /* = 1 if exists */
210
for (vl=vlist; vl<vlist+nf; vl++)
212
if (vl->screen == myscreen)
216
if (vl->class == visclass[n])
218
if (visclass[n] == GrayScale)
220
strcpy(cbuf,"GrayScale"); /* j = 0 */
223
else if (visclass[n] == StaticGray)
225
strcpy(cbuf,"StaticGray"); /* j = 1 */
228
else if (visclass[n] == PseudoColor)
230
strcpy(cbuf,"PseudoColor"); /* j = 2 */
233
else if (visclass[n] == StaticColor)
235
strcpy(cbuf,"StaticColor"); /* j = 3 */
238
else if (visclass[n] == TrueColor)
240
strcpy(cbuf,"TrueColor"); /* j = 4 */
243
else if (visclass[n] == DirectColor)
245
strcpy(cbuf,"DirectColor"); /* j = 5 */
251
visid[j] = vl->visualid;
252
visdepth[j] = vl->depth;
253
viscolsize[j] = vl->colormap_size;
257
j = vl->colormap_size;
258
(void) printf("visual id: 0x%x\n",(unsigned int)vl->visualid);
259
(void) printf(" class: %s\n",cbuf);
260
(void) printf(" depth: %d planes, colormap size: %d entries\n",vl->depth,j);
264
(void) printf("\n\n");
272
if ((*cpntr == '?') || (*cpntr == 'h'))
274
(void) printf("usage:\nXtest.exe arg1\n");
276
printf("arg1 = T for using TrueColor visual mode (if available)\n");
278
printf(" = D for using DirectColor visual mode (if available)\n");
280
(" = P for using PseudoColor visual mode - which is the default\n");
282
(" = P_L for using PseudoColor without color LUT\n");
283
(void) printf(" = X for using the default Visual\n");
287
if ((*cpntr == 'T') || (*cpntr == 't'))
289
reqclass = TrueColor;
293
else if ((*cpntr == 'D') || (*cpntr == 'd'))
295
reqclass = DirectColor;
299
else if ((*cpntr == 'P') || (*cpntr == 'p'))
301
reqclass = PseudoColor;
305
if ((*cpntr == 'L') || (*cpntr == 'l')) option = -1;
308
else if ((*cpntr == 'X') || (*cpntr == 'x'))
314
if (visex[reqvis] == -1)
316
printf("required visual not found...\n");
322
reqvis = 99; /* take the default visual */
332
yoff = dheight - 1 - ydim - (2*border) + 200;
335
/* we have to set the border, background pixel (default is CopyFromParent,
336
which could lead to BadMatch) ... */
338
valuemask = CWBorderPixel | CWBackPixel | CWColormap | CWOverrideRedirect;
340
sattributes.border_pixel = (unsigned long int) backpixel;
341
sattributes.background_pixel = (unsigned long int) backpixel;
342
sattributes.colormap = cmap[0][winfla];
343
sattributes.override_redirect = False;
344
w = XCreateWindow (mydisp[0],rw[0],
345
xoff, yoff, xdim, ydim, border,ddepth,
346
InputOutput,myvis[0],valuemask,&sattributes);
349
printf("we got an error in XCreateWindow!\n");
356
/* set Window Manager hints */
358
xwmh.initial_state = NormalState;
360
xwmh.flags = InputHint | StateHint;
361
XSetWMHints(mydisp[0],w,&xwmh);
363
myhint[0].x = xoff, myhint[0].y = yoff;
364
myhint[0].width = xdim;
365
myhint[0].height = ydim;
366
myhint[0].flags = USPosition | USSize;
369
XSetStandardProperties(mydisp[0],w,midas,midas,
370
None,&kargv,kargc,&myhint[0]);
372
gcimb = XCreateGC(mydisp[0],w,0,&xgcvals);
374
XSetBackground(mydisp[0],gcimb,0);
375
XSetForeground(mydisp[0],gcimb,0xffffffff);
376
XSetPlaneMask(mydisp[0],gcimb,maska);
377
XSetFunction(mydisp[0],gcimb,GXxor);
379
red1.pixel = mycolr[0][kred].pixel;
380
mycurs[0][0] = XCreateFontCursor(mydisp[0],XC_arrow);
381
XRecolorCursor(mydisp[0],mycurs[0][0],&red1,&wh1);
382
XDefineCursor(mydisp[0],w,mycurs[0][0]);
384
event_mask = KeyPressMask | PointerMotionMask | ButtonPressMask | ExposureMask;
387
XSelectInput(mydisp[0],w,event_mask);
389
XMapRaised (mydisp[0],w);
391
printf("we now make a %d*%d window\n",xdim,ydim);
392
xdim = 512, ydim = 200;
393
printf("and fill it with a %d*%d intensity image at the top\n",xdim,ydim);
395
XWindowEvent(mydisp[0],w,event_mask,&myevent);
399
/* prepare the image */
401
nf = ddepth; /* bitmap pad */
402
if (nf == 24) nf = 32;
404
txima[0] = XCreateImage(mydisp[0],myvis[0],ddepth,ZPixmap,0,None,
407
(void) printf("\nImage structure attributes:\n");
408
(void) printf("width = %d, height = %d\n",txima[0]->width,txima[0]->height);
409
(void) printf("xoffset = %d, format = %d\n",txima[0]->xoffset,txima[0]->format);
410
(void) printf("bitmap_unit = %d, bitmap_pad = %d, depth = %d\n",
411
txima[0]->bitmap_unit,txima[0]->bitmap_pad,txima[0]->depth);
412
if (txima[0]->byte_order == LSBFirst)
413
(void) strcpy(cbuf,"LSBFirst");
415
(void) strcpy(cbuf,"MSBFirst");
416
(void) printf("bytes_per_line = %d, bits_per_pixel = %d, byte_order = %s\n",
417
txima[0]->bytes_per_line,txima[0]->bits_per_pixel,cbuf);
420
n = txima[0]->bytes_per_line * ydim;
421
txima[0]->data = malloc((size_t)n);
423
if (txima[0]->data == (char *)0)
425
(void) printf("problems allocating %d bytes\n",n);
429
txima[1] = XCreateImage(mydisp[0],myvis[0],ddepth,ZPixmap,0,None,
431
txima[1]->data = malloc((size_t)n);
433
if (txima[1]->data == (char *)0)
435
(void) printf("problems allocating %d bytes\n",n);
441
/***************************************************/
442
/* now build the image */
443
/***************************************************/
448
swapit = 0; /* swap bytes flag */
449
newgc = XCreateGC(mydisp[0],w,0,&xgcvals);
453
redm = build32(txima[once]->data,xdim,ydim,root,1);
454
else if (ddepth == 24)
456
redm = build24(txima[once]->data,xdim,ydim,root,1);
457
redm = redm & 0x00ffffff;
459
else if (ddepth == 16)
461
redm = build16(txima[once]->data,xdim,ydim,root,1);
462
redm = redm & 0x0000ffff;
465
(void) build8(txima[once]->data,xdim,ydim,root,1);
468
XPutImage(mydisp[0],w,newgc,txima[once],0,0,xoff,yoff,xdim,ydim);
469
mypixel = XGetPixel(txima[once],510,70);
470
printf("XGetPixel returns %x at (510,70)\n",(unsigned int)mypixel);
474
redget[once] = mypixel;
484
swapit = test_swap(mydisp[0]);
486
(void) printf("no byte swapping needed... \n");
488
(void) printf("Yes - byte swapping needed... \n");
489
if (swapit == 1) goto byte_swap_loop;
494
printf("\n>> move the pointer into the window + press any mouse button\n");
496
printf(">> the pointer should be a red arrow inside the mapped window\n");
499
/***************************************************/
500
/* now set up the event loop for mouse buttons */
501
/***************************************************/
504
XWindowEvent(mydisp[0],w,event_mask,&myevent);
505
XRecolorCursor(mydisp[0],mycurs[0][0],&red1,&wh1);
506
XDefineCursor(mydisp[0],w,mycurs[0][0]);
508
switch (myevent.type)
511
/* (void) printf(" the pointer moved ...\n"); */
512
event_mask = ButtonPressMask ;
514
XSelectInput(mydisp[0],w,event_mask);
518
(void) printf(" button no., x, y, state: %d, %d, %d, %d \n",
519
myevent.xbutton.button,
520
myevent.xbutton.x,myevent.xbutton.y,myevent.xbutton.state);
521
if (myevent.xbutton.button == 1)
523
n = 0; /* if within the 2 loaded images */
524
j = myevent.xbutton.y; /* get the pixel value */
532
mypixel = XGetPixel(txima[n],myevent.xbutton.x,j);
533
printf("XGetPixel returns %x \n",(unsigned int)mypixel);
536
event_mask = ButtonPressMask ;
538
XSelectInput(mydisp[0],w,event_mask);
540
if (myevent.xbutton.button == 2)
542
XRecolorCursor(mydisp[0],mycurs[0][0],&bl1,&wh1);
543
XDefineCursor(mydisp[0],w,mycurs[0][0]);
544
XSetFunction(mydisp[0],gcimb,GXxor);
548
XDrawLine(mydisp[0],w,gcimb,0,oldy,511,oldy);
549
XDrawLine(mydisp[0],w,gcimb,oldx,0,oldx,511);
552
XDrawLine(mydisp[0],w,gcimb,0,myevent.xbutton.y,511,myevent.xbutton.y);
553
XDrawLine(mydisp[0],w,gcimb,myevent.xbutton.x,0,myevent.xbutton.x,511);
554
oldx = myevent.xbutton.x;
555
oldy = myevent.xbutton.y;
556
event_mask = ButtonPressMask ;
558
XSelectInput(mydisp[0],w,event_mask);
560
if (myevent.xbutton.button == 3)
562
(void) printf("\n>> with pointer in the window\n");
563
(void) printf(">> press any key on the keyboard (RETURN to exit),\n");
564
(void) printf(">> press 'up_arrow' for a demo of the X cursors,\n");
565
(void) printf(">> press 'down_arrow' for a demo of the X fonts\n");
573
XGetInputFocus(mydisp[0],&fw,&revert_to);
575
(void) printf("focus window = None\n");
577
(void) printf("focus window, root window, image window = %d, %d, %d\n",
578
(int)fw,(int)rw[0],(int)w);
579
if (revert_to == RevertToParent)
580
(void) printf("revert_to = RevertToParent\n");
581
else if (revert_to == RevertToPointerRoot)
582
(void) printf("revert_to = RevertToPointerRoot\n");
583
else if (revert_to == RevertToNone)
584
(void) printf("revert_to = RevertToNone\n");
586
(void) printf("revert_to = %d (what is it?)\n",revert_to);
588
(void) printf("\n>> with pointer in the window\n");
589
(void) printf(">> press any key on the keyboard (RETURN to exit),\n");
590
(void) printf(">> press 'up_arrow' for a demo of the X cursors,\n");
591
(void) printf(">> press 'down_arrow' for a demo of the X fonts\n");
593
XSetInputFocus(mydisp[0],w,RevertToParent,CurrentTime);
596
mapevent = (XMappingEvent *) &myevent;
597
xkeypntr = (XKeyEvent *) &myevent;
598
XRefreshKeyboardMapping(mapevent);
600
event_mask = KeyPressMask ;
602
XSelectInput(mydisp[0],w,event_mask);
605
XWindowEvent(mydisp[0],w,event_mask,&myevent);
608
switch (myevent.type)
611
count = XLookupString(xkeypntr,cbuf,cbufsiz,&mykey,&xcstat);
613
(void) printf("count, cbuf = %d, %s\n",count,cbuf);
614
(void) printf(".xkey.keycode = %d\n",myevent.xkey.keycode);
615
(void) printf(".xkey.x, .xkey.y = %d,%d\n",myevent.xkey.x,myevent.xkey.y);
618
(void) printf("key is XK_Up\n");
620
(void) printf("with pointer in the window\n");
621
(void) printf("press any key on the keyboard, RETURN to exit\n");
623
else if (mykey == XK_Down)
625
(void) printf("key is XK_Down\n");
627
(void) printf("with pointer in the window\n");
628
printf("press any key on the keyboard, RETURN to exit\n");
630
else if (mykey == XK_Left)
631
(void) printf("key is XK_Left\n");
632
else if (mykey == XK_Right)
634
(void) printf("key is XK_Right\n");
636
(void) printf("\npress any key on the keyboard, RETURN to exit\n");
639
if (mykey == XK_Return) goto end_of_it;
643
XRefreshKeyboardMapping(mapevent);
647
(void) printf("default case: eventtype = %d\n",myevent.type);
655
(void) printf("\n\nAdios muchachos - this is the end ... \n");
670
void makeLUT(), makeRGBLUT();
677
if (novis == 99) /* we take the default visual */
679
(void) printf("We take default Visual (id 0x%x) with default depth = %d,",
680
(unsigned int)myvis[0]->visualid,ddepth);
681
(void) strcpy(visbuf,defbuf);
684
if (myvis[0]->visualid == visid[j])
686
colormapsize = viscolsize[j];
690
(void) printf("colormap_size = %d\n",colormapsize);
691
reqclass = myvis[0]->class;
697
(void) strcpy(visbuf,"DirectColor");
702
(void) strcpy(visbuf,"TrueColor");
707
(void) strcpy(visbuf,"PseudoColor");
710
ddepth = visdepth[novis];
713
(void) printf("\n****** using %s Mode ******\n\n",visbuf);
716
if (myvis[0]->class != reqclass)
718
logstat = XMatchVisualInfo(mydisp[0],myscreen,ddepth,isw,&vinfo);
721
myvis[0] = vinfo.visual;
723
("We found %sVisual (id 0x%x) with depth = %d, colormap_size = %d\n",
724
visbuf,(unsigned int)vinfo.visualid,vinfo.depth,vinfo.colormap_size);
725
colormapsize = vinfo.colormap_size;
729
printf("we could not get a %s Visual ...!\n",visbuf);
735
redm = myvis[0]->red_mask;
736
greenm = myvis[0]->green_mask;
737
bluem = myvis[0]->blue_mask;
738
(void) printf("red_mask = %8.8x, green_mask = %8.8x, blue_mask = %8.8x\n",
744
(void) printf("RGBord = %d (B G R)\n",RGBord);
749
(void) printf("RGBord = %d (R G B)\n",RGBord);
752
count = myvis[0]->bits_per_rgb;
755
redsz = greensz = bluesz = 0;
756
k = 0x0001; /* only bit 0 set */
757
for (n=0; n<ddepth; n++)
759
if ((redm & k) > 0) redsz ++;
760
if ((greenm & k) > 0) greensz ++;
761
if ((bluem & k) > 0) bluesz ++;
767
printf("bits_per_rgb = %d - redsz = %d, greensz = %d, bluesz = %d\n\n",
768
count,redsz,greensz,bluesz);
771
printf("option used internally for choosing colors = %d\n",option);
773
cmap[0][0] = DefaultColormap(mydisp[0],myscreen);
779
cmap[0][1] = XCreateColormap(mydisp[0],rw[0],myvis[0],AllocNone);
782
cmap[0][1] = XCreateColormap(mydisp[0],rw[0],myvis[0],AllocNone);
786
makeRGBLUT(myvis[0]->map_entries);
787
else if (option == 2)
793
makeRGBLUT(myvis[0]->map_entries);
807
int build8(data,xsiz,ysiz,root,incr)
808
unsigned char *data, root, incr;
814
unsigned char shred, shgreen, shblue, modred, modgreen, modblue;
815
unsigned char pixval, jred, jgreen, jblue;
816
unsigned char *jdata, myroot;
818
unsigned char shift80[3] = { 0,3,6}; /* red,green,blue for RGBord 0 */
819
unsigned char shift81[3] = { 5,2,0}; /* red,green,blue for RGBord 1 */
827
printf("\nbuilding 8 bit image...\n");
829
if (reqvis == 2) /* pseudocolor */
831
for (ny=0; ny<ysiz; ny++)
834
for (nx=0; nx<xsiz; nx+=2)
845
/* here for true/direct colour with 8 bits */
850
shgreen = shift80[1];
856
shgreen = shift81[1];
860
modred = 5; /* red size = 3 bits */
861
modgreen = 5; /* green size = 3 bits */
862
modblue = 6; /* blue size = 2 bits */
865
/* first we show a grayscale */
867
printf("displaying a grayscale band on top \n");
869
for (ny=0; ny<50; ny++)
871
myroot = (unsigned char) root; /* that should be a grayscale */
872
for (nx=0; nx<xsiz; nx+=2)
874
jred = jgreen = jblue = myroot;
875
jred = jred >> modred;
876
jgreen = jgreen >> modgreen;
877
jblue = jblue >> modblue;
879
jred = jred << shred;
880
jgreen = jgreen << shgreen;
881
jblue = jblue << shblue;
882
pixval = jred | jgreen | jblue;
891
printf("displaying a scale in red below\n");
893
for (ny=0; ny<50; ny++)
895
myroot = (int) root; /* that should be a scale in red */
896
for (nx=0; nx<xsiz; nx+=2)
899
jred = jred >> modred;
900
jred = jred << shred;
909
printf("displaying a scale in green below\n");
911
for (ny=0; ny<50; ny++)
913
myroot = (int) root; /* that should be a scale in green */
914
for (nx=0; nx<xsiz; nx+=2)
917
jgreen = jgreen >> modgreen;
918
jgreen = jgreen << shgreen;
927
printf("displaying a scale in blue below\n");
929
for (ny=0; ny<50; ny++)
931
myroot = (int) root; /* that should be a scale in blue */
932
for (nx=0; nx<xsiz; nx+=2)
935
jblue = jblue >> modblue;
936
jblue = jblue << shblue;
944
return 0; /* return value not needed here */
951
int build16(data,xsiz,ysiz,root,incr)
953
char *data, root, incr;
958
short int pixval, jblue, jgreen, jred;
960
short int myroot, myincr;
961
short int shred, shgreen, shblue, modred, modgreen, modblue;
963
static int shift16[3] =
965
0, /* red/blue for RGBord 0/1 */
967
11 /* blue/red for RGBord 0/1 */
973
jdata = (short int *) data;
974
myincr = (short int) incr;
976
printf("\nbuilding 16 bit image...\n");
982
shgreen = shift16[1];
988
shgreen = shift16[1];
992
modred = 3; /* red size = 5 bits */
993
modgreen = 2; /* green size = 6 bits */
994
modblue = 3; /* blue size = 5 bits */
997
/* first we show a grayscale */
999
printf("displaying a grayscale band on top \n");
1001
for (ny=0; ny<50; ny++)
1003
myroot = (int) root; /* that should be a grayscale */
1004
for (nx=0; nx<xsiz; nx+=2)
1006
jred = jgreen = jblue = myroot;
1007
jred = jred >> modred;
1008
jgreen = jgreen >> modgreen;
1009
jblue = jblue >> modblue;
1011
jred = jred << shred;
1012
jgreen = jgreen << shgreen;
1013
jblue = jblue << shblue;
1014
pixval = jred | jgreen | jblue;
1016
if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1024
printf("displaying a scale in red below - ");
1026
for (ny=0; ny<50; ny++)
1028
myroot = (int) root; /* that should be a scale in red */
1029
for (nx=0; nx<xsiz; nx+=2)
1032
jred = jred >> modred;
1033
jred = jred << shred;
1036
if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1044
printf("full red pixel: %x\n",pixval);
1045
retval = (int) pixval;
1047
printf("displaying a scale in green below\n");
1049
for (ny=0; ny<50; ny++)
1051
myroot = (int) root; /* that should be a scale in green */
1052
for (nx=0; nx<xsiz; nx+=2)
1055
jgreen = jgreen >> modgreen;
1056
jgreen = jgreen << shgreen;
1059
if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1067
printf("displaying a scale in blue below\n");
1069
for (ny=0; ny<50; ny++)
1071
myroot = (int) root; /* that should be a scale in blue */
1072
for (nx=0; nx<xsiz; nx+=2)
1075
jblue = jblue >> modblue;
1076
jblue = jblue << shblue;
1079
if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1091
int build24(data,xsiz,ysiz,root,incr)
1093
char *data, root, incr;
1098
int nx, ny, pixval, ired, igreen, iblue;
1099
int myroot, myincr, retval;
1100
int shred, shgreen, shblue, modred, modgreen, modblue;
1102
static int shift24[3] =
1104
0, /* red/blue for RGBord 0/1 */
1106
16 /* blue/red for RGBord 0/1 */
1112
idata = (int *) data;
1113
myincr = (int) incr;
1115
printf("\nbuilding 24 bit image...\n");
1121
shgreen = shift24[1];
1122
shblue = shift24[2];
1127
shgreen = shift24[1];
1128
shblue = shift24[0];
1130
modred = modgreen = modblue = 0; /* all have size = 8 bits */
1133
/* first we show a grayscale */
1135
printf("displaying a grayscale band on top \n");
1137
for (ny=0; ny<50; ny++)
1139
myroot = (int) root; /* that should be a grayscale */
1140
for (nx=0; nx<xsiz; nx+=2)
1142
ired = igreen = iblue = myroot;
1143
ired = ired >> modred;
1144
igreen = igreen >> modgreen;
1145
iblue = iblue >> modblue;
1147
ired = ired << shred;
1148
igreen = igreen << shgreen;
1149
iblue = iblue << shblue;
1150
pixval = ired | igreen | iblue;
1152
if (swapit != 0) pixval = XSWAP_INT(pixval);
1161
printf("displaying a scale in red below - ");
1163
for (ny=0; ny<50; ny++)
1165
myroot = (int) root; /* that should be a scale in red */
1166
for (nx=0; nx<xsiz; nx+=2)
1169
ired = ired >> modred;
1170
pixval = ired << shred;
1172
if (swapit != 0) pixval = XSWAP_INT(pixval);
1180
printf("full red pixel: %x\n",pixval);
1181
retval = (int) pixval;
1183
printf("displaying a scale in green below\n");
1185
for (ny=0; ny<50; ny++)
1187
myroot = (int) root; /* that should be a scale in green */
1188
for (nx=0; nx<xsiz; nx+=2)
1191
igreen = igreen >> modgreen;
1192
pixval = igreen << shgreen;
1194
if (swapit != 0) pixval = XSWAP_INT(pixval);
1203
printf("displaying a scale in blue below\n");
1205
for (ny=0; ny<50; ny++)
1207
myroot = (int) root; /* that should be a scale in blue */
1208
for (nx=0; nx<xsiz; nx+=2)
1211
iblue = iblue >> modblue;
1212
pixval = iblue << shblue;
1214
if (swapit != 0) pixval = XSWAP_INT(pixval);
1226
int build32(data,xsiz,ysiz,root,incr)
1228
char *data, root, incr;
1240
jdata = (int *) data;
1241
myincr = (int) incr;
1244
printf("\nbuilding 32 bit image...\n");
1246
for (ny=0; ny<ysiz; ny++)
1249
myroot = (long int) root;
1250
for (nx=0; nx<xsiz; nx+=2)
1253
if (swapit != 0) pixval = XSWAP_INT(pixval);
1267
int findendian(void)
1273
unsigned char hilo[4];
1275
endian = (int *) &hilo[0];
1276
*endian = 0x1256abef;
1279
if (hilo[0] == 0x12)
1281
printf("\nWe have a big-endian architecture\n");
1286
printf("\nWe have a little-endian architecture\n");
1291
/* the version from "Linux Kernel development": */
1297
if (* (char *) &x == 1)
1299
printf("\nWe have a little-endian architecture\n");
1306
printf("\nWe have a big-endian architecture\n");
1313
/* function `test_swap()' is also stored in the IDI-library,
1314
so it can be used in Xwstinit() */
1316
int test_swap(mydisp)
1322
unsigned char hilo[4];
1326
/* find byte order at Xhost */
1328
nn = XImageByteOrder(mydisp);
1330
nn = 0; /* least signif. byte first */
1332
nn = 1; /* most signif. byte first */
1335
/* get byte order locally */
1337
endian = (int *) &hilo[0];
1338
*endian = 0x1256abef;
1339
if (hilo[0] == 0x12)
1341
/* the most significant byte (0x12) is stored first,
1342
we have a big-endian architecture */
1347
/* the most significant byte (0x12) is stored last,
1348
we have a little-endian architecture */
1361
int getsomecols(indx)
1365
XAllocNamedColor(mydisp[0],cmap[0][indx],wh_col,&wh1,&wh2) ;
1366
XAllocNamedColor(mydisp[0],cmap[0][indx],bl_col,&bl1,&bl2);
1367
XAllocNamedColor(mydisp[0],cmap[0][indx],bl_col,&bbl1,&bbl2);
1368
XAllocNamedColor(mydisp[0],cmap[0][indx],red_col,&red1,&red2);
1369
XAllocNamedColor(mydisp[0],cmap[0][indx],green_col,&green1,&green2);
1370
XAllocNamedColor(mydisp[0],cmap[0][indx],blu_col,&blu1,&blu2);
1371
XAllocNamedColor(mydisp[0],cmap[0][indx],yel_col,&yel1,&yel2);
1372
XAllocNamedColor(mydisp[0],cmap[0][indx],mag_col,&mag1,&mag2);
1373
XAllocNamedColor(mydisp[0],cmap[0][indx],cyan_col,&cyan1,&cyan2);
1376
("XColor red: pixel = %8.8x, red = %d, green = %d, blue = %d\n",
1377
(int)red2.pixel,red2.red,red2.green,red2.blue);
1379
("XColor green: pixel = %8.8x, red = %d, green = %d, blue = %d\n",
1380
(int)green2.pixel,green2.red,green2.green,green2.blue);
1382
("XColor blue: pixel = %8.8x, red = %d, green = %d, blue = %d\n\n",
1383
(int)blu2.pixel,blu2.red,blu2.green,blu2.blue);
1395
float lutval, rval, fval;
1400
color_loop: /* try to allocate `k' colors */
1401
x11stat = XAllocColorCells(mydisp[0],cmap[0][winfla],0,plane_mask,0,pixels,k);
1407
printf("could not allocate at least %d colours... \n",k);
1415
k = myvis[0]->map_entries - k;
1420
if (n > 4) n = 4; /* max 4 LUTs */
1421
jalloc = 256; /* max 256 colours */
1423
else if (jalloc > 0)
1431
for (i=0; i<jalloc; i++)
1433
mycolr[0][i].pixel = i;
1434
mycolr[0][i].flags = DoRed | DoGreen | DoBlue;
1437
getsomecols(winfla);
1439
printf("%d colours already allocated by the XWindow Manager\n",k);
1440
printf("first 5 color cells have index: %d, %d, %d, %d, %d\n",
1441
(int)pixels[0],(int)pixels[1],(int)pixels[2],(int)pixels[3],(int)pixels[4]);
1443
/* get 16 default colours */
1447
XQueryColors(mydisp[0],DefaultColormap(mydisp[0],myscreen),
1448
&mycolr[0][0],jalloc);
1451
if (mywhite > 2) /* we keep the high end of the LUT */
1453
k = jalloc - sys_colors - plot_colors;
1457
else /* we keep the low end of the LUT */
1460
ioff = sys_colors + plot_colors;
1463
kred = k + 2; /* save index */
1473
mycolr[0][k].red = wh1.red;
1474
mycolr[0][k].green = wh1.green;
1475
mycolr[0][k].blue = wh1.blue;
1476
mycolr[0][k+1].red = bl1.red;
1477
mycolr[0][k+1].green = bl1.green;
1478
mycolr[0][k+1].blue = bl1.blue;
1479
mycolr[0][k+2].red = red1.red;
1480
mycolr[0][k+2].green = red1.green;
1481
mycolr[0][k+2].blue = red1.blue;
1482
mycolr[0][k+3].red = green1.red;
1483
mycolr[0][k+3].green = green1.green;
1484
mycolr[0][k+3].blue = green1.blue;
1485
mycolr[0][k+4].red = blu1.red;
1486
mycolr[0][k+4].green = blu1.green;
1487
mycolr[0][k+4].blue = blu1.blue;
1488
mycolr[0][k+5].red = yel1.red;
1489
mycolr[0][k+5].green = yel1.green;
1490
mycolr[0][k+5].blue = yel1.blue;
1491
mycolr[0][k+6].red = mag1.red;
1492
mycolr[0][k+6].green = mag1.green;
1493
mycolr[0][k+6].blue = mag1.blue;
1494
mycolr[0][k+7].red = cyan1.red;
1495
mycolr[0][k+7].green = cyan1.green;
1496
mycolr[0][k+7].blue = cyan1.blue;
1499
/* load grayscale LUT */
1501
for (i=0; i<jalloc; i++) /* reset pixels */
1502
mycolr[0][i].pixel = pixels[i];
1505
rval = 1.0 / (jalloc - sys_colors - plot_colors - 1);
1507
for (i=ioff; i<iend; i++)
1509
lutval = fval * XLUTFACT;
1510
mycolr[0][i].red = (unsigned short) lutval;
1511
mycolr[0][i].green = (unsigned short) lutval;
1512
mycolr[0][i].blue = (unsigned short) lutval;
1516
XStoreColors(mydisp[0],cmap[0][winfla],mycolr[0],jalloc);
1521
printf("We copy %d system colours and use %d plot colours\n",
1522
sys_colors,plot_colors);
1523
jalloc -= (sys_colors+plot_colors);
1528
printf("so we can use no LUT for Midas - bye, bye...\n\n");
1532
printf("so we can use a LUT of %d colours.\n\n",jalloc);
1535
printf("We can use %d LUTs of %d colours each for Midas\n\n",n,jalloc);
1536
printf("You have to edit the file syskeys.dat (see the installation doc)");
1537
printf(" to modify\nthe contents of the keyword DAZDEVR:\n");
1538
printf("DAZDEVR(2) = %d, DAZDEVR(3) = %d\n",n,jalloc);
1539
printf("Another possibility is to execute the MIDAS command\n");
1540
printf("'initialize/display %d,%d' each time you get into MIDAS.\n\n",
1549
void makeRGBLUT(mplen)
1557
if (mplen>256) mplen=256;
1560
/* let's build a grayscale LUT */
1562
ifact = 0xffff / (mplen - 1);
1565
wh1.flags = DoRed | DoGreen | DoBlue;
1567
for (i=0; i<mplen; i++)
1569
wh1.red = wh1.green = wh1.blue = j;
1572
if (XAllocColor(mydisp[0], cmap[0][winfla], &wh1)) isw++;
1580
(void) printf("No entries in LUT!\n");
1585
printf("Only %d entries in LUT (of size %d)!\n",isw,mplen);
1588
getsomecols(winfla);
1591
unsigned short int XSWAP_SHORT(jnni)
1592
unsigned short int jnni;
1595
unsigned short int ja, jb, jn;
1597
jb = jnni & 0xff; /* input: ab */
1598
ja = (jnni >> 8) & 0xff;
1601
jn = jb | ja; /* output: ba */
1609
unsigned int XSWAP_INT(inni)
1613
unsigned short int ia, ib, ka, kb;
1614
unsigned int na, nb, nn;
1619
ib = (short int) (inni & 0xffff);
1620
kb = XSWAP_SHORT(ib); /* kb: dc */
1621
ia = (short int) ((inni >> 16) & 0xffff);
1622
ka = XSWAP_SHORT(ia); /* ka: ba */
1624
na = (unsigned int) ka;
1625
nb = (unsigned int) kb;
1628
nn = nb | na; /* output: dcba */