Debian Codegraph @

libsrc/idi/cidi/x11/iid1.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 iid1.c : contains the following routines
31 *
32 * IIDINIT : initialize structures
33 * IIDOPN_C : Open Display;
34 *
35 * pars24 : map 3 digits xyz -> co_flg, rd_flg, wr_flg
36 * = flag24[2], [1], [0]
37 *
38 *************************************************************************
39 * V 1.1 871201: P. Santin - Trieste Astronomical Observatory
40 * V 2.0 881130 Klaus Banse - ESO Garching
41 *
42 * 090826 last modif
43 * 150827 DISPLAY may be very long string (Mac OSX 10.10) (KB)
44 * so increase size of Xworkst[].name and buffer record in IIDOPN
45 *************************************************************************
46 */
47
48 # include <stdlib.h>
49 # include <stdio.h>
50
51
52 # include <idi.h>
53 # include <idistruct.h>
54 # include <proto_idi.h>
55 # include <midas_def.h>
56 # include <osparms.h>
57
58
59 static int f_wndw[MAX_WST], f_lut[MAX_WST], f_RGB[MAX_WST];
60 static int start_flag = -1;
61
62 static char ididir[64];
63
64 /*
65
66 */
67
68 int pars24(ival,flags)
69 int ival, *flags;
70
71 {
72 int wf, rf, sf;
73 int mm;
74
75
76
77 if (ival > 99)
78 {
79 sf = ival/100;
80 mm = ival - (sf*100);
81 rf = mm/10;
82 wf = mm - (rf*10);
83 }
84 else if (ival > 9)
85 {
86 sf = 0;
87 rf = ival/10;
88 wf = ival - (rf*10);
89 }
90 else /* no special flag for copy/display */
91 {
92 sf = rf = 0;
93 wf = ival;
94 }
95
96 if (wf == 2) /* 1 = on, 0 or 2 = off */
97 flags[0] = 0;
98 else
99 flags[0] = wf;
100 if (rf == 2)
101 flags[1] = 0;
102 else
103 flags[1] = rf;
104 if (sf == 2)
105 flags[2] = 0;
106 else
107 flags[2] = sf;
108
109 /*
110 printf("sf = %d, rf = %d, wf = %d\n",flags[2],flags[1],flags[0]);
111 */
112
113 return 0;
114 }
115
116 /*
117
118 */
119
120 /************************************************************************/
121
122 void IIDINIT()
123
124 {
125 int i, m;
126
127 char muni[4];
128
129
130 for (i=0; i<MAX_DEV; i++)
131 {
132 ididev[i].opened = 0;
133 ididev[i].screen = 0;
134 ididev[i].devname[0] = '\0';
135 }
136
137 OSY_GETSYMB("DAZUNIT",muni,4);
138 muni[2] = '\0';
139
140 for (i=0; i<MAX_WST; i++)
141 {
142 f_wndw[i] = 0;
143 f_lut[i] = 1;
144 Xworkst[i].name[0] = '\0';
145 (void) strcpy(Xworkst[i].miduni,muni); /* save MIDAS unit */
146 }
147
148 (void) OSY_TRNLOG("MID_WORK",ididir,64,&m);
149
150 }
151
152 /*
153
154 */
155
156 /************************************************************************
157 * IIDOPN_C routine : opens a new display for subsequent operations *
158 * *
159 * synopsis IIDOPN_C (display, displayid); *
160 * *
161 * char[] display; input device name *
162 * int *displayid; output display identifier *
163 ************************************************************************/
164
165 int IIDOPN_C (display, displayid)
166 int *displayid;
167 char display[];
168
169 {
170 int x0, y0, fontno[4];
171 int devxoff, devyoff, devxdim, devydim, dstatus;
172 int shadow, ival[5], len, k1, screeno, gsize;
173 int i, j, k, m;
174 int limited, con_main, minlut, RGBmode, flag24;
175 int fp;
176 register int nr;
177 unsigned int allbytes;
178
179 char dspchar, cbuf[12], record[120], name[24];
180 char *disp_var;
181
182 float rval, fval;
183 double dval;
184
185 LUT_DATA *lut;
186 ITT_DATA *itt;
187 CURS_DATA *curs;
188 ALPH_DATA *alph;
189 ROI_DATA *roi;
190 CONF_DATA *conf;
191 MEM_DATA *mem;
192 INTER_DATA *ixter;
193 LOCATOR *loca;
194 TRIGGER *trigg;
195 GLIST *graph;
196 TLIST *txt;
197 INTBAR *bar;
198
199
200 /* look, if we're here for the very first time */
201
202 if (start_flag == -1)
203 {
204 IIDINIT(); /* initialize the stuff */
205 start_flag = 0;
206 }
207
208 else if (display[0] == ' ') /* we only wanted the connection */
209 {
210 for (i=0; i<MAX_DEV; i++)
211 {
212 if (ididev[i].devname[0] != '\0')
213 {
214 *displayid = i;
215 ididev [i].opened = 1;
216 loc_zero(i); /* reset locators */
217 return(ENTRYFND); /* indicate, that already there */
218 }
219 }
220 }
221
222
223 /* search through all opened ididevs */
224
225 for (i=0; i<MAX_DEV; i++)
226 {
227 if (strcmp(display,ididev[i].devname) == 0)
228 {
229 *displayid = i;
230 ididev [i].opened = 1;
231 loc_zero(i); /* reset locators */
232 return(ENTRYFND); /* indicate, that already there */
233 }
234 }
235
236 /* so look for empty ididev structure */
237
238 for (i=0; i<MAX_DEV; i++)
239 {
240 if (ididev[i].devname[0] == '\0')
241 {
242 *displayid = i;
243 goto first_time;
244 }
245 }
246
247 return (NOAVAILDEV); /* return with error */
248
249
250
251 /* get ididev parameters from sxwAB...dat file */
252 /* ---------------------------------------------- */
253
254
255 first_time:
256
257 shadow = -1;
258 limited = 0;
259 j = 5;
260
261 dspchar = display[j++];
262 switch (display[j])
263 {
264 case 'g':
265 ididev[i].devtyp = 'g'; /* it's a graphics window */
266 limited = 1;
267 break;
268 case 'z': /* if "sxwAB0z", it's a zoom window */
269 ididev[i].devtyp = 'z';
270 break;
271 case 'c': /* if "sxwAB0c" => cursor window */
272 ididev[i].devtyp = 'c';
273 limited = 2;
274 break;
275 case 's': /* "sxwAB0s", display shadow window */
276 ididev[i].devtyp = 'i';
277 shadow = 0;
278 break;
279 case 't': /* "sxwAB0t", graphic shadow window */
280 ididev[i].devtyp = 'g';
281 limited = 1;
282 shadow = 0;
283 break;
284 default:
285 ididev[i].devtyp = 'i'; /* everything else is image window */
286 }
287
288 (void) strcpy(record,ididir);
289 if (display[0] == ' ') /* we just wanted to connect */
290 return(DCTFILERR);
291
292 (void) strcat(record,display);
293 (void) strcat(record,".dat");
294
295 fp = osaopen(record,READ);
296 if (fp < 0)
297 { /* wait 1 sec + try one more time */
298 unsigned int ms;
299
300 ms = 1000;
301 OSY_SLEEP(ms,0);
302 fp = osaopen(record,READ);
303 if (fp < 0)
304 {
305 (void) printf("IIDOPN: where is %s ?\n",record);
306 return(DCTFILERR);
307 }
308 }
309
310 (void) strcpy (ididev[i].devname,display);
311 con_main = -1;
312
313
314 /* first of all get Xworkstation name */
315
316 if ((len = osaread(fp,record,72)) < 1) goto file_err;
317 for (nr=0; nr<len; nr++)
318 {
319 if (record[nr] == ' ')
320 {
321 record[nr] = '\0';
322 break;
323 }
324 }
325
326 if (strcmp(record,"default") == 0)
327 {
328 if (!(disp_var = getenv("DISPLAY")))
329 {
330 dstatus = 9;
331 goto gen_err;
332 }
333 len = (int) strlen(disp_var);
334 if (len > 119) /* size of Xworkst[].name: 120 chars */
335 {
336 dstatus = 9;
337 goto gen_err;
338 }
339 (void) strcpy(record,disp_var);
340 }
341
342 else if ( ((record[0]=='z')&&(record[1]=='o')) ||
343 ((record[0]=='c')&&(record[1]=='u')) ) /* zoom or cursor w. */
344 {
345 for (nr=0; nr<MAX_DEV; nr++) /* look for main window */
346 {
347 if ( (nr != i) &&
348 (ididev[nr].devname[0] != '\0') &&
349 (ididev[nr].devname[5] == display[5]) )
350 {
351 con_main = nr; /* save connected main window */
352 if (record[4] != ',') /* same Xstation */
353 {
354 screeno = ididev[nr].screen;
355 goto xwst_ok;
356 }
357 else
358 { /* zoom,Xstation */
359 if (strcmp(&record[5],"default") == 0)
360 {
361 if (!(disp_var = getenv("DISPLAY")))
362 {
363 dstatus = 9;
364 goto gen_err;
365 }
366 len = (int) strlen(disp_var);
367 if (len > 119)
368 {
369 dstatus = 9;
370 goto gen_err;
371 }
372 (void) strcpy(record,disp_var);
373 }
374 else
375 (void) strcpy(record,&record[5]); /* move to begin */
376 goto find_Xst;
377 }
378 }
379 }
380
381 dstatus = WSTNAMERR; /* no main window found */
382 goto gen_err;
383 }
384
385
386 /* look for same Xstation or attach new one */
387
388 find_Xst:
389 for (nr=0; nr<MAX_WST; nr++)
390 {
391 if (strcmp(record,Xworkst[nr].name) == 0)
392 {
393 screeno = nr;
394 goto xwst_ok;
395 }
396 }
397 for (nr=0; nr<MAX_WST; nr++)
398 {
399 if (Xworkst[nr].name[0] == '\0')
400 {
401 screeno = nr;
402 (void) strcpy(Xworkst[nr].name,record);
403 goto xwst_ok;
404 }
405 }
406
407 dstatus = WSTNAMERR; /* return with error */
408 goto gen_err;
409
410
411 /* check if we are a shadow window => update owner entry */
412
413 xwst_ok:
414 ididev[i].screen = screeno;
415 ididev[i].ref = '\0';
416 for (j=0; j<MAX_DEV; j++) ididev[i].shadow[j] = -1;
417
418 if (shadow == 0) /* read "shadow,ref-id" line */
419 {
420 if ((len = osaread(fp,record,72)) < 1) goto file_err;
421 len = CGN_INDEXC(record,',');
422 (void) strncpy(cbuf,display,5); /* construct name of ref. window */
423 cbuf[5] = record[++len];
424 if (ididev[i].devtyp == 'g')
425 (void) strcpy(&cbuf[6],"g");
426 else
427 cbuf[6] = '\0';
428 for (nr=0; nr<MAX_DEV; nr++)
429 {
430 if (strcmp(cbuf,ididev[nr].devname) == 0)
431 {
432 shadow = nr; /* save owner id for later */
433 ididev[i].ref = cbuf[5]; /* save reference display */
434 goto next_rec;
435 }
436 }
437 dstatus = ILLSHADOW; /* no reference display found */
438 goto gen_err;
439 }
440
441
442 /* get alpha_memo flag, RGB mode, backgr. colour, 24bit flag */
443
444 next_rec:
445 if ((len = osaread(fp,record,72)) > 0)
446 len = CGN_CNVT(record,1,4,ival,&fval,&dval);
447 if (len < 4) goto file_err;
448 ididev[i].alpno = ival[0];
449 RGBmode = ival[1];
450 k = ival[2];
451 ididev[i].backpix = ival[2]; /* just save the index for now */
452 flag24 = ival[3]; /* serves as byte swap for special,read,write flag */
453
454
455 /* get display offset + dimensions */
456
457 if ((len = osaread(fp,record,72)) > 0)
458 len = CGN_CNVT(record,1,4,ival,&fval,&dval);
459 if (len < 4) goto file_err;
460 devxoff = ival[0]; devyoff = ival[1];
461 devxdim = ival[2]; devydim = ival[3];
462
463
464 /* get noLUTS, maxLUTsize, minLUTsize, ownLUT, LUToffset */
465
466 if ((len = osaread(fp,record,72)) > 0)
467 len = CGN_CNVT(record,1,5,ival,&fval,&dval);
468 if (len < 5) goto file_err;
469 minlut = ival[2];
470 ididev[i].lutoff = ival[4];
471
472 if (f_wndw[screeno] == 0)
473 { /* connect to display */
474 dstatus = Xwstinit(0,Xworkst[screeno].name,screeno,fontno,minlut);
475 if (dstatus != II_SUCCESS) goto gen_err;
476 Xworkst[screeno].nolut = ival[0];
477 Xworkst[screeno].lutsize = ival[1];
478 Xworkst[screeno].ownlut = ival[3]; /* maybe modified by Xwstinit ... */
479 }
480
481
482 /* get font numbers for small, medium, large font */
483
484 if ((len = osaread(fp,record,72)) > 0)
485 {
486 len = CGN_CNVT(record,1,3,fontno,&fval,&dval); /* fontno[4] is special */
487 if (len < 3) goto file_err; /* we need 3 fonts */
488 }
489
490 ididev[i].opened = 1;
491 ididev[i].xsize = devxdim; /* set by display window section */
492 ididev[i].ysize = devydim; /* set by display window section */
493
494 ididev[i].trigger = 0; /* exit trigger is 0 */
495 ididev[i].inter_mask = 0;
496 ididev[i].n_inter = 0;
497 ididev[i].ncurs = 2;
498 ididev[i].lutsect = 0; /* default to 1. (maybe only) LUT section */
499 ididev[i].lookup = 0;
500 ididev[i].bar = 0;
501 ididev[i].hcopy = (char *) 0;
502 ididev[i].curswin = -1;
503 ididev[i].link[0] = 0;
504 ididev[i].link[1] = -1;
505
506
507
508 /* ----------------------- */
509 /* create virtual display */
510 /* ----------------------- */
511
512
513 if (RGBmode == 1)
514 name[0] = 'T'; /* TrueColor */
515 else
516 {
517 name[0] = 'P'; /* PseudoColor */
518 if (RGBmode == 0)
519 name[1] = 'S';
520 else if (RGBmode == 2)
521 name[1] = 'D'; /* on top of DirectColor */
522 else
523 {
524 RGBmode = 2;
525 name[1] = 'T'; /* on top of TrueColor */
526 }
527 }
528
529 if (f_wndw[screeno] == 0)
530 { /* get fonts + colour maps */
531 if (ididev[i].devtyp == 'g')
532 f_wndw[screeno] = 2; /* graphics window is first */
533 else
534 f_wndw[screeno] = 1; /* display window is first */
535
536 dstatus = Xwstinit(f_wndw[screeno],name,screeno,fontno,minlut);
537 if (dstatus != II_SUCCESS) goto gen_err;
538 set_wcur(i,-1); /* create all cursor shapes */
539 if (Xworkst[screeno].lutflag != 0)
540 f_wndw[screeno] = 1; /* we did already everything */
541 if (Xworkst[screeno].visual == 4)
542 RGBmode = 2; /* emulate Pseudo on DirectColor */
543
544 f_RGB[screeno] = RGBmode;
545 }
546
547 else if (f_wndw[screeno] == 2)
548 {
549 if (ididev[i].devtyp != 'g') /* display window after graphics */
550 {
551 f_wndw[screeno] = 1;
552 dstatus = Xwstinit(3,name,screeno,fontno,minlut);
553 if (dstatus != II_SUCCESS) goto gen_err;
554 }
555 }
556
557 RGBmode = f_RGB[screeno]; /* so all windows have same RGBflag */
558
559 /* flag24 uses 3 digits: x y z 1 = on, 2 = off (also 0 = off)
560 used for special_flag (x), read_flag (y), write_flag (z)
561 Xworkst[screeno].flag24[0,1,2] = z,y,x */
562
563 if (flag24 == 0) /* if not set, check it here */
564 {
565 if (test_swap(i) == 1) /* yes we swap bytes */
566 flag24 = 11;
567 }
568 (void) pars24(flag24,Xworkst[screeno].flag24);
569
570
571 if (ididev[i].alpno >= 90)
572 {
573 ididev[i].alphx = devxdim-2; /* border width = 1 pixel */
574 ididev[i].alphy = 50;
575 ididev[i].alphxscal = 512./80.;
576 ididev[i].alphlinsz = 12; /* pixels per line */
577 m = devydim + ididev[i].alphy + 2; /* add space for alpha subwindow */
578 dstatus = crea_win(i,devxoff,devyoff,devxdim,m,dspchar);
579 crealph(i,devydim); /* create also the alphanumerics window */
580 }
581 else
582 {
583 ididev[i].alphy = -2;
584 dstatus = crea_win(i,devxoff,devyoff,devxdim,devydim,dspchar);
585 if (ididev[i].devtyp == 'c') /* cursor window have no alpha mem */
586 {
587 ididev[con_main].curswin = i;
588 ididev[i].curswin = -con_main; /* keep pointer to main w. */
589 }
590 }
591
592 if (dstatus != II_SUCCESS) goto gen_err;
593 sendX(i); /* flush out Xstuff */
594 x0 = ididev[i].xsize / 2;
595 y0 = ididev[i].ysize / 2;
596 ididev[i].depth = Xworkst[screeno].depth;
597
598 dstatus = MEMALLERR;
599 for (j=0; j<ididev[i].ncurs; j++)
600 {
601 allbytes = sizeof(struct curs_data);
602 curs = (struct curs_data *) malloc((size_t)allbytes);
603 if (curs == II_NULL) goto gen_err;
604
605 ididev[i].cursor[j] = curs;
606 curs->sh = -1; /* sh = -1 : cursor not defined */
607 curs->col = 0;
608 curs->vis = 0;
609 curs->xpos = x0;
610 curs->ypos = y0;
611 }
612
613 allbytes = sizeof(struct roi_data);
614 roi = (struct roi_data *) malloc((size_t)allbytes);
615 if (roi == II_NULL) goto gen_err;
616
617 ididev[i].roi = roi;
618 roi->sh = -1; /* roi_sh = -1 : ROI not defined */
619 roi->col = 0;
620 roi->vis = 0;
621 roi->xmin = x0 - 20;
622 roi->ymin = y0 - 20;
623 roi->xmax = x0 + 20;
624 roi->ymax = y0 + 20;
625 roi->radiusi = 20;
626 roi->radiusm = 0;
627 roi->radiuso = 0;
628 roi->radno = 4;
629
630 allbytes = sizeof(struct conf_data);
631 conf = (struct conf_data *) malloc((size_t)allbytes);
632 if (conf == II_NULL) goto gen_err;
633
634 ididev[i].confptr = conf;
635 conf->memid = 0;
636 conf->RGBmode = RGBmode;
637
638
639 /* get no. of memories + size of GLIST segments */
640
641 if ((len = osaread(fp,record,72)) > 0)
642 len = CGN_CNVT(record,1,2,ival,&fval,&dval);
643 if (len < 2) goto file_err;
644
645 if (RGBmode == 1)
646 k1 = 1;
647 else
648 k1 = ival[0];
649 gsize = ival[1];
650
651 for (k=0; k<k1; k++) /* loop over memories */
652 {
653 allbytes = sizeof(struct mem_data);
654 mem = (struct mem_data *) malloc((size_t)allbytes);
655 if (mem == II_NULL) goto gen_err;
656
657 conf->memory[k] = mem;
658 if ((len = osaread(fp,record,72)) > 0)
659 len = CGN_CNVT(record,1,3,ival,&fval,&dval);
660 if (len < 3) goto file_err;
661
662 mem->xsize = ival[0];
663 mem->ysize = ival[1];
664 if (ival[2] < 0)
665 mem->depth = ididev[i].depth;
666 else
667 mem->depth = ival[2];
668
669 if (ididev[i].devtyp == 'g')
670 mem->type = II_GRAPHIC | II_TEXT;
671 else
672 mem->type = II_IMAGE | II_GRAPHIC | II_TEXT;
673 if (RGBmode == 1) mem->type = mem->type | II_RGB;
674 mem->mmbm = (char *) 0;
675 mem->zmbm = (char *) 0;
676 mem->pixmap = 0;
677 if (k == 0)
678 mem->visibility = 1; /* make first channel visible */
679 else
680 mem->visibility = 0;
681 clmem(mem); /* set all memory parameters */
682
683 if (ididev[i].alpno >= 90)
684 { /* allocate alpha memory */
685 allbytes = sizeof(struct alph_data);
686 alph = (struct alph_data *) malloc((size_t)allbytes);
687 if (alph == II_NULL) goto gen_err;
688
689 conf->alpmem[k] = alph;
690 for (nr=0; nr<16; nr++)
691 alph->savx[nr] = -1;
692 }
693
694 if (ididev[i].devtyp == 'g')
695 mem->ittpntr = (ITT_DATA *)0; /* no ITT for graph/cursor windows */
696 else
697 {
698 allbytes = sizeof(struct itt_data);
699 itt = (struct itt_data *) malloc((size_t)allbytes);
700 if (itt == II_NULL) goto gen_err;
701 mem->ittpntr = itt;
702 itt->vis = 0; /* default to ITT visibility off */
703 for (nr=0; nr<Xworkst[screeno].lutlen; nr++)
704 itt->val[nr] = nr;
705 }
706
707 if (gsize <= 0)
708 mem->gpntr = (GLIST *)0; /* no graphics structure */
709 else
710 {
711 allbytes = sizeof(struct glist);
712 graph = (struct glist *) malloc((size_t)allbytes);
713 if (graph == II_NULL) goto gen_err;
714 mem->gpntr = graph;
715 graph->geln = 0;
716 graph->maxpnt = gsize;
717 len = graph->maxpnt/2;
718 allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */
719 graph->x = (int *) malloc((size_t)allbytes); /* color, lwidth, */
720 if (graph->x == II_NULL) goto gen_err;
721 graph->y = graph->x + graph->maxpnt;
722 graph->color = graph->y + graph->maxpnt;
723 graph->lwidth = graph->color + len;
724 graph->off = graph->lwidth + len;
725 graph->count = graph->off + len;
726 *(graph->off) = 0;
727 }
728
729 if (limited > 0)
730 mem->tpntr = (TLIST *)0;
731 else
732 {
733 allbytes = sizeof(struct tlist);
734 txt = (struct tlist *) malloc((size_t)allbytes);
735 if (txt == II_NULL) goto gen_err;
736 mem->tpntr = txt;
737 txt->teln = 0;
738 txt->off[0] = 0;
739 }
740 mem->plane_no = 1;
741 }
742
743 osaclose(fp);
744
745
746 /* for graphics window
747 the overlay channel is the image channel itself */
748
749 if (ididev[i].devtyp == 'g')
750 {
751 conf->nmem = k1;
752 conf->overlay = conf->memid;
753 }
754 else
755 {
756 conf->nmem = k1 + 1; /* add 1 for overlay channel */
757 conf->overlay = k1; /* last channel */
758
759
760 /* now also init the structure for the added overlay/graphics channel */
761
762 allbytes = sizeof(struct mem_data);
763 mem = (struct mem_data *) malloc((size_t)allbytes);
764 if (mem == II_NULL) return(MEMALLERR);
765
766 conf->memory[k1] = mem;
767 mem->xsize = ival[0]; /* use values of last channel */
768 mem->ysize = ival[1];
769 mem->depth = ival[2];
770 mem->type = II_IMAGE | II_GRAPHIC | II_TEXT;
771 if (RGBmode == 1) mem->type = mem->type | II_RGB;
772 mem->mmbm = (char *) 0;
773 mem->zmbm = (char *) 0;
774 mem->pixmap = 0;
775 mem->visibility = 1; /* we enable overlay right away */
776 clmem(mem);
777 mem->ittpntr = (ITT_DATA *)0;
778
779 if (gsize <= 0)
780 mem->gpntr = (GLIST *)0; /* no graphics structure */
781 else
782 {
783 allbytes = sizeof(struct glist);
784 graph = (struct glist *) malloc((size_t)allbytes);
785 if (graph == II_NULL) return(MEMALLERR);
786 mem->gpntr = graph;
787 graph->geln = 0;
788 graph->maxpnt = gsize;
789 len = graph->maxpnt/2;
790 allbytes = sizeof(int) * (2*graph->maxpnt + 4*len); /* for x,y */
791 graph->x = (int *) malloc((size_t)allbytes); /* color, lwidth, */
792 if (graph->x == II_NULL) return(MEMALLERR); /* off and count */
793 graph->y = graph->x + graph->maxpnt;
794 graph->color = graph->y + graph->maxpnt;
795 graph->lwidth = graph->color + len;
796 graph->off = graph->lwidth + len;
797 graph->count = graph->off + len;
798 *(graph->off) = 0;
799 }
800
801 allbytes = sizeof(struct tlist);
802 txt = (struct tlist *) malloc((size_t)allbytes);
803 if (txt == II_NULL) return(MEMALLERR);
804 mem->tpntr = txt;
805 txt->teln = 0;
806 txt->off[0] = 0;
807 mem->plane_no = 1;
808 }
809
810 if (limited != 2) /* not for cursor window */
811 {
812 for (j=0; j<MAX_INTER; j++)
813 {
814 allbytes = sizeof(struct inter_data);
815 ixter = (struct inter_data *) malloc((size_t)allbytes);
816 if (ixter == II_NULL) return(MEMALLERR);
817
818 ididev[i].inter[j] = ixter;
819 }
820
821 intdevtable[i].nloc = MAX_LOC;
822 intdevtable[i].ntrig = MAX_TRG;
823
824 for (j=0; j<intdevtable[i].nloc; j++)
825 {
826 allbytes = sizeof(struct locator);
827 loca = (struct locator *) malloc((size_t)allbytes);
828 if (loca == II_NULL) return(MEMALLERR);
829
830 if (j == 0)
831 loca->interactor = II_MOUSE;
832 else
833 loca->interactor = II_KEYB;
834 intdevtable[i].loc[j] = loca;
835 }
836
837 loc_zero(i); /* reset all locators */
838
839 for (j=0; j<intdevtable[i].ntrig; j++)
840 {
841 allbytes = sizeof(struct trigger);
842 trigg = (struct trigger *) malloc((size_t)allbytes);
843 if (trigg == II_NULL) return(MEMALLERR);
844
845 if (j < 2) /* assume 2 buttons on the mouse */
846 trigg->interactor = II_MOUSE;
847 else
848 trigg->interactor = II_KEYB;
849 intdevtable[i].trig[j] = trigg;
850 }
851 }
852
853 if (shadow >= 0) /* if shadow window update owner */
854 {
855 for (j=0; j<MAX_DEV; j++)
856 {
857 if (ididev[shadow].shadow[j] == -1)
858 {
859 ididev[shadow].shadow[j] = i;
860 break;
861 }
862 }
863 }
864
865
866
867 /* create LUT bar structure */
868
869 allbytes = sizeof(struct lut_bar);
870 bar = (struct lut_bar *) malloc((size_t)allbytes);
871 if (bar == II_NULL) return(MEMALLERR);
872
873 ididev[i].bar = bar;
874 bar->wp = 0;
875 bar->vis = 0;
876
877
878 /* check if we have own LUT handling */
879
880 if ( (limited > 0) ||
881 ((Xworkst[screeno].visual != 4) && (Xworkst[screeno].ownlut == 0)) )
882 return(II_SUCCESS);
883
884
885 if (Xworkst[screeno].ownlut == -1)
886 {
887 for (nr=0; nr<256; nr++) /* add LUT offset at least... */
888 {
889 j = nr + ididev[i].lutoff;
890 if (j > 255) j = 0;
891 Xworkst[screeno].mapin[nr] = j;
892 Xworkst[screeno].mapout[j] = nr;
893 }
894 return(II_SUCCESS);
895 }
896
897
898 allbytes = sizeof(struct lut_data);
899 lut = (struct lut_data *) malloc((size_t)allbytes);
900 if (lut == II_NULL) return(MEMALLERR);
901 ididev[i].lookup = lut;
902 lut->vis = 1; /* make LUT always visible */
903
904
905 /* send black + white LUT only the very first time */
906
907 if (f_lut[screeno] == 1)
908 {
909 float lut0[768];
910
911 f_lut[screeno] = 0;
912 len = Xworkst[screeno].lutlen;
913 rval = 1.0 / (len - 1.0);
914 m = len + len;
915 fval = 0.0;
916
917 for (nr=0; nr<len; nr++)
918 {
919 lut0[nr] = fval;
920 lut0[len + nr] = fval;
921 lut0[m + nr] = fval;
922 fval += rval;
923 }
924
925 m = IILWLT_C(i,0,0,len,lut0);
926 LUTinstall(i); /* install LUT if needed */
927 }
928 else
929 rd_lut(i,lut); /* get current LUT */
930
931 return(II_SUCCESS);
932
933
934 gen_err:
935 (void) osaclose(fp);
936 return(dstatus);
937
938 file_err:
939 (void) osaclose(fp);
940 return(DCTREADERR);
941 }
942