~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to libsrc/idi/cidi/x11/iid1.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

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