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

« back to all changes in this revision

Viewing changes to prim/display/libsrc/sizer.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
/* @(#)sizer.c  19.1 (ESO-DMD) 02/25/03 14:00:00 */
 
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 Massachusetts Ave, Cambridge, 
 
18
  MA 02139, USA.
 
19
 
 
20
  Correspondence 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   (c) 1994 European Southern Observatory
 
31
.IDENTIFIER  SIZER_C
 
32
.LANGUAGE    C
 
33
.AUTHOR      K. Banse                   ESO Garching
 
34
.KEYWORDS    memory size
 
35
.PURPOSE     a) compute the size of an image on the image memory channel
 
36
             b) compute the size of the window in the frame for above
 
37
.ALGORITHM   straight forward
 
38
.INPUT/OUTPUT
 
39
   call as   SIZER_C(memsz,npix,scale,scale_flag,icen,nima,nssta,nf,nfsta)
 
40
 
 
41
  input:
 
42
         int  memsz             x/y-size of memory
 
43
         int  npix              no. of pixels in one dimension
 
44
         int  scale             scaling factor for image
 
45
                                make image smaller, if > 1
 
46
                                make image larger, if <  1
 
47
         int  scale_flag        = 0, omit lines; > 0, average over area
 
48
         int  icen[2]           frame pixel and screen pixel which should
 
49
                                be the fix point
 
50
 
 
51
  output:
 
52
         int  *nima             no. of pixels in image memory
 
53
         int  *nssta            start screen pixel
 
54
         int  *nf               no. of frame pixels
 
55
         int  *nfsta            start frame pixel
 
56
 
 
57
.RETURNS     nothing
 
58
.ENVIRONment MIDAS
 
59
             #include <midas_def.h>      Prototypes for MIDAS interfaces
 
60
             #include <idinumd.h>     Global variables for DISPLAY interfaces
 
61
 
 
62
.VERSIONS    1.00       940325  F->C, converted from LOADWN.FOR   RvH
 
63
 980507
 
64
------------------------------------------------------------*/
 
65
 
 
66
 
 
67
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
68
 
 
69
#define  _POSIX_SOURCE 1
 
70
 
 
71
 
 
72
 
 
73
#include <midas_def.h>
 
74
 
 
75
 
 
76
 
 
77
/*
 
78
 
 
79
*/
 
80
 
 
81
void SIZER_C(memsz, npix, scale, scale_flag, icen, nima, nssta, nf, nfsta)
 
82
int  memsz, npix, scale, scale_flag, *icen, *nima, *nssta, *nf, *nfsta;
 
83
 
 
84
{
 
85
int kcomp, nfhi, nshi, nflo, nslo, nn, mfp1, mfp2;
 
86
 
 
87
 
 
88
mfp1 = icen[1];                         /* screen fix point (center pixel) */
 
89
if (mfp1 < 0)                           /* 0,1,... */
 
90
   mfp1 = 0;
 
91
else if (mfp1 >= memsz)     
 
92
   mfp1 = memsz - 1;
 
93
 
 
94
mfp2 = icen[0];                         /* frame fix point (center pixel) */
 
95
if (mfp2 < 1)                           /* 1,2,... */
 
96
   mfp2 = 1;
 
97
else if (mfp2 > npix)     
 
98
   mfp2 = npix;
 
99
 
 
100
nslo = mfp1;                    /* screen pixels to the left */
 
101
nshi = memsz - mfp1;            /* fixpoint + scr. pixels to the right */
 
102
 
 
103
nflo = mfp2 - 1;                /* frame pixels to the left */
 
104
nfhi = npix - nflo;             /* fixpoint + fr. pixels to the right */
 
105
 
 
106
 
 
107
/* we shrink the image */
 
108
 
 
109
if (scale > 1)     
 
110
   {
 
111
   if (scale_flag == 0)         /* omit rows/columns */
 
112
      {
 
113
      kcomp = nflo / scale;
 
114
      if (kcomp < nslo) nslo = kcomp;
 
115
      nflo = nslo * scale;
 
116
      kcomp = (nfhi+scale-1)/scale;             /* start with center pixel */
 
117
      if (kcomp < nshi) nshi = kcomp;
 
118
 
 
119
      *nima = nslo + nshi;
 
120
      *nf   = *nima * scale;
 
121
      if (*nf <= 0)     
 
122
         {
 
123
         *nf = 1;                       /* if scaling too big ... */
 
124
         *nima = 1;
 
125
         }
 
126
      }
 
127
   else                         /* we average over areas */
 
128
      {
 
129
      mfp2 -= (scale/2);                /* left end of center area */
 
130
      if (mfp2 < 1) mfp2 = 1;
 
131
      nflo = mfp2 - 1;
 
132
      kcomp = nflo / scale;
 
133
      if (kcomp < nslo) nslo = kcomp;
 
134
      nflo = nslo * scale;
 
135
 
 
136
      kcomp = (npix-mfp2+1)/scale;      /* start with center area */
 
137
      if (kcomp < nshi) nshi = kcomp;
 
138
 
 
139
      *nima = nslo + nshi;
 
140
      *nf   = *nima * scale;
 
141
      if (*nf <= 0)     
 
142
         {
 
143
         *nf = 1;                       /* if scaling too big ... */
 
144
         *nima = 1;
 
145
         }
 
146
      }
 
147
   }
 
148
 
 
149
 
 
150
/* we expand the image */
 
151
 
 
152
else if (scale < -1)     
 
153
   {
 
154
   nn = -scale;
 
155
   kcomp = nflo * nn;
 
156
   if (kcomp < nslo) nslo = kcomp;
 
157
   nflo = nslo / nn;
 
158
   nslo = nflo * nn;                    /* now really multiples */
 
159
   kcomp = nfhi * nn;
 
160
   if (kcomp < nshi) nshi = kcomp;
 
161
 
 
162
   *nima = nslo + nshi;
 
163
   *nf   = *nima / nn;
 
164
   }
 
165
 
 
166
 
 
167
/* we keep the image size */
 
168
 
 
169
else 
 
170
   {
 
171
   if (nflo < nslo) nslo = nflo;
 
172
   nflo = nslo;
 
173
   if (nfhi < nshi) nshi = nfhi;
 
174
 
 
175
   *nima = nslo + nshi;                 /* total no. of screen pixels */
 
176
   *nf = *nima;                         /* total no. of frame pixels */
 
177
   }
 
178
 
 
179
*nssta = mfp1 - nslo;                   /* start screen pixel */
 
180
*nfsta = mfp2 - nflo;                   /* start frame pixel */
 
181
}