Back to index

radiance  4R0+20100331
resolu.h
Go to the documentation of this file.
00001 /* RCSid $Id: resolu.h,v 2.11 2009/05/21 18:08:43 greg Exp $ */
00002 /*
00003  * Definitions for resolution line in image file.
00004  *
00005  * Include after <stdio.h>
00006  *
00007  * True image orientation is defined by an xy coordinate system
00008  * whose origin is at the lower left corner of the image, with
00009  * x increasing to the right and y increasing in the upward direction.
00010  * This true orientation is independent of how the pixels are actually
00011  * ordered in the file, which is indicated by the resolution line.
00012  * This line is of the form "{+-}{XY} xyres {+-}{YX} yxres\n".
00013  * A typical line for a 1024x600 image might be "-Y 600 +X 1024\n",
00014  * indicating that the scanlines are in English text order (PIXSTANDARD).
00015  */
00016 #ifndef _RAD_RESOLU_H_
00017 #define _RAD_RESOLU_H_
00018 
00019 #include <time.h>
00020 
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026                      /* flags for scanline ordering */
00027 #define  XDECR                     1
00028 #define  YDECR                     2
00029 #define  YMAJOR                    4
00030 
00031                      /* standard scanline ordering */
00032 #define  PIXSTANDARD        (YMAJOR|YDECR)
00033 #define  PIXSTDFMT          "-Y %d +X %d\n"
00034 
00035                      /* structure for image dimensions */
00036 typedef struct {
00037        int    rt;           /* orientation (from flags above) */
00038        int    xr, yr;              /* x and y resolution */
00039 } RESOLU;
00040 
00041                      /* macros to get scanline length and number */
00042 #define  scanlen(rs)        ((rs)->rt & YMAJOR ? (rs)->xr : (rs)->yr)
00043 #define  numscans(rs)              ((rs)->rt & YMAJOR ? (rs)->yr : (rs)->xr)
00044 
00045                      /* resolution string buffer and its size */
00046 #define  RESOLU_BUFLEN             32
00047 extern char  resolu_buf[RESOLU_BUFLEN];
00048 
00049                      /* macros for reading/writing resolution struct */
00050 #define  fputsresolu(rs,fp) fputs(resolu2str(resolu_buf,rs),fp)
00051 #define  fgetsresolu(rs,fp) str2resolu(rs, \
00052                                    fgets(resolu_buf,RESOLU_BUFLEN,fp))
00053 
00054                      /* reading/writing of standard ordering */
00055 #define  fprtresolu(sl,ns,fp)      fprintf(fp,PIXSTDFMT,ns,sl)
00056 #define  fscnresolu(sl,ns,fp)      (fscanf(fp,PIXSTDFMT,ns,sl)==2)
00057 
00058                      /* identify header lines */
00059 #define  isheadid(s) headidval(NULL,s)
00060 #define  isformat(s) formatval(NULL,s)
00061 #define  isdate(s)   dateval(NULL,s)
00062 #define  isgmt(s)    gmtval(NULL,s)
00063 
00064 #define  LATLONSTR   "LATLONG="
00065 #define  LLATLONSTR  8
00066 #define  islatlon(hl)              (!strncmp(hl,LATLONSTR,LLATLONSTR))
00067 #define  latlonval(ll,hl)   sscanf((hl)+LLATLONSTR, "%f %f", \
00068                                           &(ll)[0],&(ll)[1])
00069 #define  fputlatlon(lat,lon,fp)    fprintf(fp,"%s %.6f %.6f\n",LATLONSTR,lat,lon)
00070 
00071                                    /* defined in resolu.c */
00072 extern void   fputresolu(int ord, int sl, int ns, FILE *fp);
00073 extern int    fgetresolu(int *sl, int *ns, FILE *fp);
00074 extern char * resolu2str(char *buf, RESOLU *rp);
00075 extern int    str2resolu(RESOLU *rp, char *buf);
00076                                    /* defined in header.c */
00077 extern void   newheader(char *t, FILE *fp);
00078 extern int    headidval(char *r, char *s);
00079 extern int    dateval(time_t *t, char *s);
00080 extern int    gmtval(time_t *t, char *s);
00081 extern void   fputdate(time_t t, FILE *fp);
00082 extern void   fputnow(FILE *fp);
00083 extern void   printargs(int ac, char **av, FILE *fp);
00084 extern int    formatval(char *r, char *s);
00085 extern void   fputformat(char *s, FILE *fp);
00086 typedef int gethfunc(char *s, void *p); /* callback to process header lines */
00087 extern int    getheader(FILE *fp, gethfunc *f, void *p);
00088 extern int    globmatch(char *pat, char *str);
00089 extern int    checkheader(FILE *fin, char *fmt, FILE *fout);
00090 
00091 #ifdef __cplusplus
00092 }
00093 #endif
00094 #endif /* _RAD_RESOLU_H_ */
00095