File: imgread.c

package info (click to toggle)
saoimage 1.29.3-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,952 kB
  • ctags: 4,265
  • sloc: ansic: 50,317; makefile: 243; sh: 35
file content (235 lines) | stat: -rw-r--r-- 6,451 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#ifndef lint
static char SccsId[] = "%W%  %G%";
#endif

/* Module:	imgread.c (Image Read)
 * Purpose:	Read image headers and image files
 * Subroutine:	init_image()			returns: int
 * Subroutine:	load_image()
 * Xlib calls:	none
 * Copyright:	1989 Smithsonian Astrophysical Observatory
 *		You may do anything you like with this file except remove
 *		this copyright.  The Smithsonian Astrophysical Observatory
 *		makes no representations about the suitability of this
 *		software for any purpose.  It is provided "as is" without
 *		express or implied warranty.
 * Modified:	{0} Michael VanHilst	initial version	         1 July 1989
 *		{n} <who> -- <does what> -- <when>
 */

#include <stdio.h>			/* stderr, NULL, etc. */
#include <X11/Xlib.h>			/* X window stuff */
#include <X11/Xutil.h>			/* X window manager stuff */
#include "hfiles/constant.h"		/* constants and codes */
#include "hfiles/struct.h"		/* declare structure types */
#include "hfiles/extern.h"		/* extern main parameter structures */

static int init_imtool;

/*
 * Subroutine:	init_image
 * Purpose:	Set the image dimensions
 * Returns:	1 if OK, 0 if trouble
 * Method:	set image info from known values or read from a header
 */
int init_image ( )
{
  int get_fbconfig();		/* get IRAF expected frame size */
  void init_img(), init_dispcen();
#ifdef FITS
  int init_fits();
#endif
#ifdef OIF
  int init_irafimh();
#endif

  /* read and strip subsection suffix */
/* %%  get_subsection(&img); */
  switch( img.file_type ) {
  case SOP_Array:
#ifdef DEBUG
    if( (img.filerows <= 0) || (img.filecols <= 0) ) {
      (void)fprintf(stderr, "Error: array dimensions not set");
      return( 0 );
    }
#endif
    img.block_type = SOP_ZoomNone;
    break;
  case SOP_FITS:
#ifdef FITS
    if( (img.fd = init_fits(&img)) < 0 )
      return( 0 );
    img.block_type = SOP_ZoomNone;
    break;
#else
    (void)fprintf(stderr, "WARNING: not compiled with -DFITS switch\n");
    return( 0 );
#endif
  case SOP_IRAF:
#ifdef OIF
    if( (img.fd = init_irafimh(&img)) < 0 )
      return( 0 );
    img.block_type = SOP_ZoomNone;
    break;
#else
    (void)fprintf(stderr, "WARNING: not compiled with -DIRAF switch\n");
    return( 0 );
#endif
  case SOP_SAOCCD:
#ifdef SAOCCD
    init_saoccd(&img);
    img.block_type = SOP_ZoomNone;
    break;
#else
    (void)fprintf(stderr, "WARNING: not compiled with -DSAOCCD switch\n");
    return( 0 );
#endif
  case SOP_Imtool:
  case SOP_PROS:
#ifdef IMTOOL
    /* remote access from iraf, start with standard screen size */
fprintf (stdout,"DBG: img.fbconfig=%d  -> ",img.fbconfig);
    if( get_fbconfig(img.fbconfig, &img.filecols, &img.filerows) == 0 ) {
      img.filecols = 512;
      img.filerows = 512;
    }
fprintf (stdout,"filecols=%d  filerows=%d\n",img.filecols,img.filecols);fflush(stdout);
    img.block_type = SOP_ZoomNone;
    /* signal load_image to load a default image */
    init_imtool = 1;
    break;
#else
    (void)fprintf(stderr, "Note: IRAF pipe support not compiled.\n");
    return( 0 );
#endif
  case SOP_Logo:
  default:
    img.filerows = 512;
    img.filecols = 512;
    img.block_type = SOP_ZoomNone;
    break;
  }
  /* fix up image record parameters and img to file conversions */
  init_img(&img, &coord);
  init_dispcen(&img, &coord);
  return( 1 );
}

