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

« back to all changes in this revision

Viewing changes to prim/general/libsrc/luttbl.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
/* @(#)luttbl.c 19.1 (ES0-DMD) 02/25/03 14:01:07 */
 
2
/*===========================================================================
 
3
  Copyright (C) 1995 European Southern Observatory (ESO)
 
4
 
 
5
  This program is free software; you can redistribute it and/or 
 
6
  modify it under the terms of the GNU General Public License as 
 
7
  published by the Free Software Foundation; either version 2 of 
 
8
  the License, or (at your option) any later version.
 
9
 
 
10
  This program is distributed in the hope that it will be useful,
 
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
  GNU General Public License for more details.
 
14
 
 
15
  You should have received a copy of the GNU General Public 
 
16
  License along with this program; if not, write to the Free 
 
17
  Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, 
 
18
  MA 02139, USA.
 
19
 
 
20
  Corresponding concerning ESO-MIDAS should be addressed as follows:
 
21
        Internet e-mail: midas@eso.org
 
22
        Postal address: European Southern Observatory
 
23
                        Data Management Division 
 
24
                        Karl-Schwarzschild-Strasse 2
 
25
                        D 85748 Garching bei Muenchen 
 
26
                        GERMANY
 
27
===========================================================================*/
 
28
 
 
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
30
.COPYRIGHT:  Copyright (c) 1994 European Southern Observatory,
 
31
                                         all rights reserved
 
32
.IDENTIFIER  module LUTTBL
 
33
.LANGUAGE    C
 
34
.AUTHOR      K. Banse                   ESO - IPG, Garching
 
35
.KEYWORDS    LUT/ITT tables
 
36
.PURPOSE     use table interfaces
 
37
.CONTAINS    OPNTBL, CRELUT & CREITT
 
38
.ENVIRONment MIDAS
 
39
             #include <midas_def.h>   Prototypes for MIDAS interfaces
 
40
 
 
41
.VERSIONS    1.00       940704  F77 -> C, from TABSUBS.FOR    R.M.van Hees
 
42
.VERSIONS    1.10       941109  cleanup + fix it
 
43
------------------------------------------------------------*/
 
44
 
 
45
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
46
 
 
47
#define  _POSIX_SOURCE 1
 
48
 
 
49
#include <stdio.h>
 
50
#include <midas_def.h>
 
51
 
 
52
#define MYLUTSZ         256
 
53
 
 
54
/*
 
55
 
 
56
*/
 
57
 
 
58
/*++++++++++++++++++++++++++++++
 
59
.IDENTIFIER  OPNTBL
 
60
.PURPOSE     open LUT or ITT tables
 
61
.INPUT/OUTPUT
 
62
  call as    OPNTBL( table, tid, ncols, nrows )
 
63
     input:
 
64
         char *table :          table name
 
65
     output:
 
66
         int  *tid   :          id of table
 
67
         int  *ncols :          number of columns
 
68
         int  *nrows :          number of rows
 
69
 
 
70
.RETURNS     nothing
 
71
--------------------------------*/
 
72
 
 
73
void OPNTBL( table, tid, ncols, nrows )
 
74
char *table;
 
75
int  *tid, *ncols, *nrows;
 
76
 
 
77
{      
 
78
int  allcol, allrow, ec, el, ed, nsort, stat;
 
79
char file[84];
 
80
 
 
81
static int  con_alw = 1, log_no = 0, dis_no = 0;     /* variables for SCECNT */
 
82
 
 
83
 
 
84
/* first look for table in current directory,
 
85
   then for table in MID_WORK, finally look for system table */
 
86
 
 
87
(void) SCECNT( "GET", &ec, &el, &ed );
 
88
(void) SCECNT( "PUT", &con_alw, &log_no, &dis_no );
 
89
stat = TCTOPN( table, F_I_MODE, tid );
 
90
 
 
91
nsort = 0;              /* use as indicator of SCECNT */
 
92
if (stat != ERR_NORMAL)
 
93
   {
 
94
   (void) sprintf( file, "MID_WORK:%-s", table );
 
95
   stat = TCTOPN( file, F_I_MODE, tid );
 
96
   if ( stat != 0 )
 
97
      {
 
98
      (void) sprintf( file, "MID_SYSTAB:%-s", table );
 
99
      (void) SCECNT( "PUT", &ec, &el, &ed );
 
100
      nsort = 1;        
 
101
      stat = TCTOPN( file, F_I_MODE, tid );
 
102
      }
 
103
   }
 
104
 
 
105
/* get info about table */
 
106
 
 
107
if (nsort == 0) (void) SCECNT( "PUT", &ec, &el, &ed );
 
108
(void) TCIGET( *tid, ncols, nrows, &nsort, &allcol, &allrow );
 
109
}
 
110
/*
 
111
 
 
112
*/
 
113
 
 
114
/*++++++++++++++++++++++++++++++
 
115
.IDENTIFIER  CRELUT
 
116
.PURPOSE     create + fill LUT tables for Image Display
 
117
.INPUT/OUTPUT
 
118
  call as    CRELUT( table, rlut )
 
119
     input:
 
120
         char *table:   table name
 
121
         float *rlut:   LUT table (red, green, blue)
 
122
         int   lutlen:  LUT size
 
123
         int   format:  format = 0 for Midas table, 9 for ASCII file
 
124
         int   *range:  low, high range (0,1 or 0,255 supported)
 
125
 
 
126
.RETURNS     nothing
 
127
--------------------------------*/
 
128
 
 
129
void CRELUT (table,rlut,lutlen,format,range)
 
