Debian Codegraph @

system/idiserv/src/Xtest.c

raw symbols SCIP
1 /*===========================================================================
2 Copyright (C) 1990-2009 European Southern Observatory (ESO)
3
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.
8
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.
13
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,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28
29 /*
30 Xtest.c K.Banse 901206 creation
31
32 execute via: Xtest.exe [visual]
33 with visual = P (PseudoColor)
34 T (TrueColor)
35 D (DirectColor)
36 X (Default Visual)
37 ? (for help))
38
39
40 another way of obtaining the X11 capabilities of the display is to use
41 the command: xdpyinfo
42
43
44 090709 last modif
45
46 */
47
48 # include <stdio.h>
49 # include <stdlib.h>
50 # include <idi.h>
51 # include <x11defs.h>
52
53 unsigned int border = 2; /* pad border */
54 Window w, fw;
55
56 char *cpntr, root;
57
58 static char *display = "";
59 static char midas[6] = "MIDAS";
60 char cbuf[24], defbuf[24];
61
62 int once, i, j, k, n;
63 int redget[2], redput[2];
64 int option, dwidth, dheight, ddepth, reqclass;
65 int oldx, oldy, RGBord;
66 int xoff , yoff , status;
67 int cbufsiz, count;
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;
73 int swapit;
74
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;
79
80 GC gcimb, newgc;
81 XColor wh1, wh2, bbl1, bbl2, bl1, bl2, red1, red2;
82 XColor green1, green2, yel1, yel2, blu1, blu2;
83 XColor mag1, mag2, cyan1, cyan2;
84 XKeyEvent *xkeypntr;
85 XMappingEvent *mapevent;
86 XVisualInfo *vlist, *vl;
87 XImage *txima[2];
88 Status logstat;
89
90 static int visclass[6] = {TrueColor, DirectColor, PseudoColor,
91 StaticColor, GrayScale, StaticGray};
92
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";
96
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();
101 int getsomecols();
102
103 /*
104
105 */
106
107 int main(argc,argv)
108 int argc;
109 char *argv[];
110
111 {
112 int kargc;
113
114 char *disp_var, *kargv;
115
116
117
118 (void) printf("\n****** X Window test program of Midas ******\n");
119
120
121
122 /* Connect to X server */
123
124 #if vms
125 mydisp[0] = XOpenDisplay("DECW$DISPLAY");
126 #else
127
128 if (!(disp_var = getenv("DISPLAY")))
129 {
130 printf("\n<<<<< You have to set the variable DISPLAY first! >>>>>\n");
131 exit(1);
132 }
133 mydisp[0] = XOpenDisplay(display);
134 #endif
135
136 if (!mydisp[0])
137 {
138 printf("we got an error in XOpenDisplay!\n");
139 return (-1);
140 }
141
142
143 oldx = -99;
144 root = 0;
145 sys_colors = 0;
146 plot_colors = 0;
147
148 myscreen = DefaultScreen(mydisp[0]);
149 mywhite = WhitePixel(mydisp[0],myscreen);
150 myblack = BlackPixel(mydisp[0],myscreen);
151 rw[0] = RootWindow(mydisp[0],myscreen);
152
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);
160
161 option = 0;
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)
172 {
173 option = 2;
174 strcpy(defbuf,"TrueColor");
175 }
176 else if (myvis[0]->class == DirectColor)
177 {
178 option = 1;
179 strcpy(defbuf,"DirectColor");
180 }
181 else
182 {
183 printf("class looks exotic, value = %d\n",myvis[0]->class);
184 exit(1);
185 }
186
187 (void) printf("\nDefault Visual (id = 0x%x) is %s\n",(unsigned int) myvis[0]->visualid,defbuf);
188
189
190
191 /* get list of all possible Visuals */
192
193 vlist = XGetVisualInfo(mydisp[0],VisualNoMask,&vinfo,&nf);
194 if (nf < 1)
195 {
196 (void) printf("\nNo Visuals available...\n");
197 exit(1);
198 }
199
200
201 k = 0;
202 for (vl=vlist; vl<vlist+nf; vl++)
203 {
204 if (vl->screen == myscreen) k++;
205 }
206 (void) printf("\nNo. of Visuals: %d\n",k);
207
208 for (n=0; n<6; n++) visex[n] = 0; /* = 1 if exists */
209
210 for (vl=vlist; vl<vlist+nf; vl++)
211 {
212 if (vl->screen == myscreen)
213 {
214 for (n=0; n<6; n++)
215 {
216 if (vl->class == visclass[n])
217 {
218 if (visclass[n] == GrayScale)
219 {
220 strcpy(cbuf,"GrayScale"); /* j = 0 */
221 j = 0;
222 }
223 else if (visclass[n] == StaticGray)
224 {
225 strcpy(cbuf,"StaticGray"); /* j = 1 */
226 j = 1;
227 }
228 else if (visclass[n] == PseudoColor)
229 {
230 strcpy(cbuf,"PseudoColor"); /* j = 2 */
231 j = 2;
232 }
233 else if (visclass[n] == StaticColor)
234 {
235 strcpy(cbuf,"StaticColor"); /* j = 3 */
236 j = 3;
237 }
238 else if (visclass[n] == TrueColor)
239 {
240 strcpy(cbuf,"TrueColor"); /* j = 4 */
241 j = 4;
242 }
243 else if (visclass[n] == DirectColor)
244 {
245 strcpy(cbuf,"DirectColor"); /* j = 5 */
246 j = 5;
247 }
248 visex[j] ++;
249 if (visex[j] == 1)
250 {
251 visid[j] = vl->visualid;
252 visdepth[j] = vl->depth;
253 viscolsize[j] = vl->colormap_size;
254 }
255 }
256 }
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);
261 }
262 }
263
264 (void) printf("\n\n");
265
266
267 winfla = 1;
268
269 if (argc > 1)
270 {
271 cpntr = argv[1];
272 if ((*cpntr == '?') || (*cpntr == 'h'))
273 {
274 (void) printf("usage:\nXtest.exe arg1\n");
275 (void)
276 printf("arg1 = T for using TrueColor visual mode (if available)\n");
277 (void)
278 printf(" = D for using DirectColor visual mode (if available)\n");
279 (void) printf
280 (" = P for using PseudoColor visual mode - which is the default\n");
281 (void) printf
282 (" = P_L for using PseudoColor without color LUT\n");
283 (void) printf(" = X for using the default Visual\n");
284 (void) exit(1);
285 }
286
287 if ((*cpntr == 'T') || (*cpntr == 't'))
288 {
289 reqclass = TrueColor;
290 reqvis = 4;
291 option = 2;
292 }
293 else if ((*cpntr == 'D') || (*cpntr == 'd'))
294 {
295 reqclass = DirectColor;
296 reqvis = 5;
297 option = 1;
298 }
299 else if ((*cpntr == 'P') || (*cpntr == 'p'))
300 {
301 reqclass = PseudoColor;
302 reqvis = 2;
303 option = 0;
304 cpntr += 2;
305 if ((*cpntr == 'L') || (*cpntr == 'l')) option = -1;
306 }
307
308 else if ((*cpntr == 'X') || (*cpntr == 'x'))
309 {
310 reqvis = 99;
311 goto get_visual;
312 }
313
314 if (visex[reqvis] == -1)
315 {
316 printf("required visual not found...\n");
317 exit(1);
318 }
319 }
320
321 else
322 reqvis = 99; /* take the default visual */
323
324
325 get_visual:
326 getvisual(reqvis);
327
328
329 xdim = 512;
330 ydim = 512;
331 xoff = 0;
332 yoff = dheight - 1 - ydim - (2*border) + 200;
333
334
335 /* we have to set the border, background pixel (default is CopyFromParent,
336 which could lead to BadMatch) ... */
337
338 valuemask = CWBorderPixel | CWBackPixel | CWColormap | CWOverrideRedirect;
339 backpixel = myblack;
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);
347 if (w == 0)
348 {
349 printf("we got an error in XCreateWindow!\n");
350 exit(1);
351 }
352
353 XFlush (mydisp[0]);
354
355
356 /* set Window Manager hints */
357
358 xwmh.initial_state = NormalState;
359 xwmh.input = True;
360 xwmh.flags = InputHint | StateHint;
361 XSetWMHints(mydisp[0],w,&xwmh);
362
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;
367
368 kargc = 0;
369 XSetStandardProperties(mydisp[0],w,midas,midas,
370 None,&kargv,kargc,&myhint[0]);
371
372 gcimb = XCreateGC(mydisp[0],w,0,&xgcvals);
373 maska = 0xffffffff;
374 XSetBackground(mydisp[0],gcimb,0);
375 XSetForeground(mydisp[0],gcimb,0xffffffff);
376 XSetPlaneMask(mydisp[0],gcimb,maska);
377 XSetFunction(mydisp[0],gcimb,GXxor);
378
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]);
383
384 event_mask = KeyPressMask | PointerMotionMask | ButtonPressMask | ExposureMask;
385
386 XSync(mydisp[0],1);
387 XSelectInput(mydisp[0],w,event_mask);
388
389 XMapRaised (mydisp[0],w);
390
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);
394
395 XWindowEvent(mydisp[0],w,event_mask,&myevent);
396 XFlush (mydisp[0]);
397
398
399 /* prepare the image */
400
401 nf = ddepth; /* bitmap pad */
402 if (nf == 24) nf = 32;
403
404 txima[0] = XCreateImage(mydisp[0],myvis[0],ddepth,ZPixmap,0,None,
405 xdim,ydim,nf,0);
406
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");
414 else
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);
418
419
420 n = txima[0]->bytes_per_line * ydim;
421 txima[0]->data = malloc((size_t)n);
422
423 if (txima[0]->data == (char *)0)
424 {
425 (void) printf("problems allocating %d bytes\n",n);
426 exit(1);
427 }
428
429 txima[1] = XCreateImage(mydisp[0],myvis[0],ddepth,ZPixmap,0,None,
430 xdim,ydim,nf,0);
431 txima[1]->data = malloc((size_t)n);
432
433 if (txima[1]->data == (char *)0)
434 {
435 (void) printf("problems allocating %d bytes\n",n);
436 exit(1);
437 }
438
439
440
441 /***************************************************/
442 /* now build the image */
443 /***************************************************/
444
445 xoff = 0;
446 yoff = 0;
447 once = 0;
448 swapit = 0; /* swap bytes flag */
449 newgc = XCreateGC(mydisp[0],w,0,&xgcvals);
450
451 byte_swap_loop:
452 if (ddepth == 32)
453 redm = build32(txima[once]->data,xdim,ydim,root,1);
454 else if (ddepth == 24)
455 {
456 redm = build24(txima[once]->data,xdim,ydim,root,1);
457 redm = redm & 0x00ffffff;
458 }
459 else if (ddepth == 16)
460 {
461 redm = build16(txima[once]->data,xdim,ydim,root,1);
462 redm = redm & 0x0000ffff;
463 }
464 else
465 (void) build8(txima[once]->data,xdim,ydim,root,1);
466
467
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);
471
472 if (ddepth > 8)
473 {
474 redget[once] = mypixel;
475 redput[once] = redm;
476
477 yoff += 200;
478 once ++;
479
480 if (once < 2)
481 {
482 (void) findendian();
483
484 swapit = test_swap(mydisp[0]);
485 if (swapit == 0)
486 (void) printf("no byte swapping needed... \n");
487 else
488 (void) printf("Yes - byte swapping needed... \n");
489 if (swapit == 1) goto byte_swap_loop;
490 }
491 }
492
493 (void)
494 printf("\n>> move the pointer into the window + press any mouse button\n");
495 (void)
496 printf(">> the pointer should be a red arrow inside the mapped window\n");
497
498
499 /***************************************************/
500 /* now set up the event loop for mouse buttons */
501 /***************************************************/
502
503 event_loop:
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]);
507
508 switch (myevent.type)
509 {
510 case MotionNotify:
511 /* (void) printf(" the pointer moved ...\n"); */
512 event_mask = ButtonPressMask ;
513 XSync(mydisp[0],1);
514 XSelectInput(mydisp[0],w,event_mask);
515 goto event_loop;
516
517 case ButtonPress:
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)
522 {
523 n = 0; /* if within the 2 loaded images */
524 j = myevent.xbutton.y; /* get the pixel value */
525 if (j > 199)
526 {
527 j -= 200;
528 n = 1;
529 }
530 if (j < 200)
531 {
532 mypixel = XGetPixel(txima[n],myevent.xbutton.x,j);
533 printf("XGetPixel returns %x \n",(unsigned int)mypixel);
534 }
535
536 event_mask = ButtonPressMask ;
537 XSync(mydisp[0],1);
538 XSelectInput(mydisp[0],w,event_mask);
539 }
540 if (myevent.xbutton.button == 2)
541 {
542 XRecolorCursor(mydisp[0],mycurs[0][0],&bl1,&wh1);
543 XDefineCursor(mydisp[0],w,mycurs[0][0]);
544 XSetFunction(mydisp[0],gcimb,GXxor);
545 XFlush(mydisp[0]);
546 if (oldx != -99)
547 {
548 XDrawLine(mydisp[0],w,gcimb,0,oldy,511,oldy);
549 XDrawLine(mydisp[0],w,gcimb,oldx,0,oldx,511);
550 XFlush(mydisp[0]);
551 }
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 ;
557 XSync(mydisp[0],1);
558 XSelectInput(mydisp[0],w,event_mask);
559 }
560 if (myevent.xbutton.button == 3)
561 {
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");
566 goto next_step;
567 }
568 }
569 goto event_loop;
570
571 next_step:
572 (void) printf("\n");
573 XGetInputFocus(mydisp[0],&fw,&revert_to);
574 if (fw == None)
575 (void) printf("focus window = None\n");
576 else
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");
585 else
586 (void) printf("revert_to = %d (what is it?)\n",revert_to);
587
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");
592
593 XSetInputFocus(mydisp[0],w,RevertToParent,CurrentTime);
594 (void) printf("\n");
595
596 mapevent = (XMappingEvent *) &myevent;
597 xkeypntr = (XKeyEvent *) &myevent;
598 XRefreshKeyboardMapping(mapevent);
599 XSync(mydisp[0],1);
600 event_mask = KeyPressMask ;
601 XSync(mydisp[0],1);
602 XSelectInput(mydisp[0],w,event_mask);
603
604 nevent_loop:
605 XWindowEvent(mydisp[0],w,event_mask,&myevent);
606 cbufsiz = 20;
607
608 switch (myevent.type)
609 {
610 case KeyPress:
611 count = XLookupString(xkeypntr,cbuf,cbufsiz,&mykey,&xcstat);
612 cbuf[count] = '\0';
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);
616 if (mykey == XK_Up)
617 {
618 (void) printf("key is XK_Up\n");
619 curs_demo(w);
620 (void) printf("with pointer in the window\n");
621 (void) printf("press any key on the keyboard, RETURN to exit\n");
622 }
623 else if (mykey == XK_Down)
624 {
625 (void) printf("key is XK_Down\n");
626 text_demo(w,gcimb);
627 (void) printf("with pointer in the window\n");
628 printf("press any key on the keyboard, RETURN to exit\n");
629 }
630 else if (mykey == XK_Left)
631 (void) printf("key is XK_Left\n");
632 else if (mykey == XK_Right)
633 {
634 (void) printf("key is XK_Right\n");
635 own_test(1);
636 (void) printf("\npress any key on the keyboard, RETURN to exit\n");
637 }
638
639 if (mykey == XK_Return) goto end_of_it;
640 break;
641
642 case MappingNotify:
643 XRefreshKeyboardMapping(mapevent);
644 break;
645
646 default:
647 (void) printf("default case: eventtype = %d\n",myevent.type);
648 break;
649 }
650
651 goto nevent_loop;
652
653
654 end_of_it:
655 (void) printf("\n\nAdios muchachos - this is the end ... \n");
656
657 exit(0);
658 }
659
660 /*
661
662 */
663
664 int getvisual(novis)
665 int novis;
666
667 {
668 int isw;
669
670 void makeLUT(), makeRGBLUT();
671
672 char visbuf[16];
673
674
675
676 isw = 0;
677 if (novis == 99) /* we take the default visual */
678 {
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);
682 for (j=0; j<6; j++)
683 {
684 if (myvis[0]->visualid == visid[j])
685 {
686 colormapsize = viscolsize[j];
687 reqvis = j;
688 }
689 }
690 (void) printf("colormap_size = %d\n",colormapsize);
691 reqclass = myvis[0]->class;
692 }
693 else
694 {
695 if (novis == 5)
696 {
697 (void) strcpy(visbuf,"DirectColor");
698 isw = DirectColor;
699 }
700 else if (novis == 4)
701 {
702 (void) strcpy(visbuf,"TrueColor");
703 isw = TrueColor;
704 }
705 else
706 {
707 (void) strcpy(visbuf,"PseudoColor");
708 isw = PseudoColor;
709 }
710 ddepth = visdepth[novis];
711 }
712
713 (void) printf("\n****** using %s Mode ******\n\n",visbuf);
714
715
716 if (myvis[0]->class != reqclass)
717 {
718 logstat = XMatchVisualInfo(mydisp[0],myscreen,ddepth,isw,&vinfo);
719 if (logstat)
720 {
721 myvis[0] = vinfo.visual;
722 (void) printf
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;
726 }
727 else
728 {
729 printf("we could not get a %s Visual ...!\n",visbuf);
730 exit(1);
731 }
732 }
733
734
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",
739 redm,greenm,bluem);
740
741 if (redm < bluem)
742 {
743 RGBord = 0;
744 (void) printf("RGBord = %d (B G R)\n",RGBord);
745 }
746 else
747 {
748 RGBord = 1;
749 (void) printf("RGBord = %d (R G B)\n",RGBord);
750 }
751
752 count = myvis[0]->bits_per_rgb;
753 if (reqvis != 2)
754 {
755 redsz = greensz = bluesz = 0;
756 k = 0x0001; /* only bit 0 set */
757 for (n=0; n<ddepth; n++)
758 {
759 if ((redm & k) > 0) redsz ++;
760 if ((greenm & k) > 0) greensz ++;
761 if ((bluem & k) > 0) bluesz ++;
762 k = k << 1;
763 }
764 }
765
766 (void)
767 printf("bits_per_rgb = %d - redsz = %d, greensz = %d, bluesz = %d\n\n",
768 count,redsz,greensz,bluesz);
769
770
771 printf("option used internally for choosing colors = %d\n",option);
772
773 cmap[0][0] = DefaultColormap(mydisp[0],myscreen);
774 if (option < 1)
775 {
776 if (option == 0)
777 winfla = 0;
778 else
779 cmap[0][1] = XCreateColormap(mydisp[0],rw[0],myvis[0],AllocNone);
780 }
781 else
782 cmap[0][1] = XCreateColormap(mydisp[0],rw[0],myvis[0],AllocNone);
783
784
785 if (option == 1)
786 makeRGBLUT(myvis[0]->map_entries);
787 else if (option == 2)
788 getsomecols(1);
789 else
790 {
791 if (option == -1)
792 {
793 makeRGBLUT(myvis[0]->map_entries);
794 getsomecols(0);
795 }
796 else
797 makeLUT();
798 }
799
800 return 0;
801 }
802
803 /*
804
805 */
806
807 int build8(data,xsiz,ysiz,root,incr)
808 unsigned char *data, root, incr;
809 int xsiz, ysiz;
810
811 {
812 int nx,ny;
813
814 unsigned char shred, shgreen, shblue, modred, modgreen, modblue;
815 unsigned char pixval, jred, jgreen, jblue;
816 unsigned char *jdata, myroot;
817
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 */
820
821
822
823
824 myroot = 0;
825 jdata = data;
826
827 printf("\nbuilding 8 bit image...\n");
828
829 if (reqvis == 2) /* pseudocolor */
830 {
831 for (ny=0; ny<ysiz; ny++)
832 {
833 myroot = root;
834 for (nx=0; nx<xsiz; nx+=2)
835 {
836 *jdata++ = myroot;
837 *jdata++ = myroot;
838 myroot ++;
839 }
840 }
841 return (int) myroot;
842 }
843
844
845 /* here for true/direct colour with 8 bits */
846
847 if (RGBord != 1)
848 {
849 shred = shift80[0];
850 shgreen = shift80[1];
851 shblue = shift80[2];
852 }
853 else
854 {
855 shred = shift81[2];
856 shgreen = shift81[1];
857 shblue = shift81[0];
858 }
859
860 modred = 5; /* red size = 3 bits */
861 modgreen = 5; /* green size = 3 bits */
862 modblue = 6; /* blue size = 2 bits */
863
864
865 /* first we show a grayscale */
866
867 printf("displaying a grayscale band on top \n");
868
869 for (ny=0; ny<50; ny++)
870 {
871 myroot = (unsigned char) root; /* that should be a grayscale */
872 for (nx=0; nx<xsiz; nx+=2)
873 {
874 jred = jgreen = jblue = myroot;
875 jred = jred >> modred;
876 jgreen = jgreen >> modgreen;
877 jblue = jblue >> modblue;
878
879 jred = jred << shred;
880 jgreen = jgreen << shgreen;
881 jblue = jblue << shblue;
882 pixval = jred | jgreen | jblue;
883
884 *jdata++ = pixval;
885 *jdata++ = pixval;
886 myroot ++;
887 }
888 }
889
890
891 printf("displaying a scale in red below\n");
892
893 for (ny=0; ny<50; ny++)
894 {
895 myroot = (int) root; /* that should be a scale in red */
896 for (nx=0; nx<xsiz; nx+=2)
897 {
898 jred = myroot;
899 jred = jred >> modred;
900 jred = jred << shred;
901
902 *jdata++ = jred;
903 *jdata++ = jred;
904 myroot ++;
905 }
906 }
907
908
909 printf("displaying a scale in green below\n");
910
911 for (ny=0; ny<50; ny++)
912 {
913 myroot = (int) root; /* that should be a scale in green */
914 for (nx=0; nx<xsiz; nx+=2)
915 {
916 jgreen = myroot;
917 jgreen = jgreen >> modgreen;
918 jgreen = jgreen << shgreen;
919
920 *jdata++ = jgreen;
921 *jdata++ = jgreen;
922 myroot ++;
923 }
924 }
925
926
927 printf("displaying a scale in blue below\n");
928
929 for (ny=0; ny<50; ny++)
930 {
931 myroot = (int) root; /* that should be a scale in blue */
932 for (nx=0; nx<xsiz; nx+=2)
933 {
934 jblue = myroot;
935 jblue = jblue >> modblue;
936 jblue = jblue << shblue;
937
938 *jdata++ = jblue;
939 *jdata++ = jblue;
940 myroot ++;
941 }
942 }
943
944 return 0; /* return value not needed here */
945 }
946
947 /*
948
949 */
950
951 int build16(data,xsiz,ysiz,root,incr)
952
953 char *data, root, incr;
954 int xsiz, ysiz;
955
956 {
957 int nx, ny, retval;
958 short int pixval, jblue, jgreen, jred;
959 short int *jdata;
960 short int myroot, myincr;
961 short int shred, shgreen, shblue, modred, modgreen, modblue;
962
963 static int shift16[3] =
964 {
965 0, /* red/blue for RGBord 0/1 */
966 5, /* green */
967 11 /* blue/red for RGBord 0/1 */
968 };
969
970
971
972 pixval = 0;
973 jdata = (short int *) data;
974 myincr = (short int) incr;
975
976 printf("\nbuilding 16 bit image...\n");
977
978
979 if (RGBord != 1)
980 {
981 shred = shift16[0];
982 shgreen = shift16[1];
983 shblue = shift16[2];
984 }
985 else
986 {
987 shred = shift16[2];
988 shgreen = shift16[1];
989 shblue = shift16[0];
990 }
991
992 modred = 3; /* red size = 5 bits */
993 modgreen = 2; /* green size = 6 bits */
994 modblue = 3; /* blue size = 5 bits */
995
996
997 /* first we show a grayscale */
998
999 printf("displaying a grayscale band on top \n");
1000
1001 for (ny=0; ny<50; ny++)
1002 {
1003 myroot = (int) root; /* that should be a grayscale */
1004 for (nx=0; nx<xsiz; nx+=2)
1005 {
1006 jred = jgreen = jblue = myroot;
1007 jred = jred >> modred;
1008 jgreen = jgreen >> modgreen;
1009 jblue = jblue >> modblue;
1010
1011 jred = jred << shred;
1012 jgreen = jgreen << shgreen;
1013 jblue = jblue << shblue;
1014 pixval = jred | jgreen | jblue;
1015
1016 if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1017
1018 *jdata++ = pixval;
1019 *jdata++ = pixval;
1020 myroot ++;
1021 }
1022 }
1023
1024 printf("displaying a scale in red below - ");
1025
1026 for (ny=0; ny<50; ny++)
1027 {
1028 myroot = (int) root; /* that should be a scale in red */
1029 for (nx=0; nx<xsiz; nx+=2)
1030 {
1031 jred = myroot;
1032 jred = jred >> modred;
1033 jred = jred << shred;
1034 pixval = jred;
1035
1036 if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1037
1038 *jdata++ = pixval;
1039 *jdata++ = pixval;
1040 myroot ++;
1041 }
1042 }
1043
1044 printf("full red pixel: %x\n",pixval);
1045 retval = (int) pixval;
1046
1047 printf("displaying a scale in green below\n");
1048
1049 for (ny=0; ny<50; ny++)
1050 {
1051 myroot = (int) root; /* that should be a scale in green */
1052 for (nx=0; nx<xsiz; nx+=2)
1053 {
1054 jgreen = myroot;
1055 jgreen = jgreen >> modgreen;
1056 jgreen = jgreen << shgreen;
1057 pixval = jgreen;
1058
1059 if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1060
1061 *jdata++ = pixval;
1062 *jdata++ = pixval;
1063 myroot ++;
1064 }
1065 }
1066
1067 printf("displaying a scale in blue below\n");
1068
1069 for (ny=0; ny<50; ny++)
1070 {
1071 myroot = (int) root; /* that should be a scale in blue */
1072 for (nx=0; nx<xsiz; nx+=2)
1073 {
1074 jblue = myroot;
1075 jblue = jblue >> modblue;
1076 jblue = jblue << shblue;
1077 pixval = jblue;
1078
1079 if (swapit != 0) pixval = XSWAP_SHORT(pixval);
1080
1081 *jdata++ = pixval;
1082 *jdata++ = pixval;
1083 myroot ++;
1084 }
1085 }
1086
1087 return retval;
1088 }
1089
1090
1091 int build24(data,xsiz,ysiz,root,incr)
1092
1093 char *data, root, incr;
1094 int xsiz, ysiz;
1095
1096 {
1097 int *idata;
1098 int nx, ny, pixval, ired, igreen, iblue;
1099 int myroot, myincr, retval;
1100 int shred, shgreen, shblue, modred, modgreen, modblue;
1101
1102 static int shift24[3] =
1103 {
1104 0, /* red/blue for RGBord 0/1 */
1105 8, /* green */
1106 16 /* blue/red for RGBord 0/1 */
1107 };
1108
1109
1110
1111 pixval = 0;
1112 idata = (int *) data;
1113 myincr = (int) incr;
1114
1115 printf("\nbuilding 24 bit image...\n");
1116
1117
1118 if (RGBord != 1)
1119 {
1120 shred = shift24[0];
1121 shgreen = shift24[1];
1122 shblue = shift24[2];
1123 }
1124 else
1125 {
1126 shred = shift24[2];
1127 shgreen = shift24[1];
1128 shblue = shift24[0];
1129 }
1130 modred = modgreen = modblue = 0; /* all have size = 8 bits */
1131
1132
1133 /* first we show a grayscale */
1134
1135 printf("displaying a grayscale band on top \n");
1136
1137 for (ny=0; ny<50; ny++)
1138 {
1139 myroot = (int) root; /* that should be a grayscale */
1140 for (nx=0; nx<xsiz; nx+=2)
1141 {
1142 ired = igreen = iblue = myroot;
1143 ired = ired >> modred;
1144 igreen = igreen >> modgreen;
1145 iblue = iblue >> modblue;
1146
1147 ired = ired << shred;
1148 igreen = igreen << shgreen;
1149 iblue = iblue << shblue;
1150 pixval = ired | igreen | iblue;
1151
1152 if (swapit != 0) pixval = XSWAP_INT(pixval);
1153
1154 *idata++ = pixval;
1155 *idata++ = pixval;
1156 myroot ++;
1157 }
1158 }
1159
1160
1161 printf("displaying a scale in red below - ");
1162
1163 for (ny=0; ny<50; ny++)
1164 {
1165 myroot = (int) root; /* that should be a scale in red */
1166 for (nx=0; nx<xsiz; nx+=2)
1167 {
1168 ired = myroot;
1169 ired = ired >> modred;
1170 pixval = ired << shred;
1171
1172 if (swapit != 0) pixval = XSWAP_INT(pixval);
1173
1174 *idata++ = pixval;
1175 *idata++ = pixval;
1176 myroot ++;
1177 }
1178 }
1179
1180 printf("full red pixel: %x\n",pixval);
1181 retval = (int) pixval;
1182
1183 printf("displaying a scale in green below\n");
1184
1185 for (ny=0; ny<50; ny++)
1186 {
1187 myroot = (int) root; /* that should be a scale in green */
1188 for (nx=0; nx<xsiz; nx+=2)
1189 {
1190 igreen = myroot;
1191 igreen = igreen >> modgreen;
1192 pixval = igreen << shgreen;
1193
1194 if (swapit != 0) pixval = XSWAP_INT(pixval);
1195
1196 *idata++ = pixval;
1197 *idata++ = pixval;
1198 myroot ++;
1199 }
1200 }
1201
1202
1203 printf("displaying a scale in blue below\n");
1204
1205 for (ny=0; ny<50; ny++)
1206 {
1207 myroot = (int) root; /* that should be a scale in blue */
1208 for (nx=0; nx<xsiz; nx+=2)
1209 {
1210 iblue = myroot;
1211 iblue = iblue >> modblue;
1212 pixval = iblue << shblue;
1213
1214 if (swapit != 0) pixval = XSWAP_INT(pixval);
1215
1216 *idata++ = pixval;
1217 *idata++ = pixval;
1218 myroot ++;
1219 }
1220 }
1221
1222 return retval;
1223 }
1224
1225
1226 int build32(data,xsiz,ysiz,root,incr)
1227
1228 char *data, root, incr;
1229 int xsiz, ysiz;
1230
1231 {
1232 int nx,ny;
1233 int *jdata, pixval;
1234 int myroot, myincr;
1235
1236 char sroot;
1237
1238
1239 pixval = 0;
1240 jdata = (int *) data;
1241 myincr = (int) incr;
1242 sroot = root;
1243
1244 printf("\nbuilding 32 bit image...\n");
1245
1246 for (ny=0; ny<ysiz; ny++)
1247 {
1248 root = sroot;
1249 myroot = (long int) root;
1250 for (nx=0; nx<xsiz; nx+=2)
1251 {
1252 pixval = myroot;
1253 if (swapit != 0) pixval = XSWAP_INT(pixval);
1254
1255 *jdata++ = pixval;
1256 *jdata++ = pixval;
1257 myroot += pixval;
1258 }
1259 }
1260
1261 return pixval;
1262 }
1263 /*
1264
1265 */
1266
1267 int findendian(void)
1268
1269 {
1270 /* my own version:
1271
1272 int *endian;
1273 unsigned char hilo[4];
1274
1275 endian = (int *) &hilo[0];
1276 *endian = 0x1256abef;
1277
1278
1279 if (hilo[0] == 0x12)
1280 {
1281 printf("\nWe have a big-endian architecture\n");
1282 return 1;
1283 }
1284 else
1285 {
1286 printf("\nWe have a little-endian architecture\n");
1287 return 0;
1288 }
1289 */
1290
1291 /* the version from "Linux Kernel development": */
1292
1293 int x = 1;
1294
1295
1296
1297 if (* (char *) &x == 1)
1298 {
1299 printf("\nWe have a little-endian architecture\n");
1300 return 0;
1301 }
1302
1303 else
1304
1305 {
1306 printf("\nWe have a big-endian architecture\n");
1307 return 1;
1308 }
1309 }
1310
1311
1312
1313 /* function `test_swap()' is also stored in the IDI-library,
1314 so it can be used in Xwstinit() */
1315
1316 int test_swap(mydisp)
1317 Display *mydisp;
1318
1319 {
1320 int nn, mm;
1321 int *endian;
1322 unsigned char hilo[4];
1323
1324
1325
1326 /* find byte order at Xhost */
1327
1328 nn = XImageByteOrder(mydisp);
1329 if (nn == LSBFirst)
1330 nn = 0; /* least signif. byte first */
1331 else
1332 nn = 1; /* most signif. byte first */
1333
1334
1335 /* get byte order locally */
1336
1337 endian = (int *) &hilo[0];
1338 *endian = 0x1256abef;
1339 if (hilo[0] == 0x12)
1340
1341 /* the most significant byte (0x12) is stored first,
1342 we have a big-endian architecture */
1343 mm = 1;
1344
1345 else
1346
1347 /* the most significant byte (0x12) is stored last,
1348 we have a little-endian architecture */
1349 mm = 0;
1350
1351
1352 if (mm == nn)
1353 return 0;
1354 else
1355 return 1;
1356 }
1357 /*
1358
1359 */
1360
1361 int getsomecols(indx)
1362 int indx;
1363
1364 {
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);
1374
1375 printf
1376 ("XColor red: pixel = %8.8x, red = %d, green = %d, blue = %d\n",
1377 (int)red2.pixel,red2.red,red2.green,red2.blue);
1378 printf
1379 ("XColor green: pixel = %8.8x, red = %d, green = %d, blue = %d\n",
1380 (int)green2.pixel,green2.red,green2.green,green2.blue);
1381 printf
1382 ("XColor blue: pixel = %8.8x, red = %d, green = %d, blue = %d\n\n",
1383 (int)blu2.pixel,blu2.red,blu2.green,blu2.blue);
1384
1385 return 0;
1386 }
1387
1388 /*
1389
1390 */
1391
1392 void makeLUT()
1393
1394 {
1395 float lutval, rval, fval;
1396
1397
1398 k = 512;
1399
1400 color_loop: /* try to allocate `k' colors */
1401 x11stat = XAllocColorCells(mydisp[0],cmap[0][winfla],0,plane_mask,0,pixels,k);
1402 if (!x11stat)
1403 {
1404 k -= 2;
1405 if (k < 8)
1406 {
1407 printf("could not allocate at least %d colours... \n",k);
1408 k = 0;
1409 }
1410 else
1411 goto color_loop;
1412 }
1413
1414 jalloc = k;
1415 k = myvis[0]->map_entries - k;
1416
1417 if (jalloc > 256)
1418 {
1419 n = jalloc / 256;
1420 if (n > 4) n = 4; /* max 4 LUTs */
1421 jalloc = 256; /* max 256 colours */
1422 }
1423 else if (jalloc > 0)
1424 n = 1;
1425 else
1426 {
1427 jalloc = 256;
1428 n = 0;
1429 }
1430
1431 for (i=0; i<jalloc; i++)
1432 {
1433 mycolr[0][i].pixel = i;
1434 mycolr[0][i].flags = DoRed | DoGreen | DoBlue;
1435 }
1436
1437 getsomecols(winfla);
1438
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]);
1442
1443 /* get 16 default colours */
1444
1445 if (sys_colors > 0)
1446 {
1447 XQueryColors(mydisp[0],DefaultColormap(mydisp[0],myscreen),
1448 &mycolr[0][0],jalloc);
1449 XSync(mydisp[0],1);
1450
1451 if (mywhite > 2) /* we keep the high end of the LUT */
1452 {
1453 k = jalloc - sys_colors - plot_colors;
1454 ioff = 0;
1455 iend = k;
1456 }
1457 else /* we keep the low end of the LUT */
1458 {
1459 k = sys_colors;
1460 ioff = sys_colors + plot_colors;
1461 iend = jalloc;
1462 }
1463 kred = k + 2; /* save index */
1464 }
1465 else
1466 {
1467 ioff = 0;
1468 iend = jalloc;
1469 kred = 0;
1470 k = 0;
1471 }
1472
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;
1497
1498
1499 /* load grayscale LUT */
1500
1501 for (i=0; i<jalloc; i++) /* reset pixels */
1502 mycolr[0][i].pixel = pixels[i];
1503
1504 fval = 0.0;
1505 rval = 1.0 / (jalloc - sys_colors - plot_colors - 1);
1506
1507 for (i=ioff; i<iend; i++)
1508 {
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;
1513 fval += rval;
1514 }
1515
1516 XStoreColors(mydisp[0],cmap[0][winfla],mycolr[0],jalloc);
1517 XFlush(mydisp[0]);
1518
1519 if (sys_colors > 0)
1520 {
1521 printf("We copy %d system colours and use %d plot colours\n",
1522 sys_colors,plot_colors);
1523 jalloc -= (sys_colors+plot_colors);
1524 }
1525
1526 if (n == 0)
1527 {
1528 printf("so we can use no LUT for Midas - bye, bye...\n\n");
1529 exit(1);
1530 }
1531 else if (n == 1)
1532 printf("so we can use a LUT of %d colours.\n\n",jalloc);
1533 else
1534 {
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",
1541 n,jalloc);
1542 }
1543 }
1544
1545 /*
1546
1547 */
1548
1549 void makeRGBLUT(mplen)
1550 int mplen;
1551
1552 {
1553 int ifact, isw;
1554
1555
1556
1557 if (mplen>256) mplen=256;
1558
1559
1560 /* let's build a grayscale LUT */
1561
1562 ifact = 0xffff / (mplen - 1);
1563 j = 0;
1564 isw = 0;
1565 wh1.flags = DoRed | DoGreen | DoBlue;
1566
1567 for (i=0; i<mplen; i++)
1568 {
1569 wh1.red = wh1.green = wh1.blue = j;
1570 j += ifact;
1571
1572 if (XAllocColor(mydisp[0], cmap[0][winfla], &wh1)) isw++;
1573 }
1574
1575
1576 if (isw != mplen)
1577 {
1578 if (isw == 0)
1579 {
1580 (void) printf("No entries in LUT!\n");
1581 exit(1);
1582 }
1583 else
1584 (void)
1585 printf("Only %d entries in LUT (of size %d)!\n",isw,mplen);
1586 }
1587
1588 getsomecols(winfla);
1589 }
1590
1591 unsigned short int XSWAP_SHORT(jnni)
1592 unsigned short int jnni;
1593
1594 {
1595 unsigned short int ja, jb, jn;
1596
1597 jb = jnni & 0xff; /* input: ab */
1598 ja = (jnni >> 8) & 0xff;
1599
1600 jb = jb << 8;
1601 jn = jb | ja; /* output: ba */
1602
1603 return jn;
1604 }
1605
1606
1607
1608
1609 unsigned int XSWAP_INT(inni)
1610 unsigned int inni;
1611
1612 {
1613 unsigned short int ia, ib, ka, kb;
1614 unsigned int na, nb, nn;
1615
1616
1617 /* input: abcd */
1618
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 */
1623
1624 na = (unsigned int) ka;
1625 nb = (unsigned int) kb;
1626
1627 nb = nb << 16;
1628 nn = nb | na; /* output: dcba */
1629 return nn;
1630 }
1631