/*
 * Subroutine:	load_image
 * Purpose:	Open if necessary, then read the appropriate image file
 *		and create a 16 bit image array
 */
void load_image ( fb, buf, bftrans, imgbuf, filebuf, buf_squared, buf_doubled )
     Edges *fb;			/* coord structures (for disp or pan) */
     Coordsys *buf;
     Transform *bftrans;
     short *imgbuf;
     char *filebuf;
     int buf_squared, buf_doubled;	/* buf is larger to enable rotation */
{
  static int init = 1;	/* signal first time through */
  int x, y;
  int width, height;
  int read_image;	/* avoid doing rotate if there is nothing to rotate */
  void read_array(), rotate_buf(), clear_coord_area(), load_logo();

#ifdef SUBSEC
  float X, Y;
  void i_transform();
  /* THIS ISN'T RIGHT (WHAT IF IMAGE IS ROTATED OR FLIPPED?) */
  /* get file coords of buffer's 0,0 element */
  i_transform(bftrans, 0, 0, &X, &Y);
  x = (int)(X + 0.5);
  y = (int)(Y + 0.5);
#else
  x = 0;
  y = 0;
  fb->block = 1;
#endif
  /* if rotation has a 90 degree component, get cross zoom factor */
  if( img.rotate_code & 1 ) {
    width = buf->height;
    height = buf->width;
  } else {
    width = buf->width;
    height = buf->height;
  }
  read_image = 0;
  switch(img.file_type) {
  case SOP_Array:
    read_array(-1, &img, imgbuf, filebuf, width, height, x, y,
	       fb->block, control.verbose);
    read_image = 1;
    break;
#ifdef FITS
  case SOP_FITS:
#endif
#ifdef OIF
  case SOP_IRAF:
#endif
    read_array(img.fd, &img, imgbuf, filebuf,
	       width, height, x, y, fb->block, control.verbose);
    read_image = 1;
    break;
#ifdef SAOCCD
  case SOP_SAOCCD:
    load_saoccd(&img, imgbuf, width, height, x, y, fb->block);
    read_image = 1;
    break;
#endif
#ifdef XRAY
  case SOP_HRI:
  case SOP_IPC:
    load_einstein(&img, imgbuf, width, height,
		  fb->cenX, fb->cenY, fb->block);
    read_image = 1;
    break;
#endif
#ifdef ROSAT
  case SOP_ROSAT:
    load_rosat(&img, imgbuf, width, height, fb->cenX, fb->cenY, fb->block);
    read_image = 1;
    break;
#endif
#ifdef IMTOOL
  case SOP_Imtool:
  case SOP_PROS:
    if( init )
      load_logo(imgbuf, width, height);
    if( init_imtool ) {
      init_imtool = 0;
    }
    break;
#endif
  case SOP_Logo:
    if( init )
      load_logo(imgbuf, width, height);
  default:
    break;
  }
  if( read_image ) {
    if( (img.row_order != 0) || (img.rotate_code != 0) ) {
      rotate_buf(imgbuf, img.row_order, img.rotate_code, width, height,
		 buf_squared, buf_doubled);
    }
    if( (img.file_type != SOP_Imtool) && (img.file_type != SOP_PROS) ) {
      /* we loaded a non-imtool image */
      img.imtool_200 = 0;
      /* if there was a second coordinate system, cancel it */
      if( coord.imtool_aux ) {
	clear_coord_area();
	coord.imtool_aux = 0;
      }
      /* if artificial limits were applied to input, mark short_buf extremes */
      if( img.fimin < img.fimax ) {
	buffer.clipmin = (int)((img.fimin - img.fibias) / img.fiscale);
	buffer.clipmax = (int)((img.fimax - img.fibias) / img.fiscale);
      } else {
	/* imtool limits are set when an image is read from the pipe */
	buffer.clipmin = -32768;
	buffer.clipmax = 32767;
      }
    }
  }
}