1
/* @(#)sizer.c 19.1 (ESO-DMD) 02/25/03 14:00:00 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
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.
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.
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,
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
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT (c) 1994 European Southern Observatory
33
.AUTHOR K. Banse ESO Garching
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
39
call as SIZER_C(memsz,npix,scale,scale_flag,icen,nima,nssta,nf,nfsta)
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
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
59
#include <midas_def.h> Prototypes for MIDAS interfaces
60
#include <idinumd.h> Global variables for DISPLAY interfaces
62
.VERSIONS 1.00 940325 F->C, converted from LOADWN.FOR RvH
64
------------------------------------------------------------*/
67
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
69
#define _POSIX_SOURCE 1
73
#include <midas_def.h>
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;
85
int kcomp, nfhi, nshi, nflo, nslo, nn, mfp1, mfp2;
88
mfp1 = icen[1]; /* screen fix point (center pixel) */
89
if (mfp1 < 0) /* 0,1,... */
91
else if (mfp1 >= memsz)
94
mfp2 = icen[0]; /* frame fix point (center pixel) */
95
if (mfp2 < 1) /* 1,2,... */
100
nslo = mfp1; /* screen pixels to the left */
101
nshi = memsz - mfp1; /* fixpoint + scr. pixels to the right */
103
nflo = mfp2 - 1; /* frame pixels to the left */
104
nfhi = npix - nflo; /* fixpoint + fr. pixels to the right */
107
/* we shrink the image */
111
if (scale_flag == 0) /* omit rows/columns */
113
kcomp = nflo / scale;
114
if (kcomp < nslo) nslo = kcomp;
116
kcomp = (nfhi+scale-1)/scale; /* start with center pixel */
117
if (kcomp < nshi) nshi = kcomp;
123
*nf = 1; /* if scaling too big ... */
127
else /* we average over areas */
129
mfp2 -= (scale/2); /* left end of center area */
130
if (mfp2 < 1) mfp2 = 1;
132
kcomp = nflo / scale;
133
if (kcomp < nslo) nslo = kcomp;
136
kcomp = (npix-mfp2+1)/scale; /* start with center area */
137
if (kcomp < nshi) nshi = kcomp;
143
*nf = 1; /* if scaling too big ... */
150
/* we expand the image */
156
if (kcomp < nslo) nslo = kcomp;
158
nslo = nflo * nn; /* now really multiples */
160
if (kcomp < nshi) nshi = kcomp;
167
/* we keep the image size */
171
if (nflo < nslo) nslo = nflo;
173
if (nfhi < nshi) nshi = nfhi;
175
*nima = nslo + nshi; /* total no. of screen pixels */
176
*nf = *nima; /* total no. of frame pixels */
179
*nssta = mfp1 - nslo; /* start screen pixel */
180
*nfsta = mfp2 - nflo; /* start frame pixel */