Debian Codegraph @

libsrc/idi/cidi/x11/idilocal1.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-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 * file idilocal1.c
31 *
32 * IDI Device Dependent Routines
33 * (version for XWindows release 11)
34 *
35 *
36 * V 1.00 880219 F.Pasian, P.Santin - Trieste Astronomical Observatory
37 * V 2.00 890102 K. Banse ESO - Garching
38 *
39 * Xwstinit : Connect to display + fill Xworkst structure;
40 * wr_lut : Write XWindows LUT;
41 * rd_lut : Read XWindows LUT;
42 * allo_mem : Allocate memory for "Display Channel"
43 * allo_zmem : Allocate memory for "Display Channel"
44 * get_hcopy : Get hardcopy
45 * smv : Set Memory Visibility : no scroll + zoom
46 * int_enable : Enable Interaction;
47 * int_disable : Disable Intaraction;
48 * exit_trg_enable : Enable Exit Trigger;
49 * wait_int : Wait for Interaction;
50 * trigsta : Test Trigger Status;
51
52 090424 last modif
53 ************************************************************************/
54
55 /*
56
57 */
58
59 #include <stdlib.h>
60 #include <stdio.h>
61
62 #include <idi.h>
63 #include <idistruct.h>
64 #include <x11defs.h>
65 #include <filedef.h>
66 #include <proto_idi.h>
67
68
69
70 static Bool discard = True;
71
72 static int error_X;
73 static int interact = 0;
74
75 static long int Def_Mask = (ExposureMask | StructureNotifyMask);
76
77 static float rval;
78
79 static Window mywindow;
80
81
82 /*
83 set up for "normal" case [*][0] and inverse byte order [*][1]
84 RGBord = 1: 0 R G B -> B G R 0 with inverse byte order
85 RGBord = 0: 0 B G R -> R G B 0 with inverse byte order
86 (lowest byte is right)
87 */
88
89 static int shift24[3][2] =
90 {
91 {0, 24}, /* red/blue for RGBord 0/1 */
92 {8, 16}, /* green */
93 {16, 8}, /* blue/red for RGBord 0/1 */
94 };
95
96 static int shift16[3] =
97 {
98 0, /* red/blue for RGBord 0/1 */
99 5, /* green */
100 11 /* blue/red for RGBord 0/1 */
101 };
102 /*
103
104 */
105
106 int myhandler(mydisp,myerr)
107
108 Display *mydisp;
109 XErrorEvent *myerr;
110
111 {
112 error_X = 1; /* indicate an error */
113 return (0);
114 }
115
116 /*
117
118 */
119
120 /* ---- Connect to Xserver + fill Xworkst stuff ----------------------*/
121
122 int Xwstinit(flg,screen,no,fono,minlut)
123 int flg; /* IN: 0 = first call
124 1 = second call for image window
125 2 = second call for graphics window
126 3 = ? */
127 int no, *fono, minlut;
128 char *screen; /* IN: name of display if flg=0
129 Pseudo or True if flg>0 */
130
131 {
132 unsigned long int plane_mask[1], pixels[256];
133 int ii, jalloc, sys_colors, plot_colors;
134 int isw, ddepth, tmpx, i, j, np, rgbset;
135 register int k, nr;
136
137 unsigned char tempa;
138 static char *plotcolors[9] =
139 { "black", "black", "white", "red", "green",
140 "blue", "yellow", "magenta", "cyan" };
141
142
143
144
145
146 /* ----------------- */
147 /* Connect to X server */
148 /* ----------------- */
149
150
151 if (flg == 0)
152 {
153 #ifdef vms
154 if (no == 0) /* index 0 reserved for "default" display */
155 mydisp[no] = XOpenDisplay("DECW$DISPLAY");
156 else
157 #endif
158
159 mydisp[no] = XOpenDisplay(screen);
160 if (!mydisp[no]) return(XCONNERR);
161
162 myscreen = DefaultScreen(mydisp[no]);
163 rw[no] = XRootWindow(mydisp[no],myscreen);
164 Xworkst[no].white = WhitePixel(mydisp[no],myscreen);
165 Xworkst[no].black = BlackPixel(mydisp[no],myscreen);
166
167
168 /* build up full byte of black pixels */
169
170 tempa = (unsigned char) Xworkst[no].black;
171 Xworkst[no].blmask = tempa;
172 for (i=0; i<8; i++)
173 {
174 Xworkst[no].blmask <<= 1;
175 Xworkst[no].blmask += tempa;
176 }
177
178 Xworkst[no].width = DisplayWidth(mydisp[no],myscreen);
179 Xworkst[no].height = DisplayHeight(mydisp[no],myscreen);
180 Xworkst[no].depth = DefaultDepth(mydisp[no],myscreen);
181 Xworkst[no].nobyt = -99; /* indicate, that it's not set yet */
182 Xworkst[no].lutsize = 0;
183 Xworkst[no].lutlen = 0;
184 Xworkst[no].auxcol = 0;
185 Xworkst[no].RGBord = 0;
186
187 return (II_SUCCESS);
188 }
189
190
191 /* ----------------- */
192 /* here for the 2. call of Xwstinit */
193 /* ----------------- */
194
195 /* get Fonts: first try given font no.s,
196 then fixed names, finally fixed names with wild card */
197
198 if (flg != 3)
199 {
200 k = font_load(0,no,fono); /* get Fonts */
201 if (k < 0) return(NOFONTS);
202 }
203
204 sys_colors = 0;
205 plot_colors = 0;
206
207 myvis[no] = XDefaultVisual(mydisp[no],myscreen);
208 rgbset = DoRed | DoGreen | DoBlue;
209
210 if (*screen == 'T')
211 {
212 isw = DirectColor;
213 ddepth = 24;
214 Xworkst[no].visual = 3;
215 Xworkst[no].lutflag = -1;
216 Xworkst[no].ownlut = -1; /* only display of LUT is o.k. */
217 Xworkst[no].nolut = 1;
218
219 if (myvis[no]->class != isw)
220 { /* we cannot use default visual */
221 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
222 if (!k)
223 {
224 isw = TrueColor;
225 if (myvis[no]->class != isw)
226 { /* also this not the default visual */
227 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
228 if (!k) return (BADVISUAL);
229
230 myvis[no] = vinfo.visual;
231 Xworkst[no].depth = vinfo.depth;
232 }
233 }
234 else
235 {
236 myvis[no] = vinfo.visual;
237 Xworkst[no].depth = vinfo.depth;
238 }
239 }
240
241 if (Xworkst[no].depth == 24 )
242 nr = 0x00ff0000;
243 else
244 nr = 0xff000000;
245 if (myvis[no]->red_mask == nr) Xworkst[no].RGBord = 1;
246 }
247
248 else
249 {
250 Xworkst[no].lutflag = 0;
251 Xworkst[no].ownlut = 1;
252
253 if (*(screen+1) == 'S') /* PseudoColor */
254 {
255 isw = PseudoColor;
256 Xworkst[no].visual = 2; /* visual = 2 for PseudoColor */
257 ddepth = 8;
258
259 if (myvis[no]->class != isw)
260 { /* we cannot use default visual */
261 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
262 if (!k) goto Pseudo_on_RGB; /* no Pseudo visual there! */
263
264 myvis[no] = vinfo.visual;
265 Xworkst[no].depth = vinfo.depth;
266 }
267 goto after_visual;
268 }
269
270 else if (*(screen+1) == 'D') /* PseudoColor on top of DirectColor */
271 isw = DirectColor;
272
273 else /* PseudoColor on top of TrueColor */
274 {
275 isw = TrueColor;
276 Xworkst[no].ownlut = 0;
277 }
278
279 if (myvis[no]->class != isw)
280 {
281 ddepth = 24;
282 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
283 if (!k) return (BADVISUAL);
284
285 myvis[no] = vinfo.visual;
286 Xworkst[no].depth = vinfo.depth;
287 }
288 goto setup_RGB;
289
290
291 /* first try PseudoColor on top of DirectColor and then on TrueColor */
292
293 Pseudo_on_RGB:
294 isw = DirectColor;
295 if (myvis[no]->class != isw)
296 {
297 ddepth = 24;
298 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
299 if (!k)
300 {
301 isw = TrueColor;
302 Xworkst[no].ownlut = 0;
303 if (myvis[no]->class != isw)
304 {
305 k = XMatchVisualInfo(mydisp[no],myscreen,ddepth,isw,&vinfo);
306 if (!k) return (BADVISUAL);
307
308 myvis[no] = vinfo.visual;
309 Xworkst[no].depth = vinfo.depth;
310 }
311 }
312 else
313 {
314 myvis[no] = vinfo.visual;
315 Xworkst[no].depth = vinfo.depth;
316 }
317 }
318
319 setup_RGB:
320 Xworkst[no].nolut = 1;
321 Xworkst[no].visual = 4;
322
323 /* A 16-bit truecolor emulation of pseudo should really be >= 256 cells */
324
325 if (myvis[no]->class == TrueColor && Xworkst[no].depth == 16
326 && myvis[no]->map_entries <= 256)
327 {
328 (void) printf("16 bit display: no. of cells = %d, will be set to 256\n",
329 myvis[no]->map_entries);
330 myvis[no]->map_entries = 256;
331 }
332
333 Xworkst[no].lutsize = myvis[no]->map_entries;
334 if (Xworkst[no].depth == 16 )
335 nr = 0x00f800;
336 else
337 nr = 0x00ff0000;
338 if (myvis[no]->red_mask == nr) Xworkst[no].RGBord = 1;
339 }
340
341
342
343 /* we don't work with less than 8 bits/pixel anymore... (980112) */
344
345 after_visual:
346 if (Xworkst[no].depth < 8) return (BADXWTYPE);
347
348
349 for (nr=0; nr<256; nr++)
350 {
351 Xworkst[no].mapin[nr] = Xworkst[no].mapout[nr] = nr;
352 }
353
354
355 if (myvis[no]->class != PseudoColor)
356 {
357 Xworkst[no].nobyt = 3;
358
359 if (myvis[no]->class == DirectColor)
360 {
361 cmap[no][0] = XCreateColormap(mydisp[no],rw[no],myvis[no],AllocNone);
362
363 if (Xworkst[no].visual == 3)
364 {
365 Xworkst[no].lutsize = 256;
366 k = buildRGBLUT(no,Xworkst[no].lutsize,mycolr[no],pixels);
367 if (k < 16) return (NOCOLALLO);
368 Xworkst[no].lutsize = k;
369
370 for (i=0; i<9; i++)
371 {
372 fixcolr[no][i].flags = rgbset;
373 x11stat = XAllocNamedColor(mydisp[no],cmap[no][0],plotcolors[i],
374 &exact,&fixcolr[no][i]);
375 }
376 }
377
378 else /* PseudoColor on DirectColor */
379 {
380 plot_colors = 9;
381 for (ii=0; ii<plot_colors;ii++)
382 {
383 x11stat = XAllocNamedColor(mydisp[no],cmap[no][0],plotcolors[ii],
384 &exact,&fixcolr[no][ii]);
385 if (!x11stat)
386 {
387 (void) printf
388 ("could not allocate NamedColor %s\n",plotcolors[ii]);
389 return(NOCOLALLO);
390 }
391 pixels[ii] = fixcolr[no][ii].pixel;
392 }
393 plane_mask[0] = 0; /* free the color cells */
394 XFreeColors(mydisp[no],cmap[no][0],pixels,plot_colors,plane_mask[0]);
395
396 ii = Xworkst[no].lutsize + plot_colors;
397 k = buildRGBLUT(no,ii,mycolr[no],pixels);
398 if (k < 16) return (NOCOLALLO);
399 Xworkst[no].lutsize = k;
400
401 for (nr=0,j=0; j<plot_colors; nr++,j++)
402 {
403 mycolr[no][nr].red = fixcolr[no][j].red;
404 mycolr[no][nr].green = fixcolr[no][j].green;
405 mycolr[no][nr].blue = fixcolr[no][j].blue;
406 fixcolr[no][j].pixel = pixels[nr];
407 }
408 XStoreColors(mydisp[no],cmap[no][0],&mycolr[no][0],plot_colors);
409
410 Xworkst[no].lutflag = 1;
411 }
412 }
413
414 else /* TrueColor - no change of colors possible */
415 {
416 cmap[no][0] = XCreateColormap(mydisp[0],rw[no],myvis[no],AllocNone);
417
418 plot_colors = 9;
419 for (ii=0; ii<plot_colors;ii++)
420 {
421 x11stat = XAllocNamedColor(mydisp[no],cmap[no][0],plotcolors[ii],
422 &exact,&fixcolr[no][ii]);
423 if (!x11stat)
424 {
425 (void) printf
426 ("could not allocate NamedColor %s\n",plotcolors[ii]);
427 return(NOCOLALLO);
428 }
429 pixels[ii] = fixcolr[no][ii].pixel;
430 }
431 }
432
433
434 /*
435 Xworkst[no].auxcol = plot_colors;
436 Xworkst[no].lutlen = Xworkst[no].lutsize - Xworkst[no].auxcol;
437 */
438 Xworkst[no].lutlen = Xworkst[no].lutsize;
439 goto after_colors;
440 }
441
442 else
443 {
444 Xworkst[no].lutlen = 2 << (Xworkst[no].depth-1);
445 if (Xworkst[no].depth > 8)
446 Xworkst[no].nobyt = 2;
447 else
448 Xworkst[no].nobyt = 1;
449 }
450
451
452 LUTretry:
453 Xworkst[no].auxcol = sys_colors + plot_colors;
454
455 np = 0;
456
457
458 if (Xworkst[no].lutflag == 0)
459 {
460 for (i=0; i<Xworkst[no].nolut; i++)
461 {
462 jalloc = Xworkst[no].lutsize;
463 cmap[no][i] = DefaultColormap(mydisp[no],myscreen);
464
465 if (Xworkst[no].ownlut == -1) /* we only do it for i = 0 */
466 {
467 Xworkst[no].lutlen = Xworkst[no].lutsize;
468 for (ii=0; ii<9;ii++)
469 x11stat = XAllocNamedColor(mydisp[no],cmap[no][i],plotcolors[ii],
470 &exact,&fixcolr[no][ii]);
471 goto after_colors;
472 }
473
474 if (flg != 3)
475 {
476 for (ii=0; ii<9;ii++)
477 x11stat = XAllocNamedColor(mydisp[no],cmap[no][i],plotcolors[ii],
478 &exact,&fixcolr[no][ii]);
479 Xworkst[no].lutlen = 9;
480 }
481
482 if (flg != 2)
483 {
484 color_loop:
485 x11stat = XAllocColorCells(mydisp[no],cmap[no][i],0,plane_mask,
486 0,pixels,jalloc);
487 if (x11stat)
488 {
489 Xworkst[no].lutsize = jalloc;
490 tmpx = jalloc - 1; /* index of last pixel */
491 }
492 else
493 {
494 jalloc --;
495 if (jalloc < minlut) /* not enough space in Colormap */
496 {
497 if (flg == 3)
498 { /* we have already allocated plot colours */
499 for (ii=0; ii<9;ii++) pixels[ii] = fixcolr[no][ii].pixel;
500 plane_mask[0] = 0;
501 XFreeColors(mydisp[no],cmap[no][i],pixels,9,plane_mask[0]);
502 }
503 flg = 2; /* we do it only once */
504 Xworkst[no].lutflag = 1;
505 sys_colors = 16;
506 plot_colors = 9;
507 goto LUTretry;
508 }
509 else
510 goto color_loop;
511 }
512
513 k = np;
514 if (pixels[0] > pixels[tmpx])
515 {
516 for (nr=0; nr<jalloc; nr++)
517 {
518 mycolr[no][k].pixel = Xworkst[no].mapin[k] = pixels[tmpx--];
519 mycolr[no][k].flags = rgbset;
520 k ++;
521 }
522 }
523 else
524 {
525 for (nr=0; nr<jalloc; nr++)
526 {
527 mycolr[no][k].pixel = Xworkst[no].mapin[k] = pixels[nr];
528 mycolr[no][k].flags = rgbset;
529 k ++;
530 }
531 }
532 for (nr=0; nr<jalloc; nr++)
533 {
534 k = Xworkst[no].mapin[nr];
535 Xworkst[no].mapout[k] = nr;
536 }
537
538 np += jalloc;
539
540 Xworkst[no].lutlen = Xworkst[no].lutsize;
541 }
542 }
543 }
544
545 else if (Xworkst[no].lutflag > 0) /* private LUT */
546 {
547
548 int koff;
549
550 if (Xworkst[no].ownlut == -1)
551 {
552 Xworkst[no].lutlen = Xworkst[no].lutsize;
553 goto after_colors;
554 }
555
556 jalloc = myvis[no]->map_entries;
557 if (jalloc > Xworkst[no].lutsize)
558 { /* copy as many current colors as possible */
559 sys_colors = myvis[no]->map_entries - Xworkst[no].lutsize - plot_colors;
560 Xworkst[no].auxcol = sys_colors + plot_colors;
561 }
562
563
564 if (Xworkst[no].white > 2)
565 { /* keep high end of LUT */
566 koff = jalloc - Xworkst[no].auxcol;
567 Xworkst[no].lutflag = 2;
568 }
569 else
570 { /* keep low end of LUT */
571 Xworkst[no].lutflag = 1;
572 koff = sys_colors;
573 }
574
575 for (i=0; i<Xworkst[no].nolut; i++)
576 {
577 cmap[no][i] = XCreateColormap(mydisp[no],rw[no],myvis[no],AllocNone);
578
579
580 /* get the color components for the Plot Colors and
581 free the color cells again */
582
583 if (i == 0) /* do it only once */
584 {
585 for (ii=0; ii<9;ii++)
586 {
587 x11stat = XAllocNamedColor(mydisp[no],cmap[no][i],plotcolors[ii],
588 &exact,&fixcolr[no][ii]);
589 if (!x11stat)
590 {
591 (void) printf
592 ("could not allocate NamedColor %s\n",plotcolors[ii]);
593 return(NOCOLALLO);
594 }
595 pixels[ii] = fixcolr[no][ii].pixel;
596 }
597 plane_mask[0] = 0; /* free the color cells */
598 XFreeColors(mydisp[no],cmap[no][i],pixels,9,plane_mask[0]);
599 }
600
601
602 /* now allocate all wanted color cells */
603
604 x11stat = XAllocColorCells(mydisp[no],cmap[no][i],0,plane_mask,
605 0,pixels,jalloc);
606
607 if (!x11stat)
608 {
609 (void) printf("could not allocate %d color cells...\n",jalloc);
610 return(NOCOLALLO);
611 }
612
613 k = np;
614 for (nr=0; nr<jalloc; nr++)
615 {
616 mycolr[no][k].pixel = k;
617 mycolr[no][k].flags = rgbset;
618 k ++;
619 }
620
621
622 /* copy all colors from the Default Color Map */
623
624 XQueryColors(mydisp[no],DefaultColormap(mydisp[no],myscreen),
625 &mycolr[no][np],jalloc);
626
627 k = np;
628 for (nr=0; nr<jalloc; nr++) /* reset pixels */
629 {
630 mycolr[no][k].pixel = pixels[nr];
631 Xworkst[no].mapin[k] = pixels[nr] + Xworkst[no].auxcol;
632 k++;
633 }
634
635 for (nr=0; nr<jalloc; nr++)
636 {
637 k = Xworkst[no].mapin[nr];
638 Xworkst[no].mapout[k] = nr;
639 }
640
641 for (nr=koff,j=0; j<plot_colors; nr++,j++)
642 {
643 mycolr[no][nr].red = fixcolr[no][j].red;
644 mycolr[no][nr].green = fixcolr[no][j].green;
645 mycolr[no][nr].blue = fixcolr[no][j].blue;
646 fixcolr[no][j].pixel = pixels[nr];
647 }
648
649 XStoreColors(mydisp[no],cmap[no][i],&mycolr[no][koff],plot_colors);
650
651 np += jalloc;
652 }
653
654 Xworkst[no].lutsize = jalloc;
655 Xworkst[no].lutlen = jalloc - Xworkst[no].auxcol;
656 }
657
658
659 after_colors:
660 for (ii=0; ii<9; ii++) /* save pixel value of fixed colours */
661 Xworkst[no].fixpix[ii] = fixcolr[no][ii].pixel;
662
663 Xworkst[no].white = Xworkst[no].fixpix[2];
664 Xworkst[no].black = Xworkst[no].fixpix[1];
665
666 Xworkst[no].lutfct = XLUTFACT;
667 Xworkst[no].lutinv = 1.0 / Xworkst[no].lutfct;
668
669 return (II_SUCCESS);
670 }
671
672 /*
673
674 */
675
676 /* ---- write XWindows LUT ------------------------------------------- */
677
678 /* load look up table */
679
680 void wr_lut (dspno,lut,flag)
681 int dspno; /* IN: display no. */
682 int flag; /* IN: visibility flag, 0 = off, 1 = on */
683 LUT_DATA *lut; /* IN: pointer to LUT data */
684
685 {
686 CONF_DATA *conf;
687 MEM_DATA *mem;
688 ITT_DATA *itt;
689
690 int no, memid, ioff;
691 int np, j, k, i;
692 float lutval, fval;
693 register int loop;
694
695
696
697 itt = (ITT_DATA *) 0;
698
699 no = ididev[dspno].screen;
700 np = ididev[dspno].lutsect;
701 j = np * Xworkst[no].lutsize;
702 ioff = j;
703 if (Xworkst[no].lutflag == 1) ioff += Xworkst[no].auxcol;
704
705 conf = ididev[dspno].confptr;
706 memid = conf->memid;
707 if (memid == conf->overlay)
708 k = 0; /* no ITT for overlay channel */
709 else
710 {
711 mem = conf->memory[memid];
712 itt = mem->ittpntr;
713 k = itt->vis;
714 }
715 i = 0;
716
717
718 if (Xworkst[no].ownlut == 1) goto no_pix_shift;
719
720 if (Xworkst[no].visual == 4)
721 { /* Pseudo on top of TrueColor */
722 float fr;
723 int ired, igreen, iblue;
724 int i0, shred, shblue, shgreen; /* shift */
725 INTBAR *bar;
726
727
728
729
730 /* handle 16bit LUT here */
731
732 if ((Xworkst[no].depth == 16) && (myvis[no]->map_entries <= 256))
733 {
734 unsigned short int koko, jojo;
735 unsigned int modred, modblue, modgreen;
736 int i1;
737 unsigned char* bytptra=(unsigned char *) &koko;
738 unsigned char* bytptrb=(unsigned char *) &jojo;
739
740 if (Xworkst[no].flag24[0] == 0) /* write swap flag */
741 { /* normal byte order */
742 i0 = 0; /* b[0] = a[0], b[1] = a[1] */
743 i1 = 1;
744 }
745 else /* low bytes swapped */
746 {
747 i0 = 1; /* b[0] = a[1], b[1] = a[0] */
748 i1 = 0;
749 }
750
751
752 if (Xworkst[no].RGBord != 1)
753 {
754 shred = shift16[0];
755 shgreen = shift16[1];
756 shblue = shift16[2];
757 }
758 else
759 {
760 shred = shift16[2];
761 shgreen = shift16[1];
762 shblue = shift16[0];
763 }
764 modred = 3; /* red size = 5 bits */
765 modgreen = 2; /* green size = 6 bits */
766 modblue = 3; /* blue size = 5 bits */
767 jojo = 0;
768
769 if (flag > 0)
770 {
771 fr = (Xworkst[no].lutlen - 1.0)/Xworkst[no].lutfct;
772
773 if (k == 1)
774 {
775 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
776 {
777 k = itt->val[i++];
778 ired = (int) (fr * lut->lutr[k]);
779 ired = ired >> modred;
780 igreen = (int) (fr * lut->lutg[k]);
781 igreen = igreen >> modgreen;
782 iblue = (int) (fr * lut->lutb[k]);
783 iblue = iblue >> modblue;
784
785 koko = (unsigned short int) ((ired << shred) |
786 (igreen << shgreen) | (iblue << shblue));
787 *bytptrb = *(bytptra+i0);
788 *(bytptrb+1) = *(bytptra+i1);
789 Xworkst[no].mapin[loop] = jojo;
790 }
791 }
792 else
793 {
794 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
795 {
796 ired = (int) (fr * lut->lutr[i]);
797 ired = ired >> modred;
798 igreen = (int) (fr * lut->lutg[i]);
799 igreen = igreen >> modgreen;
800 iblue = (int) (fr * lut->lutb[i++]);
801 iblue = iblue >> modblue;
802
803 koko = (unsigned short int) ((ired << shred) |
804 (igreen << shgreen) | (iblue << shblue));
805 *bytptrb = *(bytptra+i0);
806 *(bytptrb+1) = *(bytptra+i1);
807 Xworkst[no].mapin[loop] = jojo;
808 }
809 }
810 }
811 else
812 {
813 fr = Xworkst[no].lutlen - 1.0;
814 rval = 1.0 / fr;
815
816 if (k == 1)
817 {
818 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
819 {
820 igreen = iblue = ired = itt->val[i++]; /* in [0,LUTsize-1] */
821 ired = ired >> modred;
822 igreen = igreen >> modgreen;
823 iblue = iblue >> modblue;
824
825 koko = (unsigned short int) ((ired << shred) |
826 (igreen << shgreen) | (iblue << shblue));
827 *bytptrb = *(bytptra+i0);
828 *(bytptrb+1) = *(bytptra+i1);
829 Xworkst[no].mapin[loop] = jojo;
830 }
831 }
832 else
833 {
834 fval = 0.0;
835 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
836 {
837 igreen = iblue = ired = (int) (fval * fr);
838 ired = ired >> modred;
839 igreen = igreen >> modgreen;
840 iblue = iblue >> modblue;
841
842 koko = (unsigned short int) ((ired << shred) |
843 (igreen << shgreen) | (iblue << shblue));
844 *bytptrb = *(bytptra+i0);
845 *(bytptrb+1) = *(bytptra+i1);
846 Xworkst[no].mapin[loop] = jojo;
847
848 fval += rval;
849 }
850 }
851 }
852 }
853
854
855 /* handle 24bit LUT here */
856
857 else
858 {
859 if (Xworkst[no].flag24[0] == 0) /* write swap flag */
860 i0 = 0; /* normal byte order */
861 else
862 i0 = 1;
863
864 if (Xworkst[no].RGBord != 1)
865 {
866 shred = shift24[0][i0];
867 shgreen = shift24[1][i0];
868 shblue = shift24[2][i0];
869 }
870 else
871 {
872 shred = shift24[2][i0];
873 shgreen = shift24[1][i0];
874 shblue = shift24[0][i0];
875 }
876
877 if (flag > 0)
878 {
879 fr = (Xworkst[no].lutlen - 1.0)/Xworkst[no].lutfct;
880
881 if (k == 1)
882 {
883 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
884 {
885 k = itt->val[i++];
886 ired = (int) (fr * lut->lutr[k]);
887 igreen = (int) (fr * lut->lutg[k]);
888 iblue = (int) (fr * lut->lutb[k]);
889 ired = ired << shred;
890 igreen = igreen << shgreen;
891 iblue = iblue << shblue;
892 Xworkst[no].mapin[loop] = ired | igreen | iblue;
893 }
894 }
895 else
896 {
897 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
898 {
899 ired = (int) (fr * lut->lutr[i]);
900 igreen = (int) (fr * lut->lutg[i]);
901 iblue = (int) (fr * lut->lutb[i++]);
902 ired = ired << shred;
903 igreen = igreen << shgreen;
904 iblue = iblue << shblue;
905 Xworkst[no].mapin[loop] = ired | igreen | iblue;
906 }
907 }
908 }
909 else
910 {
911 fr = Xworkst[no].lutlen - 1.0;
912 rval = 1.0 / fr;
913
914 if (k == 1)
915 {
916 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
917 {
918 igreen = iblue = ired = itt->val[i++]; /* in [0,LUTsize-1] */
919 ired = ired << shred;
920 igreen = igreen << shgreen;
921 iblue = iblue << shblue;
922 Xworkst[no].mapin[loop] = ired | igreen | iblue;
923 }
924 }
925 else
926 {
927 fval = 0.0;
928 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
929 {
930 igreen = iblue = ired = (int) (fval * fr);
931 ired = ired << shred;
932 igreen = igreen << shgreen;
933 iblue = iblue << shblue;
934 Xworkst[no].mapin[loop] = ired | igreen | iblue;
935 fval += rval;
936 }
937 }
938 }
939 }
940
941 if (ididev[dspno].bar != 0)
942 {
943 bar = ididev[dspno].bar;
944 if (bar->vis == 1) updalutbar(dspno,bar);
945 }
946 }
947 return;
948
949
950 no_pix_shift:
951 if (flag > 0)
952 {
953 if (k == 1)
954 {
955 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
956 {
957 k = itt->val[i++];
958 mycolr[no][loop].red = (unsigned short) lut->lutr[k];
959 mycolr[no][loop].green = (unsigned short) lut->lutg[k];
960 mycolr[no][loop].blue = (unsigned short) lut->lutb[k];
961 }
962 }
963 else
964 {
965 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
966 {
967 mycolr[no][loop].red = (unsigned short) lut->lutr[i];
968 mycolr[no][loop].green = (unsigned short) lut->lutg[i];
969 mycolr[no][loop].blue = (unsigned short) lut->lutb[i++];
970 }
971 }
972 }
973
974 else
975 {
976 rval = 1.0 / (Xworkst[no].lutlen - 1.0);
977 if (k == 1)
978 {
979 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
980 {
981 fval = (float) itt->val[i++]; /* in [0,LUTsize-1] */
982 fval *= rval; /* now in [0.,1.] */
983 lutval = fval * Xworkst[no].lutfct;
984 mycolr[no][loop].red = (unsigned short) lutval;
985 mycolr[no][loop].green = (unsigned short) lutval;
986 mycolr[no][loop].blue = (unsigned short) lutval;
987 }
988 }
989 else
990 {
991 fval = 0.0;
992 for (loop=ioff; loop<(Xworkst[no].lutlen+ioff); loop++)
993 {
994 lutval = fval * Xworkst[no].lutfct;
995 mycolr[no][loop].red = (unsigned short) lutval;
996 mycolr[no][loop].green = (unsigned short) lutval;
997 mycolr[no][loop].blue = (unsigned short) lutval;
998 fval += rval;
999 }
1000 }
1001 }
1002
1003
1004 XStoreColors (mydisp[no],cmap[no][np],&mycolr[no][j],Xworkst[no].lutsize);
1005
1006 }
1007 /*
1008
1009 */
1010
1011 /* ---- read XWindows LUT ------------------------------------------- */
1012
1013 /* read look up table */
1014
1015 void rd_lut (dspno,lut)
1016 int dspno;
1017 LUT_DATA *lut;
1018
1019 {
1020 CONF_DATA *conf;
1021 MEM_DATA *mem;
1022 ITT_DATA *itt;
1023
1024 int np, j, k, no, memid, ioff;
1025 register int loop;
1026
1027
1028 no = ididev[dspno].screen;
1029 if (Xworkst[no].ownlut != 1) return; /* no LUT used ... */
1030
1031 np = ididev[dspno].lutsect;
1032 j = np * Xworkst[no].lutsize;
1033 ioff = j;
1034 if (Xworkst[no].lutflag == 1)
1035 ioff += Xworkst[no].auxcol;
1036
1037 conf = ididev[dspno].confptr;
1038 memid = conf->memid;
1039 if (memid == conf->overlay)
1040 k = 0; /* no ITT for overlay channel */
1041 else
1042 {
1043 mem = conf->memory[memid];
1044 itt = mem->ittpntr;
1045 k = itt->vis;
1046 }
1047
1048 /* we only read via X11 if ITT is not set */
1049
1050 if (k == 0)
1051 {
1052 XQueryColors (mydisp[no],cmap[no][np],&mycolr[no][j],Xworkst[no].lutlen);
1053
1054 for (loop=0; loop<Xworkst[no].lutlen; loop++)
1055 {
1056 lut->lutr[loop] = mycolr[no][loop+ioff].red;
1057 lut->lutg[loop] = mycolr[no][loop+ioff].green;
1058 lut->lutb[loop] = mycolr[no][loop+ioff].blue;
1059 }
1060 }
1061 }
1062
1063 /*
1064
1065 */
1066
1067 /* ---- allocate memory + create XImage structure -------------------- */
1068
1069 int allo_mem(dspno,mem,memid)
1070 int dspno, memid;
1071 MEM_DATA *mem;
1072
1073 {
1074 int total, np, no, x, y;
1075 int myhandler();
1076 unsigned int w, h, bw, d;
1077
1078
1079 CONF_DATA *conf;
1080
1081
1082 /* check, if it's id of overlay channel */
1083
1084 conf = ididev[dspno].confptr;
1085 if (memid == conf->overlay) return (II_SUCCESS); /* Yes. So we leave.. */
1086
1087 no = ididev[dspno].screen;
1088 if (Xworkst[no].depth > 8)
1089 np = 32;
1090 else
1091 np = 8;
1092
1093 mxpix[dspno][memid] =
1094 XCreatePixmap(mydisp[no],mwndw[dspno],mem->xsize,mem->ysize,Xworkst[no].depth);
1095
1096
1097 /* we may not have enough memory for the Pixmaps, so we have to check it */
1098
1099 error_X = 0;
1100 XSetErrorHandler(myhandler); /* use our Error handler */
1101 x11stat = XGetGeometry(mydisp[no],mxpix[dspno][memid],&mywindow,
1102 &x,&y,&w,&h,&bw,&d);
1103 XSetErrorHandler(None); /* use default Error handler */
1104
1105 myima = XCreateImage(mydisp[no],myvis[no],Xworkst[no].depth,ZPixmap,
1106 0,0,mem->xsize,mem->ysize,np,np*mem->xsize/8);
1107
1108 total = myima->bytes_per_line * mem->ysize;
1109 myima->data = malloc((size_t)total);
1110 if (myima->data == 0) return (MEMALLERR);
1111
1112
1113
1114 /* clear the allocated memory + copy to Pixmap */
1115
1116 mxima[dspno][memid] = myima;
1117 mem->mmbm = myima->data;
1118 zero_mem(dspno,mem,0,0);
1119
1120 if (error_X != 0)
1121 mem->pixmap = 0;
1122 else
1123 {
1124 mem->pixmap = 1;
1125 idi_putimage(mydisp[no],mxpix[dspno][memid],gcima[dspno],
1126 myima,0,0,0,0,mem->xsize,mem->ysize);
1127 }
1128
1129 return (II_SUCCESS);
1130 }
1131 /*
1132
1133 */
1134
1135 /* ---- allocate zoom memory + create XImage structure -------------------- */
1136
1137 int allo_zmem(dspno,mem,memid)
1138 int dspno, memid;
1139 MEM_DATA *mem;
1140
1141 {
1142 int total, np, no;
1143 int myhandler();
1144
1145 CONF_DATA *conf;
1146
1147
1148 /* check, if it's id of overlay channel */
1149
1150 conf = ididev[dspno].confptr;
1151 if (memid == conf->overlay) return (II_SUCCESS); /* Yes. So we leave.. */
1152
1153 no = ididev[dspno].screen;
1154 if (Xworkst[no].depth > 8)
1155 np = 32;
1156 else
1157 np = 8;
1158
1159 myima = XCreateImage(mydisp[no],myvis[no],Xworkst[no].depth,ZPixmap,
1160 0,0,mem->xsize,mem->ysize,np,np*mem->xsize/8);
1161
1162 total = myima->bytes_per_line * mem->ysize;
1163 myima->data = malloc((size_t)total);
1164 if (myima->data == 0) return (MEMALLERR);
1165
1166 mzima[dspno][memid] = myima;
1167 mem->zmbm = myima->data;
1168 zero_mem(dspno,mem,1,0);
1169
1170 return (II_SUCCESS);
1171 }
1172
1173 /*
1174
1175 */
1176
1177 /* ---- create XImage structure for hardcopy and fill it -------- */
1178
1179 int get_hcopy(dspno,mem,memid)
1180 int dspno, memid;
1181 MEM_DATA *mem;
1182
1183 {
1184 int total, tmpx, tmpy, np, no;
1185
1186
1187 no = ididev[dspno].screen;
1188 tmpx = ididev[dspno].xsize; tmpy = ididev[dspno].ysize;
1189
1190 if (ididev[dspno].hcopy == (char *) 0)
1191 {
1192 if (Xworkst[no].depth > 8)
1193 np = 32;
1194 else
1195 np = 8;
1196
1197
1198 /* here we create the structure + allocate memory */
1199
1200 myima = XCreateImage(mydisp[no],myvis[no],Xworkst[no].depth,ZPixmap,
1201 0,0,tmpx,tmpy,np,np*tmpx/8);
1202
1203 total = myima->bytes_per_line * tmpy;
1204 myima->data = malloc((size_t)total);
1205 if (myima->data == (char *) 0) return (MEMALLERR);
1206
1207 hcopy[dspno] = myima;
1208 ididev[dspno].hcopy = myima->data;
1209 }
1210
1211
1212 /* here we make the screen dump */
1213
1214 np = -1;
1215 xdrawable = mwndw[dspno];
1216 if (mem->pixmap == 1)
1217 {
1218 XGetWindowAttributes(mydisp[no],mwndw[dspno],&attributes);
1219 if (attributes.map_state != IsViewable)
1220 {
1221 xdrawable = mxpix[dspno][memid];
1222 copy_over(dspno,memid,1); /* put graphics into Pixmap */
1223 }
1224 }
1225
1226 hcopy[dspno] = idi_getsubimage(mydisp[no],xdrawable,0,0,tmpx,tmpy,
1227 np,ZPixmap,hcopy[dspno],no);
1228 XFlush(mydisp[no]);
1229
1230 return (II_SUCCESS);
1231 }
1232 /*
1233
1234 */
1235
1236 /* ---- set memory visibility -------------------------------------- */
1237
1238 void smv (flag,dspno,mem,memid,srcx,srcy,xdim,ydim,dstx,dsty)
1239 int flag, dspno, memid, srcx, srcy, dstx, dsty;
1240 MEM_DATA *mem;
1241 unsigned int xdim, ydim;
1242
1243 {
1244 int no;
1245
1246
1247 no = ididev[dspno].screen;
1248
1249 if (mem->zoom > 1)
1250 {
1251 if (mem->pixmap != 1) /* we have no Pixmaps (not enough memory) */
1252
1253 /* load image zoom mem. into the Window */
1254
1255 idi_putimage(mydisp[no],mwndw[dspno],gcima[dspno],mzima[dspno][memid],
1256 0,0,0,0,xdim,ydim);
1257
1258 else
1259 { /* we have Pixmaps */
1260
1261 /* first (if flag > 1), load full image mem. into Pixmap */
1262
1263 if (flag > 1)
1264 idi_putimage(mydisp[no],mxpix[dspno][memid],gcima[dspno],
1265 mzima[dspno][memid],0,0,0,0,mem->xsize,mem->ysize);
1266
1267
1268 /* then (if flag = 0, 1, or 2) copy the Pixmap to the Window */
1269
1270 if (flag < 3)
1271 XCopyArea(mydisp[no],mxpix[dspno][memid],mwndw[dspno],gcima[dspno],
1272 0,0,xdim,ydim,0,0);
1273 }
1274 }
1275
1276 else
1277 {
1278 if (flag > 10) /* do not clear for rectangles */
1279 flag -= 10;
1280 else
1281 {
1282 if (dstx != 0) /* because of scrolling */
1283 XClearArea(mydisp[no],mwndw[dspno],0,0,dstx,1024,False);
1284 if (dsty != 0)
1285 XClearArea(mydisp[no],mwndw[dspno],0,0,1024,dsty,False);
1286 }
1287
1288 if (mem->pixmap != 1) /* we have no Pixmaps (not enough memory) */
1289
1290 /* load subwindow from image mem. into the Window
1291 at corner (dstx,dsty) */
1292
1293 idi_putimage(mydisp[no],mwndw[dspno],gcima[dspno],mxima[dspno][memid],
1294 srcx,srcy,dstx,dsty,xdim,ydim);
1295
1296 else
1297 { /* we have Pixmaps */
1298
1299 /* first (if flag > 1), load full image mem. into Pixmap */
1300
1301 if (flag > 1)
1302 idi_putimage(mydisp[no],mxpix[dspno][memid],gcima[dspno],
1303 mxima[dspno][memid],0,0,0,0,mem->xsize,mem->ysize);
1304
1305
1306 /* then (if flag = 0, 1, or 2) copy the Pixmap to the Window */
1307
1308 if (flag < 3)
1309 XCopyArea(mydisp[no],mxpix[dspno][memid],mwndw[dspno],gcima[dspno],
1310 srcx,srcy,xdim,ydim,dstx,dsty);
1311 }
1312 }
1313 }
1314
1315 /*
1316
1317 */
1318
1319 /* ---- interaction enable ------------------------------------------- */
1320
1321 void int_enable (dspno)
1322 int dspno;
1323
1324 {
1325 int i, no;
1326
1327 INTER_DATA *intdata;
1328
1329
1330
1331 interact = 1; /* set flag */
1332
1333 no = ididev[dspno].screen;
1334 XSync (mydisp[no],discard);
1335
1336 for (i=0; i<ididev[dspno].n_inter; i++)
1337 {
1338 intdata = ididev[dspno].inter[i];
1339
1340 if (intdata->inttype == II_LOC) /* II_LOC */
1341 {
1342 if (intdata->interactor == II_MOUSE)
1343 ididev[dspno].inter_mask |= PointerMotionMask;
1344 else if (intdata->interactor == II_KEYB)
1345 ididev[dspno].inter_mask |= KeyPressMask;
1346 else
1347 goto end_of_loop;
1348 }
1349
1350 else /* II_TRG or II_EVLC */
1351 {
1352 if (intdata->interactor == II_MOUSE)
1353 ididev[dspno].inter_mask |= ButtonPressMask;
1354 else if (intdata->interactor == II_KEYB)
1355 ididev[dspno].inter_mask |= KeyPressMask;
1356 else
1357 goto end_of_loop;
1358 }
1359
1360 ididev[dspno].inter_mask |= Def_Mask;
1361 XSelectInput (mydisp[no],mwndw[dspno],ididev[dspno].inter_mask);
1362
1363 end_of_loop:
1364 ;
1365 }
1366
1367 set_wcur(dspno,0);
1368
1369 }
1370
1371 /*
1372
1373 */
1374
1375 /* ---- interaction disable ------------------------------------------ */
1376
1377 void int_disable (dspno)
1378 int dspno;
1379
1380 {
1381 int no;
1382
1383
1384 if (interact == 0) return; /* nothing to do */
1385
1386 interact = 0;
1387 no = ididev[dspno].screen;
1388 XSync (mydisp[no],discard);
1389
1390 ididev[dspno].inter_mask = Def_Mask;
1391 XSelectInput (mydisp[no],mwndw[dspno],ididev[dspno].inter_mask);
1392
1393 }
1394
1395
1396
1397 /* ---- exit trigger enable ------------------------------------------ */
1398
1399 void exit_trg_enable (dspno)
1400 int dspno;
1401
1402 {
1403 int trg0, no, interactor_id;
1404
1405 trg0 = ididev[dspno].trigger;
1406 interactor_id = intdevtable[dspno].trig[trg0]->interactor;
1407 no = ididev[dspno].screen;
1408
1409 if (interactor_id == II_MOUSE)
1410 ididev[dspno].inter_mask |= ButtonPressMask;
1411 else if (interactor_id == II_KEYB)
1412 ididev[dspno].inter_mask |= KeyPressMask;
1413
1414 ididev[dspno].inter_mask |= Def_Mask;
1415 XSelectInput (mydisp[no],mwndw[dspno],ididev[dspno].inter_mask);
1416 }
1417
1418 /*
1419
1420 */
1421
1422 /* ---- wait for interaction ----------------------------------------- */
1423 /* synchronous interaction routine */
1424
1425 /* type : internally defined interactor (locator , locator-buttons , */
1426 /* keyboard ... */
1427 /* data : interactor dependent (mouse-button , key ) */
1428 /* position : cursor position */
1429
1430 void wait_int (dspno,type,data,cdata,position)
1431 int dspno, *type, *data, *position;
1432 char *cdata;
1433
1434 {
1435 int i, no;
1436
1437
1438 no = ididev[dspno].screen;
1439
1440 we_wait:
1441 XWindowEvent (mydisp[no],mwndw[dspno],ididev[dspno].inter_mask,&myevent);
1442
1443 if (myevent.type == Expose)
1444 {
1445 exposed(no,dspno); /* handle that in `exposed' */
1446 goto we_wait;
1447 }
1448
1449
1450 *type = myevent.type;
1451
1452 if (myevent.type == KeyPress)
1453 {
1454 position[0] = myevent.xkey.x;
1455 position[1] = myevent.xkey.y;
1456
1457 if (myevent.xkey.send_event) /* from AutoCursor mode */
1458 {
1459 *data = myevent.xkey.keycode - 100; /* keycode is UNSIGNED int */
1460 *cdata = '\0';
1461 }
1462
1463 else /* real interactive input */
1464 {
1465 i = XLookupString(&myevent.xkey,cdata,10,&mykey,&xcstat);
1466
1467 cdata[i] = '\0';
1468 switch(mykey)
1469 {
1470 case XK_Up:
1471 *data = -1;
1472 break;
1473 case XK_Down:
1474 *data = -2;
1475 break;
1476 case XK_Right:
1477 *data = -3;
1478 break;
1479 case XK_Left:
1480 *data = -4;
1481 break;
1482 case XK_Return:
1483 *data = -5;
1484 break;
1485 case XK_F1:
1486 *data = -11;
1487 break;
1488 case XK_F2:
1489 *data = -12;
1490 break;
1491 case XK_F3:
1492 *data = -13;
1493 break;
1494 case XK_F4:
1495 *data = -14;
1496 break;
1497 case XK_0:
1498 *data = 0;
1499 break;
1500 case XK_1:
1501 *data = 1;
1502 break;
1503 case XK_2:
1504 *data = 2;
1505 break;
1506 case XK_3:
1507 *data = 3;
1508 break;
1509 case XK_4:
1510 *data = 4;
1511 break;
1512 case XK_5:
1513 *data = 5;
1514 break;
1515 case XK_6:
1516 *data = 6;
1517 break;
1518 case XK_7:
1519 *data = 7;
1520 break;
1521 case XK_8:
1522 *data = 8;
1523 break;
1524 case XK_9:
1525 *data = 9;
1526 break;
1527 default:
1528 *data = -99;
1529 }
1530 }
1531 }
1532
1533 else
1534 {
1535 position[0] = myevent.xbutton.x;
1536 position[1] = myevent.xbutton.y;
1537 if (myevent.type == ButtonPress)
1538 *data = myevent.xbutton.button;
1539 else
1540 *data = 0;
1541 *cdata = '\0';
1542 }
1543 }
1544
1545 /*
1546
1547 */
1548
1549 /* ---- test trigger status ------------------------------------------ */
1550
1551 int trigsta(dspno,trgno,event,data,cbuf)
1552 int dspno, trgno, event, data;
1553 char *cbuf;
1554
1555 {
1556 int k, flag, interactor_id, interactor_def;
1557
1558
1559 flag = 0;
1560 interactor_id = intdevtable[dspno].trig[trgno]->interactor;
1561
1562
1563 switch(interactor_id)
1564 {
1565 case II_MOUSE:
1566 if (event == ButtonPress)
1567 {
1568 if (trgno == 0) /* EXIT trigger */
1569 {
1570 if (data != 1) flag = 1;
1571 }
1572 else if (trgno == 1)
1573 {
1574 if (data == 1)
1575 {
1576 flag = 1;
1577 set_wcur(dspno,3);
1578 }
1579 }
1580 }
1581 break;
1582
1583 case II_KEYB:
1584 interactor_def = intdevtable[dspno].trig[trgno]->def;
1585
1586 if (interactor_def == II_TRG)
1587 {
1588 if (trgno == 2) /* EXECUTE trigger */
1589 {
1590 if (data == -5)
1591 {
1592 flag = 1;
1593 set_wcur(dspno,3);
1594 }
1595 }
1596 else if ((trgno > 3) && (trgno < 8)) /* triggers for arrow keys */
1597 {
1598 k = trgno - 8; /* trgno 4 => -4 etc. */
1599 if (data == k)
1600 flag = 1;
1601 }
1602 }
1603 else if (interactor_def == II_EVLC)
1604 {
1605 if (*cbuf != '\0') flag = 1;
1606 }
1607 break;
1608
1609 default:
1610 (void) printf("trigsta: interactor_id = %d\n",interactor_id);
1611 }
1612
1613 return (flag);
1614 }
1615
1616 /*
1617
1618 */
1619
1620 int buildRGBLUT(num,lutlen,xcolo,pxls)
1621 int num, lutlen;
1622 unsigned long int *pxls;
1623 XColor xcolo[];
1624
1625
1626 {
1627 int j, ifact, isw, rgbset;
1628 register int nr;
1629 unsigned long int plane_mask[1];
1630
1631
1632
1633 /* here for DirectColor (we build a linear LUT) */
1634
1635 j = myvis[num]->map_entries;
1636 if (lutlen > j) lutlen = j;
1637
1638 ifact = 0xffff / (lutlen - 1);
1639 rgbset = DoRed | DoGreen | DoBlue;
1640 j = 0;
1641 isw = 0;
1642
1643 if (Xworkst[num].visual == 3)
1644 {
1645 XColor colo;
1646
1647 colo.flags =rgbset;
1648
1649 for (nr=0; nr<lutlen; nr++)
1650 {
1651 colo.red = colo.green = colo.blue = j;
1652 j += ifact;
1653
1654 if (XAllocColor(mydisp[num],cmap[num][0],&colo)) isw++;
1655 }
1656
1657 if (isw == 0)
1658 {
1659 (void) printf("No entries in LUT!\n");
1660 return(-1);
1661 }
1662 }
1663
1664 else /* Xworkst[num].visual = 4 */
1665 {
1666 plane_mask[0] = 0;
1667 x11stat = XAllocColorCells(mydisp[num],cmap[num][0],0,plane_mask,
1668 0,pxls,lutlen);
1669
1670 if (x11stat)
1671 {
1672 isw = lutlen;
1673
1674 for (nr=0; nr<lutlen; nr++)
1675 {
1676 xcolo[nr].flags = rgbset;
1677 xcolo[nr].red = xcolo[nr].green = xcolo[nr].blue = j;
1678 j += ifact;
1679
1680 Xworkst[num].mapin[nr] = xcolo[nr].pixel = pxls[nr];
1681 }
1682 }
1683 else
1684 {
1685 (void) printf("could not allocate %d color cells for LUT!\n",lutlen);
1686 return(-1);
1687 }
1688 }
1689
1690 return (isw);
1691
1692 }
1693
1694 /*
1695
1696 */
1697
1698 void LUTinstall(dspno)
1699 int dspno;
1700
1701
1702 {
1703 int no, np;
1704
1705
1706 no = ididev[dspno].screen;
1707 if ((Xworkst[no].ownlut == 1) && (Xworkst[no].lutflag > 0))
1708 {
1709 np = ididev[dspno].lutsect;
1710 XInstallColormap(mydisp[no],cmap[no][np]);
1711 }
1712 }