130
char  *table;
 
131
float *rlut;
 
132
int   lutlen, format, *range;
 
133
 
 
134
{
 
135
register int  nn;
 
136
register float *pntrR, *pntrG, *pntrB;
 
137
 
 
138
int   idx, tid, tcolnm[3], idata[3];
 
139
float data[3];
 
140
char  mytab[61];
 
141
      
 
142
int IndxR, IndxG, IndxB;
 
143
static char *tbllab[3] = { "RED", "GREEN", "BLUE" };
 
144
 
 
145
idx = CGN_INDEXC(table,' ');
 
146
if (idx < 0) idx = strlen(table);
 
147
if (idx > 56)
 
148
   SCETER(111,"CRELUT: input table name > 56 chars....");
 
149
 
 
150
IndxR = 0;
 
151
IndxG = lutlen;
 
152
IndxB = lutlen + lutlen;
 
153
pntrR = rlut + IndxR;
 
154
pntrG = rlut + IndxG;
 
155
pntrB = rlut + IndxB;
 
156
 
 
157
 
 
158
/* check for table or ASCII file option */
 
159
 
 
160
if (format == 9)                        /* write to ASCII file */
 
161
   {
 
162
   int  fp;
 
163
 
 
164
   fp = osaopen(table,1);               /* open for writing  */
 
165
   if (fp == -1)
 
166
      SCETER(123,"Could not open output file...");
 
167
 
 
168
   if (range[1] == 1)
 
169
      {
 
170
      for (nn=1; nn<=lutlen; nn++)
 
171
         {
 
172
         data[0] = *pntrR++;
 
173
         data[1] = *pntrG++;
 
174
         data[2] = *pntrB++;
 
175
         sprintf(mytab," %8.5f  %8.5f  %8.5f",data[0],data[1],data[2]);
 
176
         osawrite(fp,mytab,strlen(mytab));
 
177
         }
 
178
      }
 
179
   else
 
180
      {
 
181
      float  rm;
 
182
 
 
183
      rm = (float) (MYLUTSZ - 1);
 
184
      for (nn=1; nn<=lutlen; nn++)
 
185
         {
 
186
         data[0] = *pntrR++;
 
187
         idata[0] = CGN_NINT(data[0]*rm);
 
188
         data[1] = *pntrG++;
 
189
         idata[1] = CGN_NINT(data[1]*rm);
 
190
         data[2] = *pntrB++;
 
191
         idata[2] = CGN_NINT(data[2]*rm);
 
192
         sprintf(mytab," %d  %d  %d",idata[0],idata[1],idata[2]);
 
193
         osawrite(fp,mytab,strlen(mytab));
 
194
         }
 
195
      }
 
196
   osaclose(fp);
 
197
   }
 
198
 
 
199
else                                    /* write to Midas table */
 
200
   {
 
201
   (void) strncpy(mytab,table,idx);
 
202
   (void) strcpy(&mytab[idx],".lut");
 
203
 
 
204
   (void) TCTINI( mytab, 0, F_O_MODE, 8, MYLUTSZ, &tid );
 
205
 
 
206
   for (nn=0; nn<3; nn++)
 
207
      (void) TCCINI( tid, D_R4_FORMAT, 1, "e12.5", " ", tbllab[nn], tcolnm+nn );
 
208
 
 
209
   for (nn=1; nn<=lutlen; nn++)
 
210
      {
 
211
      data[0] = *pntrR++;
 
212
      data[1] = *pntrG++;
 
213
      data[2] = *pntrB++;
 
214
      (void) TCRWRR( tid, nn, 3, tcolnm, data );
 
215
      }
 
216
 
 
217
   (void) TCSINI( tid );                /* release table file properly */
 
218
   (void) TCTCLO( tid );
 
219
   }
 
220
}
 
221
/*
 
222
 
 
223
*/
 
224
 
 
225
/*++++++++++++++++++++++++++++++
 
226
.IDENTIFIER  CREITT
 
227
.PURPOSE     create + fill ITT tables for Image Display
 
228
.INPUT/OUTPUT
 
229
  call as    CREITT( table, rlut )
 
230
     input:
 
231
         char *table :          table name
 
232
     output:
 
233
         float *ritt :          ITT table
 
234
 
 
235
.RETURNS     nothing
 
236
--------------------------------*/
 
237
 
 
238
void CREITT ( table, ritt )
 
239
char  *table;
 
240
float *ritt;
 
241
 
 
242
{
 
243
register int nn;
 
244
 
 
245
int  idx, tid, tcolnm;
 
246
char mytab[61];
 
247
 
 
248
static char *tbllab = "ITT";
 
249
 
 
250
idx = CGN_INDEXC(table,' ');
 
251
if (idx < 0) idx = strlen(table);
 
252
if (idx > 56)
 
253
   SCETER(111,"CREITT: input table name > 56 chars....");
 
254
 
 
255
(void) strncpy(mytab,table,idx);
 
256
(void) strcpy(&mytab[idx],".itt");
 
257
 
 
258
(void) TCTINI( mytab, 0, F_O_MODE, 4, MYLUTSZ, &tid );
 
259
(void) TCCINI( tid, D_R4_FORMAT, 1, "e12.5", " ", tbllab, &tcolnm );
 
260
 
 
261
for (nn=1; nn<=MYLUTSZ; nn++)
 
262
   (void) TCEWRR( tid, nn, tcolnm, ritt++ );
 
263
 
 
264
(void) TCSINI( tid );           /* release table file properly */
 
265
(void) TCTCLO( tid );
 
266
}